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:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user