@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +141 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
|
@@ -1,78 +1,84 @@
|
|
|
1
1
|
import { LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
|
-
|
|
3
2
|
// IM-style upward pagination: near the top of the thread, fetch the previous
|
|
4
3
|
// history page and prepend it without moving the reader's viewport.
|
|
5
4
|
export function initHistoryLoader(app) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
5
|
+
const $ = app.$;
|
|
6
|
+
let loading = false;
|
|
7
|
+
const spinner = document.createElement("li");
|
|
8
|
+
spinner.className = "history-loading";
|
|
9
|
+
spinner.setAttribute("role", "status");
|
|
10
|
+
const wheel = document.createElement("span");
|
|
11
|
+
wheel.className = "history-spinner";
|
|
12
|
+
wheel.setAttribute("aria-hidden", "true");
|
|
13
|
+
const label = document.createElement("span");
|
|
14
|
+
label.dataset.i18n = "loadingHistory";
|
|
15
|
+
label.textContent = app.t("loadingHistory");
|
|
16
|
+
spinner.append(wheel, label);
|
|
17
|
+
const prependOlder = (older, thread, list) => {
|
|
18
|
+
// The loading spinner can be the first child; only a day separator at the
|
|
19
|
+
// boundary is a duplicate to drop.
|
|
20
|
+
const tailSep = list.firstElementChild?.classList.contains("day-sep") ? list.firstElementChild : null;
|
|
21
|
+
const fragment = document.createDocumentFragment();
|
|
22
|
+
let day = null;
|
|
23
|
+
for (const message of older) {
|
|
24
|
+
const messageDay = new Date(message.createdAt).toDateString();
|
|
25
|
+
if (messageDay !== day) {
|
|
26
|
+
const separator = document.createElement("li");
|
|
27
|
+
separator.className = "day-sep";
|
|
28
|
+
separator.dataset.day = messageDay;
|
|
29
|
+
separator.textContent = app.dayText(message.createdAt);
|
|
30
|
+
fragment.append(separator);
|
|
31
|
+
day = messageDay;
|
|
32
|
+
}
|
|
33
|
+
const row = app.renderMessage(message, false);
|
|
34
|
+
row.dataset.day = messageDay;
|
|
35
|
+
fragment.append(row);
|
|
36
|
+
}
|
|
37
|
+
const beforeHeight = thread.scrollHeight, beforeTop = thread.scrollTop;
|
|
38
|
+
list.prepend(fragment);
|
|
39
|
+
if (tailSep?.classList.contains("day-sep") && new Date(older.at(-1).createdAt).toDateString() === tailSep.dataset.day)
|
|
40
|
+
tailSep.remove();
|
|
41
|
+
app.cancelThreadScrollAnimation?.();
|
|
42
|
+
thread.scrollTop = beforeTop + (thread.scrollHeight - beforeHeight);
|
|
43
|
+
app.queueReceiptRefresh?.();
|
|
44
|
+
};
|
|
45
|
+
app.loadOlderHistory = async () => {
|
|
46
|
+
const room = app.state.room, entry = room && app.state.rooms.get(room.id);
|
|
47
|
+
const thread = $("#thread"), list = $("#msgList");
|
|
48
|
+
if (!room || !entry || loading)
|
|
49
|
+
return;
|
|
50
|
+
loading = true;
|
|
51
|
+
const generation = app.state.pollGeneration;
|
|
52
|
+
try {
|
|
53
|
+
const firstRow = list.querySelector("[data-msg-id]");
|
|
54
|
+
const cachedIndex = firstRow ? entry.room.messages.findIndex((message) => message.id === firstRow.dataset.msgId) : -1;
|
|
55
|
+
if (cachedIndex > 0) {
|
|
56
|
+
prependOlder(entry.room.messages.slice(Math.max(0, cachedIndex - 100), cachedIndex), thread, list);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (entry.historyComplete || entry.historyBeforeSeq == null)
|
|
60
|
+
return;
|
|
61
|
+
list.prepend(spinner);
|
|
62
|
+
const page = await app.api(`/rooms/${encodeURIComponent(room.id)}/history?beforeSeq=${entry.historyBeforeSeq}&limit=100`);
|
|
63
|
+
if (app.state.room?.id !== room.id || app.state.pollGeneration !== generation)
|
|
64
|
+
return;
|
|
65
|
+
const known = new Set(entry.room.messages.map((message) => message.id));
|
|
66
|
+
const older = (page.messages || []).filter((message) => !known.has(message.id));
|
|
67
|
+
entry.historyComplete = !page.hasMore;
|
|
68
|
+
spinner.remove();
|
|
69
|
+
if (older.length) {
|
|
70
|
+
prependOlder(older, thread, list);
|
|
71
|
+
entry.room.messages = [...older, ...entry.room.messages].sort((left, right) => left.createdAt - right.createdAt);
|
|
72
|
+
if (entry.room.messages.length > LOADED_MESSAGE_LIMIT)
|
|
73
|
+
entry.room.messages.splice(0, entry.room.messages.length - LOADED_MESSAGE_LIMIT);
|
|
74
|
+
app.cacheRoomSoon?.(room.id);
|
|
75
|
+
}
|
|
76
|
+
entry.historyBeforeSeq = page.hasMore ? (page.nextBeforeSeq ?? entry.room.messages[0]?.seq ?? null) : null;
|
|
77
|
+
}
|
|
78
|
+
catch { /* the next scroll toward the top retries */ }
|
|
79
|
+
finally {
|
|
80
|
+
loading = false;
|
|
81
|
+
spinner.remove();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
78
84
|
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
const SPRITE = "/assets/fluent-icons.svg";
|
|
2
|
-
|
|
3
2
|
// Fluent icons are one local sprite; the class carries size and currentColor fill.
|
|
4
3
|
export function iconNode(name, className = "") {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
5
|
+
svg.setAttribute("class", `fluent-icon${className ? ` ${className}` : ""}`);
|
|
6
|
+
svg.setAttribute("aria-hidden", "true");
|
|
7
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
8
|
+
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
|
|
9
|
+
use.setAttribute("href", `${SPRITE}#fluent-${name}-24`);
|
|
10
|
+
svg.append(use);
|
|
11
|
+
return svg;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
export const icon = (name, className = "") => iconNode(name, className).outerHTML;
|
|
13
|
+
export const icon = (name, className = "") => iconNode(name, className).outerHTML;
|
|
@@ -1,174 +1,244 @@
|
|
|
1
1
|
// An image in a message opens full-screen in a native dialog. Nothing in the
|
|
2
2
|
// message list moves: the overlay is a top-layer dialog, not a row change.
|
|
3
3
|
export function initImageZoom(app) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function limits() {
|
|
18
|
-
const style = getComputedStyle(dialog);
|
|
19
|
-
const box = dialog.getBoundingClientRect();
|
|
20
|
-
const left = box.left + parseFloat(style.paddingLeft), right = box.right - parseFloat(style.paddingRight);
|
|
21
|
-
const top = box.top + parseFloat(style.paddingTop), bottom = box.bottom - parseFloat(style.paddingBottom);
|
|
22
|
-
// Flex centering keeps an oversized image centered, so its untransformed
|
|
23
|
-
// layout box may start outside the dialog; offsetLeft still gives that
|
|
24
|
-
// position, while the live rect reflects the current scale and pan.
|
|
25
|
-
const layoutLeft = box.left + parseFloat(style.borderLeftWidth) + preview.offsetLeft;
|
|
26
|
-
const layoutTop = box.top + parseFloat(style.borderTopWidth) + preview.offsetTop;
|
|
27
|
-
const scaledWidth = preview.offsetWidth * scale, scaledHeight = preview.offsetHeight * scale;
|
|
28
|
-
const baseLeft = layoutLeft + preview.offsetWidth / 2 - scaledWidth / 2;
|
|
29
|
-
const baseTop = layoutTop + preview.offsetHeight / 2 - scaledHeight / 2;
|
|
30
|
-
const fitsX = scaledWidth <= right - left, fitsY = scaledHeight <= bottom - top;
|
|
31
|
-
const minX = fitsX ? 0 : right - baseLeft - scaledWidth;
|
|
32
|
-
const maxX = fitsX ? 0 : left - baseLeft;
|
|
33
|
-
const minY = fitsY ? 0 : bottom - baseTop - scaledHeight;
|
|
34
|
-
const maxY = fitsY ? 0 : top - baseTop;
|
|
35
|
-
return { minX, maxX, minY, maxY, x: maxX - minX, y: maxY - minY };
|
|
36
|
-
}
|
|
37
|
-
function apply() {
|
|
38
|
-
const limit = limits();
|
|
39
|
-
panX = clamp(panX, limit.minX, limit.maxX); panY = clamp(panY, limit.minY, limit.maxY);
|
|
40
|
-
preview.style.transform = `translate3d(${panX}px, ${panY}px, 0) scale(${scale})`;
|
|
41
|
-
preview.classList.toggle("is-zoomed", limit.x > 0 || limit.y > 0);
|
|
42
|
-
if (zoomLevel) zoomLevel.textContent = `${Math.round(scale * 100)}%`;
|
|
43
|
-
if (zoomOut) zoomOut.disabled = scale <= fitScale + .001;
|
|
44
|
-
if (zoomIn) zoomIn.disabled = scale >= MAX - .001;
|
|
45
|
-
}
|
|
46
|
-
function zoomTo(next, x = innerWidth / 2, y = innerHeight / 2) {
|
|
47
|
-
const target = clamp(next, fitScale, MAX);
|
|
48
|
-
if (Math.abs(target - scale) < .001) return apply();
|
|
49
|
-
// Keep the point under the pointer fixed while scaling.
|
|
50
|
-
const dx = x - innerWidth / 2, dy = y - innerHeight / 2, ratio = target / scale;
|
|
51
|
-
panX = dx - ratio * (dx - panX); panY = dy - ratio * (dy - panY);
|
|
52
|
-
scale = target;
|
|
53
|
-
if (scale <= fitScale + .001) { scale = fitScale; panX = 0; panY = 0; }
|
|
54
|
-
preview.style.animation = "none";
|
|
55
|
-
apply();
|
|
56
|
-
}
|
|
57
|
-
const zoomBy = (factor) => zoomTo(scale * factor);
|
|
58
|
-
function resetZoom() {
|
|
59
|
-
fitScale = fitLimit(); scale = fitScale; pendingFit = false; panX = 0; panY = 0; apply();
|
|
60
|
-
}
|
|
61
|
-
function open(image) {
|
|
62
|
-
if (!image || !dialog) return;
|
|
63
|
-
trigger = image;
|
|
64
|
-
dialog.showModal();
|
|
65
|
-
// Reuse the URL the list already loaded, so the overlay costs no second download.
|
|
66
|
-
preview.src = image.currentSrc || image.src;
|
|
67
|
-
preview.alt = image.alt || "";
|
|
68
|
-
preview.style.animation = "";
|
|
69
|
-
scale = 1; panX = 0; panY = 0; fitScale = fitLimit();
|
|
70
|
-
pendingFit = !(preview.complete && preview.naturalWidth);
|
|
71
|
-
if (pendingFit) apply(); else resetZoom();
|
|
72
|
-
}
|
|
73
|
-
const close = () => { if (dialog.open) dialog.close(); };
|
|
74
|
-
// A click that focuses the image makes the browser scroll it into view; the
|
|
75
|
-
// overlay must leave the thread exactly where the reader left it.
|
|
76
|
-
for (const selector of ["#msgList", "#attachmentList"]) app.$(selector)?.addEventListener("mousedown", (event) => {
|
|
77
|
-
if (imageOf(event.target)) event.preventDefault();
|
|
78
|
-
});
|
|
79
|
-
for (const selector of ["#msgList", "#attachmentList"]) app.$(selector)?.addEventListener("click", (event) => {
|
|
80
|
-
const image = imageOf(event.target);
|
|
81
|
-
if (!image) return;
|
|
82
|
-
// An image wrapped in a link is zoomed, not followed.
|
|
83
|
-
event.preventDefault();
|
|
84
|
-
open(image);
|
|
85
|
-
});
|
|
86
|
-
document.addEventListener("keydown", (event) => {
|
|
87
|
-
if (event.key !== "Enter" && event.key !== " ") return;
|
|
88
|
-
const image = imageOf(event.target);
|
|
89
|
-
if (!image) return;
|
|
90
|
-
event.preventDefault();
|
|
91
|
-
open(image);
|
|
92
|
-
});
|
|
93
|
-
app.$("#btnCloseImage")?.addEventListener("click", close);
|
|
94
|
-
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
95
|
-
// The viewer owns the wheel while it is open so the thread behind it cannot scroll.
|
|
96
|
-
dialog.addEventListener("wheel", (event) => {
|
|
97
|
-
if (!dialog.open) return;
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
if (event.target.closest?.(".image-dialog-tools, .image-dialog-close")) return;
|
|
100
|
-
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY;
|
|
101
|
-
zoomTo(scale * Math.exp(-delta * .0015), event.clientX, event.clientY);
|
|
102
|
-
}, { passive: false });
|
|
103
|
-
dialog.addEventListener("keydown", (event) => {
|
|
104
|
-
if (!dialog.open) return;
|
|
105
|
-
if (event.key === "+" || event.key === "=") { event.preventDefault(); zoomBy(STEP); }
|
|
106
|
-
else if (event.key === "-" || event.key === "_") { event.preventDefault(); zoomBy(1 / STEP); }
|
|
107
|
-
else if (event.key === "0") { event.preventDefault(); resetZoom(); }
|
|
108
|
-
else if ((limits().x > 0 || limits().y > 0) && event.key.startsWith("Arrow")) {
|
|
109
|
-
event.preventDefault();
|
|
110
|
-
const step = event.shiftKey ? 120 : 40;
|
|
111
|
-
if (event.key === "ArrowLeft") panX += step;
|
|
112
|
-
else if (event.key === "ArrowRight") panX -= step;
|
|
113
|
-
else if (event.key === "ArrowUp") panY += step;
|
|
114
|
-
else panY -= step;
|
|
115
|
-
apply();
|
|
4
|
+
const dialog = app.$("#imageDialog"), preview = app.$("#imageDialogImage");
|
|
5
|
+
const zoomLevel = app.$("#zoomLevel"), zoomOut = app.$("#btnZoomOut"), zoomIn = app.$("#btnZoomIn"), zoomReset = app.$("#btnZoomReset");
|
|
6
|
+
const MAX = 4, STEP = 1.25;
|
|
7
|
+
let trigger = null, scale = 1, fitScale = 1, pendingFit = false, panX = 0, panY = 0, drag = null;
|
|
8
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
9
|
+
const imageOf = (node) => node?.closest?.("#msgList img, #attachmentList img");
|
|
10
|
+
function fitLimit() {
|
|
11
|
+
const style = getComputedStyle(dialog);
|
|
12
|
+
const width = dialog.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
|
|
13
|
+
const height = dialog.clientHeight - parseFloat(style.paddingTop) - parseFloat(style.paddingBottom);
|
|
14
|
+
if (!preview.naturalWidth || !preview.naturalHeight)
|
|
15
|
+
return 1;
|
|
16
|
+
return Math.min(1, width / preview.naturalWidth, height / preview.naturalHeight);
|
|
116
17
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
preview.setPointerCapture(event.pointerId);
|
|
137
|
-
preview.classList.add("is-dragging");
|
|
138
|
-
event.preventDefault();
|
|
139
|
-
});
|
|
140
|
-
preview.addEventListener("pointermove", (event) => {
|
|
141
|
-
if (!drag || event.pointerId !== drag.id) return;
|
|
142
|
-
panX = drag.panX + event.clientX - drag.x; panY = drag.panY + event.clientY - drag.y;
|
|
143
|
-
apply();
|
|
144
|
-
});
|
|
145
|
-
const endDrag = (event) => {
|
|
146
|
-
if (!drag || event.pointerId !== drag.id) return;
|
|
147
|
-
drag = null; preview.classList.remove("is-dragging");
|
|
148
|
-
if (preview.hasPointerCapture(event.pointerId)) preview.releasePointerCapture(event.pointerId);
|
|
149
|
-
};
|
|
150
|
-
preview.addEventListener("pointerup", endDrag);
|
|
151
|
-
preview.addEventListener("pointercancel", endDrag);
|
|
152
|
-
dialog.addEventListener("close", () => {
|
|
153
|
-
preview.removeAttribute("src");
|
|
154
|
-
preview.style.animation = "";
|
|
155
|
-
resetZoom();
|
|
156
|
-
if (trigger?.isConnected) trigger.focus({ preventScroll: true });
|
|
157
|
-
trigger = null;
|
|
158
|
-
});
|
|
159
|
-
// Images are in the tab order so the overlay can hand focus back to them.
|
|
160
|
-
const enhance = () => {
|
|
161
|
-
for (const image of document.querySelectorAll("#msgList img, #attachmentList img")) {
|
|
162
|
-
if (image.hasAttribute("tabindex")) continue;
|
|
163
|
-
image.tabIndex = 0;
|
|
164
|
-
image.setAttribute("role", "button");
|
|
165
|
-
image.dataset.i18nAriaLabel = "zoomImage";
|
|
166
|
-
image.setAttribute("aria-label", app.t("zoomImage"));
|
|
18
|
+
function limits() {
|
|
19
|
+
const style = getComputedStyle(dialog);
|
|
20
|
+
const box = dialog.getBoundingClientRect();
|
|
21
|
+
const left = box.left + parseFloat(style.paddingLeft), right = box.right - parseFloat(style.paddingRight);
|
|
22
|
+
const top = box.top + parseFloat(style.paddingTop), bottom = box.bottom - parseFloat(style.paddingBottom);
|
|
23
|
+
// Flex centering keeps an oversized image centered, so its untransformed
|
|
24
|
+
// layout box may start outside the dialog; offsetLeft still gives that
|
|
25
|
+
// position, while the live rect reflects the current scale and pan.
|
|
26
|
+
const layoutLeft = box.left + parseFloat(style.borderLeftWidth) + preview.offsetLeft;
|
|
27
|
+
const layoutTop = box.top + parseFloat(style.borderTopWidth) + preview.offsetTop;
|
|
28
|
+
const scaledWidth = preview.offsetWidth * scale, scaledHeight = preview.offsetHeight * scale;
|
|
29
|
+
const baseLeft = layoutLeft + preview.offsetWidth / 2 - scaledWidth / 2;
|
|
30
|
+
const baseTop = layoutTop + preview.offsetHeight / 2 - scaledHeight / 2;
|
|
31
|
+
const fitsX = scaledWidth <= right - left, fitsY = scaledHeight <= bottom - top;
|
|
32
|
+
const minX = fitsX ? 0 : right - baseLeft - scaledWidth;
|
|
33
|
+
const maxX = fitsX ? 0 : left - baseLeft;
|
|
34
|
+
const minY = fitsY ? 0 : bottom - baseTop - scaledHeight;
|
|
35
|
+
const maxY = fitsY ? 0 : top - baseTop;
|
|
36
|
+
return { minX, maxX, minY, maxY, x: maxX - minX, y: maxY - minY };
|
|
167
37
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
38
|
+
function apply() {
|
|
39
|
+
const limit = limits();
|
|
40
|
+
panX = clamp(panX, limit.minX, limit.maxX);
|
|
41
|
+
panY = clamp(panY, limit.minY, limit.maxY);
|
|
42
|
+
preview.style.transform = `translate3d(${panX}px, ${panY}px, 0) scale(${scale})`;
|
|
43
|
+
preview.classList.toggle("is-zoomed", limit.x > 0 || limit.y > 0);
|
|
44
|
+
if (zoomLevel)
|
|
45
|
+
zoomLevel.textContent = `${Math.round(scale * 100)}%`;
|
|
46
|
+
if (zoomOut)
|
|
47
|
+
zoomOut.disabled = scale <= fitScale + .001;
|
|
48
|
+
if (zoomIn)
|
|
49
|
+
zoomIn.disabled = scale >= MAX - .001;
|
|
50
|
+
}
|
|
51
|
+
function zoomTo(next, x = innerWidth / 2, y = innerHeight / 2) {
|
|
52
|
+
const target = clamp(next, fitScale, MAX);
|
|
53
|
+
if (Math.abs(target - scale) < .001)
|
|
54
|
+
return apply();
|
|
55
|
+
// Keep the point under the pointer fixed while scaling.
|
|
56
|
+
const dx = x - innerWidth / 2, dy = y - innerHeight / 2, ratio = target / scale;
|
|
57
|
+
panX = dx - ratio * (dx - panX);
|
|
58
|
+
panY = dy - ratio * (dy - panY);
|
|
59
|
+
scale = target;
|
|
60
|
+
if (scale <= fitScale + .001) {
|
|
61
|
+
scale = fitScale;
|
|
62
|
+
panX = 0;
|
|
63
|
+
panY = 0;
|
|
64
|
+
}
|
|
65
|
+
preview.style.animation = "none";
|
|
66
|
+
apply();
|
|
67
|
+
}
|
|
68
|
+
const zoomBy = (factor) => zoomTo(scale * factor);
|
|
69
|
+
function resetZoom() {
|
|
70
|
+
fitScale = fitLimit();
|
|
71
|
+
scale = fitScale;
|
|
72
|
+
pendingFit = false;
|
|
73
|
+
panX = 0;
|
|
74
|
+
panY = 0;
|
|
75
|
+
apply();
|
|
76
|
+
}
|
|
77
|
+
function open(image) {
|
|
78
|
+
if (!image || !dialog)
|
|
79
|
+
return;
|
|
80
|
+
trigger = image;
|
|
81
|
+
dialog.showModal();
|
|
82
|
+
// Reuse the URL the list already loaded, so the overlay costs no second download.
|
|
83
|
+
preview.src = image.currentSrc || image.src;
|
|
84
|
+
preview.alt = image.alt || "";
|
|
85
|
+
preview.style.animation = "";
|
|
86
|
+
scale = 1;
|
|
87
|
+
panX = 0;
|
|
88
|
+
panY = 0;
|
|
89
|
+
fitScale = fitLimit();
|
|
90
|
+
pendingFit = !(preview.complete && preview.naturalWidth);
|
|
91
|
+
if (pendingFit)
|
|
92
|
+
apply();
|
|
93
|
+
else
|
|
94
|
+
resetZoom();
|
|
95
|
+
}
|
|
96
|
+
const close = () => { if (dialog.open)
|
|
97
|
+
dialog.close(); };
|
|
98
|
+
// A click that focuses the image makes the browser scroll it into view; the
|
|
99
|
+
// overlay must leave the thread exactly where the reader left it.
|
|
100
|
+
for (const selector of ["#msgList", "#attachmentList"])
|
|
101
|
+
app.$(selector)?.addEventListener("mousedown", (event) => {
|
|
102
|
+
if (imageOf(event.target))
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
});
|
|
105
|
+
for (const selector of ["#msgList", "#attachmentList"])
|
|
106
|
+
app.$(selector)?.addEventListener("click", (event) => {
|
|
107
|
+
const image = imageOf(event.target);
|
|
108
|
+
if (!image)
|
|
109
|
+
return;
|
|
110
|
+
// An image wrapped in a link is zoomed, not followed.
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
open(image);
|
|
113
|
+
});
|
|
114
|
+
document.addEventListener("keydown", (event) => {
|
|
115
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
116
|
+
return;
|
|
117
|
+
const image = imageOf(event.target);
|
|
118
|
+
if (!image)
|
|
119
|
+
return;
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
open(image);
|
|
122
|
+
});
|
|
123
|
+
app.$("#btnCloseImage")?.addEventListener("click", close);
|
|
124
|
+
// A backdrop click closes, but a drag that started inside the viewer and was
|
|
125
|
+
// released on the backdrop does not: the click target would be the dialog then.
|
|
126
|
+
let dismissPress = false;
|
|
127
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
128
|
+
dialog.addEventListener("click", (event) => {
|
|
129
|
+
if (event.target === dialog && dismissPress)
|
|
130
|
+
close();
|
|
131
|
+
dismissPress = false;
|
|
132
|
+
});
|
|
133
|
+
// The viewer owns the wheel while it is open so the thread behind it cannot scroll.
|
|
134
|
+
dialog.addEventListener("wheel", (event) => {
|
|
135
|
+
if (!dialog.open)
|
|
136
|
+
return;
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
if (event.target.closest?.(".image-dialog-tools, .image-dialog-close"))
|
|
139
|
+
return;
|
|
140
|
+
const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY;
|
|
141
|
+
zoomTo(scale * Math.exp(-delta * .0015), event.clientX, event.clientY);
|
|
142
|
+
}, { passive: false });
|
|
143
|
+
dialog.addEventListener("keydown", (event) => {
|
|
144
|
+
if (!dialog.open)
|
|
145
|
+
return;
|
|
146
|
+
if (event.key === "+" || event.key === "=") {
|
|
147
|
+
event.preventDefault();
|
|
148
|
+
zoomBy(STEP);
|
|
149
|
+
}
|
|
150
|
+
else if (event.key === "-" || event.key === "_") {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
zoomBy(1 / STEP);
|
|
153
|
+
}
|
|
154
|
+
else if (event.key === "0") {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
resetZoom();
|
|
157
|
+
}
|
|
158
|
+
else if ((limits().x > 0 || limits().y > 0) && event.key.startsWith("Arrow")) {
|
|
159
|
+
event.preventDefault();
|
|
160
|
+
const step = event.shiftKey ? 120 : 40;
|
|
161
|
+
if (event.key === "ArrowLeft")
|
|
162
|
+
panX += step;
|
|
163
|
+
else if (event.key === "ArrowRight")
|
|
164
|
+
panX -= step;
|
|
165
|
+
else if (event.key === "ArrowUp")
|
|
166
|
+
panY += step;
|
|
167
|
+
else
|
|
168
|
+
panY -= step;
|
|
169
|
+
apply();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
zoomIn?.addEventListener("click", () => zoomBy(STEP));
|
|
173
|
+
zoomOut?.addEventListener("click", () => zoomBy(1 / STEP));
|
|
174
|
+
zoomReset?.addEventListener("click", resetZoom);
|
|
175
|
+
window.addEventListener("resize", () => {
|
|
176
|
+
if (!dialog.open)
|
|
177
|
+
return;
|
|
178
|
+
const wasFit = Math.abs(scale - fitScale) < .001;
|
|
179
|
+
fitScale = fitLimit();
|
|
180
|
+
if (wasFit) {
|
|
181
|
+
scale = fitScale;
|
|
182
|
+
panX = 0;
|
|
183
|
+
panY = 0;
|
|
184
|
+
}
|
|
185
|
+
else
|
|
186
|
+
scale = Math.max(scale, fitScale);
|
|
187
|
+
apply();
|
|
188
|
+
});
|
|
189
|
+
preview.addEventListener("load", () => { if (dialog.open && pendingFit)
|
|
190
|
+
resetZoom(); });
|
|
191
|
+
// Pointer dragging pans the zoomed image; the tool buttons are the touch and
|
|
192
|
+
// keyboard alternative for changing the scale, and arrow keys pan to the edges.
|
|
193
|
+
preview.draggable = false;
|
|
194
|
+
preview.addEventListener("pointerdown", (event) => {
|
|
195
|
+
if ((limits().x <= 0 && limits().y <= 0) || event.button !== 0)
|
|
196
|
+
return;
|
|
197
|
+
drag = { id: event.pointerId, x: event.clientX, y: event.clientY, panX, panY };
|
|
198
|
+
preview.setPointerCapture(event.pointerId);
|
|
199
|
+
preview.classList.add("is-dragging");
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
});
|
|
202
|
+
preview.addEventListener("pointermove", (event) => {
|
|
203
|
+
if (!drag || event.pointerId !== drag.id)
|
|
204
|
+
return;
|
|
205
|
+
panX = drag.panX + event.clientX - drag.x;
|
|
206
|
+
panY = drag.panY + event.clientY - drag.y;
|
|
207
|
+
apply();
|
|
208
|
+
});
|
|
209
|
+
const endDrag = (event) => {
|
|
210
|
+
if (!drag || event.pointerId !== drag.id)
|
|
211
|
+
return;
|
|
212
|
+
drag = null;
|
|
213
|
+
preview.classList.remove("is-dragging");
|
|
214
|
+
if (preview.hasPointerCapture(event.pointerId))
|
|
215
|
+
preview.releasePointerCapture(event.pointerId);
|
|
216
|
+
};
|
|
217
|
+
preview.addEventListener("pointerup", endDrag);
|
|
218
|
+
preview.addEventListener("pointercancel", endDrag);
|
|
219
|
+
dialog.addEventListener("close", () => {
|
|
220
|
+
preview.removeAttribute("src");
|
|
221
|
+
preview.style.animation = "";
|
|
222
|
+
resetZoom();
|
|
223
|
+
if (trigger?.isConnected)
|
|
224
|
+
trigger.focus({ preventScroll: true });
|
|
225
|
+
trigger = null;
|
|
226
|
+
});
|
|
227
|
+
// Images are in the tab order so the overlay can hand focus back to them.
|
|
228
|
+
const enhance = () => {
|
|
229
|
+
for (const image of document.querySelectorAll("#msgList img, #attachmentList img")) {
|
|
230
|
+
if (image.hasAttribute("tabindex"))
|
|
231
|
+
continue;
|
|
232
|
+
image.tabIndex = 0;
|
|
233
|
+
image.setAttribute("role", "button");
|
|
234
|
+
image.dataset.i18nAriaLabel = "zoomImage";
|
|
235
|
+
image.setAttribute("aria-label", app.t("zoomImage"));
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
for (const selector of ["#msgList", "#attachmentList"]) {
|
|
239
|
+
const list = app.$(selector);
|
|
240
|
+
if (list)
|
|
241
|
+
new MutationObserver(enhance).observe(list, { childList: true, subtree: true });
|
|
242
|
+
}
|
|
243
|
+
enhance();
|
|
244
|
+
}
|
|
@@ -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,11 +29,14 @@ 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
33
|
import { initIntegrations } from "./integrations.js";
|
|
34
|
-
|
|
35
|
-
if (isMobileDevice())
|
|
36
|
-
|
|
34
|
+
import { initWindowControls } from "./window-controls.js";
|
|
35
|
+
if (isMobileDevice())
|
|
36
|
+
document.documentElement.dataset.mobile = "true";
|
|
37
|
+
initWindowControls();
|
|
37
38
|
initSettings(app);
|
|
39
|
+
initChatBackground(app);
|
|
38
40
|
initIntegrations(app);
|
|
39
41
|
initConfirmDialog(app);
|
|
40
42
|
initDiagramViewer(app);
|
|
@@ -50,7 +52,6 @@ initHistoryLoader(app);
|
|
|
50
52
|
initSearch(app);
|
|
51
53
|
initQuestions(app);
|
|
52
54
|
initReplies(app);
|
|
53
|
-
initForward(app);
|
|
54
55
|
initRecall(app);
|
|
55
56
|
initEvents(app);
|
|
56
57
|
initShortcuts(app);
|