feat: добавить общий виртуальный счёт, справку и восстановление позиций
Offline regression tests / windows (3.11) (push) Canceled after 0s
Offline regression tests / windows (3.12) (push) Canceled after 0s
Offline regression tests / windows (3.13) (push) Canceled after 0s

This commit is contained in:
Igol committed 2026-10-22 23:07:50 +03:00
1 parent 6aa76064dc
commit c5aed5b970
29 files changed
+3600 -224

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
let helpReturnFocus = null;
let helpFieldCounter = 0;
function helpEntries() {
const entries = HELP_EXTRA.map(([group, key, label, text]) => ({group, key, label, text}));
const groups = [
["Симулятор — настройки монет", "sim", [...MAIN_FIELDS, ...MORE_FIELDS]],
["Арбитраж — симуляция и реальная торговля", "cross", [...CX_FIELDS, ...CX_CHECKS]],
["Движок спот-фьюч — дополнительные параметры", "basis", [...BX_FIELDS, ...BX_CHECKS]]
];
for (const [group, scope, fields] of groups) {
for (const [key, label] of fields) entries.push({group, key, label, text: HELP_SETTINGS[scope][key] || "Описание этого нового параметра ещё не добавлено."});
}
const modes = state?.modes || {lead: "Ведущая биржа", vector: "Вектор", basis: "Разрыв цен"};
for (const [key, label] of Object.entries(modes)) entries.push({group: "Режимы симулятора", key, label, text: HELP_MODES[key] || "Режим предоставлен сервером. Условия входа, выхода и текущая причина блокировки показываются в карточке выбранной монеты."});
return entries;
}
function filterHelp(entries, query) {
const normalize = value => String(value).toLocaleLowerCase("ru").replace(/ё/g, "е");
const words = normalize(query).trim().split(/\s+/).filter(Boolean);
return entries.filter(entry => words.every(word => normalize(`${entry.group} ${entry.key} ${entry.label} ${entry.text}`).includes(word)));
}
function renderHelp() {
const search = document.getElementById("helpSearch"), content = document.getElementById("helpContent");
if (!search || !content) return;
const entries = filterHelp(helpEntries(), search.value);
const fragment = document.createDocumentFragment(), groups = new Map();
for (const entry of entries) {
if (!groups.has(entry.group)) {
const section = document.createElement("section"), heading = document.createElement("h3");
heading.textContent = entry.group; section.append(heading); groups.set(entry.group, section); fragment.append(section);
}
const article = document.createElement("article"), heading = document.createElement("h4"), key = document.createElement("code"), body = document.createElement("p");
article.className = "help-entry"; heading.textContent = entry.label; key.textContent = entry.key; body.textContent = entry.text;
heading.append(key); article.append(heading, body); groups.get(entry.group).append(article);
}
content.replaceChildren(fragment);
document.getElementById("helpCount").textContent = entries.length ? `Найдено разделов и параметров: ${entries.length}` : "Ничего не найдено. Попробуйте короткое название или ключ настройки.";
}
function helpOpen(query = "") {
const dialog = document.getElementById("helpDialog");
helpReturnFocus = document.activeElement;
document.getElementById("helpSearch").value = query;
renderHelp();
if (!dialog.open) dialog.showModal();
document.getElementById("helpSearch").focus();
}
function helpClose() { document.getElementById("helpDialog").close(); }
function applyHelpHints() {
document.querySelectorAll("[data-k], [data-bx]").forEach(el => {
const key = el.dataset.k || el.dataset.bx, scope = el.dataset.k ? "sim" : "cross";
const text = HELP_SETTINGS[scope][key];
if (text) el.title = text;
if (!el.id) el.id = `setting-${scope}-${key}`;
const label = el.closest(".field")?.querySelector("label");
if (label) label.htmlFor = el.id;
if (el.tagName === "INPUT" && el.type !== "checkbox") el.inputMode = "decimal";
});
document.querySelectorAll("[data-cxfee], [data-cxlimit]").forEach(el => {
el.setAttribute("aria-label", el.dataset.cxfee ? `Комиссия ${el.dataset.cxfee}` : `Лимит сделок ${el.dataset.cxlimit}`);
el.inputMode = "decimal";
});
document.querySelectorAll(".field").forEach(field => {
const label = field.querySelector("label"), input = field.querySelector("input, select");
if (!label || !input) return;
if (!input.id) input.id = `field-auto-${++helpFieldCounter}`;
label.htmlFor = input.id;
});
}
const helpDialog = document.getElementById("helpDialog");
if (helpDialog) {
helpDialog.addEventListener("close", () => { if (helpReturnFocus?.isConnected) helpReturnFocus.focus(); });
// Native <dialog> handles Escape and keeps keyboard focus inside the modal.
helpDialog.addEventListener("click", event => {
if (event.target !== helpDialog) return;
const bounds = helpDialog.getBoundingClientRect();
if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) helpClose();
});
}