@alexsun-top/opencode-chat-room 0.8.2 → 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 +10 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +466 -188
- package/package.json +8 -5
- package/packages/chat-room-channeld/README.md +25 -3
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +5 -0
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +17 -2
- 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 +1 -0
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/server/assets/base.css +3 -1
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -161
- package/server/assets/chat/announcements.js +295 -208
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +185 -156
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -33
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -47
- package/server/assets/chat/diagram-viewer.js +293 -234
- package/server/assets/chat/doc-preview.js +507 -441
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -510
- package/server/assets/chat/files.js +476 -430
- 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 -176
- package/server/assets/chat/index.js +2 -3
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +88 -86
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +689 -622
- 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 +547 -403
- 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 -480
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -417
- package/server/assets/chat/panels.js +94 -78
- 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 -121
- package/server/assets/chat/reminders.js +331 -214
- package/server/assets/chat/replies.js +165 -130
- 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 -500
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +223 -200
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -187
- package/server/assets/chat/side-pane.js +160 -150
- package/server/assets/chat/state.js +849 -735
- package/server/assets/chat/system-events.js +45 -43
- package/server/assets/chat/system-messages.js +57 -56
- 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 -587
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +32 -32
- package/server/assets/conversation.css +10 -4
- package/server/chat-server.ts +9 -1
- package/server/chat.html +2 -1
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -268
- package/src/web/integration-rules-editor.ts +2 -0
|
@@ -1,144 +1,168 @@
|
|
|
1
1
|
import { editorSelectionOffsets, replaceEditorRange } from "./editor.js";
|
|
2
|
-
|
|
3
2
|
export function initMentions(app) {
|
|
4
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
3
|
+
const $ = app.$;
|
|
4
|
+
const mention = { active: false, start: 0, query: "", items: [], index: 0, editor: null };
|
|
5
|
+
app.mention = mention;
|
|
6
|
+
app.mentionActive = false;
|
|
7
|
+
app.updateMentionList = (query = mention.query) => {
|
|
8
|
+
mention.query = query;
|
|
9
|
+
mention.items = filterNames(query, app.mentionNames());
|
|
10
|
+
mention.index = mention.items.length ? 0 : -1;
|
|
11
|
+
const picker = $("#mentionPicker");
|
|
12
|
+
picker.textContent = "";
|
|
13
|
+
const list = document.createElement("ul");
|
|
14
|
+
mention.items.forEach((name, index) => list.append(createOption(name, index, query, app)));
|
|
15
|
+
picker.append(list);
|
|
16
|
+
if (!mention.items.length) {
|
|
17
|
+
const empty = document.createElement("p");
|
|
18
|
+
empty.className = "mention-empty";
|
|
19
|
+
empty.textContent = app.t("mentionEmpty");
|
|
20
|
+
picker.append(empty);
|
|
21
|
+
}
|
|
22
|
+
const hint = document.createElement("p");
|
|
23
|
+
hint.className = "mention-hint";
|
|
24
|
+
hint.textContent = app.t("mentionHint");
|
|
25
|
+
picker.append(hint);
|
|
26
|
+
highlightMention(app, mention);
|
|
27
|
+
};
|
|
28
|
+
app.openMention = (start, query, input = $("#msgInput")) => {
|
|
29
|
+
mention.active = app.mentionActive = true;
|
|
30
|
+
mention.editor = input;
|
|
31
|
+
mention.start = start;
|
|
32
|
+
app.updateMentionList(query);
|
|
33
|
+
const picker = $("#mentionPicker");
|
|
34
|
+
picker.hidden = false;
|
|
35
|
+
if (input.id !== "msgInput") {
|
|
36
|
+
const rect = input.getBoundingClientRect();
|
|
37
|
+
Object.assign(picker.style, { position: "fixed", left: `${rect.left}px`, right: `${innerWidth - rect.right}px`, bottom: `${innerHeight - rect.top + 8}px` });
|
|
38
|
+
}
|
|
39
|
+
input.setAttribute("aria-expanded", "true");
|
|
40
|
+
};
|
|
41
|
+
app.closeMention = () => {
|
|
42
|
+
mention.active = app.mentionActive = false;
|
|
43
|
+
mention.items = [];
|
|
44
|
+
mention.editor?.setAttribute("aria-expanded", "false");
|
|
45
|
+
mention.editor?.removeAttribute("aria-activedescendant");
|
|
46
|
+
mention.editor = null;
|
|
47
|
+
const picker = $("#mentionPicker");
|
|
48
|
+
picker.hidden = true;
|
|
49
|
+
picker.removeAttribute("style");
|
|
50
|
+
};
|
|
51
|
+
app.recomputeMention = (input = $("#msgInput")) => {
|
|
52
|
+
if (!(input instanceof HTMLElement))
|
|
53
|
+
input = $("#msgInput");
|
|
54
|
+
if (mention.active && mention.editor !== input)
|
|
55
|
+
app.closeMention();
|
|
56
|
+
const match = currentMention(input);
|
|
57
|
+
if (match) {
|
|
58
|
+
mention.active ? app.updateMentionList(match.query) : app.openMention(match.start, match.query, input);
|
|
59
|
+
}
|
|
60
|
+
else if (mention.active)
|
|
61
|
+
app.closeMention();
|
|
62
|
+
};
|
|
63
|
+
app.moveMention = (direction) => {
|
|
64
|
+
if (!mention.items.length)
|
|
65
|
+
return;
|
|
66
|
+
mention.index = (mention.index + direction + mention.items.length) % mention.items.length;
|
|
67
|
+
highlightMention(app, mention);
|
|
68
|
+
};
|
|
69
|
+
app.handleMentionKey = (event, input) => {
|
|
70
|
+
if (!mention.active || mention.editor !== input || event.isComposing || event.keyCode === 229)
|
|
71
|
+
return false;
|
|
72
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
app.moveMention(event.key === "ArrowDown" ? 1 : -1);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (event.key === "Escape") {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
app.closeMention();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
if (event.key === "Enter" || event.key === "Tab") {
|
|
83
|
+
if (mention.items.length) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
app.insertMention(mention.items[mention.index]);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
app.closeMention();
|
|
89
|
+
return event.key === "Tab";
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
app.insertMention = (name) => {
|
|
94
|
+
const input = mention.editor || $("#msgInput"), end = mention.start + 1 + mention.query.length;
|
|
95
|
+
if (input.value.slice(mention.start, end) !== `@${mention.query}`)
|
|
96
|
+
return app.closeMention();
|
|
97
|
+
replaceEditorRange(input, mention.start, end, `<at>@${name}</at>`);
|
|
98
|
+
app.closeMention();
|
|
99
|
+
// Chrome can reset the selection while focus() lands; restore the caret last.
|
|
100
|
+
input.focus({ preventScroll: true });
|
|
101
|
+
input.setCaret?.(mention.start + `<at>@${name}</at>`.length);
|
|
102
|
+
input.dispatchEvent(new InputEvent("input", { bubbles: true, inputType: "insertText" }));
|
|
103
|
+
};
|
|
85
104
|
}
|
|
86
|
-
|
|
87
105
|
function filterNames(query, names) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
106
|
+
const normalized = query.toLocaleLowerCase();
|
|
107
|
+
const starts = [], contains = [];
|
|
108
|
+
for (const name of names) {
|
|
109
|
+
if (!name)
|
|
110
|
+
continue;
|
|
111
|
+
if (name.toLocaleLowerCase().startsWith(normalized))
|
|
112
|
+
starts.push(name);
|
|
113
|
+
else if (name.toLocaleLowerCase().includes(normalized))
|
|
114
|
+
contains.push(name);
|
|
115
|
+
}
|
|
116
|
+
const allMatches = !normalized || "all".includes(normalized) || "所有人".includes(normalized);
|
|
117
|
+
return (allMatches ? ["all"] : []).concat(starts, contains);
|
|
97
118
|
}
|
|
98
|
-
|
|
99
119
|
function createOption(name, index, query, app) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
const option = document.createElement("li");
|
|
121
|
+
option.className = "mention-opt";
|
|
122
|
+
option.id = `mention-opt-${index}`;
|
|
123
|
+
option.dataset.name = name;
|
|
124
|
+
option.setAttribute("role", "option");
|
|
125
|
+
const at = document.createElement("span");
|
|
126
|
+
at.className = "mention-at";
|
|
127
|
+
at.textContent = "@";
|
|
128
|
+
option.append(at);
|
|
129
|
+
const label = name === "all" ? app.t("allMembers") : name;
|
|
130
|
+
const offset = label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase());
|
|
131
|
+
if (!query || offset < 0)
|
|
132
|
+
option.append(document.createTextNode(label));
|
|
133
|
+
else {
|
|
134
|
+
option.append(document.createTextNode(label.slice(0, offset)));
|
|
135
|
+
const hit = document.createElement("span");
|
|
136
|
+
hit.className = "mention-hit";
|
|
137
|
+
hit.textContent = label.slice(offset, offset + query.length);
|
|
138
|
+
option.append(hit, document.createTextNode(label.slice(offset + query.length)));
|
|
139
|
+
}
|
|
140
|
+
return option;
|
|
120
141
|
}
|
|
121
|
-
|
|
122
142
|
function currentMention(input) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
143
|
+
const [position, end] = editorSelectionOffsets(input), value = input.value;
|
|
144
|
+
if (position !== end)
|
|
145
|
+
return null;
|
|
146
|
+
let start = position;
|
|
147
|
+
while (start > 0 && /[\p{L}\p{N}_]/u.test(value[start - 1]))
|
|
148
|
+
start--;
|
|
149
|
+
const at = start - 1;
|
|
150
|
+
if (at >= 0 && value[at] === "@" && (at === 0 || !/[A-Za-z0-9_]/.test(value[at - 1]))) {
|
|
151
|
+
return { start: at, query: value.slice(start, position) };
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
132
154
|
}
|
|
133
|
-
|
|
134
155
|
function highlightMention(app, mention) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
156
|
+
const input = mention.editor || app.$("#msgInput"), options = app.$("#mentionPicker").querySelectorAll(".mention-opt");
|
|
157
|
+
options.forEach((option, index) => {
|
|
158
|
+
option.classList.toggle("active", index === mention.index);
|
|
159
|
+
option.setAttribute("aria-selected", String(index === mention.index));
|
|
160
|
+
});
|
|
161
|
+
const active = options[mention.index];
|
|
162
|
+
if (!active) {
|
|
163
|
+
input.removeAttribute("aria-activedescendant");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
active.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
167
|
+
input.setAttribute("aria-activedescendant", active.id);
|
|
144
168
|
}
|
|
@@ -4,48 +4,55 @@
|
|
|
4
4
|
const DB_NAME = "chat-room-history";
|
|
5
5
|
const STORE = "rooms";
|
|
6
6
|
const CACHE_LIMIT = 2000;
|
|
7
|
-
|
|
8
7
|
let opening;
|
|
9
8
|
function open() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
opening ??= new Promise((resolve, reject) => {
|
|
10
|
+
if (!globalThis.indexedDB) {
|
|
11
|
+
reject(new Error("IndexedDB unavailable"));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const request = indexedDB.open(DB_NAME, 1);
|
|
15
|
+
request.onupgradeneeded = () => request.result.createObjectStore(STORE, { keyPath: "roomId" });
|
|
16
|
+
request.onsuccess = () => resolve(request.result);
|
|
17
|
+
request.onerror = () => reject(request.error);
|
|
18
|
+
request.onblocked = () => reject(new Error("IndexedDB blocked"));
|
|
19
|
+
});
|
|
20
|
+
return opening;
|
|
19
21
|
}
|
|
20
|
-
|
|
21
22
|
async function withStore(mode, run) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const db = await open();
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const transaction = db.transaction(STORE, mode);
|
|
26
|
+
const request = run(transaction.objectStore(STORE));
|
|
27
|
+
transaction.oncomplete = () => resolve(request?.result);
|
|
28
|
+
transaction.onerror = () => reject(transaction.error);
|
|
29
|
+
transaction.onabort = () => reject(transaction.error);
|
|
30
|
+
});
|
|
30
31
|
}
|
|
31
|
-
|
|
32
32
|
export async function loadCachedRooms() {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
try {
|
|
34
|
+
return (await withStore("readonly", (store) => store.getAll())) || [];
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
|
-
|
|
37
40
|
export async function deleteCachedRoom(roomId) {
|
|
38
|
-
|
|
41
|
+
try {
|
|
42
|
+
await withStore("readwrite", (store) => store.delete(roomId));
|
|
43
|
+
}
|
|
44
|
+
catch { /* optional cache */ }
|
|
39
45
|
}
|
|
40
|
-
|
|
41
46
|
const pending = new Map();
|
|
42
47
|
export function cacheRoomSoon(app, roomId) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
pending.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
if (pending.has(roomId))
|
|
49
|
+
return;
|
|
50
|
+
pending.set(roomId, setTimeout(() => {
|
|
51
|
+
pending.delete(roomId);
|
|
52
|
+
const entry = app.state.rooms.get(roomId);
|
|
53
|
+
if (!entry?.room)
|
|
54
|
+
return;
|
|
55
|
+
const snapshot = { ...entry.room, messages: entry.room.messages.slice(-CACHE_LIMIT) };
|
|
56
|
+
void withStore("readwrite", (store) => store.put({ roomId, name: entry.name, savedAt: Date.now(), room: snapshot })).catch(() => { });
|
|
57
|
+
}, 800));
|
|
51
58
|
}
|