// состояние окна карточки в записи истории (design 10–12): страница под окном, сколько записей заняли карточки // поверх неё, открыто ли окно прямым адресом export interface Background { pathname: string; search: string } export interface CardState { background: Background; depth: number; direct: boolean } export const LIST_BACKGROUND: Background = { pathname: "/issues", search: "" }; // доска не хранит состояние в адресе: «ⓘ» всегда открывает окно поверх /board export const BOARD_CARD_STATE: CardState = { background: { pathname: "/board", search: "" }, depth: 1, direct: false }; export function cardState(s: unknown): CardState | null { const c = s as { background?: { pathname?: unknown; search?: unknown }; depth?: unknown; direct?: unknown } | null; if (!c || typeof c !== "object" || !c.background || typeof c.background !== "object") return null; const { pathname, search } = c.background; if (typeof pathname !== "string" || typeof search !== "string" || typeof c.depth !== "number") return null; const depth = Number.isInteger(c.depth) && c.depth >= 0 ? c.depth : 0; // NaN, дробные и отрицательные не доходят до navigate(-depth) return { background: { pathname, search }, depth, direct: c.direct === true }; } // state ссылки на карточку: со страницы — фон = её адрес, глубина 1; из окна — тот же фон, глубина + 1 export function openCardState(loc: { pathname: string; search: string; state: unknown }): CardState { const cur = cardState(loc.state); return cur ? { ...cur, depth: cur.depth + 1 } : { background: { pathname: loc.pathname, search: loc.search }, depth: 1, direct: false }; }