// Parts placed lately, newest first ("nand", "chip:"), kept in this // browser: the parts list and the quick-add box offer them first. import { ref } from 'vue' import type { NodeKind } from './logic/types' const KEY = 'logigate:recent-parts' function load(): string[] { try { const v = JSON.parse(localStorage.getItem(KEY) ?? '[]') return Array.isArray(v) ? v.filter(x => typeof x === 'string').slice(0, 8) : [] } catch { return [] } } export const recentParts = ref(typeof localStorage === 'undefined' ? [] : load()) export function rememberPart(kind: NodeKind, chip?: string) { const key = chip ? `chip:${chip}` : kind recentParts.value = [key, ...recentParts.value.filter(k => k !== key)].slice(0, 8) try { localStorage.setItem(KEY, JSON.stringify(recentParts.value)) } catch {} }