Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

Feat/breadcrumbs navigation issue 161 (#418)

Danil7ab7ced6bdff
diff --git a/frontend/app/components/BreadCrumb.vue b/frontend/app/components/BreadCrumb.vue
deleted file mode 100644
index bad0585c..00000000
--- a/frontend/app/components/BreadCrumb.vue
+++ /dev/null
@@ -1,149 +0,0 @@
-<template>
- <nav class="no-mobile" aria-label="Breadcrumb">
- <svg
- v-if="hasNavigation.navigation"
- :class="{ disabled: !canGoBack, 'no-tablet': true }"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 -960 960 960"
- @click="goBack"
- >
- <path d="M560-240 320-480l240-240 56 56-184 184 184 184-56 56Z" />
- </svg>
-
- <svg
- v-if="hasNavigation.navigation"
- :class="{ disabled: !canGoForward, 'no-tablet': true }"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 -960 960 960"
- @click="goForward"
- >
- <path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z" />
- </svg>
-
- <ol class="list">
- <li v-for="(segment, index) in breadcrumbs" :key="index" class="item">
- <NuxtLink :to="segment.path"> {{ segment.name }} </NuxtLink>
- </li>
- </ol>
- </nav>
-</template>
-
-<script setup lang="ts">
-import type { RouteLocationNormalizedLoaded } from 'vue-router';
-
-const { t } = useI18nT();
-const route = useRoute();
-const router = useRouter();
-const preferences = usePreferencesStore();
-
-const breadcrumbs = ref<Array<{ name: string; path: string }>>([]);
-
-const canGoBack = ref(false);
-const canGoForward = ref(false);
-const hasNavigation = preferences.get('navbarItems');
-
-// Renamed for clarity
-const goBack = () => router.go(-1);
-const goForward = () => router.go(1);
-
-interface I18nBreadcrumb {
- c?: number; // Optional count for pluralization
- i18n: I18nKey;
-}
-
-declare module 'vue-router' {
- interface RouteMeta {
- breadcrumb?: ((route: RouteLocationNormalizedLoaded) => string) | I18nBreadcrumb | string;
- }
-}
-
-watchEffect(() => {
- canGoBack.value = window.history.state?.back !== null;
- canGoForward.value = window.history.state?.forward !== null;
-
- breadcrumbs.value = [];
-
- route.matched.forEach(match => {
- const meta = match.meta?.breadcrumb;
- if (!meta) return;
-
- let name = '';
-
- if (typeof meta === 'function') {
- name = meta(route);
- } else if (typeof meta === 'object' && (meta as I18nBreadcrumb)?.i18n) {
- const { c, i18n } = meta as I18nBreadcrumb;
- name = t(i18n, { count: c });
- } else {
- name = meta as string;
- }
-
- if (!name) return;
-
- breadcrumbs.value.push({
- name,
- path: router.resolve(match).path,
- });
- });
-});
-</script>
-
-<style lang="scss" scoped>
-nav {
- display: flex;
- padding: 3px;
- align-items: center;
- flex-wrap: wrap;
- gap: 8px;
-
- svg {
- width: 27px;
- height: 27px;
- border-radius: 50%;
- transition:
- background-color $transition-medium ease,
- opacity $transition-medium ease;
- cursor: pointer;
- fill: var(--text-body);
- margin-right: 8px;
-
- &:hover:not(.disabled) {
- background-color: var(--selection-color);
- opacity: 0.8;
- }
-
- &.disabled {
- opacity: 0.4;
- cursor: not-allowed;
- }
- }
-}
-
-.list {
- display: flex;
- margin: 0;
- padding: 0;
- align-items: center;
- list-style: none;
-}
-
-.item {
- display: inline-flex;
- align-items: center;
-
- a {
- padding: 4px 8px;
- border-radius: var(--radius-xs);
- font-size: 14px;
- font-weight: 500;
- color: var(--text-body);
- text-decoration: none;
- }
-
- &:not(:last-child)::after {
- margin: 0 8px;
- color: var(--text-secondary);
- content: '/';
- }
-}
-</style>
diff --git a/frontend/app/components/Navbar.vue b/frontend/app/components/Navbar.vue
index 79827643..8a5d53a9 100644
--- a/frontend/app/components/Navbar.vue
+++ b/frontend/app/components/Navbar.vue
@@ -1,14 +1,16 @@
<template>
- <header>
- <div>
+ <header class="navbar">
+ <div class="navbar__navigation">
<button v-if="!isOpened" class="open-sidebar" aria-label="open sidebar" @click="toggleSidebar">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24">
<path d="M120-240v-80h720v80H120Zm0-200v-80h720v80H120Zm0-200v-80h720v80H120Z" />
</svg>
</button>
- <BreadCrumb v-if="navbarItems.breadcrumb" />
+
+ <Navigation v-if="navbarItems.breadcrumb" />
</div>
- <div>
+
+ <div class="navbar__search">
<button v-if="navbarItems.search" class="search-btn" :title="t('components.navbar.commandCenter')" aria-label="Command center" @click="openCommandCenter">
<Icon name="search" />
<span class="search-text">
@@ -19,12 +21,15 @@
</i18n-t>
</span>
</button>
+
<ThemeToggle v-if="navbarItems.theme" aria-label="toggle theme" />
</div>
</header>
</template>
<script lang="ts" setup>
+import Navigation from "~/components/Navigation/Navigation.vue";
+
const { t } = useI18nT();
const { isOpened, toggleSidebar } = useSidebar();
const preferences = usePreferencesStore();
@@ -35,7 +40,7 @@ const openCommandCenter = () => commandCenter.open();
</script>
<style lang="scss" scoped>
-header {
+.navbar {
position: sticky;
display: flex;
width: 100%;
@@ -45,11 +50,17 @@ header {
border-bottom: 1px solid var(--border);
justify-content: space-between;
- div {
+ &__navigation,
+ &__search {
display: flex;
align-items: center;
gap: 16px;
}
+
+ &__navigation {
+ flex: 1;
+ overflow-x: auto;
+ }
}
svg {
diff --git a/frontend/app/components/Navigation/BreadCrumbs.vue b/frontend/app/components/Navigation/BreadCrumbs.vue
new file mode 100644
index 00000000..106fda7f
--- /dev/null
+++ b/frontend/app/components/Navigation/BreadCrumbs.vue
@@ -0,0 +1,111 @@
+<template>
+ <ol class="breadcrumbs">
+ <li v-for="(segment, index) in breadcrumbs" :key="index" class="breadcrumbs__item">
+ <Icon v-if="index > 0" name="chevron_right" display="sm" class="breadcrumbs__separator" />
+ <NuxtLink class="breadcrumbs__link" :class="{ 'breadcrumbs__link--active': index === breadcrumbs.length - 1 }" :to="segment.path">
+ {{ segment.name }}
+ </NuxtLink>
+ </li>
+ </ol>
+</template>
+
+<script setup lang="ts">
+interface I18nBreadcrumb {
+ c?: number; // Optional count for pluralization
+ i18n: I18nKey;
+}
+
+const route = useRoute();
+const { t } = useI18nT();
+
+const breadcrumbs = ref<{ name: string; path: string }[]>([]);
+
+watchEffect(() => {
+ breadcrumbs.value = [];
+
+ route.matched.forEach(match => {
+ const meta = match.meta?.breadcrumb;
+ if (!meta) return;
+ let name = '';
+
+ switch (typeof meta) {
+ case 'function':
+ breadcrumbs.value = [...breadcrumbs.value, ...meta(route)];
+ return;
+ case 'object':
+ if ('i18n' in meta) {
+ const { c, i18n } = meta as I18nBreadcrumb;
+ name = t(i18n, { count: c });
+ }
+ break;
+ case 'string':
+ name = meta;
+ break;
+ }
+
+ if (!name) return;
+
+ breadcrumbs.value.push({
+ name,
+ path: match.path,
+ });
+ });
+});
+</script>
+
+<style scoped lang="scss">
+.breadcrumbs {
+ --_fade: 12px;
+
+ display: flex;
+ min-width: 0;
+ margin: 0;
+ padding-inline: 8px;
+ align-items: center;
+ list-style: none;
+ overflow-x: auto;
+ -webkit-overflow-scrolling: touch;
+ white-space: nowrap;
+ scroll-behavior: smooth;
+ scrollbar-width: none;
+ mask-image: linear-gradient(to right, transparent, black var(--_fade), black calc(100% - var(--_fade)), transparent);
+ -webkit-mask-image: linear-gradient(to right, transparent, black var(--_fade), black calc(100% - var(--_fade)), transparent);
+
+ &::-webkit-scrollbar {
+ display: none;
+ }
+
+ &__item {
+ display: inline-flex;
+ align-items: center;
+ gap: 2px;
+ }
+
+ &__separator {
+ flex-shrink: 0;
+ opacity: 0.6;
+ }
+
+ &__link {
+ padding: 4px 8px;
+ border-radius: var(--radius-xs);
+ font-size: 0.85rem;
+ font-weight: 500;
+ color: var(--text-secondary);
+ text-decoration: none;
+ transition:
+ background-color 0.15s ease,
+ color 0.15s ease;
+
+ &:hover {
+ background-color: var(--surface-transparent);
+ color: var(--text-body);
+ }
+
+ &--active {
+ color: var(--text-body);
+ font-weight: 600;
+ }
+ }
+}
+</style>
diff --git a/frontend/app/components/Navigation/Navigation.vue b/frontend/app/components/Navigation/Navigation.vue
new file mode 100644
index 00000000..5b229691
--- /dev/null
+++ b/frontend/app/components/Navigation/Navigation.vue
@@ -0,0 +1,89 @@
+<template>
+ <nav class="navigation no-mobile" aria-label="Navigation">
+ <template v-if="hasNavigation.navigation">
+ <button :disabled="!canGoBack" class="navigation__item no-tablet" aria-label="Go back" type="button" @click="goBack">
+ <svg class="navigation__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
+ <path d="M560-240 320-480l240-240 56 56-184 184 184 184-56 56Z" />
+ </svg>
+ </button>
+
+ <button :disabled="!canGoForward" class="navigation__item no-tablet" aria-label="Go forward" type="button" @click="goForward">
+ <svg class="navigation__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960">
+ <path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z" />
+ </svg>
+ </button>
+ </template>
+
+ <BreadCrumbs />
+ </nav>
+</template>
+
+<script setup lang="ts">
+import BreadCrumbs from '~/components/Navigation/BreadCrumbs.vue';
+
+const router = useRouter();
+const preferences = usePreferencesStore();
+
+const hasNavigation = preferences.get('navbarItems');
+
+const canGoBack = ref(false);
+const canGoForward = ref(false);
+
+const goBack = () => router.go(-1);
+const goForward = () => router.go(1);
+
+function handleState(state: History['state']) {
+ if (!state) return;
+
+ canGoBack.value = state.back !== null;
+ canGoForward.value = state.forward !== null;
+}
+
+router.afterEach(() => handleState(window.history.state));
+</script>
+
+<style scoped lang="scss">
+.navigation {
+ display: flex;
+ padding: 3px;
+ align-items: center;
+ gap: 8px;
+ overflow-x: auto;
+ -webkit-overflow-scrolling: touch;
+ white-space: nowrap;
+ scroll-behavior: smooth;
+
+ &__item {
+ display: inline-flex;
+ padding: 0;
+ border-radius: 50%;
+ overflow: hidden;
+ cursor: pointer;
+ min-width: 27px;
+ min-height: 27px;
+
+ &:hover:not(:disabled) {
+ .navigation__icon {
+ background-color: var(--selection-color);
+ opacity: 0.8;
+ }
+ }
+
+ &:disabled {
+ .navigation__icon {
+ opacity: 0.4;
+ cursor: not-allowed;
+ }
+ }
+ }
+
+ &__icon {
+ width: 27px;
+ height: 27px;
+ fill: var(--text-body);
+ transition:
+ background-color $transition-medium ease,
+ opacity $transition-medium ease;
+ }
+}
+</style>
diff --git a/frontend/app/components/Node/Card/NodeCard.vue b/frontend/app/components/Node/Card/NodeCard.vue
index 114628ad..71bdba48 100644
--- a/frontend/app/components/Node/Card/NodeCard.vue
+++ b/frontend/app/components/Node/Card/NodeCard.vue
@@ -51,7 +51,6 @@ const user = computed(() => userStore.getById(props.node.user_id || ''));
const deleteDoc = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { node: props.node } }));
function showContextMenu(event: MouseEvent) {
- if (props.node.role === -1) return; // Prevent context menu on nav items
useContextMenu().open(shallowRef(NodeContextMenu), event, {
props: { node: props.node, contextMenu: true },
});
diff --git a/frontend/app/components/Node/List/Inline.vue b/frontend/app/components/Node/List/Inline.vue
index c19dfbc9..ce3679e5 100644
--- a/frontend/app/components/Node/List/Inline.vue
+++ b/frontend/app/components/Node/List/Inline.vue
@@ -45,7 +45,6 @@ const user = computed(() => userStore.getById(props.document.user_id || ''));
const deleteDoc = () => useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { node: props.document } }));
function showContextMenu(event: MouseEvent) {
- if (props.document.role === -1) return; // Prevent context menu on nav items
useContextMenu().open(shallowRef(NodeContextMenu), event, {
props: { node: props.document as Node, contextMenu: true },
});
diff --git a/frontend/app/composables/useBreadcrumbs.ts b/frontend/app/composables/useBreadcrumbs.ts
new file mode 100644
index 00000000..689c3896
--- /dev/null
+++ b/frontend/app/composables/useBreadcrumbs.ts
@@ -0,0 +1,27 @@
+import type { NodeRole } from '~/stores';
+
+const ROUTE_ROLE_MAPPING: Record<NodeRole, string> = {
+ 1: '/dashboard/categories',
+ 2: '/dashboard/categories',
+ 3: '/dashboard/docs',
+ 4: '/dashboard/cdn',
+};
+
+export function useBreadcrumbs() {
+ const nodesStore = useNodesStore();
+
+ function generateBreadcrumbsById(id: string) {
+ const nodes = nodesStore.getByIdWithParents(id);
+
+ return nodes
+ .map(node => ({
+ name: node.name,
+ path: `${ROUTE_ROLE_MAPPING[node.role]}/${node.id}`,
+ }))
+ .reverse();
+ }
+
+ return {
+ generateBreadcrumbsById,
+ };
+}
diff --git a/frontend/app/pages/(public)/doc/[id]/index.vue b/frontend/app/pages/(public)/doc/[id]/index.vue
index bf22ac0f..6bb6b557 100644
--- a/frontend/app/pages/(public)/doc/[id]/index.vue
+++ b/frontend/app/pages/(public)/doc/[id]/index.vue
@@ -14,7 +14,7 @@
<NodeDocumentHeader :doc="article" :public="true" style="margin: 20px 0" />
<!-- Document content if available -->
- <NodeDocumentContentCompiled v-if="hasContent" :node="article" ref="elementComponent" />
+ <NodeDocumentContentCompiled v-if="hasContent" ref="elementComponent" :node="article" />
<!-- Hierarchical children tree -->
<NodeTree v-if="children.length > 0" :nodes="children" :parent-id="article.id" />
diff --git a/frontend/app/pages/dashboard.vue b/frontend/app/pages/dashboard.vue
index 2ce424ba..7dd3e158 100644
--- a/frontend/app/pages/dashboard.vue
+++ b/frontend/app/pages/dashboard.vue
@@ -11,8 +11,6 @@
</div>
</template>
<script setup lang="ts">
-definePageMeta({ breadcrumb: { i18n: 'dashboard.pages.home' } });
-
const nodesStore = useNodesStore();
const userStore = useUserStore();
diff --git a/frontend/app/pages/dashboard/categories/[id]/index.vue b/frontend/app/pages/dashboard/categories/[id]/index.vue
index df3be382..e6ec8e88 100644
--- a/frontend/app/pages/dashboard/categories/[id]/index.vue
+++ b/frontend/app/pages/dashboard/categories/[id]/index.vue
@@ -6,7 +6,11 @@
import type { RouteLocationNormalizedLoaded } from 'vue-router';
import type { Node } from '~/stores';
-definePageMeta({ breadcrumb: (route: RouteLocationNormalizedLoaded) => useNodesStore().getById(route.params.id as string)?.name || '' });
+definePageMeta({
+ breadcrumb: (route: RouteLocationNormalizedLoaded) => {
+ return useBreadcrumbs().generateBreadcrumbsById(route.params.id as string);
+ },
+});
const route = useRoute();
const nodesStore = useNodesStore();
diff --git a/frontend/app/pages/dashboard/docs/[id].vue b/frontend/app/pages/dashboard/docs/[id].vue
index 1d66f515..041146e4 100644
--- a/frontend/app/pages/dashboard/docs/[id].vue
+++ b/frontend/app/pages/dashboard/docs/[id].vue
@@ -19,18 +19,24 @@
</template>
<script setup lang="ts">
import type { RouteLocationNormalizedLoaded } from 'vue-router';
-
import type { Node } from '~/stores';
import NodeContextMenu from '~/components/Node/Action/ContextMenu.vue';
import NodeDocumentContentCompiled from '~/components/Node/Document/ContentCompiled.vue';
import DeleteNodeModal from '~/components/Node/Modals/Delete.vue';
+definePageMeta({
+ breadcrumb: (route: RouteLocationNormalizedLoaded) => {
+ return useBreadcrumbs().generateBreadcrumbsById(route.params.id as string);
+ },
+});
+
const documentsStore = useNodesStore();
const preferencesStore = usePreferencesStore();
const devise = useDevice();
const nodesTree = useNodesTree();
+const contextMenu = useContextMenu();
const route = useRoute();
const router = useRouter();
@@ -62,13 +68,6 @@ watchEffect(async () => {
useHead({ title: node.value?.name || '' });
});
-definePageMeta({
- breadcrumb: (route: RouteLocationNormalizedLoaded) => {
- const doc = useNodesStore().getById(route.params.id as string);
- return doc?.name || '';
- },
-});
-
const next = computed(() => nodesTree.nextDocument(node.value?.id));
const previous = computed(() => nodesTree.prevDocument(node.value?.id));
const width = computed(() => {
@@ -77,9 +76,6 @@ const width = computed(() => {
return '700px';
});
-// Context menu
-const contextMenu = useContextMenu();
-
function showContextMenu(event: MouseEvent) {
contextMenu.open(shallowRef(NodeContextMenu), event, {
props: { contextMenu: true, node: node.value },
diff --git a/frontend/app/pages/dashboard/home.vue b/frontend/app/pages/dashboard/home.vue
index 5291a6ae..b257962a 100644
--- a/frontend/app/pages/dashboard/home.vue
+++ b/frontend/app/pages/dashboard/home.vue
@@ -146,6 +146,8 @@ import { resolveIcon, resolveNodeLink, resolveNodeType } from '~/helpers/node';
import CreateCategoryModal from '~/components/Node/Modals/CreateCategory.vue';
import type { Node } from '~/stores';
+definePageMeta({ breadcrumb: { i18n: 'dashboard.pages.home' } });
+
const router = useRouter();
const nodesStore = useNodesStore();
const userStore = useUserStore();
diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.ts
index 11383c82..f7a2111e 100644
--- a/frontend/app/stores/db_strustures.d.ts
+++ b/frontend/app/stores/db_strustures.d.ts
@@ -5,7 +5,7 @@ export interface DB_Node {
name: string;
description?: string;
tags?: string;
- role: -1 | 1 | 2 | 3 | 4; // 1: Workspace; 2: Category; 3: Document; 4: Resource; -1: Internal (frontend use only)
+ role: NodeRole; // 1: Workspace; 2: Category; 3: Document; 4: Resource; -1: Internal (frontend use only)
color?: number; // -1: Default; 0: None; 1-7: App colors
icon?: string;
thumbnail?: string;
@@ -72,7 +72,7 @@ export interface NodeSearchResult {
name: string;
description?: string;
tags?: string;
- role: number;
+ role: NodeRole;
accessibility: number;
icon?: string;
relevance: number;
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index 41629721..1cabba8a 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -1,6 +1,11 @@
import { Collection } from './collection';
import type { DB_Node, ImportJob, Node, NodeSearchResult, Permission, PublicNodeResponse } from './db_strustures';
+export type CategoryRole = 1 | 2;
+export type DocumentRole = 3;
+export type ResourceRole = 4;
+export type NodeRole = CategoryRole | DocumentRole | ResourceRole;
+
export interface SearchOptions {
query?: string;
fromDate?: Date;
@@ -11,7 +16,7 @@ export interface SearchOptions {
sortBy?: 'created' | 'modified' | 'name';
sortType?: 'ascending' | 'descending';
matchMode?: 'includes' | 'starts' | 'exact';
- role?: 1 | 2 | 3 | 4;
+ role?: NodeRole;
}
export const useNodesStore = defineStore('nodes', {
@@ -25,6 +30,28 @@ export const useNodesStore = defineStore('nodes', {
getAll: state => state.nodes,
getAllTags: state => state.allTags,
getById: state => (id: string) => state.nodes.get(id),
+ getByIdWithParents: state => (id: string) => {
+ const node = state.nodes.get(id);
+
+ if (!node) return [];
+
+ const result = [node];
+
+ if (!node.parent_id) return result;
+
+ const getParents = (children: Node) => {
+ state.nodes.forEach(node => {
+ if (node.id === children.parent_id) {
+ result.push(node);
+ getParents(node);
+ }
+ });
+ };
+
+ getParents(node);
+
+ return result;
+ },
getByCategories: state => (category: string) => state.nodes.filter(d => d.parent_id == category),
getParents: state => state.nodes.filter(c => !c.parent_id),
getChilds: state => (id: string) => state.nodes.filter(c => c.parent_id == id),