@alexsun-top/opencode-chat-room 0.8.4 → 0.8.6
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 +17 -3
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/cli.ts +20 -1
- package/dist/cli.js +3785 -1462
- package/package.json +19 -11
- package/packages/chat-room-channeld/README.md +16 -10
- package/packages/chat-room-channeld/src/delivery.ts +0 -4
- package/packages/chat-room-channeld/src/host.ts +48 -37
- package/packages/chat-room-channeld/src/inbound.ts +3 -6
- package/packages/chat-room-channeld/src/pg/database.ts +141 -49
- package/packages/chat-room-channeld/src/pg/sql.mjs +157 -142
- package/packages/chat-room-channeld/src/pg/sql.mts +175 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +148 -99
- package/packages/chat-room-channeld/src/pg/worker.mts +201 -0
- package/packages/chat-room-channeld/src/state-rows.ts +132 -0
- package/packages/chat-room-channeld/src/state.ts +129 -157
- package/plugin.ts +21 -5
- package/server/app.ts +9 -0
- package/server/assets/base.css +22 -2
- package/server/assets/chat/admin.js +17 -1
- package/server/assets/chat/announcements.js +79 -34
- package/server/assets/chat/attachments.js +3 -3
- package/server/assets/chat/clipboard.js +1 -1
- package/server/assets/chat/confirm-dialog.js +3 -0
- package/server/assets/chat/copy-action.js +1 -1
- package/server/assets/chat/create-room-dialog.js +7 -0
- package/server/assets/chat/diagram-viewer.js +4 -8
- package/server/assets/chat/doc-preview.js +71 -31
- package/server/assets/chat/editor.js +49 -10
- package/server/assets/chat/events.js +13 -6
- package/server/assets/chat/files.js +33 -27
- package/server/assets/chat/history-loader.js +31 -15
- package/server/assets/chat/integration-editor.js +27 -1
- package/server/assets/chat/integrations.js +108 -16
- package/server/assets/chat/join-requests.js +40 -2
- package/server/assets/chat/locales/de.js +5 -3
- package/server/assets/chat/locales/es.js +5 -3
- package/server/assets/chat/locales/fr.js +5 -3
- package/server/assets/chat/locales/it.js +5 -3
- package/server/assets/chat/locales/ja.js +5 -3
- package/server/assets/chat/locales/ko.js +5 -3
- package/server/assets/chat/markdown-footnotes.js +27 -15
- package/server/assets/chat/markdown.js +6 -12
- package/server/assets/chat/members.js +34 -22
- package/server/assets/chat/mentions.js +8 -5
- package/server/assets/chat/message-cache.js +9 -3
- package/server/assets/chat/message-polling.js +10 -4
- package/server/assets/chat/message-window.js +58 -1
- package/server/assets/chat/messages.js +90 -37
- package/server/assets/chat/office-preview.js +3 -3
- package/server/assets/chat/operator.js +624 -0
- package/server/assets/chat/palette.js +7 -10
- package/server/assets/chat/panels.js +42 -0
- package/server/assets/chat/questions.js +75 -58
- package/server/assets/chat/recall.js +14 -5
- package/server/assets/chat/receipts.js +63 -7
- package/server/assets/chat/refresh-timing.js +6 -0
- package/server/assets/chat/reminders.js +47 -13
- package/server/assets/chat/replies.js +39 -25
- package/server/assets/chat/resource-format.js +6 -3
- package/server/assets/chat/room-list.js +202 -3
- package/server/assets/chat/room-watcher.js +3 -1
- package/server/assets/chat/rooms.js +29 -7
- package/server/assets/chat/settings.js +37 -6
- package/server/assets/chat/shortcuts.js +3 -1
- package/server/assets/chat/side-pane.js +1 -1
- package/server/assets/chat/state.js +51 -18
- package/server/assets/chat/system-events.js +3 -2
- package/server/assets/chat/system-messages.js +15 -15
- package/server/assets/chat/tasks.js +37 -14
- package/server/assets/chat/window-controls.js +25 -15
- package/server/assets/code-highlight.css +0 -13
- package/server/assets/conversation.css +45 -5
- package/server/assets/doc-preview.css +9 -0
- package/server/assets/files.css +4 -0
- package/server/assets/monaco/integration-rules.js +1 -1
- package/server/assets/office/THIRD-PARTY-NOTICES.txt +23 -1
- package/server/assets/office/licenses/docx-preview-HEADER.txt +6 -0
- package/server/assets/office/licenses/echarts-LICENSE-d3.txt +27 -0
- package/server/assets/office/licenses/echarts-NOTICE.txt +5 -0
- package/server/assets/office/licenses/immediate-LICENSE.txt +20 -0
- package/server/assets/office/licenses/lie-LICENSE.txt +7 -0
- package/server/assets/office/licenses/pako-LICENSE.txt +21 -0
- package/server/assets/office/licenses/pako-ZLIB.txt +18 -0
- package/server/assets/office/licenses/setimmediate-LICENSE.txt +20 -0
- package/server/assets/responsive.css +12 -2
- package/server/assets/settings.css +3 -1
- package/server/assets/tasks.css +6 -1
- package/server/assets/window-controls.css +3 -1
- package/server/channels.ts +3 -2
- package/server/chat.html +7 -2
- package/server/inbox.ts +3 -1
- package/server/join-requests.ts +8 -1
- package/server/member-routes.ts +16 -2
- package/server/newrooms.ts +2 -13
- package/server/operator-auth.ts +21 -0
- package/server/operator-routes.ts +150 -0
- package/server/operator-state.ts +64 -0
- package/server/operator.css +139 -0
- package/server/room-owner.ts +17 -0
- package/server/routes/inbox.ts +15 -5
- package/server/routes/pages.ts +12 -2
- package/server/routes/room-actions.ts +4 -3
- package/server/sw.js +3 -1
- package/server/system.html +109 -0
- package/server/wake.ts +1 -1
- package/skills/chatroom/SKILL.md +9 -0
- package/src/README.md +1 -1
- package/src/acp/client.ts +254 -0
- package/src/acp/protocol.ts +300 -0
- package/src/acp/watch.ts +498 -0
- package/src/agent/agent-receipts.ts +98 -8
- package/src/center/center-client.ts +6 -1
- package/src/center/center-inbox.ts +54 -7
- package/src/center/center-wake.ts +57 -3
- package/src/center/forward-client.ts +48 -0
- package/src/center/mentions.ts +16 -3
- package/src/center/notification-delay.ts +139 -0
- package/src/center/queue.ts +3 -0
- package/src/config/file-config.ts +25 -0
- package/src/mcp/server.ts +389 -0
- package/src/protocol/config.ts +7 -0
- package/src/runtime/plugin-notifications.ts +43 -9
- package/src/runtime/v2-plugin.ts +14 -3
- package/src/runtime/v2-receiver.ts +10 -2
- package/src/runtime/watch.ts +5 -1
- package/src/state/pg-database.ts +133 -49
- package/src/state/pg-sql.mjs +157 -142
- package/src/state/pg-sql.mts +175 -0
- package/src/state/pg-worker.mjs +148 -99
- package/src/state/pg-worker.mts +201 -0
- package/src/state/receiver-state.ts +47 -0
- package/src/state/sqlite-database.ts +6 -2
- package/src/state/sqlite-members.ts +48 -4
- package/src/state/sqlite-messages.ts +25 -12
- package/src/state/sqlite-schema.ts +4 -1
- package/src/state/sqlite-state.ts +1 -1
- package/src/state/store.ts +31 -11
- package/src/tui/app-types.mjs +1 -0
- package/src/tui/app-types.mts +175 -0
- package/src/tui/app.mjs +473 -423
- package/src/tui/app.mts +543 -0
- package/src/tui/config.mjs +166 -158
- package/src/tui/config.mts +247 -0
- package/src/tui/http.mjs +239 -206
- package/src/tui/http.mts +412 -0
- package/src/tui/i18n.mjs +17 -20
- package/src/tui/i18n.mts +42 -0
- package/src/tui/info-app.mjs +431 -427
- package/src/tui/info-app.mts +500 -0
- package/src/tui/info-content.mjs +205 -199
- package/src/tui/info-content.mts +341 -0
- package/src/tui/join-app.mjs +75 -64
- package/src/tui/join-app.mts +99 -0
- package/src/tui/locales/en.mjs +302 -320
- package/src/tui/locales/en.mts +349 -0
- package/src/tui/locales/zh-CN.mjs +302 -320
- package/src/tui/locales/zh-CN.mts +349 -0
- package/src/tui/main.mjs +219 -213
- package/src/tui/main.mts +255 -0
- package/src/tui/markdown.mjs +128 -272
- package/src/tui/markdown.mts +152 -0
- package/src/tui/mentions.mjs +181 -184
- package/src/tui/mentions.mts +251 -0
- package/src/tui/message-app.mjs +181 -173
- package/src/tui/message-app.mts +213 -0
- package/src/tui/message-view.mjs +90 -111
- package/src/tui/message-view.mts +151 -0
- package/src/tui/messages.mjs +55 -49
- package/src/tui/messages.mts +106 -0
- package/src/tui/palette-app.mjs +364 -344
- package/src/tui/palette-app.mts +388 -0
- package/src/tui/palette.mjs +100 -98
- package/src/tui/palette.mts +176 -0
- package/src/tui/prefs.mjs +56 -63
- package/src/tui/prefs.mts +126 -0
- package/src/tui/reminder-app.mjs +191 -181
- package/src/tui/reminder-app.mts +228 -0
- package/src/tui/room-settings-app.mjs +275 -242
- package/src/tui/room-settings-app.mts +318 -0
- package/src/tui/session.mjs +30 -29
- package/src/tui/session.mts +51 -0
- package/src/tui/settings-app.mjs +151 -138
- package/src/tui/settings-app.mts +179 -0
- package/src/tui/ui-content.mjs +426 -421
- package/src/tui/ui-content.mts +499 -0
- package/src/tui/ui-help.mjs +58 -67
- package/src/tui/ui-help.mts +87 -0
- package/src/tui/ui-mentions.mjs +34 -36
- package/src/tui/ui-mentions.mts +60 -0
- package/src/tui/ui-overlay-view.mjs +259 -267
- package/src/tui/ui-overlay-view.mts +322 -0
- package/src/tui/ui-suggest-view.mjs +54 -57
- package/src/tui/ui-suggest-view.mts +78 -0
- package/src/tui/ui-suggest.mjs +164 -167
- package/src/tui/ui-suggest.mts +248 -0
- package/src/tui/ui-theme.mjs +52 -57
- package/src/tui/ui-theme.mts +98 -0
- package/src/tui/ui-view.mjs +267 -275
- package/src/tui/ui-view.mts +308 -0
- package/src/tui/ui.mjs +372 -359
- package/src/tui/ui.mts +440 -0
- package/src/tui/wire.mjs +215 -0
- package/src/tui/wire.mts +383 -0
- package/src/web/integration-rules-editor.ts +25 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { LS } from "./state.js";
|
|
2
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
3
|
+
import { waitForRefresh } from "./refresh-timing.js";
|
|
2
4
|
export function initAnnouncements(app) {
|
|
3
5
|
const $ = (selector) => {
|
|
4
6
|
const node = app.$(selector);
|
|
@@ -11,6 +13,7 @@ export function initAnnouncements(app) {
|
|
|
11
13
|
const dialog = $("#announcementDialog"), heading = $("#announcementDialogHeading");
|
|
12
14
|
const panelHeading = $("#announcementHeading"), chatView = $("#chatView");
|
|
13
15
|
let items = [], selected = "", generation = 0, roomGeneration = 0, editorRevision = 0, saveToken = 0;
|
|
16
|
+
let editorDirty = false;
|
|
14
17
|
let opener = null, pendingReopen = false, restoreSurfaceFocus = true;
|
|
15
18
|
const key = (id, name = selected) => `${id}\0${name ? `item\0${name}` : "new"}`;
|
|
16
19
|
const roomId = () => app.state.room?.id;
|
|
@@ -31,6 +34,17 @@ export function initAnnouncements(app) {
|
|
|
31
34
|
}
|
|
32
35
|
function status(text) { $("#announcementStatus").textContent = text; }
|
|
33
36
|
function formStatus(text) { $("#announcementDialogStatus").textContent = text; }
|
|
37
|
+
// Show motion without touching the rows, so a fast refresh never collapses the list.
|
|
38
|
+
const setLoading = (loading) => {
|
|
39
|
+
const line = $("#announcementStatus");
|
|
40
|
+
if (!loading && line.classList.contains("is-loading"))
|
|
41
|
+
line.textContent = "";
|
|
42
|
+
line.classList.toggle("is-loading", loading);
|
|
43
|
+
if (loading)
|
|
44
|
+
list.setAttribute("aria-busy", "true");
|
|
45
|
+
else
|
|
46
|
+
list.removeAttribute("aria-busy");
|
|
47
|
+
};
|
|
34
48
|
function count() { $("#announcementCount").textContent = app.t("announcementCount", { count: Array.from($("#announcementContent").value).length }); }
|
|
35
49
|
const clearPane = () => {
|
|
36
50
|
surface.classList.remove("is-pane");
|
|
@@ -67,6 +81,8 @@ export function initAnnouncements(app) {
|
|
|
67
81
|
if (surface.open)
|
|
68
82
|
surface.close();
|
|
69
83
|
};
|
|
84
|
+
// This Escape closed the panel, so it can be the first press; defer past the dispatch.
|
|
85
|
+
const noteEscapeClose = () => queueMicrotask(() => document.dispatchEvent(new CustomEvent("chat-overlay-escaped")));
|
|
70
86
|
function openSurface() {
|
|
71
87
|
const id = roomId();
|
|
72
88
|
if (!id)
|
|
@@ -85,19 +101,32 @@ export function initAnnouncements(app) {
|
|
|
85
101
|
panelHeading.focus();
|
|
86
102
|
void load(id);
|
|
87
103
|
}
|
|
104
|
+
function updateSelection() {
|
|
105
|
+
for (const button of Array.from(list.querySelectorAll("button"))) {
|
|
106
|
+
if (button.textContent === selected)
|
|
107
|
+
button.setAttribute("aria-current", "true");
|
|
108
|
+
else
|
|
109
|
+
button.removeAttribute("aria-current");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// One atomic commit: the old rows survive until the new set replaces them together.
|
|
88
113
|
function render() {
|
|
89
|
-
|
|
114
|
+
const fragment = document.createDocumentFragment();
|
|
90
115
|
for (const entry of items) {
|
|
91
116
|
const li = document.createElement("li"), button = document.createElement("button");
|
|
92
117
|
button.type = "button";
|
|
93
118
|
button.textContent = entry.name;
|
|
94
119
|
button.setAttribute("aria-haspopup", "dialog");
|
|
95
|
-
if (entry.name === selected)
|
|
96
|
-
button.setAttribute("aria-current", "true");
|
|
97
120
|
button.addEventListener("click", (event) => { event.stopPropagation(); openEditor(entry); });
|
|
98
121
|
li.append(button);
|
|
99
|
-
|
|
122
|
+
fragment.append(li);
|
|
100
123
|
}
|
|
124
|
+
const focused = document.activeElement instanceof HTMLElement && list.contains(document.activeElement)
|
|
125
|
+
? document.activeElement.textContent : "";
|
|
126
|
+
list.replaceChildren(fragment);
|
|
127
|
+
updateSelection();
|
|
128
|
+
if (focused)
|
|
129
|
+
Array.from(list.querySelectorAll("button")).find((button) => button.textContent === focused)?.focus({ preventScroll: true });
|
|
101
130
|
if (!items.length)
|
|
102
131
|
status(app.t("announcementEmpty"));
|
|
103
132
|
}
|
|
@@ -116,11 +145,12 @@ export function initAnnouncements(app) {
|
|
|
116
145
|
name.value = selected || saved?.name || "";
|
|
117
146
|
content.value = saved?.content ?? entry?.content ?? "";
|
|
118
147
|
$("#btnDeleteAnnouncement").hidden = !selected;
|
|
119
|
-
|
|
148
|
+
updateSelection();
|
|
120
149
|
count();
|
|
121
150
|
}
|
|
122
151
|
function openEditor(entry) {
|
|
123
152
|
select(entry);
|
|
153
|
+
editorDirty = false;
|
|
124
154
|
if (entry) {
|
|
125
155
|
delete heading.dataset.i18n;
|
|
126
156
|
heading.textContent = entry.name;
|
|
@@ -139,39 +169,50 @@ export function initAnnouncements(app) {
|
|
|
139
169
|
return;
|
|
140
170
|
const request = ++generation, context = roomGeneration;
|
|
141
171
|
status(app.t("announcementLoading"));
|
|
172
|
+
setLoading(true);
|
|
173
|
+
const started = performance.now();
|
|
174
|
+
let result = null, failure = null;
|
|
142
175
|
try {
|
|
143
|
-
|
|
144
|
-
if (roomId() !== id || context !== roomGeneration || generation !== request)
|
|
145
|
-
return;
|
|
146
|
-
items = Array.isArray(result.announcements) ? result.announcements : [];
|
|
147
|
-
status("");
|
|
148
|
-
const chosen = items.find((item) => item.name === selected);
|
|
149
|
-
if (!chosen) {
|
|
150
|
-
const stale = selected && draft(id, selected);
|
|
151
|
-
if (stale) {
|
|
152
|
-
drafts.set(key(id, ""), { ...stale, name: $("#announcementName").value.trim() || stale.name });
|
|
153
|
-
drafts.delete(key(id, selected));
|
|
154
|
-
}
|
|
155
|
-
select(null);
|
|
156
|
-
}
|
|
157
|
-
else
|
|
158
|
-
select(chosen);
|
|
159
|
-
render();
|
|
176
|
+
result = await app.api(`/rooms/${encodeURIComponent(id)}/announcements`);
|
|
160
177
|
}
|
|
161
178
|
catch (error) {
|
|
162
|
-
|
|
163
|
-
|
|
179
|
+
failure = error;
|
|
180
|
+
}
|
|
181
|
+
if (failure?.status !== 401)
|
|
182
|
+
await waitForRefresh(started);
|
|
183
|
+
if (roomId() !== id || context !== roomGeneration || generation !== request)
|
|
184
|
+
return;
|
|
185
|
+
setLoading(false);
|
|
186
|
+
if (failure) {
|
|
164
187
|
status(app.t("announcementLoadFailed"));
|
|
165
|
-
if (
|
|
188
|
+
if (failure.status === 401)
|
|
166
189
|
app.openChatSettings();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
items = Array.isArray(result?.announcements) ? result.announcements : [];
|
|
193
|
+
const chosen = items.find((item) => item.name === selected);
|
|
194
|
+
if (!chosen) {
|
|
195
|
+
const stale = selected && draft(id, selected);
|
|
196
|
+
if (stale) {
|
|
197
|
+
drafts.set(key(id, ""), { ...stale, name: $("#announcementName").value.trim() || stale.name });
|
|
198
|
+
drafts.delete(key(id, selected));
|
|
199
|
+
}
|
|
200
|
+
select(null);
|
|
167
201
|
}
|
|
202
|
+
else
|
|
203
|
+
select(chosen);
|
|
204
|
+
render();
|
|
205
|
+
if (items.length)
|
|
206
|
+
status("");
|
|
168
207
|
}
|
|
169
208
|
$("#announcementContent").addEventListener("input", () => {
|
|
209
|
+
editorDirty = true;
|
|
170
210
|
editorRevision++;
|
|
171
211
|
count();
|
|
172
212
|
storeDraft();
|
|
173
213
|
});
|
|
174
214
|
$("#announcementName").addEventListener("input", () => {
|
|
215
|
+
editorDirty = true;
|
|
175
216
|
editorRevision++;
|
|
176
217
|
storeDraft();
|
|
177
218
|
});
|
|
@@ -191,6 +232,7 @@ export function initAnnouncements(app) {
|
|
|
191
232
|
});
|
|
192
233
|
if (currentRoom(id, context)) {
|
|
193
234
|
generation++;
|
|
235
|
+
setLoading(false);
|
|
194
236
|
items = [...items.filter((item) => item.name !== name), result.announcement];
|
|
195
237
|
render();
|
|
196
238
|
clearDraftIfUnchanged(id, draftName, captured);
|
|
@@ -237,6 +279,7 @@ export function initAnnouncements(app) {
|
|
|
237
279
|
await app.api(`/rooms/${encodeURIComponent(id)}/announcements/${encodeURIComponent(name)}`, { method: "DELETE", body: JSON.stringify({ sessionID: LS.sessionID }) });
|
|
238
280
|
if (currentRoom(id, context)) {
|
|
239
281
|
generation++;
|
|
282
|
+
setLoading(false);
|
|
240
283
|
items = items.filter((item) => item.name !== name);
|
|
241
284
|
render();
|
|
242
285
|
clearDraftIfUnchanged(id, name, captured);
|
|
@@ -259,13 +302,18 @@ export function initAnnouncements(app) {
|
|
|
259
302
|
$("#btnRefreshAnnouncements").addEventListener("click", () => void load());
|
|
260
303
|
$("#btnCloseAnnouncement").addEventListener("click", () => dialog.close());
|
|
261
304
|
$("#btnCancelAnnouncement").addEventListener("click", () => dialog.close());
|
|
305
|
+
// A backdrop click closes an untouched editor; a draft or a save in flight holds it.
|
|
306
|
+
closeOnBackdrop(dialog, () => { if (!editorDirty && !$("#btnSaveAnnouncement").disabled)
|
|
307
|
+
dialog.close(); });
|
|
262
308
|
trigger.addEventListener("click", () => {
|
|
263
309
|
// The entry lives in the Options menu, so choosing it closes that menu first.
|
|
264
310
|
app.closePanels();
|
|
265
311
|
openSurface();
|
|
266
312
|
});
|
|
267
313
|
$("#btnCloseAnnouncements").addEventListener("click", () => closeSurface());
|
|
268
|
-
|
|
314
|
+
// The announcement list is a list, so a backdrop click closes it; the editor stays.
|
|
315
|
+
closeOnBackdrop(surface, () => closeSurface());
|
|
316
|
+
surface.addEventListener("cancel", (event) => { event.preventDefault(); closeSurface(); noteEscapeClose(); });
|
|
269
317
|
surface.addEventListener("close", () => {
|
|
270
318
|
if (pendingReopen) {
|
|
271
319
|
pendingReopen = false;
|
|
@@ -279,14 +327,8 @@ export function initAnnouncements(app) {
|
|
|
279
327
|
if (focus && target?.isConnected)
|
|
280
328
|
target.focus({ preventScroll: true });
|
|
281
329
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return;
|
|
285
|
-
if (!surface.contains(document.activeElement))
|
|
286
|
-
return;
|
|
287
|
-
event.preventDefault();
|
|
288
|
-
closeSurface();
|
|
289
|
-
});
|
|
330
|
+
// A docked pane is part of the workspace, not a popup: Escape leaves it and its
|
|
331
|
+
// focus alone. Only the modal list/editor answer Escape, plus Alt+Esc.
|
|
290
332
|
app.registerPanelSurface?.("announcements", { element: surface, close: (restore = false) => closeSurface(restore) });
|
|
291
333
|
app.watchPanel?.("announcements", syncMode);
|
|
292
334
|
const closePanels = app.closePanels;
|
|
@@ -303,8 +345,11 @@ export function initAnnouncements(app) {
|
|
|
303
345
|
generation++;
|
|
304
346
|
saveToken++;
|
|
305
347
|
$("#btnSaveAnnouncement").disabled = false;
|
|
348
|
+
// Drop the old room's rows before the new request starts, never during it.
|
|
306
349
|
selected = "";
|
|
307
350
|
items = [];
|
|
351
|
+
setLoading(false);
|
|
352
|
+
list.replaceChildren();
|
|
308
353
|
select(null);
|
|
309
354
|
void load(id);
|
|
310
355
|
});
|
|
@@ -27,8 +27,8 @@ export function initAttachments(app) {
|
|
|
27
27
|
// crypto.randomUUID needs a secure context; the chat also runs on plain-HTTP LANs.
|
|
28
28
|
function newUploadID() {
|
|
29
29
|
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
30
|
-
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
31
|
-
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
30
|
+
bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x40;
|
|
31
|
+
bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;
|
|
32
32
|
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
33
33
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
34
34
|
}
|
|
@@ -234,7 +234,7 @@ export function initAttachments(app) {
|
|
|
234
234
|
if (roomId() === id)
|
|
235
235
|
render();
|
|
236
236
|
};
|
|
237
|
-
app.completeAttachmentsFromText = (id, text) => app.completeAttachments?.(id, [...String(text).matchAll(/\[\[resource:([\da-f-]{36})\]\]/gi)].map((match) => match[1]));
|
|
237
|
+
app.completeAttachmentsFromText = (id, text) => app.completeAttachments?.(id, [...String(text).matchAll(/\[\[resource:([\da-f-]{36})\]\]/gi)].map((match) => match[1] ?? ""));
|
|
238
238
|
const applyLocale = app.applyLocale;
|
|
239
239
|
app.applyLocale = () => { applyLocale(); updateLocale(); };
|
|
240
240
|
function updateLocale() {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """ };
|
|
4
4
|
export async function copyTextToClipboard(text, mentionSource = false) {
|
|
5
5
|
// The HTML marker lets a later paste rebuild mention chips; unmarked external text stays literal.
|
|
6
|
-
const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) => ESCAPES[char])}</div>` : "";
|
|
6
|
+
const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) => ESCAPES[char] ?? char)}</div>` : "";
|
|
7
7
|
try {
|
|
8
8
|
if (html && navigator.clipboard?.write && typeof ClipboardItem !== "undefined") {
|
|
9
9
|
await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([text], { type: "text/plain" }), "text/html": new Blob([html], { type: "text/html" }) })]);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
1
2
|
export function initConfirmDialog(app) {
|
|
2
3
|
const dialog = app.$("#confirmDialog"), message = app.$("#confirmMessage");
|
|
3
4
|
const accept = app.$("#btnAcceptConfirm"), cancel = app.$("#btnCancelConfirm");
|
|
@@ -18,6 +19,8 @@ export function initConfirmDialog(app) {
|
|
|
18
19
|
};
|
|
19
20
|
accept.addEventListener("click", () => close(true));
|
|
20
21
|
cancel.addEventListener("click", () => close(false));
|
|
22
|
+
// The backdrop is a cancel path; it must never accept the pending action.
|
|
23
|
+
closeOnBackdrop(dialog, () => close(false));
|
|
21
24
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(false); });
|
|
22
25
|
dialog.addEventListener("close", () => {
|
|
23
26
|
// A close from outside the buttons still settles the promise; a re-open in the
|
|
@@ -25,7 +25,7 @@ export function setCopyFeedback(button, app, copied) {
|
|
|
25
25
|
feedback.textContent = app.t(key);
|
|
26
26
|
button.setAttribute("aria-label", app.t(key));
|
|
27
27
|
button.title = app.t(key);
|
|
28
|
-
button._copyFeedbackTimer = setTimeout(() => {
|
|
28
|
+
button._copyFeedbackTimer = window.setTimeout(() => {
|
|
29
29
|
button.classList.remove("is-copied", "is-copy-failed");
|
|
30
30
|
button.setAttribute("aria-label", app.t("copyMessage"));
|
|
31
31
|
button.title = app.t("copyMessage");
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
1
2
|
// The rail "+" opens a large modal instead of a small popover, so the create
|
|
2
3
|
// form has room for its name, join policy, and inline validation.
|
|
3
4
|
export function initCreateRoomDialog(app) {
|
|
4
5
|
const dialog = app.$("#createRoomDialog");
|
|
5
6
|
const input = app.$("#inRoomNameChat");
|
|
7
|
+
const approval = app.$("#inApprovalRequiredChat");
|
|
6
8
|
const error = app.$("#createRoomError");
|
|
7
9
|
const trigger = app.$("#btnNewRoom");
|
|
8
10
|
if (!dialog || !input || !error || !trigger)
|
|
@@ -49,5 +51,10 @@ export function initCreateRoomDialog(app) {
|
|
|
49
51
|
});
|
|
50
52
|
app.$("#btnCloseCreateRoom")?.addEventListener("click", () => close());
|
|
51
53
|
app.$("#btnCancelCreateRoom")?.addEventListener("click", () => close());
|
|
54
|
+
// A typed name, a changed policy, or an in-flight create holds the form open.
|
|
55
|
+
closeOnBackdrop(dialog, () => {
|
|
56
|
+
if (!input.value && !approval?.checked && !app.state.joinBusy)
|
|
57
|
+
close();
|
|
58
|
+
});
|
|
52
59
|
input.addEventListener("input", app.hideCreateRoomError);
|
|
53
60
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createRandomId } from "./state.js";
|
|
2
2
|
import { iconNode } from "./icons.js";
|
|
3
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
3
4
|
const MIN_SCALE = .5, MAX_SCALE = 4, ZOOM_STEP = 1.25, FIT_PADDING = 24;
|
|
4
5
|
let mermaidReady = false, mermaidPalette = "";
|
|
5
6
|
const diagramSources = new WeakMap();
|
|
@@ -215,14 +216,9 @@ export function initDiagramViewer(app) {
|
|
|
215
216
|
return { width: width > 0 ? width : 640, height: height > 0 ? height : 420 };
|
|
216
217
|
}
|
|
217
218
|
const outside = (target) => target instanceof Element && target.closest(".diagram-viewer-toolbar");
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
dialog
|
|
221
|
-
dialog.addEventListener("click", (event) => {
|
|
222
|
-
if (event.target === dialog && dismissPress)
|
|
223
|
-
close();
|
|
224
|
-
dismissPress = false;
|
|
225
|
-
});
|
|
219
|
+
// Panning ends on the stage, never on the backdrop, so this only closes when
|
|
220
|
+
// the press and the release both land outside the dialog box.
|
|
221
|
+
closeOnBackdrop(dialog, close);
|
|
226
222
|
dialog.addEventListener("wheel", (event) => {
|
|
227
223
|
if (!dialog.open)
|
|
228
224
|
return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
2
2
|
import { docPreviewFormat, OFFICE_KINDS, OFFICE_PREVIEW_LIMIT, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
3
3
|
import { createCopyButton, copyResourceText } from "./copy-action.js";
|
|
4
|
+
import { closeOnBackdrop } from "./panels.js";
|
|
4
5
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
5
6
|
const MONACO_BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
6
7
|
const MONACO_STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
@@ -212,21 +213,41 @@ export function initDocPreview(app) {
|
|
|
212
213
|
// finish after the user has switched files; it must never touch the live body.
|
|
213
214
|
const host = document.createElement("div");
|
|
214
215
|
host.className = "office-preview";
|
|
215
|
-
|
|
216
|
+
if (width) {
|
|
217
|
+
// A reflow (resize, full screen) keeps the deck already on screen while the
|
|
218
|
+
// new one is laid out in a hidden, out-of-flow host, then swaps in one paint.
|
|
219
|
+
host.style.cssText = `position:fixed;left:0;top:0;visibility:hidden;pointer-events:none;width:${width}px;`;
|
|
220
|
+
body.append(host);
|
|
221
|
+
}
|
|
222
|
+
else
|
|
223
|
+
body.replaceChildren(host);
|
|
216
224
|
empty.hidden = true;
|
|
217
225
|
notice.hidden = true;
|
|
218
226
|
// The blob is already here, so download stays available while parsing or after a failure.
|
|
219
227
|
download.disabled = false;
|
|
220
228
|
const module = await import("/assets/chat/office-preview.js");
|
|
221
|
-
if (request !== token || render !== officeRender)
|
|
229
|
+
if (request !== token || render !== officeRender || !host.isConnected) {
|
|
230
|
+
host.remove();
|
|
222
231
|
return;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
await module.renderOffice(kind, data, host, {
|
|
235
|
+
width: width || undefined,
|
|
236
|
+
onProgress: () => { if (request === token && render === officeRender)
|
|
237
|
+
status.textContent = app.t("resourceLoading"); },
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
host.remove();
|
|
242
|
+
if (request === token && render === officeRender)
|
|
243
|
+
status.textContent = "";
|
|
244
|
+
throw error;
|
|
245
|
+
}
|
|
246
|
+
if (request !== token || render !== officeRender || !host.isConnected) {
|
|
247
|
+
host.remove();
|
|
229
248
|
return;
|
|
249
|
+
}
|
|
250
|
+
host.style.cssText = "";
|
|
230
251
|
body.replaceChildren(host);
|
|
231
252
|
if (kind === "pptx")
|
|
232
253
|
pptxWidth = Math.round(width || body.clientWidth);
|
|
@@ -242,7 +263,7 @@ export function initDocPreview(app) {
|
|
|
242
263
|
if (width < 200 || Math.abs(width - pptxWidth) < 8)
|
|
243
264
|
return;
|
|
244
265
|
clearTimeout(pptxTimer);
|
|
245
|
-
pptxTimer = setTimeout(() => {
|
|
266
|
+
pptxTimer = window.setTimeout(() => {
|
|
246
267
|
if (dialog.open && officeKind === "pptx" && blob) {
|
|
247
268
|
void renderOfficeDocument("pptx", blob, token, width).catch(() => undefined);
|
|
248
269
|
}
|
|
@@ -250,22 +271,26 @@ export function initDocPreview(app) {
|
|
|
250
271
|
};
|
|
251
272
|
if (typeof ResizeObserver === "function")
|
|
252
273
|
new ResizeObserver(resizePptx).observe(body);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
frame.src = objectUrl;
|
|
261
|
-
frame.addEventListener("error", () => {
|
|
274
|
+
// PDF and SVG bytes load through a blob URL; only an explicit element renders them.
|
|
275
|
+
const showBlob = (data, type, request, make) => {
|
|
276
|
+
objectUrl = URL.createObjectURL(data.type === type ? data : data.slice(0, data.size, type));
|
|
277
|
+
const node = make(objectUrl);
|
|
278
|
+
node.addEventListener("error", () => {
|
|
279
|
+
if (request !== token)
|
|
280
|
+
return; // a superseded blob must not clear the live preview
|
|
262
281
|
clearFrame();
|
|
263
282
|
body.textContent = "";
|
|
264
283
|
status.textContent = app.t("docPreviewFailed");
|
|
265
284
|
download.disabled = false;
|
|
266
285
|
}, { once: true });
|
|
267
|
-
body.
|
|
268
|
-
|
|
286
|
+
body.replaceChildren(node);
|
|
287
|
+
};
|
|
288
|
+
const renderPdf = (resource, data, request) => {
|
|
289
|
+
const frame = document.createElement("iframe");
|
|
290
|
+
frame.className = "doc-pdf-frame";
|
|
291
|
+
frame.title = resource.name;
|
|
292
|
+
copyButton.hidden = true;
|
|
293
|
+
showBlob(data, "application/pdf", request, (url) => { frame.src = url; return frame; });
|
|
269
294
|
dialog.classList.add("is-pdf");
|
|
270
295
|
languageLabel.textContent = "PDF";
|
|
271
296
|
languageLabel.hidden = false;
|
|
@@ -274,6 +299,20 @@ export function initDocPreview(app) {
|
|
|
274
299
|
status.textContent = "";
|
|
275
300
|
download.disabled = false;
|
|
276
301
|
};
|
|
302
|
+
// SVG decodes in an isolated image context: scripts do not run, external refs do not load.
|
|
303
|
+
const renderSvg = (resource, data, request) => {
|
|
304
|
+
const image = document.createElement("img");
|
|
305
|
+
image.className = "doc-svg-image";
|
|
306
|
+
image.alt = resource.name;
|
|
307
|
+
copyButton.hidden = true;
|
|
308
|
+
showBlob(data, "image/svg+xml", request, (url) => { image.src = url; return image; });
|
|
309
|
+
languageLabel.textContent = "SVG";
|
|
310
|
+
languageLabel.hidden = false;
|
|
311
|
+
empty.hidden = true;
|
|
312
|
+
notice.hidden = true;
|
|
313
|
+
status.textContent = "";
|
|
314
|
+
download.disabled = false;
|
|
315
|
+
};
|
|
277
316
|
const open = async (roomId, resource, source) => {
|
|
278
317
|
opener = source instanceof HTMLElement ? source : null;
|
|
279
318
|
openerResourceID = source instanceof HTMLElement ? source.dataset.previewResource || null : null;
|
|
@@ -327,7 +366,11 @@ export function initDocPreview(app) {
|
|
|
327
366
|
return;
|
|
328
367
|
}
|
|
329
368
|
if (format.kind === "pdf") {
|
|
330
|
-
renderPdf(resource, data);
|
|
369
|
+
renderPdf(resource, data, request);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (format.kind === "svg") {
|
|
373
|
+
renderSvg(resource, data, request);
|
|
331
374
|
return;
|
|
332
375
|
}
|
|
333
376
|
if (office) {
|
|
@@ -451,22 +494,19 @@ export function initDocPreview(app) {
|
|
|
451
494
|
fullscreenButton?.addEventListener("click", () => setFullscreen(!fullscreen));
|
|
452
495
|
download.addEventListener("click", downloadDocument);
|
|
453
496
|
// A drag that starts in the document and ends on the backdrop produces a click
|
|
454
|
-
// whose target is the dialog; only a press and release
|
|
455
|
-
|
|
456
|
-
dialog
|
|
457
|
-
|
|
458
|
-
if (event.target === dialog && dismissPress && !fullscreen && !dialog.classList.contains("is-pane"))
|
|
459
|
-
close();
|
|
460
|
-
dismissPress = false;
|
|
461
|
-
});
|
|
497
|
+
// whose target is the dialog; closeOnBackdrop only honors a press and release
|
|
498
|
+
// on the backdrop, and the pane and full screen have no backdrop to hit.
|
|
499
|
+
closeOnBackdrop(dialog, () => { if (!fullscreen && !dialog.classList.contains("is-pane"))
|
|
500
|
+
close(); });
|
|
462
501
|
const escapePreview = (event) => {
|
|
463
502
|
const key = event && "key" in event && typeof event.key === "string" ? event.key : "";
|
|
464
503
|
const altKey = Boolean(event && "altKey" in event && event.altKey);
|
|
465
504
|
if (!event || altKey || key !== "Escape" || !dialog.open)
|
|
466
505
|
return;
|
|
506
|
+
if (!fullscreen && dialog.classList.contains("is-pane"))
|
|
507
|
+
return; // docked panes leave Esc to the page
|
|
467
508
|
event.preventDefault();
|
|
468
509
|
event.stopPropagation();
|
|
469
|
-
// The first Esc leaves full screen; the next one closes the preview.
|
|
470
510
|
if (fullscreen)
|
|
471
511
|
setFullscreen(false);
|
|
472
512
|
else
|
|
@@ -474,7 +514,7 @@ export function initDocPreview(app) {
|
|
|
474
514
|
};
|
|
475
515
|
document.addEventListener("keydown", (event) => {
|
|
476
516
|
// Capture Escape while the preview is open: leaving full screen closes and
|
|
477
|
-
// reopens the dialog, and the reopened dialog must still
|
|
517
|
+
// reopens the dialog, and the reopened dialog must still apply its mode guard.
|
|
478
518
|
escapePreview(event);
|
|
479
519
|
}, true);
|
|
480
520
|
dialog.addEventListener("cancel", escapePreview);
|
|
@@ -15,7 +15,7 @@ export function editorText(editor, draft = false) {
|
|
|
15
15
|
if (editor.childNodes.length === 1 && editor.firstChild?.nodeName === "DIV" && editor.firstElementChild?.nodeName === "BR")
|
|
16
16
|
return "";
|
|
17
17
|
let value = "";
|
|
18
|
-
const block = (node) => node
|
|
18
|
+
const block = (node) => node?.nodeName === "DIV";
|
|
19
19
|
const walk = (node) => {
|
|
20
20
|
if (node.nodeType === Node.TEXT_NODE)
|
|
21
21
|
value += draft ? encodeDraftText(node.nodeValue ?? "") : node.nodeValue ?? "";
|
|
@@ -80,7 +80,7 @@ export function setEditorText(editor, value, draft = false) {
|
|
|
80
80
|
offset = pattern.lastIndex;
|
|
81
81
|
continue;
|
|
82
82
|
}
|
|
83
|
-
editor.append(createMention(editor, draft ? match[2] : match[1]));
|
|
83
|
+
editor.append(createMention(editor, (draft ? match[2] : match[1]) ?? ""));
|
|
84
84
|
offset = pattern.lastIndex;
|
|
85
85
|
}
|
|
86
86
|
appendText(editor, String(value).slice(offset));
|
|
@@ -113,7 +113,7 @@ export function editorSelectionOffsets(editor) {
|
|
|
113
113
|
return [offset(selected.startContainer, selected.startOffset, true), offset(selected.endContainer, selected.endOffset, false)];
|
|
114
114
|
}
|
|
115
115
|
function lengthBefore(root, target, position) {
|
|
116
|
-
const block = (node) => node
|
|
116
|
+
const block = (node) => node?.nodeName === "DIV";
|
|
117
117
|
const length = (node) => {
|
|
118
118
|
if (node instanceof Text)
|
|
119
119
|
return node.length;
|
|
@@ -128,6 +128,8 @@ function lengthBefore(root, target, position) {
|
|
|
128
128
|
let sum = 0;
|
|
129
129
|
for (let index = 0; index < until; index++) {
|
|
130
130
|
const child = parent.childNodes[index];
|
|
131
|
+
if (!child)
|
|
132
|
+
break;
|
|
131
133
|
if (index && (block(child) || block(parent.childNodes[index - 1])))
|
|
132
134
|
sum++;
|
|
133
135
|
if (!(block(child) && child.childNodes.length === 1 && child.firstChild?.nodeName === "BR"))
|
|
@@ -142,6 +144,8 @@ function lengthBefore(root, target, position) {
|
|
|
142
144
|
let total = 0;
|
|
143
145
|
for (let index = 0; index < node.childNodes.length; index++) {
|
|
144
146
|
const child = node.childNodes[index];
|
|
147
|
+
if (!child)
|
|
148
|
+
break;
|
|
145
149
|
if (index && (block(child) || block(node.childNodes[index - 1])))
|
|
146
150
|
total++;
|
|
147
151
|
if (child === target || child.contains(target))
|
|
@@ -208,7 +212,7 @@ function editorPoint(editor, offset) {
|
|
|
208
212
|
}
|
|
209
213
|
return [editor, editor.childNodes.length - 1];
|
|
210
214
|
}
|
|
211
|
-
const block = (node) => node
|
|
215
|
+
const block = (node) => node?.nodeName === "DIV";
|
|
212
216
|
let left = offset, point = null;
|
|
213
217
|
const visit = (node) => {
|
|
214
218
|
if (point)
|
|
@@ -241,6 +245,9 @@ function editorPoint(editor, offset) {
|
|
|
241
245
|
}
|
|
242
246
|
else
|
|
243
247
|
node.childNodes.forEach((child, index, all) => {
|
|
248
|
+
// An earlier match wins; a later block boundary must not move the caret.
|
|
249
|
+
if (point)
|
|
250
|
+
return;
|
|
244
251
|
if (index && (block(child) || block(all[index - 1]))) {
|
|
245
252
|
if (left === 0) {
|
|
246
253
|
point = [node, index];
|
|
@@ -261,9 +268,33 @@ function editorPoint(editor, offset) {
|
|
|
261
268
|
export function replaceEditorRange(editor, start, end, value, parseMentions = true) {
|
|
262
269
|
const emptyBefore = !editorText(editor);
|
|
263
270
|
setEditorSelection(editor, start, end);
|
|
264
|
-
|
|
265
|
-
|
|
271
|
+
// Plain text goes in as escaped HTML so newlines stay <br>. Chrome's
|
|
272
|
+
// insertText emits block DIVs, and a mention inserted at the end of such a
|
|
273
|
+
// block is lifted outside it, adding a phantom newline that redo repeats.
|
|
274
|
+
const plain = !parseMentions ? String(value) : null;
|
|
275
|
+
const trailingNewline = plain !== null && /(\r\n|\r|\n)$/.test(plain);
|
|
276
|
+
const pasteTail = trailingNewline ? createRandomId() : "";
|
|
277
|
+
const plainHTML = plain === null ? "" : textHTML(plain) + (pasteTail ? `<br data-chat-tail="true" data-chat-paste="${pasteTail}">` : "");
|
|
278
|
+
if (plain !== null && (plain
|
|
279
|
+
? document.execCommand("insertHTML", false, plainHTML)
|
|
280
|
+
: document.execCommand("insertText", false, ""))) {
|
|
281
|
+
if (emptyBefore && !trailingNewline)
|
|
266
282
|
trimTrailingBreak(editor);
|
|
283
|
+
// A caret between the pasted newline and its ignored tail BR makes undo
|
|
284
|
+
// leave the text behind; seat it after the tail instead.
|
|
285
|
+
const tail = pasteTail ? editor.querySelector(`br[data-chat-paste="${pasteTail}"]`) : null;
|
|
286
|
+
if (tail) {
|
|
287
|
+
tail.removeAttribute("data-chat-paste");
|
|
288
|
+
const text = document.createTextNode("");
|
|
289
|
+
tail.after(text);
|
|
290
|
+
const range = document.createRange(), selection = getSelection();
|
|
291
|
+
range.setStart(text, 0);
|
|
292
|
+
range.collapse(true);
|
|
293
|
+
selection?.removeAllRanges();
|
|
294
|
+
selection?.addRange(range);
|
|
295
|
+
}
|
|
296
|
+
else
|
|
297
|
+
setCaret(editor, start + plain.length);
|
|
267
298
|
editor.dataset.empty = editorText(editor) ? "false" : "true";
|
|
268
299
|
return;
|
|
269
300
|
}
|
|
@@ -273,9 +304,9 @@ export function replaceEditorRange(editor, start, end, value, parseMentions = tr
|
|
|
273
304
|
let html = "", cursor = 0, match;
|
|
274
305
|
while (token && (match = token.exec(content))) {
|
|
275
306
|
html += textHTML(content.slice(cursor, match.index));
|
|
276
|
-
const
|
|
307
|
+
const mention = match[1] ?? "", name = escapeHTML(mention), label = escapeHTML(chipLabel(editor, mention));
|
|
277
308
|
const chipID = createRandomId();
|
|
278
|
-
trustedChipNames.set(chipID,
|
|
309
|
+
trustedChipNames.set(chipID, mention);
|
|
279
310
|
html += `<span class="editor-mention" data-mention="${name}" data-chat-chip="${chipID}" data-insert-marker="${marker}" contenteditable="false" role="img" aria-label="Mention ${label}">@${label}</span>`;
|
|
280
311
|
cursor = token.lastIndex;
|
|
281
312
|
}
|
|
@@ -309,9 +340,17 @@ function trimTrailingBreak(editor) {
|
|
|
309
340
|
if (last?.nodeName === "BR")
|
|
310
341
|
last.remove();
|
|
311
342
|
}
|
|
343
|
+
// Chromium can leave an attribute-free DIV block behind (native paste or
|
|
344
|
+
// insertText). editorText() already models those, and rebuilding the editor
|
|
345
|
+
// here would clear the native undo stack. Every descendant is checked on its
|
|
346
|
+
// own, so a foreign node inside a DIV is still rejected.
|
|
347
|
+
function allowedNode(node) {
|
|
348
|
+
return node.tagName === "BR" || node.classList.contains("editor-mention")
|
|
349
|
+
|| node.hasAttribute("data-chat-auto-separator") || (node.tagName === "DIV" && node.attributes.length === 0);
|
|
350
|
+
}
|
|
312
351
|
function sanitizeEditor(editor) {
|
|
313
352
|
for (const node of editor.querySelectorAll("*")) {
|
|
314
|
-
if (
|
|
353
|
+
if (allowedNode(node))
|
|
315
354
|
continue;
|
|
316
355
|
const selection = getSelection(), range = selection?.rangeCount ? selection.getRangeAt(0) : null;
|
|
317
356
|
const [start, end] = editorSelectionOffsets(editor), text = editorText(editor);
|
|
@@ -332,7 +371,7 @@ function knownMentions(editor, text) {
|
|
|
332
371
|
return text.replace(/<at>@([^<]+)<\/at>/g, (token, name) => editor.isKnownMention && !editor.isKnownMention(name) ? `@${name}` : token);
|
|
333
372
|
}
|
|
334
373
|
const HTML_ESCAPES = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" };
|
|
335
|
-
function escapeHTML(text) { return String(text).replace(/[&<>"']/g, (char) => HTML_ESCAPES[char]); }
|
|
374
|
+
function escapeHTML(text) { return String(text).replace(/[&<>"']/g, (char) => HTML_ESCAPES[char] ?? char); }
|
|
336
375
|
function textHTML(text) { return escapeHTML(text).replace(/\r\n|\r|\n/g, "<br>"); }
|
|
337
376
|
function createMention(editor, name) {
|
|
338
377
|
const chip = document.createElement("span"), label = chipLabel(editor, name);
|