@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +141 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
const clampOpacity = (value) => {
|
|
8
|
+
const number = Number(value);
|
|
9
|
+
return Number.isFinite(number) ? Math.min(100, Math.max(0, Math.round(number))) : DEFAULT_OPACITY;
|
|
10
|
+
};
|
|
11
|
+
const normalize = (value) => {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
13
|
+
return null;
|
|
14
|
+
const opacity = clampOpacity(value.opacity);
|
|
15
|
+
if (value.kind === "image" && typeof value.image === "string" && value.image.startsWith("data:image/") && value.image.length <= MAX_DATA_URL_LENGTH) {
|
|
16
|
+
const name = typeof value.name === "string" ? value.name.slice(0, 120) : "";
|
|
17
|
+
return { kind: "image", image: value.image, name, opacity };
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
const readStored = () => {
|
|
22
|
+
try {
|
|
23
|
+
return normalize(JSON.parse(localStorage.getItem(GLOBAL_KEY) || "null"));
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const writeStored = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
if (value)
|
|
32
|
+
localStorage.setItem(GLOBAL_KEY, JSON.stringify(value));
|
|
33
|
+
else
|
|
34
|
+
localStorage.removeItem(GLOBAL_KEY);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const clearStored = () => {
|
|
42
|
+
try {
|
|
43
|
+
localStorage.removeItem(GLOBAL_KEY);
|
|
44
|
+
const roomKeys = [];
|
|
45
|
+
for (let index = 0; index < localStorage.length; index++) {
|
|
46
|
+
const key = localStorage.key(index);
|
|
47
|
+
if (key?.startsWith(ROOM_PREFIX))
|
|
48
|
+
roomKeys.push(key);
|
|
49
|
+
}
|
|
50
|
+
for (const key of roomKeys)
|
|
51
|
+
localStorage.removeItem(key);
|
|
52
|
+
}
|
|
53
|
+
catch { /* Storage may be blocked; nothing to clear. */ }
|
|
54
|
+
};
|
|
55
|
+
const readImage = (file) => new Promise((resolve, reject) => {
|
|
56
|
+
const reader = new FileReader();
|
|
57
|
+
reader.onload = () => typeof reader.result === "string" ? resolve(reader.result) : reject(new Error("image"));
|
|
58
|
+
reader.onerror = () => reject(reader.error || new Error("image"));
|
|
59
|
+
reader.readAsDataURL(file);
|
|
60
|
+
});
|
|
61
|
+
export function initChatBackground(app) {
|
|
62
|
+
const $ = app.$;
|
|
63
|
+
const dialog = $("#chatSettings");
|
|
64
|
+
const mode = $("#inChatBackgroundMode"), imageInput = $("#inChatBackgroundImage");
|
|
65
|
+
const opacity = $("#inChatBackgroundOpacity"), opacityValue = $("#chatBackgroundOpacityValue");
|
|
66
|
+
const imageField = $("#chatBackgroundImageField");
|
|
67
|
+
const opacityField = $("#chatBackgroundOpacityField");
|
|
68
|
+
const preview = $("#chatBackgroundPreview"), fileName = $("#chatBackgroundFileName");
|
|
69
|
+
const status = $("#chatBackgroundStatus");
|
|
70
|
+
if (!dialog || !mode || !imageInput || !opacity || !imageField || !opacityField || !preview || !status)
|
|
71
|
+
return;
|
|
72
|
+
let previewURL = null;
|
|
73
|
+
const clearPreview = () => {
|
|
74
|
+
if (previewURL) {
|
|
75
|
+
URL.revokeObjectURL(previewURL);
|
|
76
|
+
previewURL = null;
|
|
77
|
+
}
|
|
78
|
+
preview.hidden = true;
|
|
79
|
+
preview.removeAttribute("src");
|
|
80
|
+
if (fileName) {
|
|
81
|
+
fileName.hidden = true;
|
|
82
|
+
fileName.textContent = "";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const setPreview = (src, name) => {
|
|
86
|
+
if (previewURL) {
|
|
87
|
+
URL.revokeObjectURL(previewURL);
|
|
88
|
+
previewURL = null;
|
|
89
|
+
}
|
|
90
|
+
preview.src = src;
|
|
91
|
+
preview.hidden = false;
|
|
92
|
+
if (fileName) {
|
|
93
|
+
fileName.textContent = name || "";
|
|
94
|
+
fileName.hidden = !name;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const setStatus = (key, values, error = false) => {
|
|
98
|
+
status.classList.toggle("is-error", error);
|
|
99
|
+
if (!key) {
|
|
100
|
+
status.hidden = true;
|
|
101
|
+
status.textContent = "";
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
app.setText(status, key, values);
|
|
105
|
+
status.hidden = false;
|
|
106
|
+
};
|
|
107
|
+
const syncPreview = (value) => {
|
|
108
|
+
if (value?.kind === "image" && typeof value.image === "string")
|
|
109
|
+
setPreview(value.image, value.name);
|
|
110
|
+
else
|
|
111
|
+
clearPreview();
|
|
112
|
+
};
|
|
113
|
+
const syncControls = (value) => {
|
|
114
|
+
mode.value = value?.kind === "image" ? "image" : "default";
|
|
115
|
+
opacity.value = String(value?.opacity ?? DEFAULT_OPACITY);
|
|
116
|
+
opacityValue.textContent = `${opacity.value}%`;
|
|
117
|
+
opacityField.hidden = mode.value !== "image";
|
|
118
|
+
imageField.hidden = mode.value !== "image";
|
|
119
|
+
syncPreview(value);
|
|
120
|
+
};
|
|
121
|
+
const apply = () => {
|
|
122
|
+
const value = readStored();
|
|
123
|
+
const root = document.documentElement;
|
|
124
|
+
root.classList.toggle("has-chat-background", Boolean(value));
|
|
125
|
+
root.dataset.chatBackground = value?.kind || "default";
|
|
126
|
+
if (!value) {
|
|
127
|
+
root.style.removeProperty("--chat-background-image");
|
|
128
|
+
root.style.removeProperty("--chat-background-opacity");
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
root.style.setProperty("--chat-background-image", `url("${value.image}")`);
|
|
132
|
+
root.style.setProperty("--chat-background-opacity", String(value.opacity / 100));
|
|
133
|
+
};
|
|
134
|
+
const persist = (value) => {
|
|
135
|
+
if (!writeStored(value))
|
|
136
|
+
return false;
|
|
137
|
+
apply();
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
const onModeChange = () => {
|
|
141
|
+
setStatus("");
|
|
142
|
+
const stored = readStored();
|
|
143
|
+
if (mode.value === "default") {
|
|
144
|
+
clearStored();
|
|
145
|
+
imageInput.value = "";
|
|
146
|
+
clearPreview();
|
|
147
|
+
apply();
|
|
148
|
+
syncControls({ kind: "default", opacity: stored?.opacity ?? clampOpacity(opacity.value) });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
imageField.hidden = false;
|
|
152
|
+
syncControls(stored || { kind: "image", opacity: clampOpacity(opacity.value) });
|
|
153
|
+
};
|
|
154
|
+
const onImageChange = async () => {
|
|
155
|
+
const file = imageInput.files?.[0];
|
|
156
|
+
if (!file)
|
|
157
|
+
return;
|
|
158
|
+
const name = file.name || "image";
|
|
159
|
+
setStatus("chatBackgroundApplying", { name });
|
|
160
|
+
const objectURL = URL.createObjectURL(file);
|
|
161
|
+
setPreview(objectURL, name);
|
|
162
|
+
previewURL = objectURL;
|
|
163
|
+
if (!file.type.startsWith("image/")) {
|
|
164
|
+
setStatus("chatBackgroundInvalidType", undefined, true);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (file.size > MAX_IMAGE_BYTES) {
|
|
168
|
+
setStatus("chatBackgroundTooLarge", undefined, true);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
const image = await readImage(file);
|
|
173
|
+
if (!persist({ kind: "image", image, name, opacity: clampOpacity(opacity.value) })) {
|
|
174
|
+
setStatus("chatBackgroundSaveFailed", undefined, true);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
syncControls(readStored());
|
|
178
|
+
setStatus("chatBackgroundApplied", { name });
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
setStatus("chatBackgroundImageFailed", undefined, true);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
mode.addEventListener("change", onModeChange);
|
|
185
|
+
opacity.addEventListener("input", () => {
|
|
186
|
+
opacityValue.textContent = `${opacity.value}%`;
|
|
187
|
+
const stored = readStored();
|
|
188
|
+
if (stored)
|
|
189
|
+
persist({ ...stored, opacity: clampOpacity(opacity.value) });
|
|
190
|
+
});
|
|
191
|
+
// Clearing before the picker opens keeps the chosen file name visible after
|
|
192
|
+
// selection while still allowing the same file to be chosen again.
|
|
193
|
+
imageInput.addEventListener("click", () => { imageInput.value = ""; });
|
|
194
|
+
imageInput.addEventListener("change", () => { void onImageChange(); });
|
|
195
|
+
dialog.addEventListener("toggle", () => {
|
|
196
|
+
if (!dialog.open) {
|
|
197
|
+
clearPreview();
|
|
198
|
+
setStatus("");
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
syncControls(readStored());
|
|
202
|
+
setStatus("");
|
|
203
|
+
});
|
|
204
|
+
app.applyChatBackground = apply;
|
|
205
|
+
apply();
|
|
206
|
+
}
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
// Clipboard writes with a legacy fallback for browsers or permissions that block
|
|
2
2
|
// the async Clipboard API. Mention copy keeps its marker HTML for later pastes.
|
|
3
3
|
export async function copyTextToClipboard(text, mentionSource = false) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
// The HTML marker lets a later paste rebuild mention chips; unmarked external text stays literal.
|
|
5
|
+
const html = mentionSource ? `<div data-chatroom-mentions>${String(text).replace(/[&<>"]/g, (char) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[char])}</div>` : "";
|
|
6
|
+
try {
|
|
7
|
+
if (html && navigator.clipboard?.write && typeof ClipboardItem !== "undefined") {
|
|
8
|
+
await navigator.clipboard.write([new ClipboardItem({ "text/plain": new Blob([text], { type: "text/plain" }), "text/html": new Blob([html], { type: "text/html" }) })]);
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (navigator.clipboard?.writeText) {
|
|
12
|
+
await navigator.clipboard.writeText(text);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
catch { /* Use the legacy clipboard command when permission is unavailable. */ }
|
|
17
|
+
const field = document.createElement(html ? "div" : "textarea"), selection = getSelection(), active = document.activeElement;
|
|
18
|
+
const ranges = selection ? Array.from({ length: selection.rangeCount }, (_, index) => selection.getRangeAt(index).cloneRange()) : [];
|
|
19
|
+
if (html) {
|
|
20
|
+
field.contentEditable = "true";
|
|
21
|
+
field.innerHTML = html;
|
|
14
22
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
else
|
|
24
|
+
field.value = text;
|
|
25
|
+
field.setAttribute("readonly", "");
|
|
26
|
+
field.style.cssText = "position:fixed;left:-9999px;top:0";
|
|
27
|
+
document.body.append(field);
|
|
28
|
+
if (html && selection) {
|
|
29
|
+
const range = document.createRange();
|
|
30
|
+
range.selectNodeContents(field);
|
|
31
|
+
selection.removeAllRanges();
|
|
32
|
+
selection.addRange(range);
|
|
33
|
+
}
|
|
34
|
+
else if (!html)
|
|
35
|
+
field.select();
|
|
36
|
+
let copied = false;
|
|
37
|
+
try {
|
|
38
|
+
copied = document.execCommand("copy");
|
|
39
|
+
}
|
|
40
|
+
catch { /* Clipboard access may be disabled. */ }
|
|
41
|
+
field.remove();
|
|
42
|
+
if (selection) {
|
|
43
|
+
selection.removeAllRanges();
|
|
44
|
+
ranges.forEach((range) => selection.addRange(range));
|
|
45
|
+
}
|
|
46
|
+
if (active instanceof HTMLElement)
|
|
47
|
+
active.focus({ preventScroll: true });
|
|
48
|
+
return copied;
|
|
49
|
+
}
|
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
// One shared confirmation dialog replaces the browser's native confirmation
|
|
2
2
|
// window, so a destructive action stays inside the page.
|
|
3
3
|
export function initConfirmDialog(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
|
-
|
|
4
|
+
const dialog = app.$("#confirmDialog"), message = app.$("#confirmMessage");
|
|
5
|
+
const accept = app.$("#btnAcceptConfirm"), cancel = app.$("#btnCancelConfirm");
|
|
6
|
+
let pending = null, opener = null;
|
|
7
|
+
const settle = (value) => { const resolve = pending; pending = null; resolve?.(value); };
|
|
8
|
+
function close(value) { settle(value); dialog.close(); }
|
|
9
|
+
app.confirmAction = (text) => {
|
|
10
|
+
// One dialog at a time: a newer request dismisses the open one as cancelled.
|
|
11
|
+
if (dialog.open)
|
|
12
|
+
close(false);
|
|
13
|
+
opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
14
|
+
message.textContent = text;
|
|
15
|
+
dialog.showModal();
|
|
16
|
+
cancel.focus();
|
|
17
|
+
return new Promise((resolve) => { pending = resolve; });
|
|
18
|
+
};
|
|
19
|
+
accept.addEventListener("click", () => close(true));
|
|
20
|
+
cancel.addEventListener("click", () => close(false));
|
|
21
|
+
dialog.addEventListener("cancel", (event) => { event.preventDefault(); close(false); });
|
|
22
|
+
dialog.addEventListener("close", () => {
|
|
23
|
+
// A close from outside the buttons still settles the promise; a re-open in the
|
|
24
|
+
// same task leaves the dialog open, so the stale event must not clear it.
|
|
25
|
+
if (dialog.open)
|
|
26
|
+
return;
|
|
27
|
+
settle(false);
|
|
28
|
+
message.textContent = "";
|
|
29
|
+
const target = opener;
|
|
30
|
+
opener = null;
|
|
31
|
+
requestAnimationFrame(() => {
|
|
32
|
+
if (dialog.open)
|
|
33
|
+
return;
|
|
34
|
+
if (app.focusChatComposer?.({ force: true }))
|
|
35
|
+
return;
|
|
36
|
+
if (target?.isConnected && target.getClientRects().length)
|
|
37
|
+
target.focus({ preventScroll: true });
|
|
38
|
+
});
|
|
36
39
|
});
|
|
37
|
-
|
|
38
|
-
}
|
|
40
|
+
}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
// Copy buttons for resource cards, the file list, and the preview header.
|
|
2
2
|
import { copyTextToClipboard } from "./clipboard.js";
|
|
3
3
|
import { iconNode } from "./icons.js";
|
|
4
|
-
|
|
5
4
|
export function createCopyButton(app, className = "") {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
button.setAttribute("aria-label", app.t("copyMessage"));
|
|
12
|
-
button.title = app.t("copyMessage");
|
|
13
|
-
const feedback = document.createElement("span");
|
|
14
|
-
feedback.className = "copy-feedback";
|
|
15
|
-
feedback.setAttribute("role", "status");
|
|
16
|
-
feedback.setAttribute("aria-live", "polite");
|
|
17
|
-
button.append(iconNode("copy", "copy-action-icon copy-icon"), iconNode("checkmark", "copy-action-icon copy-check"), feedback);
|
|
18
|
-
return button;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function setCopyFeedback(button, app, copied) {
|
|
22
|
-
clearTimeout(button._copyFeedbackTimer);
|
|
23
|
-
button.classList.toggle("is-copied", copied);
|
|
24
|
-
button.classList.toggle("is-copy-failed", !copied);
|
|
25
|
-
const key = copied ? "copied" : "copyMessageFailed";
|
|
26
|
-
const feedback = button.querySelector(".copy-feedback");
|
|
27
|
-
if (feedback) feedback.textContent = app.t(key);
|
|
28
|
-
button.setAttribute("aria-label", app.t(key));
|
|
29
|
-
button.title = app.t(key);
|
|
30
|
-
button._copyFeedbackTimer = setTimeout(() => {
|
|
31
|
-
button.classList.remove("is-copied", "is-copy-failed");
|
|
5
|
+
const button = document.createElement("button");
|
|
6
|
+
button.type = "button";
|
|
7
|
+
button.className = `copy-action ${className}`.trim();
|
|
8
|
+
button.dataset.i18nAriaLabel = "copyMessage";
|
|
9
|
+
button.dataset.i18nTitle = "copyMessage";
|
|
32
10
|
button.setAttribute("aria-label", app.t("copyMessage"));
|
|
33
11
|
button.title = app.t("copyMessage");
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
const feedback = document.createElement("span");
|
|
13
|
+
feedback.className = "copy-feedback";
|
|
14
|
+
feedback.setAttribute("role", "status");
|
|
15
|
+
feedback.setAttribute("aria-live", "polite");
|
|
16
|
+
button.append(iconNode("copy", "copy-action-icon copy-icon"), iconNode("checkmark", "copy-action-icon copy-check"), feedback);
|
|
17
|
+
return button;
|
|
18
|
+
}
|
|
19
|
+
export function setCopyFeedback(button, app, copied) {
|
|
20
|
+
clearTimeout(button._copyFeedbackTimer);
|
|
21
|
+
button.classList.toggle("is-copied", copied);
|
|
22
|
+
button.classList.toggle("is-copy-failed", !copied);
|
|
23
|
+
const key = copied ? "copied" : "copyMessageFailed";
|
|
24
|
+
const feedback = button.querySelector(".copy-feedback");
|
|
25
|
+
if (feedback)
|
|
26
|
+
feedback.textContent = app.t(key);
|
|
27
|
+
button.setAttribute("aria-label", app.t(key));
|
|
28
|
+
button.title = app.t(key);
|
|
29
|
+
button._copyFeedbackTimer = setTimeout(() => {
|
|
30
|
+
button.classList.remove("is-copied", "is-copy-failed");
|
|
31
|
+
button.setAttribute("aria-label", app.t("copyMessage"));
|
|
32
|
+
button.title = app.t("copyMessage");
|
|
33
|
+
if (feedback)
|
|
34
|
+
feedback.textContent = "";
|
|
35
|
+
}, 1600);
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
export async function copyResourceText(button, app, readText) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
let copied = false;
|
|
39
|
+
try {
|
|
40
|
+
const text = await readText();
|
|
41
|
+
copied = typeof text === "string" && text.length > 0 && await copyTextToClipboard(text);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
copied = false;
|
|
45
|
+
}
|
|
46
|
+
setCopyFeedback(button, app, copied);
|
|
47
|
+
return copied;
|
|
48
|
+
}
|
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
// The rail "+" opens a large modal instead of a small popover, so the create
|
|
2
2
|
// form has room for its name, join policy, and inline validation.
|
|
3
3
|
export function initCreateRoomDialog(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
|
-
|
|
4
|
+
const dialog = app.$("#createRoomDialog");
|
|
5
|
+
const input = app.$("#inRoomNameChat");
|
|
6
|
+
const error = app.$("#createRoomError");
|
|
7
|
+
const trigger = app.$("#btnNewRoom");
|
|
8
|
+
if (!dialog || !input || !error || !trigger)
|
|
9
|
+
return;
|
|
10
|
+
let opener = null;
|
|
11
|
+
let restoreFocus = true;
|
|
12
|
+
const close = (restore = true) => {
|
|
13
|
+
if (!dialog.open)
|
|
14
|
+
return;
|
|
15
|
+
restoreFocus = restore;
|
|
16
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
17
|
+
dialog.close();
|
|
18
|
+
};
|
|
19
|
+
app.showCreateRoomError = (key, values = {}) => {
|
|
20
|
+
app.setText(error, key, values);
|
|
21
|
+
error.dataset.errorKey = key;
|
|
22
|
+
error.hidden = false;
|
|
23
|
+
};
|
|
24
|
+
app.hideCreateRoomError = () => { error.hidden = true; delete error.dataset.errorKey; };
|
|
25
|
+
app.openCreateRoomDialog = () => {
|
|
26
|
+
opener = document.activeElement instanceof HTMLElement && document.activeElement !== document.body
|
|
27
|
+
? document.activeElement : trigger;
|
|
28
|
+
app.hideCreateRoomError();
|
|
29
|
+
if (!dialog.open)
|
|
30
|
+
dialog.showModal();
|
|
31
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
32
|
+
input.focus();
|
|
33
|
+
input.select();
|
|
34
|
+
};
|
|
35
|
+
app.closeCreateRoomDialog = (restore = true) => close(restore);
|
|
36
|
+
dialog.addEventListener("cancel", () => trigger.setAttribute("aria-expanded", "false"));
|
|
37
|
+
dialog.addEventListener("close", () => {
|
|
38
|
+
const target = opener, restore = restoreFocus;
|
|
39
|
+
opener = null;
|
|
40
|
+
restoreFocus = true;
|
|
41
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
42
|
+
app.hideCreateRoomError();
|
|
43
|
+
if (!restore)
|
|
44
|
+
return;
|
|
45
|
+
if (app.focusChatComposer?.({ force: true }))
|
|
46
|
+
return;
|
|
47
|
+
if (target?.isConnected)
|
|
48
|
+
target.focus({ preventScroll: true });
|
|
49
|
+
});
|
|
50
|
+
app.$("#btnCloseCreateRoom")?.addEventListener("click", () => close());
|
|
51
|
+
app.$("#btnCancelCreateRoom")?.addEventListener("click", () => close());
|
|
52
|
+
input.addEventListener("input", app.hideCreateRoomError);
|
|
53
|
+
}
|