@alexsun-top/opencode-chat-room 0.8.1 → 0.8.2
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 +23 -0
- package/README.md +10 -10
- package/README.zh-CN.md +10 -10
- package/dist/cli.js +544 -88
- package/package.json +4 -4
- package/packages/chat-room-channeld/README.md +17 -12
- package/packages/chat-room-channeld/src/adapter.ts +145 -7
- package/packages/chat-room-channeld/src/host.ts +24 -9
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/protocol.ts +52 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/plugin.ts +1 -1
- package/server/assets/base.css +8 -2
- package/server/assets/chat/admin.js +0 -2
- package/server/assets/chat/announcements.js +2 -4
- package/server/assets/chat/chat-background.js +177 -0
- package/server/assets/chat/confirm-dialog.js +0 -1
- package/server/assets/chat/create-room-dialog.js +0 -1
- package/server/assets/chat/diagram-viewer.js +7 -1
- package/server/assets/chat/doc-preview.js +71 -15
- package/server/assets/chat/events.js +13 -5
- package/server/assets/chat/files.js +10 -6
- package/server/assets/chat/image-zoom.js +8 -1
- package/server/assets/chat/index.js +4 -2
- package/server/assets/chat/integration-account-schema.js +99 -0
- package/server/assets/chat/integration-editor.js +1 -1
- package/server/assets/chat/integrations.js +207 -57
- package/server/assets/chat/locales/de.js +1 -1
- package/server/assets/chat/locales/es.js +1 -1
- package/server/assets/chat/locales/fr.js +1 -1
- package/server/assets/chat/locales/it.js +1 -1
- package/server/assets/chat/locales/ja.js +1 -1
- package/server/assets/chat/locales/ko.js +1 -1
- package/server/assets/chat/markdown-footnotes.js +1 -1
- package/server/assets/chat/markdown.js +23 -0
- package/server/assets/chat/messages.js +1 -0
- package/server/assets/chat/palette.js +6 -1
- package/server/assets/chat/panels.js +23 -3
- package/server/assets/chat/receipts.js +2 -3
- package/server/assets/chat/reminders.js +2 -4
- package/server/assets/chat/replies.js +0 -6
- package/server/assets/chat/rooms.js +1 -6
- package/server/assets/chat/settings.js +69 -3
- package/server/assets/chat/shortcuts.js +0 -3
- package/server/assets/chat/side-pane.js +33 -8
- package/server/assets/chat/state.js +48 -18
- package/server/assets/chat/system-events.js +29 -3
- package/server/assets/chat/system-messages.js +9 -0
- package/server/assets/chat/tasks.js +2 -8
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +55 -12
- 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.html +71 -37
- package/server/manifest.webmanifest +1 -0
- package/server/sw.js +1 -0
- 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 +139 -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
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Personalized chat backgrounds are browser-local: no room or server state.
|
|
2
|
+
const GLOBAL_KEY = "chat.background";
|
|
3
|
+
const ROOM_PREFIX = "chat.background.room.";
|
|
4
|
+
const MAX_IMAGE_BYTES = 2 * 1024 * 1024;
|
|
5
|
+
const MAX_DATA_URL_LENGTH = Math.ceil((MAX_IMAGE_BYTES * 4) / 3) + 64;
|
|
6
|
+
const DEFAULT_OPACITY = 35;
|
|
7
|
+
|
|
8
|
+
const clampOpacity = (value) => {
|
|
9
|
+
const number = Number(value);
|
|
10
|
+
return Number.isFinite(number) ? Math.min(100, Math.max(0, Math.round(number))) : DEFAULT_OPACITY;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const normalize = (value) => {
|
|
14
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
15
|
+
const opacity = clampOpacity(value.opacity);
|
|
16
|
+
if (value.kind === "image" && typeof value.image === "string" && value.image.startsWith("data:image/") && value.image.length <= MAX_DATA_URL_LENGTH) {
|
|
17
|
+
const name = typeof value.name === "string" ? value.name.slice(0, 120) : "";
|
|
18
|
+
return { kind: "image", image: value.image, name, opacity };
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const readStored = () => {
|
|
24
|
+
try { return normalize(JSON.parse(localStorage.getItem(GLOBAL_KEY) || "null")); } catch { return null; }
|
|
25
|
+
};
|
|
26
|
+
const writeStored = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
if (value) localStorage.setItem(GLOBAL_KEY, JSON.stringify(value));
|
|
29
|
+
else localStorage.removeItem(GLOBAL_KEY);
|
|
30
|
+
return true;
|
|
31
|
+
} catch { return false; }
|
|
32
|
+
};
|
|
33
|
+
const clearStored = () => {
|
|
34
|
+
try {
|
|
35
|
+
localStorage.removeItem(GLOBAL_KEY);
|
|
36
|
+
const roomKeys = [];
|
|
37
|
+
for (let index = 0; index < localStorage.length; index++) {
|
|
38
|
+
const key = localStorage.key(index);
|
|
39
|
+
if (key?.startsWith(ROOM_PREFIX)) roomKeys.push(key);
|
|
40
|
+
}
|
|
41
|
+
for (const key of roomKeys) localStorage.removeItem(key);
|
|
42
|
+
} catch { /* Storage may be blocked; nothing to clear. */ }
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const readImage = (file) => new Promise((resolve, reject) => {
|
|
46
|
+
const reader = new FileReader();
|
|
47
|
+
reader.onload = () => typeof reader.result === "string" ? resolve(reader.result) : reject(new Error("image"));
|
|
48
|
+
reader.onerror = () => reject(reader.error || new Error("image"));
|
|
49
|
+
reader.readAsDataURL(file);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export function initChatBackground(app) {
|
|
53
|
+
const $ = app.$;
|
|
54
|
+
const dialog = $("#chatSettings");
|
|
55
|
+
const mode = $("#inChatBackgroundMode"), imageInput = $("#inChatBackgroundImage");
|
|
56
|
+
const opacity = $("#inChatBackgroundOpacity"), opacityValue = $("#chatBackgroundOpacityValue");
|
|
57
|
+
const imageField = $("#chatBackgroundImageField");
|
|
58
|
+
const opacityField = $("#chatBackgroundOpacityField");
|
|
59
|
+
const preview = $("#chatBackgroundPreview"), fileName = $("#chatBackgroundFileName");
|
|
60
|
+
const status = $("#chatBackgroundStatus");
|
|
61
|
+
if (!dialog || !mode || !imageInput || !opacity || !imageField || !opacityField || !preview || !status) return;
|
|
62
|
+
|
|
63
|
+
let previewURL = null;
|
|
64
|
+
const clearPreview = () => {
|
|
65
|
+
if (previewURL) { URL.revokeObjectURL(previewURL); previewURL = null; }
|
|
66
|
+
preview.hidden = true;
|
|
67
|
+
preview.removeAttribute("src");
|
|
68
|
+
if (fileName) { fileName.hidden = true; fileName.textContent = ""; }
|
|
69
|
+
};
|
|
70
|
+
const setPreview = (src, name) => {
|
|
71
|
+
if (previewURL) { URL.revokeObjectURL(previewURL); previewURL = null; }
|
|
72
|
+
preview.src = src;
|
|
73
|
+
preview.hidden = false;
|
|
74
|
+
if (fileName) {
|
|
75
|
+
fileName.textContent = name || "";
|
|
76
|
+
fileName.hidden = !name;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const setStatus = (key, values, error = false) => {
|
|
81
|
+
status.classList.toggle("is-error", error);
|
|
82
|
+
if (!key) { status.hidden = true; status.textContent = ""; return; }
|
|
83
|
+
app.setText(status, key, values);
|
|
84
|
+
status.hidden = false;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const syncPreview = (value) => {
|
|
88
|
+
if (value?.kind === "image" && typeof value.image === "string") setPreview(value.image, value.name);
|
|
89
|
+
else clearPreview();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const syncControls = (value) => {
|
|
93
|
+
mode.value = value?.kind === "image" ? "image" : "default";
|
|
94
|
+
opacity.value = String(value?.opacity ?? DEFAULT_OPACITY);
|
|
95
|
+
opacityValue.textContent = `${opacity.value}%`;
|
|
96
|
+
opacityField.hidden = mode.value !== "image";
|
|
97
|
+
imageField.hidden = mode.value !== "image";
|
|
98
|
+
syncPreview(value);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const apply = () => {
|
|
102
|
+
const value = readStored();
|
|
103
|
+
const root = document.documentElement;
|
|
104
|
+
root.classList.toggle("has-chat-background", Boolean(value));
|
|
105
|
+
root.dataset.chatBackground = value?.kind || "default";
|
|
106
|
+
if (!value) {
|
|
107
|
+
root.style.removeProperty("--chat-background-image");
|
|
108
|
+
root.style.removeProperty("--chat-background-opacity");
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
root.style.setProperty("--chat-background-image", `url("${value.image}")`);
|
|
112
|
+
root.style.setProperty("--chat-background-opacity", String(value.opacity / 100));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const persist = (value) => {
|
|
116
|
+
if (!writeStored(value)) return false;
|
|
117
|
+
apply();
|
|
118
|
+
return true;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const onModeChange = () => {
|
|
122
|
+
setStatus("");
|
|
123
|
+
const stored = readStored();
|
|
124
|
+
if (mode.value === "default") {
|
|
125
|
+
clearStored();
|
|
126
|
+
imageInput.value = "";
|
|
127
|
+
clearPreview();
|
|
128
|
+
apply();
|
|
129
|
+
syncControls({ kind: "default", opacity: stored?.opacity ?? clampOpacity(opacity.value) });
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
imageField.hidden = false;
|
|
133
|
+
syncControls(stored || { kind: "image", opacity: clampOpacity(opacity.value) });
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const onImageChange = async () => {
|
|
137
|
+
const file = imageInput.files?.[0];
|
|
138
|
+
if (!file) return;
|
|
139
|
+
const name = file.name || "image";
|
|
140
|
+
setStatus("chatBackgroundApplying", { name });
|
|
141
|
+
const objectURL = URL.createObjectURL(file);
|
|
142
|
+
setPreview(objectURL, name);
|
|
143
|
+
previewURL = objectURL;
|
|
144
|
+
if (!file.type.startsWith("image/")) { setStatus("chatBackgroundInvalidType", undefined, true); return; }
|
|
145
|
+
if (file.size > MAX_IMAGE_BYTES) { setStatus("chatBackgroundTooLarge", undefined, true); return; }
|
|
146
|
+
try {
|
|
147
|
+
const image = await readImage(file);
|
|
148
|
+
if (!persist({ kind: "image", image, name, opacity: clampOpacity(opacity.value) })) {
|
|
149
|
+
setStatus("chatBackgroundSaveFailed", undefined, true);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
syncControls(readStored());
|
|
153
|
+
setStatus("chatBackgroundApplied", { name });
|
|
154
|
+
} catch {
|
|
155
|
+
setStatus("chatBackgroundImageFailed", undefined, true);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
mode.addEventListener("change", onModeChange);
|
|
160
|
+
opacity.addEventListener("input", () => {
|
|
161
|
+
opacityValue.textContent = `${opacity.value}%`;
|
|
162
|
+
const stored = readStored();
|
|
163
|
+
if (stored) persist({ ...stored, opacity: clampOpacity(opacity.value) });
|
|
164
|
+
});
|
|
165
|
+
// Clearing before the picker opens keeps the chosen file name visible after
|
|
166
|
+
// selection while still allowing the same file to be chosen again.
|
|
167
|
+
imageInput.addEventListener("click", () => { imageInput.value = ""; });
|
|
168
|
+
imageInput.addEventListener("change", () => { void onImageChange(); });
|
|
169
|
+
dialog.addEventListener("toggle", () => {
|
|
170
|
+
if (!dialog.open) { clearPreview(); setStatus(""); return; }
|
|
171
|
+
syncControls(readStored());
|
|
172
|
+
setStatus("");
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
app.applyChatBackground = apply;
|
|
176
|
+
apply();
|
|
177
|
+
}
|
|
@@ -20,7 +20,6 @@ export function initConfirmDialog(app) {
|
|
|
20
20
|
accept.addEventListener("click", () => close(true));
|
|
21
21
|
cancel.addEventListener("click", () => close(false));
|
|
22
22
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(false); });
|
|
23
|
-
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(false); });
|
|
24
23
|
dialog.addEventListener("close", () => {
|
|
25
24
|
// A close from outside the buttons still settles the promise; a re-open in the
|
|
26
25
|
// same task leaves the dialog open, so the stale event must not clear it.
|
|
@@ -33,7 +33,6 @@ export function initCreateRoomDialog(app) {
|
|
|
33
33
|
};
|
|
34
34
|
app.closeCreateRoomDialog = (restore = true) => close(restore);
|
|
35
35
|
|
|
36
|
-
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
37
36
|
dialog.addEventListener("cancel", () => trigger.setAttribute("aria-expanded", "false"));
|
|
38
37
|
dialog.addEventListener("close", () => {
|
|
39
38
|
const target = opener, restore = restoreFocus;
|
|
@@ -181,7 +181,13 @@ export function initDiagramViewer(app) {
|
|
|
181
181
|
return { width: width > 0 ? width : 640, height: height > 0 ? height : 420 };
|
|
182
182
|
}
|
|
183
183
|
const outside = (target) => target?.closest?.(".diagram-viewer-toolbar");
|
|
184
|
-
|
|
184
|
+
// Only a press that began on the backdrop closes; a drag out of the canvas does not.
|
|
185
|
+
let dismissPress = false;
|
|
186
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
187
|
+
dialog.addEventListener("click", (event) => {
|
|
188
|
+
if (event.target === dialog && dismissPress) close();
|
|
189
|
+
dismissPress = false;
|
|
190
|
+
});
|
|
185
191
|
dialog.addEventListener("wheel", (event) => {
|
|
186
192
|
if (!dialog.open) return;
|
|
187
193
|
event.preventDefault();
|
|
@@ -3,9 +3,45 @@
|
|
|
3
3
|
import { formatBytes, renderMarkdown } from "./markdown.js";
|
|
4
4
|
import { docPreviewFormat, OFFICE_KINDS, OFFICE_PREVIEW_LIMIT, TEXT_PREVIEW_LIMIT } from "./resource-format.js";
|
|
5
5
|
import { createCopyButton, copyResourceText } from "./copy-action.js";
|
|
6
|
-
import { enhanceCodeElement } from "./shiki.js";
|
|
7
6
|
|
|
8
7
|
const PANE_QUERY = "(min-width: 1100px) and (min-height: 560px)";
|
|
8
|
+
const MONACO_BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
9
|
+
const MONACO_STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
10
|
+
let monacoPromise = null;
|
|
11
|
+
let codeEditor = null;
|
|
12
|
+
|
|
13
|
+
function loadMonaco() {
|
|
14
|
+
if (!monacoPromise) {
|
|
15
|
+
monacoPromise = import(MONACO_BUNDLE_URL)
|
|
16
|
+
.then((module) => {
|
|
17
|
+
if (!document.querySelector("link[data-doc-code-editor]")) {
|
|
18
|
+
const link = document.createElement("link");
|
|
19
|
+
link.rel = "stylesheet";
|
|
20
|
+
link.href = MONACO_STYLES_URL;
|
|
21
|
+
link.dataset.docCodeEditor = "true";
|
|
22
|
+
document.head.append(link);
|
|
23
|
+
}
|
|
24
|
+
return module;
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
// A blocked asset must not surface as an uncaught page error; the plain text view stays.
|
|
28
|
+
console.warn("Code preview editor unavailable; keeping the plain text view.", error);
|
|
29
|
+
throw error;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return monacoPromise;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fallback for a failed Monaco import: the same plain block the preview used before.
|
|
36
|
+
function plainCode(text, format) {
|
|
37
|
+
const pre = document.createElement("pre");
|
|
38
|
+
pre.className = "code-block doc-code";
|
|
39
|
+
const code = document.createElement("code");
|
|
40
|
+
code.className = format.language ? `language-${format.language}` : "";
|
|
41
|
+
code.textContent = text;
|
|
42
|
+
pre.append(code);
|
|
43
|
+
return pre;
|
|
44
|
+
}
|
|
9
45
|
|
|
10
46
|
export function initDocPreview(app) {
|
|
11
47
|
const dialog = app.$("#docPreview");
|
|
@@ -98,24 +134,38 @@ export function initDocPreview(app) {
|
|
|
98
134
|
const contentPath = (roomId, id) => `/rooms/${encodeURIComponent(roomId)}/resources/${encodeURIComponent(id)}/content`;
|
|
99
135
|
|
|
100
136
|
const clearFrame = () => {
|
|
137
|
+
codeEditor?.dispose();
|
|
138
|
+
codeEditor = null;
|
|
101
139
|
if (objectUrl) { URL.revokeObjectURL(objectUrl); objectUrl = null; }
|
|
102
|
-
dialog.classList.remove("is-pdf", "is-office");
|
|
140
|
+
dialog.classList.remove("is-pdf", "is-office", "is-code");
|
|
103
141
|
};
|
|
104
142
|
|
|
105
|
-
const renderText = (text, format) => {
|
|
143
|
+
const renderText = async (text, format, request) => {
|
|
106
144
|
copyButton.hidden = false;
|
|
107
145
|
languageLabel.textContent = format.label || "";
|
|
108
146
|
languageLabel.hidden = !format.label;
|
|
109
147
|
if (!text) { empty.hidden = false; return; }
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
code.textContent = text;
|
|
115
|
-
pre.append(code);
|
|
116
|
-
body.append(pre);
|
|
148
|
+
dialog.classList.add("is-code");
|
|
149
|
+
const host = document.createElement("div");
|
|
150
|
+
host.className = "doc-monaco";
|
|
151
|
+
body.append(host);
|
|
117
152
|
empty.hidden = true;
|
|
118
|
-
|
|
153
|
+
try {
|
|
154
|
+
const module = await loadMonaco();
|
|
155
|
+
// Another document or a close may have run while the import was pending.
|
|
156
|
+
if (request !== token || !dialog.open || !host.isConnected) return;
|
|
157
|
+
codeEditor = module.createCodePreviewEditor({
|
|
158
|
+
container: host,
|
|
159
|
+
value: text,
|
|
160
|
+
language: format.language || "plaintext",
|
|
161
|
+
});
|
|
162
|
+
} catch {
|
|
163
|
+
host.remove();
|
|
164
|
+
if (request !== token || !dialog.open) return;
|
|
165
|
+
// Let the plain block use the normal padded scroll area.
|
|
166
|
+
dialog.classList.remove("is-code");
|
|
167
|
+
body.append(plainCode(text, format));
|
|
168
|
+
}
|
|
119
169
|
};
|
|
120
170
|
|
|
121
171
|
const showTooLarge = (format) => {
|
|
@@ -175,7 +225,7 @@ export function initDocPreview(app) {
|
|
|
175
225
|
clearTimeout(pptxTimer);
|
|
176
226
|
pptxTimer = setTimeout(() => {
|
|
177
227
|
if (dialog.open && officeKind === "pptx" && blob) {
|
|
178
|
-
void renderOfficeDocument("pptx", blob, token, width);
|
|
228
|
+
void renderOfficeDocument("pptx", blob, token, width).catch(() => undefined);
|
|
179
229
|
}
|
|
180
230
|
}, 150);
|
|
181
231
|
};
|
|
@@ -253,7 +303,7 @@ export function initDocPreview(app) {
|
|
|
253
303
|
const text = await data.text();
|
|
254
304
|
if (request !== token) return;
|
|
255
305
|
rawText = text;
|
|
256
|
-
if (format.kind === "text") renderText(text, format);
|
|
306
|
+
if (format.kind === "text") void renderText(text, format, request);
|
|
257
307
|
else {
|
|
258
308
|
renderMarkdown(body, text, app);
|
|
259
309
|
empty.hidden = body.children.length > 0;
|
|
@@ -346,16 +396,22 @@ export function initDocPreview(app) {
|
|
|
346
396
|
|
|
347
397
|
app.openDocPreview = (roomId, resource, source) => { void open(roomId, resource, source); };
|
|
348
398
|
app.closeDocPreview = (restoreFocus = true) => close(restoreFocus);
|
|
399
|
+
app.registerDismissibleSurface?.("docPreview", { element: dialog, close: (restore = true) => close(restore) });
|
|
349
400
|
updateFullscreenButton();
|
|
350
401
|
|
|
351
402
|
app.$("#btnCloseDocPreview")?.addEventListener("click", () => close());
|
|
352
403
|
fullscreenButton?.addEventListener("click", () => setFullscreen(!fullscreen));
|
|
353
404
|
download.addEventListener("click", downloadDocument);
|
|
405
|
+
// A drag that starts in the document and ends on the backdrop produces a click
|
|
406
|
+
// whose target is the dialog; only a press and release on the backdrop closes.
|
|
407
|
+
let dismissPress = false;
|
|
408
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
354
409
|
dialog.addEventListener("click", (event) => {
|
|
355
|
-
if (event.target === dialog && !fullscreen && !dialog.classList.contains("is-pane")) close();
|
|
410
|
+
if (event.target === dialog && dismissPress && !fullscreen && !dialog.classList.contains("is-pane")) close();
|
|
411
|
+
dismissPress = false;
|
|
356
412
|
});
|
|
357
413
|
const escapePreview = (event) => {
|
|
358
|
-
if (!event || event.key !== "Escape" || !dialog.open) return;
|
|
414
|
+
if (!event || event.altKey || event.key !== "Escape" || !dialog.open) return;
|
|
359
415
|
event.preventDefault();
|
|
360
416
|
event.stopPropagation();
|
|
361
417
|
// The first Esc leaves full screen; the next one closes the preview.
|
|
@@ -258,10 +258,6 @@ export function initEvents(app) {
|
|
|
258
258
|
void app.refreshRoomList();
|
|
259
259
|
});
|
|
260
260
|
$("#btnCancelToken").addEventListener("click", () => $("#tokenBox").close());
|
|
261
|
-
$("#tokenBox").addEventListener("close", () => {
|
|
262
|
-
if (LS.token) return;
|
|
263
|
-
try { sessionStorage.setItem("chat.keyPromptDismissed", "1"); } catch { /* Storage may be blocked. */ }
|
|
264
|
-
});
|
|
265
261
|
$("#btnRefreshRooms").addEventListener("click", () => void app.refreshRoomList());
|
|
266
262
|
$("#btnNewRoom").addEventListener("click", () => app.openCreateRoomDialog());
|
|
267
263
|
$("#railRoomForm").addEventListener("submit", (event) => { event.preventDefault(); void app.createRoom(); });
|
|
@@ -335,6 +331,9 @@ export function initEvents(app) {
|
|
|
335
331
|
// Trackpad pinch arrives as Ctrl/Cmd + wheel. Blocking it at a scroll
|
|
336
332
|
// edge would also block browser zoom-out.
|
|
337
333
|
if (event.ctrlKey || event.metaKey) return;
|
|
334
|
+
// While pinch-zoomed the default wheel action pans the visual viewport.
|
|
335
|
+
// The document itself never overflows, so preventing it would freeze the page.
|
|
336
|
+
if (Math.abs((window.visualViewport?.scale ?? 1) - 1) > 0.01) return;
|
|
338
337
|
markScrollIntent();
|
|
339
338
|
const gap = thread.scrollHeight - thread.clientHeight - thread.scrollTop;
|
|
340
339
|
if (event.deltaY < 0 && thread.scrollTop <= 0 || event.deltaY > 0 && gap <= 2) event.preventDefault();
|
|
@@ -430,14 +429,23 @@ export function initEvents(app) {
|
|
|
430
429
|
});
|
|
431
430
|
});
|
|
432
431
|
|
|
432
|
+
// A press inside a dialog released over the backdrop dispatches click to the
|
|
433
|
+
// dialog's common ancestor (body), so it used to read as an outside click and
|
|
434
|
+
// close the dialog through closePanels. Only a press that started outside may.
|
|
435
|
+
let pressInDialog = false;
|
|
436
|
+
document.addEventListener("pointerdown", (event) => {
|
|
437
|
+
pressInDialog = Boolean(event.target.closest?.("dialog[open]"));
|
|
438
|
+
}, true);
|
|
433
439
|
document.addEventListener("click", (event) => {
|
|
440
|
+
const releasedFromDialog = pressInDialog && !event.target.closest?.("dialog");
|
|
441
|
+
pressInDialog = false;
|
|
434
442
|
const save = event.target.closest("[data-token-save]");
|
|
435
443
|
if (save) {
|
|
436
444
|
saveAccessToken(save, app);
|
|
437
445
|
return;
|
|
438
446
|
}
|
|
439
447
|
if (app.mentionActive && !event.target.closest("#mentionPicker")) app.closeMention();
|
|
440
|
-
if (!event.target.closest(".anchor, dialog")) app.closePanels();
|
|
448
|
+
if (!releasedFromDialog && !event.target.closest(".anchor, dialog")) app.closePanels();
|
|
441
449
|
});
|
|
442
450
|
let lastEscapeAt = -Infinity;
|
|
443
451
|
document.addEventListener("keydown", (event) => {
|
|
@@ -25,7 +25,7 @@ export function initFiles(app) {
|
|
|
25
25
|
const empty = $("#filesEmpty"), error = $("#filesError"), more = $("#btnFilesMore");
|
|
26
26
|
const roomName = $("#filesRoomName"), heading = $("#filesHeading"), trigger = $("#btnFiles"), chatView = $("#chatView");
|
|
27
27
|
let items = [], total = 0, loading = false, generation = 0, opener = null, preview = null, previewToken = 0;
|
|
28
|
-
let pendingReopen = false;
|
|
28
|
+
let pendingReopen = false, restoreFocus = true;
|
|
29
29
|
|
|
30
30
|
const mediaKind = (mime) => /^image\//.test(mime || "") ? "image"
|
|
31
31
|
: /^audio\//.test(mime || "") ? "audio"
|
|
@@ -359,22 +359,24 @@ export function initFiles(app) {
|
|
|
359
359
|
};
|
|
360
360
|
app.openFilesDialog = open;
|
|
361
361
|
|
|
362
|
-
const close = () => {
|
|
362
|
+
const close = (restore = true) => {
|
|
363
|
+
restoreFocus = restore;
|
|
364
|
+
if (dialog.open) dialog.close();
|
|
365
|
+
};
|
|
363
366
|
|
|
364
367
|
trigger?.addEventListener("click", () => { app.closePanels(); open(); });
|
|
365
368
|
$("#btnCloseFiles")?.addEventListener("click", close);
|
|
366
369
|
document.addEventListener("keydown", (event) => {
|
|
367
|
-
if (event.key !== "Escape" || !dialog.open || !dialog.classList.contains("is-pane")) return;
|
|
370
|
+
if (event.key !== "Escape" || event.altKey || !dialog.open || !dialog.classList.contains("is-pane")) return;
|
|
368
371
|
if (!dialog.contains(document.activeElement)) return;
|
|
369
372
|
event.preventDefault();
|
|
370
373
|
close();
|
|
371
374
|
});
|
|
372
|
-
app.registerPanelSurface?.("files", { close });
|
|
375
|
+
app.registerPanelSurface?.("files", { element: dialog, close: (restore = true) => close(restore) });
|
|
373
376
|
app.watchPanel?.("files", syncMode);
|
|
374
377
|
$("#btnRefreshFiles")?.addEventListener("click", () => void load(true));
|
|
375
378
|
more.addEventListener("click", () => void load(false));
|
|
376
379
|
select.addEventListener("change", render);
|
|
377
|
-
dialog.addEventListener("click", (event) => { if (event.target === dialog) close(); });
|
|
378
380
|
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(); });
|
|
379
381
|
dialog.addEventListener("close", () => {
|
|
380
382
|
// close() queues this event; a rapid reopen can land before it runs, and
|
|
@@ -396,7 +398,9 @@ export function initFiles(app) {
|
|
|
396
398
|
const target = opener;
|
|
397
399
|
opener = null;
|
|
398
400
|
// A document preview opens right after the file list closes; keep focus there.
|
|
399
|
-
|
|
401
|
+
const focus = restoreFocus;
|
|
402
|
+
restoreFocus = true;
|
|
403
|
+
if (focus && target?.isConnected && !document.querySelector("dialog[open]")) target.focus({ preventScroll: true });
|
|
400
404
|
});
|
|
401
405
|
list.addEventListener("click", (event) => {
|
|
402
406
|
const button = event.target.closest?.("[data-file-action]");
|
|
@@ -91,7 +91,14 @@ export function initImageZoom(app) {
|
|
|
91
91
|
open(image);
|
|
92
92
|
});
|
|
93
93
|
app.$("#btnCloseImage")?.addEventListener("click", close);
|
|
94
|
-
|
|
94
|
+
// A backdrop click closes, but a drag that started inside the viewer and was
|
|
95
|
+
// released on the backdrop does not: the click target would be the dialog then.
|
|
96
|
+
let dismissPress = false;
|
|
97
|
+
dialog.addEventListener("pointerdown", (event) => { dismissPress = event.target === dialog; });
|
|
98
|
+
dialog.addEventListener("click", (event) => {
|
|
99
|
+
if (event.target === dialog && dismissPress) close();
|
|
100
|
+
dismissPress = false;
|
|
101
|
+
});
|
|
95
102
|
// The viewer owns the wheel while it is open so the thread behind it cannot scroll.
|
|
96
103
|
dialog.addEventListener("wheel", (event) => {
|
|
97
104
|
if (!dialog.open) return;
|
|
@@ -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,15 @@ 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
|
+
import { initWindowControls } from "./window-controls.js";
|
|
34
35
|
|
|
35
36
|
if (isMobileDevice()) document.documentElement.dataset.mobile = "true";
|
|
36
37
|
|
|
38
|
+
initWindowControls();
|
|
37
39
|
initSettings(app);
|
|
40
|
+
initChatBackground(app);
|
|
38
41
|
initIntegrations(app);
|
|
39
42
|
initConfirmDialog(app);
|
|
40
43
|
initDiagramViewer(app);
|
|
@@ -50,7 +53,6 @@ initHistoryLoader(app);
|
|
|
50
53
|
initSearch(app);
|
|
51
54
|
initQuestions(app);
|
|
52
55
|
initReplies(app);
|
|
53
|
-
initForward(app);
|
|
54
56
|
initRecall(app);
|
|
55
57
|
initEvents(app);
|
|
56
58
|
initShortcuts(app);
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Account form generated from the JSON Schema a plugin declares in initialize.
|
|
2
|
+
const CONTROL = { string: "text", secret: "password", number: "number" };
|
|
3
|
+
|
|
4
|
+
function textFor(field, fallback) {
|
|
5
|
+
return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function addField(container, field, existing, stored, text) {
|
|
9
|
+
const label = document.createElement("label");
|
|
10
|
+
label.className = "field integration-schema-field";
|
|
11
|
+
const caption = document.createElement("span");
|
|
12
|
+
caption.className = "field-label";
|
|
13
|
+
caption.textContent = textFor(field, field.key);
|
|
14
|
+
if (field.required) {
|
|
15
|
+
const required = document.createElement("span");
|
|
16
|
+
required.className = "integration-required";
|
|
17
|
+
required.textContent = " *";
|
|
18
|
+
caption.append(required);
|
|
19
|
+
}
|
|
20
|
+
let control;
|
|
21
|
+
if (field.type === "boolean" || field.type === "select") {
|
|
22
|
+
control = document.createElement("select");
|
|
23
|
+
control.className = "input";
|
|
24
|
+
const blank = document.createElement("option");
|
|
25
|
+
blank.value = "";
|
|
26
|
+
blank.textContent = existing
|
|
27
|
+
? (stored ? text("integrationsKeepStored") : text("integrationsNotSet"))
|
|
28
|
+
: "";
|
|
29
|
+
control.append(blank);
|
|
30
|
+
const options = field.type === "boolean"
|
|
31
|
+
? [{ value: "1", label: "True" }, { value: "0", label: "False" }]
|
|
32
|
+
: Array.isArray(field.options) ? field.options : [];
|
|
33
|
+
for (const option of options) {
|
|
34
|
+
const node = document.createElement("option");
|
|
35
|
+
node.value = String(option.value);
|
|
36
|
+
node.textContent = typeof option.label === "string" && option.label ? option.label : String(option.value);
|
|
37
|
+
control.append(node);
|
|
38
|
+
}
|
|
39
|
+
if (!existing && typeof field.default === "string" && field.default !== "") {
|
|
40
|
+
control.value = field.type === "boolean"
|
|
41
|
+
? (["1", "true", "on", "yes"].includes(field.default.toLowerCase()) ? "1" : "0")
|
|
42
|
+
: field.default;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
control = document.createElement("input");
|
|
46
|
+
control.className = "input";
|
|
47
|
+
control.type = CONTROL[field.type] || "text";
|
|
48
|
+
control.autocomplete = field.type === "secret" ? "new-password" : "off";
|
|
49
|
+
if (existing) control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
|
|
50
|
+
else if (typeof field.default === "string") control.value = field.default;
|
|
51
|
+
}
|
|
52
|
+
control.dataset.accountKey = field.key;
|
|
53
|
+
control.dataset.accountType = field.type || "string";
|
|
54
|
+
control.dataset.accountRequired = field.required ? "1" : "0";
|
|
55
|
+
control.dataset.accountStored = stored ? "1" : "0";
|
|
56
|
+
label.append(caption, control);
|
|
57
|
+
if (typeof field.description === "string" && field.description.trim()) {
|
|
58
|
+
const hint = document.createElement("span");
|
|
59
|
+
hint.className = "hint";
|
|
60
|
+
hint.textContent = field.description;
|
|
61
|
+
label.append(hint);
|
|
62
|
+
}
|
|
63
|
+
container.append(label);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function renderAccountSchema(container, plugin, account, text) {
|
|
67
|
+
container.textContent = "";
|
|
68
|
+
const fields = Array.isArray(plugin?.account?.schema) ? plugin.account.schema : [];
|
|
69
|
+
container.hidden = fields.length === 0;
|
|
70
|
+
if (!fields.length) return;
|
|
71
|
+
const existing = Boolean(account);
|
|
72
|
+
const stored = new Set(account?.envKeys || []);
|
|
73
|
+
for (const field of fields) {
|
|
74
|
+
if (!field || typeof field.key !== "string") continue;
|
|
75
|
+
addField(container, field, existing, stored.has(field.key), text);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Values still land in the account env map; blank means "keep stored". */
|
|
80
|
+
export function readAccountSchema(container, text) {
|
|
81
|
+
const values = {};
|
|
82
|
+
const keys = new Set();
|
|
83
|
+
const missing = [];
|
|
84
|
+
for (const control of container.querySelectorAll("[data-account-key]")) {
|
|
85
|
+
const key = control.dataset.accountKey;
|
|
86
|
+
keys.add(key);
|
|
87
|
+
const value = String(control.value ?? "").trim();
|
|
88
|
+
if (value !== "") {
|
|
89
|
+
values[key] = value;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (control.dataset.accountRequired === "1" && control.dataset.accountStored !== "1") {
|
|
93
|
+
const label = control.closest(".integration-schema-field")?.querySelector(".field-label")?.textContent || key;
|
|
94
|
+
missing.push(label.replace(/\s*\*$/, ""));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (missing.length) throw new Error(text("integrationsAccountRequired", { fields: missing.join(", ") }));
|
|
98
|
+
return { values, keys };
|
|
99
|
+
}
|
|
@@ -45,7 +45,7 @@ export function initIntegrationEditor(app, options) {
|
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
const updateFormatButtons = () => {
|
|
48
|
-
const active = controller?.getFormat() || "
|
|
48
|
+
const active = controller?.getFormat() || "yaml";
|
|
49
49
|
for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
|
|
50
50
|
button.setAttribute("aria-pressed", String(button.dataset.format === active));
|
|
51
51
|
}
|