feat(Breadcrumb): create new entity that contains logic related to breadcrumb-like navigation

This commit is contained in:
Ilia Mashkov
2026-02-02 11:59:57 +03:00
parent 70f57283a8
commit a9c63f2544
5 changed files with 113 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
export * from './store/scrollBreadcrumbsStore.svelte';
@@ -0,0 +1,29 @@
import type { Snippet } from 'svelte';
export interface BreadcrumbItem {
index: number;
title: Snippet<[{ className?: string }]>;
}
class ScrollBreadcrumbsStore {
#items = $state<BreadcrumbItem[]>([]);
get items() {
// Keep them sorted by index for Swiss orderliness
return this.#items.sort((a, b) => a.index - b.index);
}
add(item: BreadcrumbItem) {
if (!this.#items.find(i => i.index === item.index)) {
this.#items.push(item);
}
}
remove(index: number) {
this.#items = this.#items.filter(i => i.index !== index);
}
}
export function createScrollBreadcrumbsStore() {
return new ScrollBreadcrumbsStore();
}
export const scrollBreadcrumbsStore = createScrollBreadcrumbsStore();