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.

Code clean

Smaug67395e09dfd08169
diff --git a/frontend/components/AppHint.vue b/frontend/components/AppHint.vue
index 9d2f4ca8..5bbbc19b 100644
--- a/frontend/components/AppHint.vue
+++ b/frontend/components/AppHint.vue
@@ -8,12 +8,7 @@
</template>
<script setup lang="ts">
-import { ref } from 'vue';
-
-const props = defineProps<{
- text: string;
-}>();
-
+defineProps<{ text: string }>();
const show = ref(false);
</script>
@@ -35,8 +30,6 @@ const show = ref(false);
display: flex;
align-items: center;
justify-content: center;
- cursor: default;
- user-select: none;
}
.hint-tooltip {
diff --git a/frontend/components/Logo.vue b/frontend/components/Logo.vue
deleted file mode 100644
index 3feaa799..00000000
--- a/frontend/components/Logo.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-<template>
- <div style="display: flex; align-items: center; column-gap: 0.5rem">
- <img style="width: 50px" :src="`/Alexandrie-${colorMode.value}.svg`" alt="Alexandrie" />
- <NuxtLink to="/" style="font-weight: 600">Alexandrie</NuxtLink>
- </div>
-</template>
-
-<script setup lang="ts">
-const colorMode = useColorMode();
-</script>
-
-<style scoped>
-@media screen and (max-width: 768px) {
- p {
- display: none;
- }
- img {
- margin: 0 10px;
- }
-}
-</style>
diff --git a/frontend/components/Sidebar/Sidebar.vue b/frontend/components/Sidebar/Sidebar.vue
index 96a7d6d4..0b93d875 100644
--- a/frontend/components/Sidebar/Sidebar.vue
+++ b/frontend/components/Sidebar/Sidebar.vue
@@ -21,13 +21,13 @@
<div class="icons">
<NuxtLink @click="onClick" to="/dashboard/docs/new"><Icon name="add_file" :mid="true" fill="var(--font-color-dark)" /></NuxtLink>
<NuxtLink @click="onClick" to="/dashboard/categories/new"><Icon name="add_folder" :mid="true" fill="var(--font-color-dark)" /></NuxtLink>
- <NuxtLink @click="collapseAll"><Icon name="collapse" :mid="true" fill="var(--font-color-dark)" /></NuxtLink>
+ <NuxtLink @click="sidebarTree.collapseAll"><Icon name="collapse" :mid="true" fill="var(--font-color-dark)" /></NuxtLink>
</div>
</div>
</div>
<SidebarWorkspaces :options="workspaces" />
<Search />
- <CollapseItem v-for="item in items" :key="item.id" :item="item" :root="true" />
+ <CollapseItem v-for="item in tree" :key="item.id" :item="item" :root="true" />
</div>
</Resizable>
</template>
@@ -39,11 +39,9 @@ import Resizable from './Resizable.vue';
import IconClose from './IconClose.vue';
import Search from './Search.vue';
import { navigationItems } from './helpers';
-import type { Category } from '~/stores';
const { isOpened, hasSidebar, workspaceId } = useSidebar();
const categoriesStore = useCategoriesStore();
-const documentsStore = useDocumentsStore();
const preferences = usePreferencesStore();
const userStore = useUserStore();
const filter = ref<string>('');
@@ -53,62 +51,26 @@ const workspaces = computed(() => [{ text: 'All workspaces', value: null }, ...c
const handleSearchShortCut = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'q') showSearchModal.value = !showSearchModal.value;
};
-
-if (import.meta.client && useUserStore().user?.role === 2) {
- if (navigationItems[navigationItems.length - 1]?.id !== 'manage-users')
- navigationItems.push({
- id: 'manage-users',
- type: 'default',
- title: 'Manage users',
- icon: 'users',
- route: '/dashboard/admin/users',
- childrens: [],
- });
-}
-
-const items = computed((): Item[] => {
- const navigation: Item[] = navigationItems.map(item => ({ id: item.id, parent_id: '', title: item.title, route: item.route, icon: item.icon, type: 'navigation', data: item, show: ref(true) }));
- const categories: Item[] = categoriesStore.categories
- .map((category: Category) => ({
- id: category.id,
- parent_id: category.parent_id || '',
- title: category.name,
- route: category.parent_id ? `/dashboard/categories/${category.id}` : '',
- icon: category.icon,
- data: category,
- show: localStorage.getItem(`collapse-${category.id}`) === 'false' ? ref(false) : ref(true),
- }))
- .filter(c => c.data.role === 1 && c.data.name.toLowerCase().includes(filter.value.toLowerCase()));
- const documents: Item[] = documentsStore.documents
- .map(document => ({
- id: document.id,
- parent_id: document.parent_id || document.category || '',
- title: document.name,
- route: `/dashboard/docs/${document.id}`,
- data: document,
- show: localStorage.getItem(`collapse-${document.id}`) === 'false' ? ref(false) : ref(true),
- }))
- .filter(c => c.data.name.toLowerCase().includes(filter.value.toLowerCase()));
- return new SidebarTreeManager([...navigation, ...documents, ...categories]).generateTree().filter(c => {
- if (c.data.type === 'category' && workspaceId.value) return c.data.workspace_id == workspaceId.value;
- if (c.data.type === 'document' && workspaceId.value) return c.data.category === workspaceId.value;
- return true;
- });
-});
+const navigationItemsComputed = computed<Item[]>(() =>
+ navigationItems.map(item => ({
+ id: item.id,
+ parent_id: '',
+ title: item.title,
+ route: item.route,
+ icon: item.icon,
+ type: 'navigation',
+ data: item,
+ show: ref(true),
+ })),
+);
+const sidebarTree = useSidebarTree();
+const tree = computed(() => [...navigationItemsComputed.value, ...sidebarTree.filtered.value].filter(i => i.title.toLowerCase().includes(filter.value.toLowerCase())));
const handleClickOutside = (e: MouseEvent) => {
if (isOpened.value && e.target && !(e.target as Element).closest('.sidebar') && !(e.target as Element).closest('.open-sidebar')) isOpened.value = false;
};
-const collapseAll = () => {
- items.value.forEach(item => {
- if (item.show.value) {
- localStorage.setItem(`collapse-${item.id}`, 'false');
- item.show.value = false;
- }
- });
-};
-const onClick = (m: MouseEvent) => {
+const onClick = (_: MouseEvent) => {
if (isMobile()) isOpened.value = false;
};
diff --git a/frontend/composables/SidebarTreeManager.ts b/frontend/composables/SidebarTreeManager.ts
index 9531ee09..f9b0cc9d 100644
--- a/frontend/composables/SidebarTreeManager.ts
+++ b/frontend/composables/SidebarTreeManager.ts
@@ -5,6 +5,7 @@ export interface Item<T = Document | Category | DefaultItem> {
id: string;
title: string;
parent_id: string;
+ route: string;
data: T;
childrens?: Item<T>[];
show: Ref<boolean>;
@@ -23,6 +24,8 @@ export class SidebarTreeManager {
// Generate the tree structure without indexing
public generateTree(): Item[] {
+ console.log('buildTree');
+
return this.items
.filter(item => item.parent_id === '' || !this.itemMap.has(item.parent_id) || (item.data.type === 'category' && item.data.role === 2)) // Racines
.map(rootItem => this.buildTree(rootItem));
diff --git a/frontend/composables/TreeManager.ts b/frontend/composables/TreeManager.ts
deleted file mode 100644
index 56c84cf6..00000000
--- a/frontend/composables/TreeManager.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-export interface ANode<T = any> {
- id: string;
- title: string;
- icon?: string;
- route?: string;
- parent_id: string;
- children: ANode[];
- data: T;
-}
-
-export class TreeManager<T> {
- private nodeMap: Map<string, ANode<T>> = new Map();
- public items: ANode<T>[] = [];
-
- constructor(items: ANode<T>[]) {
- this.nodeMap = new Map(items.map(item => [item.id, item]));
- this.items = items;
- }
-
- public buildTree() {
- return this.items
- .filter(item => item.parent_id === '' || !this.nodeMap.has(item.parent_id)) // Racines
- .map(rootItem => this.buildSubTree(rootItem));
- }
- private buildSubTree(item: ANode<T>): ANode<T> {
- const children = this.items.filter(child => child.parent_id === item.id);
- return {
- ...item,
- children: children.map(child => this.buildSubTree(child)),
- };
- }
-}
diff --git a/frontend/composables/structuresTree.ts b/frontend/composables/structuresTree.ts
new file mode 100644
index 00000000..32846362
--- /dev/null
+++ b/frontend/composables/structuresTree.ts
@@ -0,0 +1,70 @@
+import { computed, ref } from 'vue';
+import { useCategoriesStore, useDocumentsStore } from '~/stores';
+
+function getCollapseState(id: string): boolean {
+ const stored = localStorage.getItem(`collapse-${id}`);
+ return stored !== 'false';
+}
+
+export function useSidebarTree() {
+ const categoriesStore = useCategoriesStore();
+ const documentsStore = useDocumentsStore();
+ const { workspaceId } = useSidebar();
+
+ const categories = computed<Item[]>(() =>
+ categoriesStore.categories.map(cat => ({
+ id: cat.id,
+ parent_id: cat.parent_id || '',
+ title: cat.name,
+ route: cat.parent_id ? `/dashboard/categories/${cat.id}` : '',
+ icon: cat.icon,
+ type: 'category',
+ data: cat,
+ show: ref(getCollapseState(cat.id)),
+ })),
+ );
+
+ const documents = computed<Item[]>(() =>
+ documentsStore.documents.map(doc => ({
+ id: doc.id,
+ parent_id: doc.parent_id || doc.category || '',
+ title: doc.name,
+ route: `/dashboard/docs/${doc.id}`,
+ type: 'document',
+ data: doc,
+ show: ref(getCollapseState(doc.id)),
+ })),
+ );
+
+ const allItems = computed(() => [...documents.value, ...categories.value]);
+
+ const tree = computed(() => {
+ return new SidebarTreeManager(allItems.value).generateTree();
+ });
+ const filtered = computed(() => {
+ return new SidebarTreeManager(allItems.value).generateTree().filter(item => {
+ if (item.data.type === 'category' && workspaceId.value) {
+ return item.data.workspace_id === workspaceId.value && item.data.role == 1;
+ }
+ if (item.data.type === 'document' && workspaceId.value) {
+ return item.data.category === workspaceId.value;
+ }
+ return true;
+ });
+ });
+
+ const collapseAll = () => {
+ tree.value.forEach(item => {
+ if (item.show.value) {
+ localStorage.setItem(`collapse-${item.id}`, 'false');
+ item.show.value = false;
+ }
+ });
+ };
+
+ return {
+ tree,
+ filtered,
+ collapseAll,
+ };
+}
diff --git a/frontend/components/AppFooter.vue b/frontend/pages/(public)/_components/AppFooter.vue
similarity index 50%
rename from frontend/components/AppFooter.vue
rename to frontend/pages/(public)/_components/AppFooter.vue
index 21eec174..77f5ebcc 100644
--- a/frontend/components/AppFooter.vue
+++ b/frontend/pages/(public)/_components/AppFooter.vue
@@ -1,10 +1,15 @@
<template>
<footer>
- <Logo />
- <p class="p2">Developed and designed by Smaug with ❤️</p>
+ <div style="display: flex; align-items: center; column-gap: 0.5rem">
+ <img style="width: 50px" :src="`/Alexandrie-${colorMode.value}.svg`" alt="Alexandrie" />
+ <NuxtLink to="/" style="font-weight: 600">Alexandrie</NuxtLink>
+ </div>
+ <p>Developed and designed by Smaug with ❤️</p>
</footer>
</template>
-
+<script setup lang="ts">
+const colorMode = useColorMode();
+</script>
<style scoped lang="scss">
footer {
padding: 1.5rem 2rem;
@@ -14,15 +19,6 @@ footer {
border-top: 1px solid var(--border-color);
}
-footer .p2 {
- font-size: 14px;
- font-weight: 400;
-}
-
-footer .logo {
- max-width: 100px;
-}
-
@media (max-width: 768px) {
footer {
flex-direction: column;
@@ -31,8 +27,10 @@ footer .logo {
padding: 2rem 1rem;
margin: 0;
}
-
- footer .p2 {
+ img {
+ margin: 0 10px;
+ }
+ footer p {
margin-top: 1rem;
}
}
diff --git a/frontend/components/AppHeader.vue b/frontend/pages/(public)/_components/AppHeader.vue
similarity index 100%
rename from frontend/components/AppHeader.vue
rename to frontend/pages/(public)/_components/AppHeader.vue
diff --git a/frontend/pages/index.vue b/frontend/pages/(public)/index.vue
similarity index 93%
rename from frontend/pages/index.vue
rename to frontend/pages/(public)/index.vue
index 017d15b5..cab11367 100644
--- a/frontend/pages/index.vue
+++ b/frontend/pages/(public)/index.vue
@@ -1,11 +1,8 @@
<template>
<main>
<section class="header">
- <div class="logo">
- <IconApp />
- </div>
+ <IconApp />
</section>
-
<section class="content-wrapper">
<div class="intro">
<div class="intro-text">
@@ -23,14 +20,12 @@
<img :src="`/main-${colorMode.value}.webp`" alt="Documents Image" />
</div>
</section>
-
<section class="editor-section">
<h2 class="section-title">Try editor online</h2>
<div class="editor">
<MarkdownEditor :doc="doc" :options="{ showPreview: !isMobile(), toolbar: 'minimal' }" />
</div>
</section>
-
<section class="demo-section">
<h2 class="section-title">Organize your documents</h2>
<div class="demo">
@@ -43,7 +38,7 @@
<script setup lang="ts">
import MarkdownEditor from '~/components/MarkdownEditor/MarkdownEditor.vue';
-
+import AppFooter from './_components/AppFooter.vue';
const typewriterText = ref('Your Ideas, Documents & Plans.\nAlexandrie');
onMounted(() => {
@@ -58,12 +53,10 @@ onMounted(() => {
setTimeout(type, 50); // Ajustez la vitesse d'écriture
} else element.style.borderRight = 'none';
};
-
type();
});
const colorMode = useColorMode();
-
const doc = ref({
content_markdown: `# Welcome to Alexandrie ! 🚀\n## Formatting options\n\nLorem **ipsum dolor** *sit amet*, consectetur _adipiscing elit_. ==But not sad.== \n\n### Different content blocks\n\n:::blue Blue\nA blue block\n:::\n:::red Red\nA red block\n:::\n:::green Green\nA green block\n:::\n:::grey Grey\nA grey block\n:::\n:::yellow Yellow\nA yellow block\n:::\n:::turquoise Turquoise\nA turquoise block\n:::\n:::details Details\nA details block\n:::\n\n\n:::no-print\nThis content will not be printed\n:::\n\n:::center\nThis content is centered\n:::\n\n:::definition Red Info\nBlock of content (ex: definition)\n:::\n\n:::property Blue Info\nBlock of content (ex: property)\n:::\n\n:::theorem Turquoise Info\nBlock of content (ex: theorem)\n:::\n\n:::info-u Info without background\nBlock of content (ex: info, tip, note)\n:::\n\n:::warning Warning Info\nBlock of content (ex: warning)\n:::\n\n### Bullet and Numbered Lists:\n\n- Bullet 1\n- Bullet 2\n - Sub-bullet 2-1\n\n1. Item 1\n1. Item 2\n\n### Markdown Tables\n\n| Column 1 | Column 2 | Column 3 |\n|:----------|:----------|:---------|\n|Item 1 | Item 2 | Item 3 |\n\n### Other formats\n\n$\\text{This is a math block: } f(x) = ax^2+bx+c$\n\n\`\`\`javascript\nconst hello = "Hello world";\n\`\`\`\n\n> Note: This content is a quote\n>> Nested quote\n\n## Shortcuts\n\n- **Ctrl + S**: Save\n- **Ctrl + P**: Toggle preview\n- **Ctrl + Q**: Switch to document\n- **Ctrl + B**: Bold formatting\n- **Ctrl + I**: Italic formatting\n- **Ctrl + U**: Underline formatting\n- **Ctrl + K**: Insert link\n- **Ctrl + M**: Insert image\n\n## Snippets\n\n- **!m**: Insert a math block (LaTeX)\n- **!def**: Insert a definition block\n- **!thm**: Insert a theorem block\n- **!center**: Center the content\n- **!red**: Insert a red block\n- **!green**: Insert a green block\n- **!blue**: Insert a blue block\n- **!yellow**: Insert a yellow block\n- **!details**: Insert a details block\n`,
});
@@ -92,26 +85,6 @@ h3 {
font-weight: 500;
}
-#typewriter {
- font-size: 2.5rem;
- font-weight: 700;
- white-space: pre-wrap;
- display: inline-block;
- border-right: 4px solid #333;
- height: 1.2em;
- animation: blink 0.6s step-end infinite;
-}
-
-@keyframes blink {
- from,
- to {
- border-color: transparent;
- }
- 50% {
- border-color: #333;
- }
-}
-
.section-title {
font-size: 2rem;
margin-bottom: 1.5rem;
@@ -127,11 +100,6 @@ h3 {
top: 0;
}
-.logo-img {
- width: 120px;
- height: auto;
-}
-
.content-wrapper {
display: flex;
flex-direction: column;
diff --git a/frontend/pages/login.vue b/frontend/pages/(public)/login.vue
similarity index 97%
rename from frontend/pages/login.vue
rename to frontend/pages/(public)/login.vue
index 7d10b517..822cc1da 100644
--- a/frontend/pages/login.vue
+++ b/frontend/pages/(public)/login.vue
@@ -24,7 +24,11 @@
<AppFooter />
</div>
</template>
+
<script setup lang="ts">
+import AppHeader from './_components/AppHeader.vue';
+import AppFooter from './_components/AppFooter.vue';
+
const username = ref('');
const errors = ref({
username: '',
diff --git a/frontend/pages/signup.vue b/frontend/pages/(public)/signup.vue
similarity index 97%
rename from frontend/pages/signup.vue
rename to frontend/pages/(public)/signup.vue
index 9466468a..4b608093 100644
--- a/frontend/pages/signup.vue
+++ b/frontend/pages/(public)/signup.vue
@@ -38,6 +38,9 @@
</template>
<script setup lang="ts">
+import AppHeader from './_components/AppHeader.vue';
+import AppFooter from './_components/AppFooter.vue';
+
const router = useRouter();
const username = ref('');
const email = ref('');
diff --git a/frontend/components/WorkspaceTree.vue b/frontend/pages/dashboard/categories/_components/WorkspaceTree.vue
similarity index 96%
rename from frontend/components/WorkspaceTree.vue
rename to frontend/pages/dashboard/categories/_components/WorkspaceTree.vue
index 4a29fbc6..5f0ae046 100644
--- a/frontend/components/WorkspaceTree.vue
+++ b/frontend/pages/dashboard/categories/_components/WorkspaceTree.vue
@@ -1,5 +1,5 @@
<template>
- <div class="tree-node">
+ <div class="tree-node" v-if="node.data.type === 'category'">
<div class="tree-content">
<div class="tree-label">
<Icon name="folder" style="display: inline" />
diff --git a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
index ad388760..79d2953c 100644
--- a/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
+++ b/frontend/pages/dashboard/categories/_modals/CreateCategoryModal.vue
@@ -1,5 +1,3 @@
-<!-- Category creation modal -->
-<!-- Should be like folder creation on linux or mac -->
<template>
<div class="modal">
<h2>Create a new {{ role == 1 ? 'category' : 'workspace' }}</h2>
@@ -46,7 +44,7 @@ const createCategory = () => {
<style scoped lang="scss">
.modal {
background-color: var(--bg-contrast);
- padding: 1rem;
+ padding: 0 1rem;
border-radius: 8px;
min-width: 700px;
}
diff --git a/frontend/pages/dashboard/categories/index.vue b/frontend/pages/dashboard/categories/index.vue
index 1aa3d721..5c062026 100644
--- a/frontend/pages/dashboard/categories/index.vue
+++ b/frontend/pages/dashboard/categories/index.vue
@@ -16,28 +16,17 @@
<WorkspaceTree v-for="node in workspace.childrens" :node="node" @edit="editNode" @delete="deleteNode" />
</div>
- <div v-else style="color: #6c757d; font-style: italic">No workspaces</div>
+ <div v-else style="color: #6c757d; font-style: italic">No workspaces found</div>
</div>
</template>
<script setup lang="ts">
-import CreateCategoryModal from './_modals/CreateCategoryModal.vue';
import type { Category } from '~/stores';
-const categories = useCategoriesStore().getAll;
-const tree = new SidebarTreeManager(
- categories.map((c: Category) => {
- return {
- id: c.id,
- title: c.name,
- type: 'category',
- parent_id: c.parent_id || '',
- data: c,
- show: ref(true),
- } as Item<Category>;
- }),
-).generateTree() as Item<Category>[];
+import CreateCategoryModal from './_modals/CreateCategoryModal.vue';
+import WorkspaceTree from './_components/WorkspaceTree.vue';
+const tree = useSidebarTree().tree;
-const custom_tree = tree.filter((i: Item<Category>) => i.data.role === 2);
+const custom_tree = tree.value.filter(i => i.data.type === 'category' && i.data.role == 2) as Item<Category>[];
function createWorkspace() {
useModal().modals.value?.push(new Modal(shallowRef(CreateCategoryModal), '', { role: 2 }));