@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,137 +1,159 @@
|
|
|
1
1
|
import { LOADED_MESSAGE_LIMIT } from "./state.js";
|
|
2
2
|
import { flashMessageRow } from "./message-window.js";
|
|
3
|
-
|
|
4
3
|
// Palette search: local scan first, then lazy history pages until the room's
|
|
5
4
|
// loaded window fills up. There is no server-side search endpoint.
|
|
6
5
|
export const SEARCH_RESULT_LIMIT = 100;
|
|
7
6
|
export const SEARCH_MESSAGE_LIMIT = LOADED_MESSAGE_LIMIT;
|
|
8
7
|
const PAGE_LIMIT = 100;
|
|
9
8
|
const MAX_PAGES_PER_ROOM = Math.ceil(SEARCH_MESSAGE_LIMIT / PAGE_LIMIT);
|
|
10
|
-
|
|
11
9
|
export function initSearch(app) {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
app.searchMessages = (query, scope = "room") => searchMessages(app, query, scope);
|
|
11
|
+
app.openSearchHit = (hit) => openSearchHit(app, hit);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
export async function searchMessages(app, query, scope = "room") {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
const needle = String(query ?? "").trim().toLocaleLowerCase();
|
|
15
|
+
if (!needle)
|
|
16
|
+
return [];
|
|
17
|
+
const activeId = app.state.room?.id;
|
|
18
|
+
const roomIds = [...app.state.rooms.keys()]
|
|
19
|
+
.filter((roomId) => scope === "all" || roomId === activeId)
|
|
20
|
+
.sort((left, right) => {
|
|
21
|
+
if (left === activeId)
|
|
22
|
+
return -1;
|
|
23
|
+
if (right === activeId)
|
|
24
|
+
return 1;
|
|
25
|
+
return latestAt(app, right) - latestAt(app, left);
|
|
26
26
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
const hits = [];
|
|
28
|
+
for (const roomId of roomIds) {
|
|
29
|
+
await collectRoomHits(app, roomId, needle, hits);
|
|
30
|
+
// Keep the page responsive while several rooms are scanned.
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
32
|
+
}
|
|
33
|
+
return hits
|
|
34
|
+
.sort((left, right) => right.createdAt - left.createdAt || (right.seq ?? 0) - (left.seq ?? 0))
|
|
35
|
+
.slice(0, SEARCH_RESULT_LIMIT);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
export async function openSearchHit(app, hit) {
|
|
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
|
-
|
|
38
|
+
const roomId = hit?.roomId, messageId = hit?.messageId;
|
|
39
|
+
if (!roomId || !messageId)
|
|
40
|
+
return false;
|
|
41
|
+
const entry = app.state.rooms.get(roomId);
|
|
42
|
+
if (!entry?.room)
|
|
43
|
+
return false;
|
|
44
|
+
if (!entry.room.messages.some((message) => message.id === messageId)) {
|
|
45
|
+
const seq = Number(hit.seq);
|
|
46
|
+
// beforeSeq is exclusive: seq + 1 puts the target at the end of the page.
|
|
47
|
+
if (!Number.isSafeInteger(seq))
|
|
48
|
+
return false;
|
|
49
|
+
try {
|
|
50
|
+
const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?beforeSeq=${seq + 1}&limit=${PAGE_LIMIT}`);
|
|
51
|
+
if (app.state.rooms.get(roomId) !== entry)
|
|
52
|
+
return false;
|
|
53
|
+
const messages = Array.isArray(page.messages) ? page.messages : [];
|
|
54
|
+
mergeHistory(entry, roomId, messages);
|
|
55
|
+
if (page.hasMore) {
|
|
56
|
+
// Continue upward pagination from the oldest message now loaded.
|
|
57
|
+
const oldest = entry.room.messages.find((message) => Number.isSafeInteger(message.seq))?.seq;
|
|
58
|
+
if (Number.isSafeInteger(oldest))
|
|
59
|
+
entry.historyBeforeSeq = oldest;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
entry.historyComplete = true;
|
|
63
|
+
entry.historyBeforeSeq = null;
|
|
64
|
+
}
|
|
65
|
+
app.cacheRoomSoon?.(roomId);
|
|
66
|
+
if (!entry.room.messages.some((message) => message.id === messageId))
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (app.state.room?.id !== roomId)
|
|
74
|
+
app.activateRoom(roomId);
|
|
75
|
+
if (app.state.room?.id !== roomId)
|
|
76
|
+
return false;
|
|
77
|
+
app.state.room = app.state.rooms.get(roomId)?.room || app.state.room;
|
|
78
|
+
app.state.focusMessageId = messageId;
|
|
79
|
+
app.state.followBottom = false;
|
|
80
|
+
app.state.readAnchorGuard = null;
|
|
81
|
+
app.renderMessages(false);
|
|
82
|
+
const row = document.querySelector(`[data-msg-id="${CSS.escape(messageId)}"]`);
|
|
83
|
+
if (!row)
|
|
84
|
+
return false;
|
|
85
|
+
flashMessageRow(app, row);
|
|
86
|
+
return true;
|
|
75
87
|
}
|
|
76
|
-
|
|
77
88
|
async function collectRoomHits(app, roomId, needle, hits) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
const entry = app.state.rooms.get(roomId);
|
|
90
|
+
if (!entry?.room)
|
|
91
|
+
return;
|
|
92
|
+
const seen = new Set();
|
|
93
|
+
const scan = (messages) => {
|
|
94
|
+
for (const message of messages) {
|
|
95
|
+
if (seen.has(message.id))
|
|
96
|
+
continue;
|
|
97
|
+
seen.add(message.id);
|
|
98
|
+
if (message.recalledAt || message.pending || message.senderId === "system")
|
|
99
|
+
continue;
|
|
100
|
+
const text = typeof message.text === "string" ? message.text : "";
|
|
101
|
+
if (!text || !text.toLocaleLowerCase().includes(needle))
|
|
102
|
+
continue;
|
|
103
|
+
hits.push({
|
|
104
|
+
roomId,
|
|
105
|
+
roomName: entry.room.name || roomId,
|
|
106
|
+
messageId: message.id,
|
|
107
|
+
seq: message.seq,
|
|
108
|
+
sender: message.senderId,
|
|
109
|
+
createdAt: message.createdAt,
|
|
110
|
+
text,
|
|
111
|
+
snippet: snippetFor(text, needle),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
scan(entry.room.messages);
|
|
116
|
+
let pages = 0;
|
|
117
|
+
while (!entry.historyComplete && Number.isSafeInteger(entry.historyBeforeSeq)
|
|
118
|
+
&& entry.room.messages.length < SEARCH_MESSAGE_LIMIT && pages++ < MAX_PAGES_PER_ROOM) {
|
|
119
|
+
try {
|
|
120
|
+
const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?beforeSeq=${entry.historyBeforeSeq}&limit=${PAGE_LIMIT}`);
|
|
121
|
+
if (app.state.rooms.get(roomId) !== entry)
|
|
122
|
+
return;
|
|
123
|
+
const messages = Array.isArray(page.messages) ? page.messages : [];
|
|
124
|
+
scan(messages);
|
|
125
|
+
mergeHistory(entry, roomId, messages);
|
|
126
|
+
const next = typeof page.nextBeforeSeq === "number" ? page.nextBeforeSeq : null;
|
|
127
|
+
entry.historyComplete = !page.hasMore;
|
|
128
|
+
if (entry.historyComplete)
|
|
129
|
+
entry.historyBeforeSeq = null;
|
|
130
|
+
else if (next === null || next >= entry.historyBeforeSeq)
|
|
131
|
+
break;
|
|
132
|
+
else
|
|
133
|
+
entry.historyBeforeSeq = next;
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
98
138
|
}
|
|
99
|
-
};
|
|
100
|
-
scan(entry.room.messages);
|
|
101
|
-
let pages = 0;
|
|
102
|
-
while (!entry.historyComplete && Number.isSafeInteger(entry.historyBeforeSeq)
|
|
103
|
-
&& entry.room.messages.length < SEARCH_MESSAGE_LIMIT && pages++ < MAX_PAGES_PER_ROOM) {
|
|
104
|
-
try {
|
|
105
|
-
const page = await app.api(`/rooms/${encodeURIComponent(roomId)}/history?beforeSeq=${entry.historyBeforeSeq}&limit=${PAGE_LIMIT}`);
|
|
106
|
-
if (app.state.rooms.get(roomId) !== entry) return;
|
|
107
|
-
const messages = Array.isArray(page.messages) ? page.messages : [];
|
|
108
|
-
scan(messages);
|
|
109
|
-
mergeHistory(entry, roomId, messages);
|
|
110
|
-
const next = typeof page.nextBeforeSeq === "number" ? page.nextBeforeSeq : null;
|
|
111
|
-
entry.historyComplete = !page.hasMore;
|
|
112
|
-
if (entry.historyComplete) entry.historyBeforeSeq = null;
|
|
113
|
-
else if (next === null || next >= entry.historyBeforeSeq) break;
|
|
114
|
-
else entry.historyBeforeSeq = next;
|
|
115
|
-
} catch { break; }
|
|
116
|
-
}
|
|
117
139
|
}
|
|
118
|
-
|
|
119
140
|
function mergeHistory(entry, roomId, messages) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.
|
|
141
|
+
const merged = new Map(entry.room.messages.map((message) => [message.id, message]));
|
|
142
|
+
for (const message of messages)
|
|
143
|
+
if (!merged.has(message.id))
|
|
144
|
+
merged.set(message.id, { ...message, roomId });
|
|
145
|
+
entry.room.messages = [...merged.values()]
|
|
146
|
+
.sort((left, right) => left.createdAt - right.createdAt || (left.seq ?? 0) - (right.seq ?? 0))
|
|
147
|
+
.slice(-LOADED_MESSAGE_LIMIT);
|
|
125
148
|
}
|
|
126
|
-
|
|
127
149
|
function latestAt(app, roomId) {
|
|
128
|
-
|
|
150
|
+
return app.state.rooms.get(roomId)?.room.messages.at(-1)?.createdAt ?? 0;
|
|
129
151
|
}
|
|
130
|
-
|
|
131
152
|
function snippetFor(text, needle) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
153
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
154
|
+
const index = flat.toLocaleLowerCase().indexOf(needle);
|
|
155
|
+
if (index < 0)
|
|
156
|
+
return flat.slice(0, 140);
|
|
157
|
+
const start = Math.max(0, index - 40), end = Math.min(flat.length, index + needle.length + 60);
|
|
158
|
+
return `${start > 0 ? "…" : ""}${flat.slice(start, end)}${end < flat.length ? "…" : ""}`;
|
|
159
|
+
}
|
|
@@ -1,145 +1,234 @@
|
|
|
1
1
|
// Browser settings shared by the join page and the chat: language, theme, window frame, and the optional token.
|
|
2
|
-
export const THEMES = ["system", "light", "dark", "forest", "sand"];
|
|
3
|
-
|
|
2
|
+
export const THEMES = ["system", "light", "dark", "forest", "sand", "custom"];
|
|
3
|
+
const DEFAULT_CUSTOM_THEME = "#22695c";
|
|
4
|
+
const validColor = (value) => /^#[0-9a-f]{6}$/i.test(value) ? value : DEFAULT_CUSTOM_THEME;
|
|
5
|
+
// Relative luminance, so a dark choice gets the dark palette instead of dark text on it.
|
|
6
|
+
const isDarkColor = (color) => {
|
|
7
|
+
const channels = color.slice(1).match(/../g).map((part) => {
|
|
8
|
+
const value = parseInt(part, 16) / 255;
|
|
9
|
+
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
10
|
+
});
|
|
11
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2] < 0.4;
|
|
12
|
+
};
|
|
4
13
|
export function initSettings(app) {
|
|
5
|
-
|
|
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
|
-
|
|
14
|
+
const $ = app.$;
|
|
15
|
+
const dialog = $("#chatSettings");
|
|
16
|
+
if (!dialog)
|
|
17
|
+
return;
|
|
18
|
+
const tokenInput = $("#inTokenChat"), tokenHint = $("#tokenHint");
|
|
19
|
+
const contentInput = $("#inContentTransition");
|
|
20
|
+
const pageInput = $("#inPageStep"), pageValue = $("#pageStepValue");
|
|
21
|
+
const frameSelect = $("#inWindowFrame");
|
|
22
|
+
const panelInputs = [...dialog.querySelectorAll("[data-panel-mode]")];
|
|
23
|
+
if (document.body.dataset.integrationsAdmin !== "true") {
|
|
24
|
+
$("#settingsTabIntegrations")?.remove();
|
|
25
|
+
$("#settingsPanelIntegrations")?.remove();
|
|
26
|
+
}
|
|
27
|
+
const tabs = [...dialog.querySelectorAll('[role="tab"]')];
|
|
28
|
+
const customColorInput = $("#inCustomThemeColor");
|
|
29
|
+
const scheme = matchMedia("(prefers-color-scheme: dark)");
|
|
30
|
+
let opener = null;
|
|
31
|
+
let customFrame = 0;
|
|
32
|
+
let customPersistTimer = 0;
|
|
33
|
+
let pendingCustomColor = "";
|
|
34
|
+
const CUSTOM_COLOR_PERSIST_DELAY = 300;
|
|
35
|
+
const customColor = () => validColor(app.LS.customTheme);
|
|
36
|
+
const paintCustomColor = (color) => {
|
|
37
|
+
document.documentElement.style.setProperty("--custom-bg", color);
|
|
38
|
+
document.documentElement.dataset.customDark = String(isDarkColor(color));
|
|
39
|
+
if (customColorInput)
|
|
40
|
+
customColorInput.value = color;
|
|
41
|
+
};
|
|
42
|
+
const syncCustomColor = () => {
|
|
43
|
+
const color = customColor();
|
|
44
|
+
paintCustomColor(color);
|
|
45
|
+
return color;
|
|
46
|
+
};
|
|
47
|
+
// Live drags coalesce to one paint per frame; storage and theme metadata wait.
|
|
48
|
+
const clearCustomSchedules = () => {
|
|
49
|
+
if (customFrame)
|
|
50
|
+
cancelAnimationFrame(customFrame);
|
|
51
|
+
customFrame = 0;
|
|
52
|
+
clearTimeout(customPersistTimer);
|
|
53
|
+
customPersistTimer = 0;
|
|
54
|
+
pendingCustomColor = "";
|
|
55
|
+
};
|
|
56
|
+
const scheduleCustomPaint = (color) => {
|
|
57
|
+
pendingCustomColor = color;
|
|
58
|
+
if (customFrame)
|
|
59
|
+
return;
|
|
60
|
+
customFrame = requestAnimationFrame(() => {
|
|
61
|
+
customFrame = 0;
|
|
62
|
+
paintCustomColor(pendingCustomColor);
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const commitCustomColor = (color) => {
|
|
66
|
+
clearCustomSchedules();
|
|
67
|
+
app.LS.customTheme = color;
|
|
68
|
+
if (document.documentElement.dataset.theme === "custom") {
|
|
69
|
+
paintCustomColor(color);
|
|
70
|
+
syncThemeColor();
|
|
71
|
+
}
|
|
72
|
+
else
|
|
73
|
+
applyTheme("custom", true);
|
|
74
|
+
};
|
|
75
|
+
const syncThemeColor = () => {
|
|
76
|
+
const meta = document.querySelector('meta[name="theme-color"]');
|
|
77
|
+
const token = document.documentElement.dataset.windowFrame === "borderless" ? "--surface" : "--bg";
|
|
78
|
+
const background = document.documentElement.dataset.theme === "custom" ? customColor() : getComputedStyle(document.documentElement).getPropertyValue(token).trim();
|
|
79
|
+
if (meta && background)
|
|
80
|
+
meta.content = background;
|
|
81
|
+
};
|
|
82
|
+
const syncThemeInputs = () => {
|
|
83
|
+
const stored = THEMES.includes(app.LS.theme) ? app.LS.theme : "system";
|
|
84
|
+
for (const input of dialog.querySelectorAll('input[name="theme"]'))
|
|
85
|
+
input.checked = input.value === stored;
|
|
86
|
+
if (customColorInput)
|
|
87
|
+
customColorInput.value = customColor();
|
|
88
|
+
};
|
|
89
|
+
const syncPanelInputs = () => {
|
|
90
|
+
for (const select of panelInputs)
|
|
91
|
+
select.value = app.panelMode(select.dataset.panelMode);
|
|
92
|
+
};
|
|
93
|
+
const applyTheme = (value, persist) => {
|
|
94
|
+
clearCustomSchedules();
|
|
95
|
+
const theme = THEMES.includes(value) ? value : "system";
|
|
96
|
+
syncCustomColor();
|
|
97
|
+
document.documentElement.dataset.theme = theme;
|
|
98
|
+
if (persist)
|
|
99
|
+
app.LS.theme = theme;
|
|
100
|
+
syncThemeInputs();
|
|
101
|
+
syncThemeColor();
|
|
102
|
+
};
|
|
103
|
+
app.setTheme = (value) => applyTheme(value, true);
|
|
104
|
+
app.settingsOpen = () => dialog.open;
|
|
105
|
+
const framePreference = () => app.LS.windowFrame === "borderless" ? "borderless" : "framed";
|
|
106
|
+
const applyWindowFrame = (mode, persist) => {
|
|
107
|
+
const preference = mode === "borderless" ? "borderless" : "framed";
|
|
108
|
+
document.documentElement.dataset.windowFrame = preference;
|
|
109
|
+
if (frameSelect)
|
|
110
|
+
frameSelect.value = preference;
|
|
111
|
+
if (persist)
|
|
112
|
+
app.LS.windowFrame = preference;
|
|
113
|
+
syncThemeColor();
|
|
114
|
+
};
|
|
115
|
+
app.setWindowFrame = (value) => applyWindowFrame(value, true);
|
|
116
|
+
// One tab stop for the whole tablist; arrow keys move selection like a native tab widget.
|
|
117
|
+
const activateTab = (name, { focus = false } = {}) => {
|
|
118
|
+
for (const tab of tabs) {
|
|
119
|
+
const selected = tab.dataset.settingsTab === name;
|
|
120
|
+
tab.setAttribute("aria-selected", String(selected));
|
|
121
|
+
tab.tabIndex = selected ? 0 : -1;
|
|
122
|
+
const panel = document.getElementById(tab.getAttribute("aria-controls"));
|
|
123
|
+
if (panel)
|
|
124
|
+
panel.hidden = !selected;
|
|
125
|
+
if (selected && focus)
|
|
126
|
+
tab.focus();
|
|
127
|
+
}
|
|
128
|
+
if (name === "integrations")
|
|
129
|
+
app.loadIntegrations?.();
|
|
130
|
+
};
|
|
131
|
+
const onTabKey = (event) => {
|
|
132
|
+
const index = tabs.indexOf(event.target);
|
|
133
|
+
if (index < 0)
|
|
134
|
+
return;
|
|
135
|
+
const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : event.key === "ArrowDown" || event.key === "ArrowRight" ? 1 : 0;
|
|
136
|
+
const target = event.key === "Home" ? 0 : event.key === "End" ? tabs.length - 1 : step ? (index + step + tabs.length) % tabs.length : -1;
|
|
137
|
+
if (target < 0)
|
|
138
|
+
return;
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
activateTab(tabs[target].dataset.settingsTab, { focus: true });
|
|
141
|
+
};
|
|
56
142
|
for (const tab of tabs) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
tab.tabIndex = selected ? 0 : -1;
|
|
60
|
-
const panel = document.getElementById(tab.getAttribute("aria-controls"));
|
|
61
|
-
if (panel) panel.hidden = !selected;
|
|
62
|
-
if (selected && focus) tab.focus();
|
|
143
|
+
tab.addEventListener("click", () => activateTab(tab.dataset.settingsTab));
|
|
144
|
+
tab.addEventListener("keydown", onTabKey);
|
|
63
145
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
146
|
+
const open = ({ token = false } = {}) => {
|
|
147
|
+
app.closePanels?.();
|
|
148
|
+
syncThemeInputs();
|
|
149
|
+
syncPanelInputs();
|
|
150
|
+
applyWindowFrame(framePreference(), false);
|
|
151
|
+
if (contentInput)
|
|
152
|
+
contentInput.checked = app.LS.contentTransition;
|
|
153
|
+
if (pageInput)
|
|
154
|
+
pageInput.value = String(app.LS.pageStep);
|
|
155
|
+
if (pageValue)
|
|
156
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
157
|
+
tokenInput.value = app.LS.token;
|
|
158
|
+
if (tokenHint)
|
|
159
|
+
tokenHint.hidden = !token;
|
|
160
|
+
if (dialog.open) {
|
|
161
|
+
if (token) {
|
|
162
|
+
activateTab("connection");
|
|
163
|
+
tokenInput.focus();
|
|
164
|
+
}
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
168
|
+
opener?.setAttribute("aria-expanded", "true");
|
|
169
|
+
activateTab(token ? "connection" : "general");
|
|
170
|
+
dialog.showModal();
|
|
171
|
+
(token ? tokenInput : $("#localeSelectSettings"))?.focus();
|
|
172
|
+
};
|
|
173
|
+
app.openSettings = () => open();
|
|
174
|
+
app.openChatSettings = () => open({ token: true });
|
|
175
|
+
$("#btnSettings")?.addEventListener("click", () => app.openSettings());
|
|
176
|
+
$("#btnJoinSettings")?.addEventListener("click", () => app.openSettings());
|
|
177
|
+
const close = () => {
|
|
178
|
+
opener?.setAttribute("aria-expanded", "false");
|
|
179
|
+
dialog.close();
|
|
180
|
+
};
|
|
181
|
+
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
182
|
+
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
183
|
+
pageInput?.addEventListener("input", () => {
|
|
184
|
+
app.LS.pageStep = pageInput.value;
|
|
185
|
+
pageInput.value = String(app.LS.pageStep);
|
|
186
|
+
if (pageValue)
|
|
187
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
188
|
+
});
|
|
189
|
+
customColorInput?.addEventListener("input", () => {
|
|
190
|
+
const color = validColor(customColorInput.value);
|
|
191
|
+
scheduleCustomPaint(color);
|
|
192
|
+
clearTimeout(customPersistTimer);
|
|
193
|
+
customPersistTimer = setTimeout(() => {
|
|
194
|
+
customPersistTimer = 0;
|
|
195
|
+
commitCustomColor(validColor(customColorInput.value));
|
|
196
|
+
}, CUSTOM_COLOR_PERSIST_DELAY);
|
|
197
|
+
});
|
|
198
|
+
// Release commits the final color and flushes both the paint and storage at once.
|
|
199
|
+
customColorInput?.addEventListener("change", () => {
|
|
200
|
+
commitCustomColor(validColor(customColorInput.value));
|
|
201
|
+
});
|
|
202
|
+
dialog.addEventListener("change", (event) => {
|
|
203
|
+
if (event.target instanceof HTMLInputElement && event.target.name === "theme")
|
|
204
|
+
app.setTheme(event.target.value);
|
|
205
|
+
if (event.target === frameSelect)
|
|
206
|
+
app.setWindowFrame(frameSelect.value);
|
|
207
|
+
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
208
|
+
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
209
|
+
}
|
|
210
|
+
if (event.target === contentInput)
|
|
211
|
+
app.LS.contentTransition = contentInput.checked;
|
|
212
|
+
if (event.target === pageInput) {
|
|
213
|
+
app.LS.pageStep = pageInput.value;
|
|
214
|
+
pageInput.value = String(app.LS.pageStep);
|
|
215
|
+
if (pageValue)
|
|
216
|
+
pageValue.textContent = `${app.LS.pageStep}%`;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
dialog.addEventListener("close", () => {
|
|
220
|
+
const target = opener;
|
|
221
|
+
opener = null;
|
|
222
|
+
if (target?.isConnected)
|
|
223
|
+
target.setAttribute("aria-expanded", "false");
|
|
224
|
+
if (app.focusChatComposer?.({ force: true }))
|
|
225
|
+
return;
|
|
226
|
+
if (target?.isConnected)
|
|
227
|
+
target.focus({ preventScroll: true });
|
|
228
|
+
});
|
|
229
|
+
// The palette follows the system through its media query; only the browser chrome needs a nudge.
|
|
230
|
+
scheme.addEventListener("change", () => { if (app.LS.theme === "system")
|
|
231
|
+
syncThemeColor(); });
|
|
232
|
+
applyTheme(app.LS.theme, false);
|
|
84
233
|
applyWindowFrame(framePreference(), false);
|
|
85
|
-
|
|
86
|
-
if (pageInput) pageInput.value = String(app.LS.pageStep);
|
|
87
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
88
|
-
tokenInput.value = app.LS.token;
|
|
89
|
-
if (tokenHint) tokenHint.hidden = !token;
|
|
90
|
-
if (dialog.open) {
|
|
91
|
-
if (token) {
|
|
92
|
-
activateTab("connection");
|
|
93
|
-
tokenInput.focus();
|
|
94
|
-
}
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
98
|
-
opener?.setAttribute("aria-expanded", "true");
|
|
99
|
-
activateTab(token ? "connection" : "general");
|
|
100
|
-
dialog.showModal();
|
|
101
|
-
(token ? tokenInput : $("#localeSelectSettings"))?.focus();
|
|
102
|
-
};
|
|
103
|
-
app.openSettings = () => open();
|
|
104
|
-
app.openChatSettings = () => open({ token: true });
|
|
105
|
-
|
|
106
|
-
$("#btnSettings")?.addEventListener("click", () => app.openSettings());
|
|
107
|
-
$("#btnJoinSettings")?.addEventListener("click", () => app.openSettings());
|
|
108
|
-
const close = () => {
|
|
109
|
-
opener?.setAttribute("aria-expanded", "false");
|
|
110
|
-
dialog.close();
|
|
111
|
-
};
|
|
112
|
-
$("#btnCloseSettings")?.addEventListener("click", close);
|
|
113
|
-
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
114
|
-
dialog.addEventListener("cancel", () => opener?.setAttribute("aria-expanded", "false"));
|
|
115
|
-
pageInput?.addEventListener("input", () => {
|
|
116
|
-
app.LS.pageStep = pageInput.value;
|
|
117
|
-
pageInput.value = String(app.LS.pageStep);
|
|
118
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
119
|
-
});
|
|
120
|
-
dialog.addEventListener("change", (event) => {
|
|
121
|
-
if (event.target instanceof HTMLInputElement && event.target.name === "theme") app.setTheme(event.target.value);
|
|
122
|
-
if (event.target === frameSelect) app.setWindowFrame(frameSelect.value);
|
|
123
|
-
if (event.target instanceof HTMLSelectElement && event.target.dataset.panelMode) {
|
|
124
|
-
app.setPanelMode(event.target.dataset.panelMode, event.target.value);
|
|
125
|
-
}
|
|
126
|
-
if (event.target === contentInput) app.LS.contentTransition = contentInput.checked;
|
|
127
|
-
if (event.target === pageInput) {
|
|
128
|
-
app.LS.pageStep = pageInput.value;
|
|
129
|
-
pageInput.value = String(app.LS.pageStep);
|
|
130
|
-
if (pageValue) pageValue.textContent = `${app.LS.pageStep}%`;
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
dialog.addEventListener("close", () => {
|
|
134
|
-
const target = opener;
|
|
135
|
-
opener = null;
|
|
136
|
-
if (target?.isConnected) target.setAttribute("aria-expanded", "false");
|
|
137
|
-
if (app.focusChatComposer?.({ force: true })) return;
|
|
138
|
-
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
139
|
-
});
|
|
140
|
-
// The palette follows the system through its media query; only the browser chrome needs a nudge.
|
|
141
|
-
scheme.addEventListener("change", () => { if (app.LS.theme === "system") syncThemeColor(); });
|
|
142
|
-
|
|
143
|
-
applyTheme(app.LS.theme, false);
|
|
144
|
-
applyWindowFrame(framePreference(), false);
|
|
145
|
-
}
|
|
234
|
+
}
|