feat(sidebar): метки внимания на пунктах меню

- 개인 метки пользователя в user_settings.sidebar_marks (JSON-массив id страниц)
- normalizeSidebarMarks() в lib/sidebar.js с валидацией (^[A-Za-z0-9_.-]+$, <=64 символов)
- точечные индикаторы .nav-dot на пунктах сайдбара, клик/Enter/пробел toggle
- сохранение через PUT /api/user-settings с очередью (keepalive), кэш в localStorage
- синхронизация между вкладками через событие storage
This commit is contained in:
dev
2026-12-02 21:53:17 +03:00
parent 2cd1d37445
commit f634d88cae
6 changed files with 203 additions and 29 deletions
+21
View File
@@ -105,9 +105,30 @@ function normalizeSidebarPayload(input) {
return out;
}
function normalizeSidebarMarks(value) {
let list = value;
if (typeof value === 'string') {
if (!value.trim()) return '';
try { list = JSON.parse(value); } catch { throw new Error('Некорректный список меток'); }
}
if (!Array.isArray(list)) throw new Error('Некорректный список меток');
const out = [];
const seen = new Set();
for (const raw of list) {
const page = String(raw == null ? '' : raw).trim();
if (!page) continue;
if (page.length > 64 || !/^[A-Za-z0-9_.-]+$/.test(page)) throw new Error('Некорректная метка');
if (seen.has(page)) continue;
seen.add(page);
out.push(page);
}
return out.length ? JSON.stringify(out) : '';
}
module.exports = {
DEFAULT_ITEMS,
ensureSidebarItemsTable,
listSidebarItems,
normalizeSidebarPayload,
normalizeSidebarMarks,
};