@alexsun-top/opencode-chat-room 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +18 -62
- package/README.zh-CN.md +25 -69
- package/dist/cli.js +1008 -274
- package/package.json +10 -7
- package/packages/chat-room-channeld/README.md +42 -15
- package/packages/chat-room-channeld/dist/mock-adapter.js +5 -5
- package/packages/chat-room-channeld/src/adapter.ts +150 -7
- package/packages/chat-room-channeld/src/cli.ts +72 -5
- package/packages/chat-room-channeld/src/host.ts +41 -11
- package/packages/chat-room-channeld/src/inbound.ts +13 -4
- package/packages/chat-room-channeld/src/pg/database.ts +187 -0
- package/packages/chat-room-channeld/src/pg/migrate.ts +150 -0
- package/packages/chat-room-channeld/src/pg/schema.ts +60 -0
- package/packages/chat-room-channeld/src/pg/sql.mjs +175 -0
- package/packages/chat-room-channeld/src/pg/sqlite.ts +100 -0
- package/packages/chat-room-channeld/src/pg/worker.mjs +133 -0
- package/packages/chat-room-channeld/src/protocol.ts +53 -1
- package/packages/chat-room-channeld/src/rules.ts +7 -2
- package/packages/chat-room-channeld/src/state.ts +73 -97
- package/packages/chat-room-channeld/src/stats.ts +140 -109
- package/plugin.ts +1 -1
- package/server/assets/base.css +11 -3
- package/server/assets/chat/admin-badge.js +32 -30
- package/server/assets/chat/admin.js +198 -163
- package/server/assets/chat/announcements.js +295 -210
- package/server/assets/chat/attachment-store.js +106 -75
- package/server/assets/chat/attachments.js +686 -441
- package/server/assets/chat/chat-background.js +206 -0
- package/server/assets/chat/clipboard.js +44 -25
- package/server/assets/chat/confirm-dialog.js +36 -34
- package/server/assets/chat/copy-action.js +40 -40
- package/server/assets/chat/create-room-dialog.js +50 -48
- package/server/assets/chat/diagram-viewer.js +293 -228
- package/server/assets/chat/doc-preview.js +510 -388
- package/server/assets/chat/editor.js +423 -335
- package/server/assets/chat/events.js +637 -502
- package/server/assets/chat/files.js +476 -426
- package/server/assets/chat/history-loader.js +79 -73
- package/server/assets/chat/icons.js +9 -11
- package/server/assets/chat/image-zoom.js +239 -169
- package/server/assets/chat/index.js +6 -5
- package/server/assets/chat/install-prompt.js +86 -66
- package/server/assets/chat/integration-account-schema.js +101 -0
- package/server/assets/chat/integration-editor.js +162 -153
- package/server/assets/chat/integration-values.js +109 -100
- package/server/assets/chat/integrations.js +696 -479
- package/server/assets/chat/join-requests.js +408 -358
- package/server/assets/chat/locales/de.js +193 -194
- package/server/assets/chat/locales/es.js +193 -194
- package/server/assets/chat/locales/fr.js +193 -194
- package/server/assets/chat/locales/index.js +1 -2
- package/server/assets/chat/locales/it.js +193 -194
- package/server/assets/chat/locales/ja.js +193 -193
- package/server/assets/chat/locales/ko.js +193 -193
- package/server/assets/chat/markdown-footnotes.js +134 -102
- package/server/assets/chat/markdown.js +553 -386
- package/server/assets/chat/members.js +236 -197
- package/server/assets/chat/mentions.js +157 -133
- package/server/assets/chat/message-cache.js +40 -33
- package/server/assets/chat/message-polling.js +280 -227
- package/server/assets/chat/message-window.js +74 -55
- package/server/assets/chat/messages.js +552 -479
- package/server/assets/chat/office-preview.js +46 -45
- package/server/assets/chat/palette.js +450 -412
- package/server/assets/chat/panels.js +94 -58
- package/server/assets/chat/pwa.js +144 -73
- package/server/assets/chat/questions.js +372 -302
- package/server/assets/chat/recall.js +320 -273
- package/server/assets/chat/receipts.js +149 -122
- package/server/assets/chat/reminders.js +331 -216
- package/server/assets/chat/replies.js +165 -136
- package/server/assets/chat/resource-format.js +59 -62
- package/server/assets/chat/room-list.js +58 -55
- package/server/assets/chat/room-watcher.js +72 -50
- package/server/assets/chat/rooms.js +623 -505
- package/server/assets/chat/search.js +136 -114
- package/server/assets/chat/settings.js +229 -140
- package/server/assets/chat/shiki.js +61 -62
- package/server/assets/chat/shortcuts.js +212 -190
- package/server/assets/chat/side-pane.js +166 -131
- package/server/assets/chat/state.js +851 -707
- package/server/assets/chat/system-events.js +55 -27
- package/server/assets/chat/system-messages.js +59 -49
- package/server/assets/chat/task-form.js +178 -182
- package/server/assets/chat/task-row.js +158 -155
- package/server/assets/chat/tasks.js +653 -593
- package/server/assets/chat/viewport.js +32 -29
- package/server/assets/chat/window-controls.js +37 -0
- package/server/assets/code-highlight.css +22 -6
- package/server/assets/conversation.css +65 -16
- package/server/assets/doc-preview.css +6 -1
- package/server/assets/files.css +3 -0
- package/server/assets/monaco/integration-rules.css +1 -1
- package/server/assets/monaco/integration-rules.js +841 -533
- package/server/assets/responsive.css +32 -2
- package/server/assets/settings.css +117 -13
- package/server/assets/window-controls.css +36 -0
- package/server/channel-attachments.ts +133 -0
- package/server/channel-integration.ts +79 -26
- package/server/channels.ts +15 -5
- package/server/chat-server.ts +9 -1
- package/server/chat.html +73 -38
- package/server/manifest.webmanifest +1 -0
- package/server/routes/pages.ts +7 -5
- package/server/sw.js +346 -267
- package/src/center/center-client.ts +1 -1
- package/src/state/pg-database.ts +5 -5
- package/src/state/pg-migrate.ts +7 -7
- package/src/state/pg-worker.mjs +2 -17
- package/src/state/sqlite-database.ts +14 -5
- package/src/state/sqlite-rooms.ts +130 -23
- package/src/state/sqlite-state-store.ts +6 -5
- package/src/state/sqlite.ts +3 -3
- package/src/web/integration-rules-editor.ts +141 -5
- package/src/web/integration-rules.ts +6 -2
- package/src/web/integration-schema.ts +7 -6
- package/packages/chat-room-channeld/dist/feishu-adapter.js +0 -1262
- package/packages/chat-room-channeld/src/feishu-adapter.ts +0 -303
- package/packages/chat-room-channeld/src/feishu-card.ts +0 -27
- package/packages/chat-room-channeld/src/feishu-inbound.ts +0 -158
- package/packages/chat-room-channeld/src/feishu-live.ts +0 -355
- package/packages/chat-room-channeld/src/feishu-send.ts +0 -342
- package/packages/chat-room-channeld/src/feishu-ws-frames.ts +0 -173
- package/server/assets/chat/forward.js +0 -69
|
@@ -1,32 +1,60 @@
|
|
|
1
1
|
// Room notices are inline events: a small icon, a tinted chip, and the time.
|
|
2
2
|
import { iconNode } from "./icons.js";
|
|
3
|
-
import { formatSystemMessage, systemMessageKind } from "./system-messages.js";
|
|
4
|
-
|
|
3
|
+
import { formatRelayMessage, formatSystemMessage, systemMessageKind } from "./system-messages.js";
|
|
4
|
+
import { renderMarkdown, renderResourceText } from "./markdown.js";
|
|
5
5
|
const icons = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
join: "add",
|
|
7
|
+
leave: "arrow_exit",
|
|
8
|
+
remove: "delete",
|
|
9
|
+
admin: "shield_checkmark",
|
|
10
|
+
forward: "arrow_swap",
|
|
11
|
+
reminder: "alert",
|
|
12
|
+
notice: "megaphone",
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
// Notices are Markdown and switch from a pill to a card once they pass three
|
|
15
|
+
// rendered lines; relays always keep the message-card shape because they carry
|
|
16
|
+
// attachments.
|
|
17
|
+
function markNoticeShape(row) {
|
|
18
|
+
if (row.dataset.kind === "relay")
|
|
19
|
+
return;
|
|
20
|
+
const text = row.querySelector(".sys-text");
|
|
21
|
+
if (!text || !text.isConnected)
|
|
22
|
+
return;
|
|
23
|
+
const lineHeight = Number.parseFloat(getComputedStyle(text).lineHeight) || 18;
|
|
24
|
+
row.dataset.long = text.getBoundingClientRect().height > lineHeight * 3 + 1 ? "true" : "false";
|
|
25
|
+
}
|
|
26
|
+
let resizeBound = false;
|
|
27
|
+
function bindNoticeResize() {
|
|
28
|
+
if (resizeBound)
|
|
29
|
+
return;
|
|
30
|
+
resizeBound = true;
|
|
31
|
+
window.addEventListener("resize", () => {
|
|
32
|
+
for (const row of document.querySelectorAll('.sys[data-kind]:not([data-kind="relay"])'))
|
|
33
|
+
markNoticeShape(row);
|
|
34
|
+
}, { passive: true });
|
|
35
|
+
}
|
|
15
36
|
export function renderSystemRow(row, message, app) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
row.className = "sys";
|
|
38
|
+
row.dataset.kind = systemMessageKind(message);
|
|
39
|
+
const event = document.createElement("span"), mark = document.createElement("span");
|
|
40
|
+
const text = document.createElement("span"), time = document.createElement("time");
|
|
41
|
+
event.className = "sys-event";
|
|
42
|
+
event.setAttribute("role", "note");
|
|
43
|
+
mark.className = "sys-icon";
|
|
44
|
+
mark.append(iconNode(icons[row.dataset.kind] || icons.notice, "sys-icon-glyph"));
|
|
45
|
+
text.className = "sys-text";
|
|
46
|
+
if (row.dataset.kind === "relay")
|
|
47
|
+
renderResourceText(text, formatRelayMessage(message, app), app);
|
|
48
|
+
else
|
|
49
|
+
renderMarkdown(text, formatSystemMessage(message, app), app);
|
|
50
|
+
time.className = "sys-time";
|
|
51
|
+
time.dateTime = new Date(message.createdAt).toISOString();
|
|
52
|
+
// Notices and relays both put a full, muted date first; a bare clock is
|
|
53
|
+
// ambiguous once a row has scrolled or came from another timezone.
|
|
54
|
+
time.textContent = app.fmtTime(message.createdAt);
|
|
55
|
+
event.append(mark, text, time);
|
|
56
|
+
row.append(event);
|
|
57
|
+
bindNoticeResize();
|
|
58
|
+
requestAnimationFrame(() => markNoticeShape(row));
|
|
59
|
+
return row;
|
|
60
|
+
}
|
|
@@ -1,62 +1,72 @@
|
|
|
1
1
|
// The fourth column drives the event icon and tint in the web client.
|
|
2
2
|
const patterns = [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
[/^(.*?) joined the room$/, "systemJoined", (m) => ({ name: m[1] }), "join"],
|
|
4
|
+
[/^(.*?) left the room$/, "systemLeft", (m) => ({ name: m[1] }), "leave"],
|
|
5
|
+
[/^(.*?) was removed from the room$/, "systemRemoved", (m) => ({ name: m[1] }), "remove"],
|
|
6
|
+
[/^(.*?) designated (.*?) as administrator$/, "systemDesignated", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
7
|
+
[/^(.*?) updated the room administrators$/, "systemAdminsUpdated", (m) => ({ actor: m[1] }), "admin"],
|
|
8
|
+
[/^(.*?) named (.*?) as the room successor$/, "systemSuccessorNamed", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
9
|
+
[/^(.*?) cleared the room successor$/, "systemSuccessorCleared", (m) => ({ actor: m[1] }), "admin"],
|
|
10
|
+
[/^(.*?) revoked the administrator designation$/, "systemRevoked", (m) => ({ actor: m[1] }), "admin"],
|
|
11
|
+
[/^(.*?) renamed the room from "(.*)" to "(.*)"$/, "systemRenamed", (m) => ({ actor: m[1], from: m[2], to: m[3] }), "admin"],
|
|
12
|
+
[/^(.*?) updated the room description$/, "systemDescribed", (m) => ({ actor: m[1] }), "admin"],
|
|
13
|
+
[/^(.*?) set join approval to (open|approval)$/, "systemJoinPolicy", (m) => ({ actor: m[1], policy: m[2] }), "admin"],
|
|
14
|
+
[/^(.*?) handed the room to (.*)$/, "systemHanded", (m) => ({ actor: m[1], name: m[2] }), "admin"],
|
|
15
|
+
[/^Forwarded to (.*)$/, "systemForwarded", (m) => ({ target: m[1] }), "forward"],
|
|
16
|
+
[/^Forward to (.*?) failed: (.*)$/, "systemForwardFailed", (m) => ({ target: m[1], reason: m[2] }), "forward"],
|
|
17
17
|
];
|
|
18
|
-
|
|
19
18
|
function formatLine(line, app) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
for (const [pattern, key, values] of patterns) {
|
|
20
|
+
const match = pattern.exec(line);
|
|
21
|
+
if (match)
|
|
22
|
+
return app.t(key, values(match));
|
|
23
|
+
}
|
|
24
|
+
return line;
|
|
25
|
+
}
|
|
26
|
+
export function formatRelayMessage(message, app) {
|
|
27
|
+
// Relay rows keep resource markers: the renderer turns them into attachment cards.
|
|
28
|
+
return String(message?.text ?? "")
|
|
29
|
+
.replace(/<at>@all<\/at>/g, `@${app.t("allMembers")}`)
|
|
30
|
+
.replace(/<at>([\s\S]*?)<\/at>/g, "$1");
|
|
25
31
|
}
|
|
26
|
-
|
|
27
32
|
export function formatSystemMessage(message, app) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
// `<at>@name</at>` is an editor token; system rows and previews show the plain mention.
|
|
34
|
+
let text = String(message?.text ?? "")
|
|
35
|
+
.replace(/<at>@all<\/at>/g, `@${app.t("allMembers")}`)
|
|
36
|
+
.replace(/<at>([\s\S]*?)<\/at>/g, "$1");
|
|
37
|
+
// Resource markers are internal IDs. A rail preview must not expose them.
|
|
38
|
+
const resources = /\[\[resource:[0-9a-f-]{36}\]\]/gi;
|
|
39
|
+
if (resources.test(text)) {
|
|
40
|
+
text = text.replace(resources, "").trim();
|
|
41
|
+
text = text ? `${text} · ${app.t("attachments")}` : app.t("attachments");
|
|
42
|
+
}
|
|
43
|
+
if (message?.senderId !== "system")
|
|
44
|
+
return text;
|
|
45
|
+
// One edit can log several changes joined by "; "; translate each line.
|
|
46
|
+
return text.split("; ").map((line) => formatLine(line, app)).join("; ");
|
|
41
47
|
}
|
|
42
|
-
|
|
43
48
|
// Reminders are plain text system rows, so their id is the only stable marker.
|
|
44
49
|
export function systemMessageKind(message) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (String(message?.id ?? "").startsWith("reminder:"))
|
|
51
|
+
return "reminder";
|
|
52
|
+
const line = String(message?.text ?? "").split("; ")[0];
|
|
53
|
+
// Inbound relay lines carry provider ids and read like messages, not notices.
|
|
54
|
+
if (/^\[[A-Za-z][\w .-]*\] message_id=\S+/.test(line))
|
|
55
|
+
return "relay";
|
|
56
|
+
for (const [pattern, , , kind] of patterns)
|
|
57
|
+
if (pattern.test(line))
|
|
58
|
+
return kind;
|
|
59
|
+
return "notice";
|
|
49
60
|
}
|
|
50
|
-
|
|
51
61
|
export function setRoomPreview(entry, message) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
entry.preview = message.text;
|
|
63
|
+
entry.previewAt = message.createdAt;
|
|
64
|
+
entry.previewSenderId = message.senderId;
|
|
65
|
+
entry.previewRecalled = Boolean(message.recalledAt);
|
|
56
66
|
}
|
|
57
|
-
|
|
58
67
|
export function formatRoomPreview(entry, latest, app) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
68
|
+
// A recalled message must not leak its text through the room rail.
|
|
69
|
+
if (entry?.previewRecalled || latest?.recalledAt)
|
|
70
|
+
return app.t("messageRecalled");
|
|
71
|
+
return formatSystemMessage(entry?.preview ? { senderId: entry.previewSenderId, text: entry.preview } : latest, app);
|
|
72
|
+
}
|
|
@@ -1,197 +1,193 @@
|
|
|
1
1
|
// Task form fields shared by the create and edit forms: people pickers and steps.
|
|
2
2
|
import { icon } from "./icons.js";
|
|
3
|
-
|
|
4
3
|
export const TITLE_MAX = 200, TEXT_MAX = 5000, STEP_MAX = 300, STEPS_MAX = 30;
|
|
5
|
-
|
|
6
4
|
export const roomPeople = (app) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const room = app.state.room;
|
|
6
|
+
return [...new Set([
|
|
7
|
+
...(room?.participants || []).map((person) => person.name),
|
|
8
|
+
...(app.state.memberSessions.get(room?.id) || []).map((member) => member.name),
|
|
9
|
+
].filter(Boolean))]
|
|
10
|
+
.sort((left, right) => String(left).localeCompare(String(right), app.intlLocale()));
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
export const fillAssignees = (app, select, value) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
const names = roomPeople(app);
|
|
14
|
+
if (value && !names.includes(value))
|
|
15
|
+
names.push(value);
|
|
16
|
+
select.textContent = "";
|
|
17
|
+
const add = (name, label) => {
|
|
18
|
+
const option = document.createElement("option");
|
|
19
|
+
option.value = name;
|
|
20
|
+
option.textContent = label;
|
|
21
|
+
select.append(option);
|
|
22
|
+
};
|
|
23
|
+
add("", app.t("tasksUnassigned"));
|
|
24
|
+
names.forEach((name) => add(name, name));
|
|
25
|
+
select.value = names.includes(value) ? value : "";
|
|
28
26
|
};
|
|
29
|
-
|
|
30
27
|
export const fillPeople = (app, container, selected = []) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
container.textContent = "";
|
|
29
|
+
const names = roomPeople(app);
|
|
30
|
+
// Keep participants who left visible so an unrelated edit does not drop them.
|
|
31
|
+
for (const name of selected)
|
|
32
|
+
if (!names.includes(name))
|
|
33
|
+
names.push(name);
|
|
34
|
+
names.sort((left, right) => String(left).localeCompare(String(right), app.intlLocale()));
|
|
35
|
+
for (const name of names) {
|
|
36
|
+
const label = document.createElement("label");
|
|
37
|
+
label.className = "task-person";
|
|
38
|
+
const input = document.createElement("input");
|
|
39
|
+
input.type = "checkbox";
|
|
40
|
+
input.value = name;
|
|
41
|
+
input.checked = selected.includes(name);
|
|
42
|
+
const text = document.createElement("span");
|
|
43
|
+
text.textContent = name;
|
|
44
|
+
label.append(input, text);
|
|
45
|
+
container.append(label);
|
|
46
|
+
}
|
|
46
47
|
};
|
|
47
|
-
|
|
48
48
|
export const readPeople = (container) => [...container.querySelectorAll('input[type="checkbox"]:checked')]
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
.map((input) => input.value);
|
|
51
50
|
// One editor for create and edit forms: text, done flag, and a remove button.
|
|
52
51
|
export function createStepsEditor(app, container, addButton, initial = []) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
52
|
+
const rows = [];
|
|
53
|
+
const sync = () => { addButton.disabled = rows.length >= STEPS_MAX; };
|
|
54
|
+
const addRow = (step = {}) => {
|
|
55
|
+
if (rows.length >= STEPS_MAX)
|
|
56
|
+
return null;
|
|
57
|
+
const row = document.createElement("div");
|
|
58
|
+
row.className = "task-step-row";
|
|
59
|
+
const done = document.createElement("input");
|
|
60
|
+
done.type = "checkbox";
|
|
61
|
+
done.className = "task-step-done";
|
|
62
|
+
done.checked = step.done === true;
|
|
63
|
+
done.setAttribute("data-i18n-aria-label", "tasksStepDoneLabel");
|
|
64
|
+
done.setAttribute("aria-label", app.t("tasksStepDoneLabel"));
|
|
65
|
+
const text = document.createElement("input");
|
|
66
|
+
text.className = "input task-step-text";
|
|
67
|
+
text.maxLength = STEP_MAX;
|
|
68
|
+
text.autocomplete = "off";
|
|
69
|
+
text.value = step.text || "";
|
|
70
|
+
text.setAttribute("data-i18n-placeholder", "tasksStepPlaceholder");
|
|
71
|
+
text.setAttribute("data-i18n-aria-label", "tasksStepPlaceholder");
|
|
72
|
+
text.placeholder = app.t("tasksStepPlaceholder");
|
|
73
|
+
text.setAttribute("aria-label", app.t("tasksStepPlaceholder"));
|
|
74
|
+
const remove = document.createElement("button");
|
|
75
|
+
remove.type = "button";
|
|
76
|
+
remove.className = "task-action task-step-remove";
|
|
77
|
+
remove.setAttribute("data-i18n-aria-label", "tasksRemoveStep");
|
|
78
|
+
remove.setAttribute("aria-label", app.t("tasksRemoveStep"));
|
|
79
|
+
remove.innerHTML = icon("dismiss");
|
|
80
|
+
remove.addEventListener("click", () => {
|
|
81
|
+
rows.splice(rows.indexOf(row), 1);
|
|
82
|
+
row.remove();
|
|
83
|
+
sync();
|
|
84
|
+
addButton.focus();
|
|
85
|
+
});
|
|
86
|
+
row.append(done, text, remove);
|
|
87
|
+
container.append(row);
|
|
88
|
+
rows.push(row);
|
|
89
|
+
sync();
|
|
90
|
+
return row;
|
|
91
|
+
};
|
|
92
|
+
const read = () => rows
|
|
93
|
+
.map((row) => ({ text: row.querySelector(".task-step-text").value.trim(), done: row.querySelector(".task-step-done").checked }))
|
|
94
|
+
.filter((step) => step.text);
|
|
95
|
+
const reset = () => { rows.splice(0).forEach((row) => row.remove()); sync(); };
|
|
96
|
+
addButton.addEventListener("click", () => addRow()?.querySelector(".task-step-text").focus());
|
|
97
|
+
initial.forEach((step) => addRow(step));
|
|
98
|
+
return { addRow, read, reset };
|
|
94
99
|
}
|
|
95
|
-
|
|
96
100
|
export const buildTaskForm = (view, task) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
save.disabled = true;
|
|
189
|
-
const saved = await view.onSave(task, {
|
|
190
|
-
title: nextTitle, description: description.value.trim(), dueDate: due.value,
|
|
191
|
-
participants: readPeople(people), conclusion: conclusion.value.trim(),
|
|
192
|
-
assignee: assignee.value, steps: steps.read(),
|
|
101
|
+
const { app } = view;
|
|
102
|
+
const form = document.createElement("form");
|
|
103
|
+
form.className = "task-edit-form";
|
|
104
|
+
form.noValidate = true;
|
|
105
|
+
const field = (className, key, control) => {
|
|
106
|
+
const label = document.createElement("label");
|
|
107
|
+
const text = document.createElement("span");
|
|
108
|
+
label.className = `field task-field ${className}`;
|
|
109
|
+
text.className = "field-label";
|
|
110
|
+
text.dataset.i18n = key;
|
|
111
|
+
text.textContent = app.t(key);
|
|
112
|
+
label.append(text, control);
|
|
113
|
+
return label;
|
|
114
|
+
};
|
|
115
|
+
const legendField = (className, key, children) => {
|
|
116
|
+
const set = document.createElement("fieldset");
|
|
117
|
+
const legend = document.createElement("legend");
|
|
118
|
+
const text = document.createElement("span");
|
|
119
|
+
set.className = `field task-field ${className}`;
|
|
120
|
+
legend.className = "field-label";
|
|
121
|
+
text.dataset.i18n = key;
|
|
122
|
+
text.textContent = app.t(key);
|
|
123
|
+
legend.append(text);
|
|
124
|
+
set.append(legend, ...children);
|
|
125
|
+
return set;
|
|
126
|
+
};
|
|
127
|
+
const title = document.createElement("input");
|
|
128
|
+
title.className = "input task-edit-title";
|
|
129
|
+
title.maxLength = TITLE_MAX;
|
|
130
|
+
title.autocomplete = "off";
|
|
131
|
+
title.value = task.title;
|
|
132
|
+
const description = document.createElement("textarea");
|
|
133
|
+
description.className = "input task-edit-description";
|
|
134
|
+
description.rows = 2;
|
|
135
|
+
description.maxLength = TEXT_MAX;
|
|
136
|
+
description.value = task.description || "";
|
|
137
|
+
const due = document.createElement("input");
|
|
138
|
+
due.className = "input task-edit-due";
|
|
139
|
+
due.type = "date";
|
|
140
|
+
due.value = view.dateValue(task.dueDate);
|
|
141
|
+
const assignee = document.createElement("select");
|
|
142
|
+
assignee.className = "input task-edit-assignee tasks-select";
|
|
143
|
+
fillAssignees(app, assignee, task.assignee || "");
|
|
144
|
+
const people = document.createElement("div");
|
|
145
|
+
people.className = "task-people";
|
|
146
|
+
fillPeople(app, people, view.participantsOf(task));
|
|
147
|
+
const stepsBox = document.createElement("div");
|
|
148
|
+
stepsBox.className = "task-steps-editor";
|
|
149
|
+
const addStep = document.createElement("button");
|
|
150
|
+
addStep.type = "button";
|
|
151
|
+
addStep.className = "btn ghost small task-add-step";
|
|
152
|
+
addStep.dataset.i18n = "tasksAddStep";
|
|
153
|
+
addStep.textContent = app.t("tasksAddStep");
|
|
154
|
+
const steps = createStepsEditor(app, stepsBox, addStep, view.stepsOf(task));
|
|
155
|
+
const conclusion = document.createElement("textarea");
|
|
156
|
+
conclusion.className = "input task-edit-conclusion";
|
|
157
|
+
conclusion.rows = 2;
|
|
158
|
+
conclusion.maxLength = TEXT_MAX;
|
|
159
|
+
conclusion.value = task.conclusion || "";
|
|
160
|
+
const actions = document.createElement("div");
|
|
161
|
+
actions.className = "task-edit-actions";
|
|
162
|
+
const cancel = document.createElement("button");
|
|
163
|
+
cancel.type = "button";
|
|
164
|
+
cancel.className = "btn ghost small";
|
|
165
|
+
cancel.dataset.i18n = "cancel";
|
|
166
|
+
cancel.textContent = app.t("cancel");
|
|
167
|
+
cancel.addEventListener("click", () => view.onCancel(task));
|
|
168
|
+
const save = document.createElement("button");
|
|
169
|
+
save.type = "submit";
|
|
170
|
+
save.className = "btn primary small";
|
|
171
|
+
save.dataset.i18n = "save";
|
|
172
|
+
save.textContent = app.t("save");
|
|
173
|
+
actions.append(cancel, save);
|
|
174
|
+
form.append(field("task-edit-title-field", "tasksTitleLabel", title), field("task-edit-description-field", "tasksDescriptionLabel", description), field("task-edit-due-field", "tasksDueDateLabel", due), field("task-edit-assignee-field", "tasksAssigneeLabel", assignee), legendField("task-edit-participants-field", "tasksParticipantsLabel", [people]), legendField("task-edit-steps-field", "tasksStepsLabel", [stepsBox, addStep]), field("task-edit-conclusion-field", "tasksConclusionLabel", conclusion), actions);
|
|
175
|
+
form.addEventListener("submit", async (event) => {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
const nextTitle = title.value.trim();
|
|
178
|
+
if (!nextTitle || Array.from(nextTitle).length > TITLE_MAX) {
|
|
179
|
+
view.showError("tasksInvalid");
|
|
180
|
+
title.focus();
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
save.disabled = true;
|
|
184
|
+
const saved = await view.onSave(task, {
|
|
185
|
+
title: nextTitle, description: description.value.trim(), dueDate: due.value,
|
|
186
|
+
participants: readPeople(people), conclusion: conclusion.value.trim(),
|
|
187
|
+
assignee: assignee.value, steps: steps.read(),
|
|
188
|
+
});
|
|
189
|
+
if (!saved)
|
|
190
|
+
save.disabled = false;
|
|
193
191
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return form;
|
|
197
|
-
};
|
|
192
|
+
return form;
|
|
193
|
+
};
|