@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
|
@@ -5,78 +5,98 @@ const DISMISS_MS = 30 * 24 * 60 * 60 * 1000;
|
|
|
5
5
|
const DISMISS_KEY = "chat.installDismissedAt";
|
|
6
6
|
const INSTALLED_KEY = "chat.installedApp";
|
|
7
7
|
const memory = new Map();
|
|
8
|
-
|
|
9
8
|
function read(key) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
try {
|
|
10
|
+
return localStorage.getItem(key);
|
|
11
|
+
}
|
|
12
|
+
catch { /* Try the tab next. */ }
|
|
13
|
+
try {
|
|
14
|
+
return sessionStorage.getItem(key);
|
|
15
|
+
}
|
|
16
|
+
catch { /* Use memory. */ }
|
|
17
|
+
return memory.get(key) ?? null;
|
|
13
18
|
}
|
|
14
|
-
|
|
15
19
|
function write(key, value) {
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
try {
|
|
21
|
+
localStorage.setItem(key, value);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
catch { /* Try the tab next. */ }
|
|
25
|
+
try {
|
|
26
|
+
sessionStorage.setItem(key, value);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
memory.set(key, value);
|
|
30
|
+
}
|
|
18
31
|
}
|
|
19
|
-
|
|
20
32
|
function isIos() {
|
|
21
|
-
|
|
33
|
+
return /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
|
|
22
34
|
}
|
|
23
|
-
|
|
24
35
|
function isStandalone() {
|
|
25
|
-
|
|
36
|
+
return matchMedia("(display-mode: standalone)").matches || navigator.standalone === true;
|
|
26
37
|
}
|
|
27
|
-
|
|
28
38
|
export function initInstallPrompt(app) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
39
|
+
const card = app.$("#installPrompt"), installButton = app.$("#btnInstallApp"), guideButton = app.$("#btnInstallGuide"), guide = app.$("#installGuide"), dismissButton = app.$("#btnDismissInstall");
|
|
40
|
+
const rail = app.$("#railInstall"), railInstall = app.$("#btnRailInstall"), railGuide = app.$("#railInstallGuide");
|
|
41
|
+
if (!card || !installButton || !guideButton || !guide || !dismissButton || !rail || !railInstall || !railGuide)
|
|
42
|
+
return;
|
|
43
|
+
const eligible = () => matchMedia("(max-width: 760px)").matches && window.isSecureContext;
|
|
44
|
+
const suppressed = () => read(INSTALLED_KEY) === "1" || Number(read(DISMISS_KEY) || 0) > Date.now() - DISMISS_MS;
|
|
45
|
+
let deferred = null;
|
|
46
|
+
function hide() {
|
|
47
|
+
const fromCard = card.contains(document.activeElement), fromRail = rail.contains(document.activeElement);
|
|
48
|
+
card.hidden = true;
|
|
49
|
+
rail.hidden = true;
|
|
50
|
+
if (fromCard)
|
|
51
|
+
app.$("#inName")?.focus({ preventScroll: true });
|
|
52
|
+
else if (fromRail)
|
|
53
|
+
app.$("#btnSettings")?.focus({ preventScroll: true });
|
|
54
|
+
}
|
|
55
|
+
// The join card explains itself; the room drawer carries the same offer for people
|
|
56
|
+
// who restore straight into a room and never see the join page.
|
|
57
|
+
function render(mode) {
|
|
58
|
+
const visible = Boolean(mode) && eligible() && !isStandalone() && !suppressed();
|
|
59
|
+
card.hidden = rail.hidden = !visible;
|
|
60
|
+
if (!visible)
|
|
61
|
+
return;
|
|
62
|
+
installButton.hidden = mode !== "prompt";
|
|
63
|
+
guideButton.hidden = mode !== "ios";
|
|
64
|
+
railInstall.hidden = mode !== "prompt";
|
|
65
|
+
railGuide.hidden = mode !== "ios";
|
|
66
|
+
if (mode !== "ios") {
|
|
67
|
+
guide.hidden = true;
|
|
68
|
+
guideButton.setAttribute("aria-expanded", "false");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
window.addEventListener("beforeinstallprompt", (event) => {
|
|
72
|
+
if (!eligible() || isStandalone() || suppressed())
|
|
73
|
+
return;
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
deferred = event;
|
|
76
|
+
render("prompt");
|
|
77
|
+
});
|
|
78
|
+
window.addEventListener("appinstalled", () => { write(INSTALLED_KEY, "1"); hide(); });
|
|
79
|
+
const promptInstall = async () => {
|
|
80
|
+
const prompt = deferred;
|
|
81
|
+
if (!prompt)
|
|
82
|
+
return;
|
|
83
|
+
deferred = null;
|
|
84
|
+
let accepted = false;
|
|
85
|
+
try {
|
|
86
|
+
accepted = (await prompt.prompt())?.outcome === "accepted";
|
|
87
|
+
}
|
|
88
|
+
catch { /* Count it as declined. */ }
|
|
89
|
+
write(accepted ? INSTALLED_KEY : DISMISS_KEY, accepted ? "1" : String(Date.now()));
|
|
90
|
+
hide();
|
|
91
|
+
};
|
|
92
|
+
installButton.addEventListener("click", promptInstall);
|
|
93
|
+
railInstall.addEventListener("click", promptInstall);
|
|
94
|
+
guideButton.addEventListener("click", () => {
|
|
95
|
+
const open = guide.hidden;
|
|
96
|
+
guide.hidden = !open;
|
|
97
|
+
guideButton.setAttribute("aria-expanded", String(open));
|
|
98
|
+
});
|
|
99
|
+
dismissButton.addEventListener("click", () => { write(DISMISS_KEY, String(Date.now())); hide(); });
|
|
100
|
+
if (isIos())
|
|
101
|
+
render("ios");
|
|
102
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Account form generated from the JSON Schema a plugin declares in initialize.
|
|
2
|
+
const CONTROL = { string: "text", secret: "password", number: "number" };
|
|
3
|
+
function textFor(field, fallback) {
|
|
4
|
+
return typeof field.label === "string" && field.label.trim() ? field.label : fallback;
|
|
5
|
+
}
|
|
6
|
+
function addField(container, field, existing, stored, text) {
|
|
7
|
+
const label = document.createElement("label");
|
|
8
|
+
label.className = "field integration-schema-field";
|
|
9
|
+
const caption = document.createElement("span");
|
|
10
|
+
caption.className = "field-label";
|
|
11
|
+
caption.textContent = textFor(field, field.key);
|
|
12
|
+
if (field.required) {
|
|
13
|
+
const required = document.createElement("span");
|
|
14
|
+
required.className = "integration-required";
|
|
15
|
+
required.textContent = " *";
|
|
16
|
+
caption.append(required);
|
|
17
|
+
}
|
|
18
|
+
let control;
|
|
19
|
+
if (field.type === "boolean" || field.type === "select") {
|
|
20
|
+
control = document.createElement("select");
|
|
21
|
+
control.className = "input";
|
|
22
|
+
const blank = document.createElement("option");
|
|
23
|
+
blank.value = "";
|
|
24
|
+
blank.textContent = existing
|
|
25
|
+
? (stored ? text("integrationsKeepStored") : text("integrationsNotSet"))
|
|
26
|
+
: "";
|
|
27
|
+
control.append(blank);
|
|
28
|
+
const options = field.type === "boolean"
|
|
29
|
+
? [{ value: "1", label: "True" }, { value: "0", label: "False" }]
|
|
30
|
+
: Array.isArray(field.options) ? field.options : [];
|
|
31
|
+
for (const option of options) {
|
|
32
|
+
const node = document.createElement("option");
|
|
33
|
+
node.value = String(option.value);
|
|
34
|
+
node.textContent = typeof option.label === "string" && option.label ? option.label : String(option.value);
|
|
35
|
+
control.append(node);
|
|
36
|
+
}
|
|
37
|
+
if (!existing && typeof field.default === "string" && field.default !== "") {
|
|
38
|
+
control.value = field.type === "boolean"
|
|
39
|
+
? (["1", "true", "on", "yes"].includes(field.default.toLowerCase()) ? "1" : "0")
|
|
40
|
+
: field.default;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
control = document.createElement("input");
|
|
45
|
+
control.className = "input";
|
|
46
|
+
control.type = CONTROL[field.type] || "text";
|
|
47
|
+
control.autocomplete = field.type === "secret" ? "new-password" : "off";
|
|
48
|
+
if (existing)
|
|
49
|
+
control.placeholder = stored ? text("integrationsLeaveBlank") : text("integrationsNotSet");
|
|
50
|
+
else if (typeof field.default === "string")
|
|
51
|
+
control.value = field.default;
|
|
52
|
+
}
|
|
53
|
+
control.dataset.accountKey = field.key;
|
|
54
|
+
control.dataset.accountType = field.type || "string";
|
|
55
|
+
control.dataset.accountRequired = field.required ? "1" : "0";
|
|
56
|
+
control.dataset.accountStored = stored ? "1" : "0";
|
|
57
|
+
label.append(caption, control);
|
|
58
|
+
if (typeof field.description === "string" && field.description.trim()) {
|
|
59
|
+
const hint = document.createElement("span");
|
|
60
|
+
hint.className = "hint";
|
|
61
|
+
hint.textContent = field.description;
|
|
62
|
+
label.append(hint);
|
|
63
|
+
}
|
|
64
|
+
container.append(label);
|
|
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)
|
|
71
|
+
return;
|
|
72
|
+
const existing = Boolean(account);
|
|
73
|
+
const stored = new Set(account?.envKeys || []);
|
|
74
|
+
for (const field of fields) {
|
|
75
|
+
if (!field || typeof field.key !== "string")
|
|
76
|
+
continue;
|
|
77
|
+
addField(container, field, existing, stored.has(field.key), text);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Values still land in the account env map; blank means "keep stored". */
|
|
81
|
+
export function readAccountSchema(container, text) {
|
|
82
|
+
const values = {};
|
|
83
|
+
const keys = new Set();
|
|
84
|
+
const missing = [];
|
|
85
|
+
for (const control of container.querySelectorAll("[data-account-key]")) {
|
|
86
|
+
const key = control.dataset.accountKey;
|
|
87
|
+
keys.add(key);
|
|
88
|
+
const value = String(control.value ?? "").trim();
|
|
89
|
+
if (value !== "") {
|
|
90
|
+
values[key] = value;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (control.dataset.accountRequired === "1" && control.dataset.accountStored !== "1") {
|
|
94
|
+
const label = control.closest(".integration-schema-field")?.querySelector(".field-label")?.textContent || key;
|
|
95
|
+
missing.push(label.replace(/\s*\*$/, ""));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (missing.length)
|
|
99
|
+
throw new Error(text("integrationsAccountRequired", { fields: missing.join(", ") }));
|
|
100
|
+
return { values, keys };
|
|
101
|
+
}
|
|
@@ -3,161 +3,170 @@
|
|
|
3
3
|
const BUNDLE_URL = "/assets/monaco/integration-rules.js";
|
|
4
4
|
const STYLES_URL = "/assets/monaco/integration-rules.css";
|
|
5
5
|
let bundlePromise = null;
|
|
6
|
-
|
|
7
6
|
function loadBundle() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
if (!bundlePromise) {
|
|
8
|
+
bundlePromise = import(BUNDLE_URL)
|
|
9
|
+
.then((module) => {
|
|
10
|
+
if (!document.querySelector("link[data-integration-rules-editor]")) {
|
|
11
|
+
const link = document.createElement("link");
|
|
12
|
+
link.rel = "stylesheet";
|
|
13
|
+
link.href = STYLES_URL;
|
|
14
|
+
link.dataset.integrationRulesEditor = "true";
|
|
15
|
+
document.head.append(link);
|
|
16
|
+
}
|
|
17
|
+
return module;
|
|
18
|
+
})
|
|
19
|
+
.catch((error) => {
|
|
20
|
+
// Keep this a warning: a blocked asset must not surface as an uncaught page error.
|
|
21
|
+
console.warn("Integration code editor unavailable; keeping the plain text editor.", error);
|
|
22
|
+
throw error;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return bundlePromise;
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
export function initIntegrationEditor(app, options) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
28
|
+
const host = app.$(options.editor);
|
|
29
|
+
const textarea = app.$(options.textarea);
|
|
30
|
+
const fallback = app.$(options.fallback);
|
|
31
|
+
const error = app.$(options.error);
|
|
32
|
+
const errorList = app.$(options.errors);
|
|
33
|
+
const formatGroup = app.$(options.formats);
|
|
34
|
+
let controller = null, loading = null, failed = false, editable = true;
|
|
35
|
+
if (formatGroup)
|
|
36
|
+
formatGroup.hidden = true;
|
|
37
|
+
const applyEditable = () => {
|
|
38
|
+
host?.setAttribute("data-read-only", String(!editable));
|
|
39
|
+
if (textarea)
|
|
40
|
+
textarea.readOnly = !editable;
|
|
41
|
+
for (const button of formatGroup?.querySelectorAll("[data-format]") || [])
|
|
42
|
+
button.disabled = !editable;
|
|
43
|
+
controller?.setReadOnly(!editable);
|
|
44
|
+
};
|
|
45
|
+
const updateFormatButtons = () => {
|
|
46
|
+
const active = controller?.getFormat() || "yaml";
|
|
47
|
+
for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
|
|
48
|
+
button.setAttribute("aria-pressed", String(button.dataset.format === active));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const render = (result) => {
|
|
52
|
+
if (textarea)
|
|
53
|
+
textarea.value = result.text;
|
|
54
|
+
host?.setAttribute("data-error-count", String(result.errors.length));
|
|
55
|
+
host?.setAttribute("aria-invalid", String(result.errors.length > 0));
|
|
56
|
+
updateFormatButtons();
|
|
57
|
+
if (!error || !errorList)
|
|
58
|
+
return;
|
|
59
|
+
errorList.textContent = "";
|
|
60
|
+
if (!result.errors.length) {
|
|
61
|
+
error.hidden = true;
|
|
62
|
+
errorList.hidden = true;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const first = result.errors[0];
|
|
66
|
+
error.textContent = app.t("integrationsRulesErrors", {
|
|
67
|
+
count: result.errors.length,
|
|
68
|
+
first: `Line ${first.line}: ${first.message}`,
|
|
69
|
+
});
|
|
70
|
+
error.hidden = false;
|
|
71
|
+
errorList.hidden = false;
|
|
72
|
+
for (const issue of result.errors) {
|
|
73
|
+
const item = document.createElement("li");
|
|
74
|
+
const button = document.createElement("button");
|
|
75
|
+
button.type = "button";
|
|
76
|
+
button.className = "integration-rule-error";
|
|
77
|
+
button.textContent = `Line ${issue.line}${issue.path ? ` · ${issue.path}` : ""}: ${issue.message}`;
|
|
78
|
+
button.addEventListener("click", () => controller?.reveal(issue.line, issue.column));
|
|
79
|
+
item.append(button);
|
|
80
|
+
errorList.append(item);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const clearErrors = () => {
|
|
84
|
+
if (error)
|
|
85
|
+
error.hidden = true;
|
|
86
|
+
if (errorList) {
|
|
87
|
+
errorList.hidden = true;
|
|
88
|
+
errorList.textContent = "";
|
|
89
|
+
}
|
|
90
|
+
host?.setAttribute("data-error-count", "0");
|
|
91
|
+
host?.removeAttribute("aria-invalid");
|
|
92
|
+
};
|
|
93
|
+
const ensure = () => {
|
|
94
|
+
if (controller || failed || !host)
|
|
95
|
+
return loading;
|
|
96
|
+
if (loading)
|
|
97
|
+
return loading;
|
|
98
|
+
loading = loadBundle().then((module) => {
|
|
99
|
+
controller = module.createIntegrationRulesEditor({
|
|
100
|
+
kind: options.kind,
|
|
101
|
+
container: host,
|
|
102
|
+
value: options.getValue(),
|
|
103
|
+
accounts: options.getAccounts(),
|
|
104
|
+
onChange: render,
|
|
105
|
+
});
|
|
106
|
+
host.hidden = false;
|
|
107
|
+
if (textarea)
|
|
108
|
+
textarea.hidden = true;
|
|
109
|
+
if (fallback)
|
|
110
|
+
fallback.hidden = true;
|
|
111
|
+
if (formatGroup)
|
|
112
|
+
formatGroup.hidden = false;
|
|
113
|
+
applyEditable();
|
|
114
|
+
render(controller.validate());
|
|
115
|
+
}).catch(() => {
|
|
116
|
+
failed = true;
|
|
117
|
+
if (fallback) {
|
|
118
|
+
fallback.textContent = app.t("integrationsEditorUnavailable");
|
|
119
|
+
fallback.hidden = false;
|
|
120
|
+
}
|
|
121
|
+
}).finally(() => { loading = null; });
|
|
122
|
+
return loading;
|
|
123
|
+
};
|
|
124
|
+
const refresh = () => {
|
|
125
|
+
const value = options.getValue() ?? [];
|
|
126
|
+
clearErrors();
|
|
127
|
+
if (controller)
|
|
128
|
+
controller.setValue(value);
|
|
129
|
+
else if (textarea)
|
|
130
|
+
textarea.value = JSON.stringify(value, null, 2);
|
|
131
|
+
};
|
|
132
|
+
const current = () => {
|
|
133
|
+
if (controller) {
|
|
134
|
+
const result = controller.validate();
|
|
135
|
+
render(result);
|
|
136
|
+
return { editor: true, ...result };
|
|
137
|
+
}
|
|
138
|
+
return { editor: false, text: textarea?.value || "", errors: [] };
|
|
139
|
+
};
|
|
49
140
|
for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
host?.setAttribute("data-error-count", String(result.errors.length));
|
|
57
|
-
host?.setAttribute("aria-invalid", String(result.errors.length > 0));
|
|
58
|
-
updateFormatButtons();
|
|
59
|
-
if (!error || !errorList) return;
|
|
60
|
-
errorList.textContent = "";
|
|
61
|
-
if (!result.errors.length) {
|
|
62
|
-
error.hidden = true;
|
|
63
|
-
errorList.hidden = true;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const first = result.errors[0];
|
|
67
|
-
error.textContent = app.t("integrationsRulesErrors", {
|
|
68
|
-
count: result.errors.length,
|
|
69
|
-
first: `Line ${first.line}: ${first.message}`,
|
|
70
|
-
});
|
|
71
|
-
error.hidden = false;
|
|
72
|
-
errorList.hidden = false;
|
|
73
|
-
for (const issue of result.errors) {
|
|
74
|
-
const item = document.createElement("li");
|
|
75
|
-
const button = document.createElement("button");
|
|
76
|
-
button.type = "button";
|
|
77
|
-
button.className = "integration-rule-error";
|
|
78
|
-
button.textContent = `Line ${issue.line}${issue.path ? ` · ${issue.path}` : ""}: ${issue.message}`;
|
|
79
|
-
button.addEventListener("click", () => controller?.reveal(issue.line, issue.column));
|
|
80
|
-
item.append(button);
|
|
81
|
-
errorList.append(item);
|
|
141
|
+
button.addEventListener("click", () => {
|
|
142
|
+
if (!controller || !editable)
|
|
143
|
+
return;
|
|
144
|
+
controller.setFormat(button.dataset.format === "yaml" ? "yaml" : "json");
|
|
145
|
+
updateFormatButtons();
|
|
146
|
+
});
|
|
82
147
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
render(controller.validate());
|
|
109
|
-
}).catch(() => {
|
|
110
|
-
failed = true;
|
|
111
|
-
if (fallback) {
|
|
112
|
-
fallback.textContent = app.t("integrationsEditorUnavailable");
|
|
113
|
-
fallback.hidden = false;
|
|
114
|
-
}
|
|
115
|
-
}).finally(() => { loading = null; });
|
|
116
|
-
return loading;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const refresh = () => {
|
|
120
|
-
const value = options.getValue() ?? [];
|
|
121
|
-
clearErrors();
|
|
122
|
-
if (controller) controller.setValue(value);
|
|
123
|
-
else if (textarea) textarea.value = JSON.stringify(value, null, 2);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const current = () => {
|
|
127
|
-
if (controller) {
|
|
128
|
-
const result = controller.validate();
|
|
129
|
-
render(result);
|
|
130
|
-
return { editor: true, ...result };
|
|
131
|
-
}
|
|
132
|
-
return { editor: false, text: textarea?.value || "", errors: [] };
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
for (const button of formatGroup?.querySelectorAll("[data-format]") || []) {
|
|
136
|
-
button.addEventListener("click", () => {
|
|
137
|
-
if (!controller || !editable) return;
|
|
138
|
-
controller.setFormat(button.dataset.format === "yaml" ? "yaml" : "json");
|
|
139
|
-
updateFormatButtons();
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
textarea?.addEventListener("input", clearErrors);
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
ensure,
|
|
146
|
-
refresh,
|
|
147
|
-
current,
|
|
148
|
-
showMessage: (message) => {
|
|
149
|
-
if (!error) return;
|
|
150
|
-
error.textContent = message;
|
|
151
|
-
error.hidden = false;
|
|
152
|
-
if (errorList) { errorList.hidden = true; errorList.textContent = ""; }
|
|
153
|
-
},
|
|
154
|
-
setAccounts: (accounts) => controller?.setAccounts(accounts),
|
|
155
|
-
setEditable: (next) => {
|
|
156
|
-
editable = next !== false;
|
|
157
|
-
applyEditable();
|
|
158
|
-
},
|
|
159
|
-
getText: () => textarea?.value || "",
|
|
160
|
-
hasEditor: () => Boolean(controller),
|
|
161
|
-
dispose: () => controller?.dispose(),
|
|
162
|
-
};
|
|
163
|
-
}
|
|
148
|
+
textarea?.addEventListener("input", clearErrors);
|
|
149
|
+
return {
|
|
150
|
+
ensure,
|
|
151
|
+
refresh,
|
|
152
|
+
current,
|
|
153
|
+
showMessage: (message) => {
|
|
154
|
+
if (!error)
|
|
155
|
+
return;
|
|
156
|
+
error.textContent = message;
|
|
157
|
+
error.hidden = false;
|
|
158
|
+
if (errorList) {
|
|
159
|
+
errorList.hidden = true;
|
|
160
|
+
errorList.textContent = "";
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
setAccounts: (accounts) => controller?.setAccounts(accounts),
|
|
164
|
+
setEditable: (next) => {
|
|
165
|
+
editable = next !== false;
|
|
166
|
+
applyEditable();
|
|
167
|
+
},
|
|
168
|
+
getText: () => textarea?.value || "",
|
|
169
|
+
hasEditor: () => Boolean(controller),
|
|
170
|
+
dispose: () => controller?.dispose(),
|
|
171
|
+
};
|
|
172
|
+
}
|