@alexsun-top/opencode-chat-room 0.8.2 → 0.8.3

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