This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 21:52:48 +01:00
1 parent f48843e934
commit e2c8099d9c
64 files changed
+5354 -673

No files matched your search

+42 -1
View File
@@ -78,6 +78,8 @@ window.rustProxyAclPicker = (() => {
options.addEventListener("change", event => { if (event.target.matches('input[type="checkbox"]')) sync(); });
search.addEventListener("input", syncSearch);
search.addEventListener("keydown", event => { if (event.key === "Escape") { search.value = ""; syncSearch(); details.open = false; summary.focus(); } });
root.select = ids => { for (const [id, box] of checks) box.checked = ids.includes(id); sync(); };
root.setDisabled = disabled => { root.classList.toggle("is-disabled", disabled); details.open = details.open && !disabled; summary.tabIndex = disabled ? -1 : 0; summary.setAttribute("aria-disabled", String(disabled)); };
syncSearch(); sync(); return root;
}
return { create, read: chosenIds, count: root => chosenIds(root).length };
@@ -103,7 +105,7 @@ window.rustProxyChoicePicker = (() => {
const row = el("label", undefined, "acl-picker-option"), check = el("input"); check.type = "checkbox"; check.value = item.id; check.checked = !!checked;
const content = el("span", undefined, "acl-picker-option-content"), headingRow = el("span", undefined, "acl-picker-option-heading");
headingRow.append(el("strong", item.title || item.id));
if (item.title && item.title !== item.id) headingRow.append(el("code", item.id, "acl-picker-id"));
if (item.title && item.title !== item.id && !item.title.startsWith(`${item.id} `)) headingRow.append(el("code", item.id, "acl-picker-id"));
if (item.badge) headingRow.append(el("span", item.badge, `acl-picker-policy ${item.badgeClass || "is-none"}`));
content.append(headingRow); if (item.detail) content.append(el("small", item.detail, "acl-picker-rule-preview"));
row.append(check, content); row.dataset.search = `${item.id} ${item.title || ""} ${item.search || ""} ${item.detail || ""}`.toLocaleLowerCase();
@@ -240,3 +242,42 @@ window.rustProxyCountryPicker = (() => {
}
return { attach, codes: CODES, nameOf };
})();
window.rustProxyMethodPicker = (() => {
const METHODS = [
["GET", "methodGet"], ["HEAD", "methodHead"], ["POST", "methodPost"], ["PUT", "methodPut"], ["PATCH", "methodPatch"], ["DELETE", "methodDelete"],
["OPTIONS", "methodOptions"], ["CONNECT", "methodConnect"], ["TRACE", "methodTrace"], ["TRACK", "methodTrack"], ["PURGE", "methodPurge"], ["BAN", "methodBan"],
["PROPFIND", "methodWebdav"], ["PROPPATCH", "methodWebdav"], ["MKCOL", "methodWebdav"], ["COPY", "methodWebdav"], ["MOVE", "methodWebdav"], ["LOCK", "methodWebdav"], ["UNLOCK", "methodWebdav"],
["SEARCH", "methodWebdav"], ["REPORT", "methodWebdav"], ["MKCALENDAR", "methodWebdav"],
];
const TOKEN = /^[A-Z0-9!#$%&'*+.^_`|~-]{1,32}$/;
const parse = text => [...new Set(String(text || "").split(/[\s,;]+/).map(value => value.trim().toUpperCase()).filter(Boolean))];
function attach(textarea) {
if (!textarea || textarea.dataset.methodPicker) return null;
textarea.dataset.methodPicker = "1"; textarea.hidden = true;
const wrapper = textarea.parentElement;
if (wrapper?.tagName === "LABEL") { const box = el("div", undefined, wrapper.className); box.append(...wrapper.childNodes); wrapper.replaceWith(box); }
const host = el("div", undefined, "method-picker-host"); textarea.after(host);
let picker = null, writing = false;
const build = () => {
picker = window.rustProxyChoicePicker.create({
className: "method-picker", selected: parse(textarea.value), limit: 64, unknownDetail: "methodCustom",
items: METHODS.map(([id, key]) => ({ id, title: id, detail: t(key) })),
labels: { choose: "methodPickerChoose", selected: "methodPickerSelected", none: "methodPickerNone", search: "methodPickerSearch", addHint: "methodPickerAddHint", empty: "methodPickerEmpty" },
custom: raw => {
const id = String(raw || "").trim().toUpperCase(); if (!id) return null;
if (!TOKEN.test(id)) throw new Error(t("methodPickerInvalid").replace("{value}", raw));
return { id, title: id, detail: t("methodCustom") };
},
});
picker.addEventListener("choicechange", event => { if (writing) return; const value = (event.detail || []).join("\n"); if (value === textarea.value) return; textarea.value = value; textarea.dispatchEvent(new Event("input", { bubbles: true })); textarea.dispatchEvent(new Event("change", { bubbles: true })); });
host.replaceChildren(picker);
picker.setDisabled(textarea.disabled);
};
const refresh = () => { writing = true; try { build(); } finally { writing = false; } };
refresh();
new MutationObserver(() => picker?.setDisabled(textarea.disabled)).observe(textarea, { attributes: true, attributeFilter: ["disabled"] });
return { refresh, host };
}
return { attach, methods: METHODS.map(([id]) => id) };
})();