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.

Sidebar item context menu + duplicate documents

Smaug67391458c2534b1d
diff --git a/frontend/app/App.vue b/frontend/app/App.vue
index 78b979f0..a04d87b4 100644
--- a/frontend/app/App.vue
+++ b/frontend/app/App.vue
@@ -1,6 +1,7 @@
<template>
<div style="height: 100vh">
<ModalManager />
+ <ContextMenuManager />
<NuxtPage />
<Notification />
</div>
diff --git a/frontend/app/components/ContextMenuManager.vue b/frontend/app/components/ContextMenuManager.vue
new file mode 100644
index 00000000..e5d2eb0d
--- /dev/null
+++ b/frontend/app/components/ContextMenuManager.vue
@@ -0,0 +1,47 @@
+<template>
+ <div v-if="menu">
+ <!-- Backdrop transparent -->
+ <div class="context-backdrop" @click="contextMenu.close"></div>
+
+ <!-- Menu -->
+ <div class="context-menu" :style="{ top: menu.y + 'px', left: menu.x + 'px', zIndex: 6000 }">
+ <component :is="menu.component" v-bind="menu.options.props" class="context-menu-content" @close="contextMenu.close" />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+const contextMenu = useContextMenu();
+const menu = contextMenu.menu;
+
+function handleClickOutside(event: MouseEvent) {
+ const target = event.target as HTMLElement;
+ if (menu && !target.closest('.context-menu')) {
+ contextMenu.close();
+ }
+}
+onMounted(() => document.addEventListener('click', handleClickOutside));
+onBeforeUnmount(() => document.removeEventListener('click', handleClickOutside));
+</script>
+
+<style scoped lang="scss">
+.context-menu {
+ position: fixed;
+ background: var(--bg-color);
+ border-radius: 6px;
+ box-shadow: 0 2px 10px var(--shadow);
+ min-width: 250px;
+ overflow: hidden;
+}
+
+.context-menu-content {
+ display: flex;
+ flex-direction: column;
+}
+.context-backdrop {
+ position: fixed;
+ inset: 0;
+ background: transparent;
+ z-index: 5000;
+}
+</style>
diff --git a/frontend/app/components/Node/NodeContextMenu.vue b/frontend/app/components/Node/NodeContextMenu.vue
new file mode 100644
index 00000000..925d4424
--- /dev/null
+++ b/frontend/app/components/Node/NodeContextMenu.vue
@@ -0,0 +1,104 @@
+<template>
+ <div>
+ <button @click="action('open')"><Icon fill="var(--font-color)" name="file_open" /> Open</button>
+ <NuxtLink :to="`/dashboard/docs/${props.node.id}`" target="_blank"
+ ><button><Icon fill="var(--font-color)" name="new_tab" />Open in new tab</button></NuxtLink
+ >
+ <template v-if="nodesStore.hasPermissions(node, 2)">
+ <button @click="action('edit')"><Icon fill="var(--font-color)" name="edit_page" /> Edit</button>
+ <button @click="action('pin')">
+ <Icon fill="var(--font-color)" :name="node.order === -1 ? 'pin_off' : 'pin'" /> {{ node.order === -1 ? 'Unpin' : 'Pin' }}
+ </button>
+ <button @click="action('duplicate')"><Icon fill="var(--font-color)" name="duplicate" /> Duplicate</button>
+ </template>
+ <button @click="action('copyLink')"><Icon fill="var(--font-color)" name="link" /> Copy link</button>
+ <button @click="action('copyId')"><Icon fill="var(--font-color)" name="snippets" /> Copy ID</button>
+ <template v-if="nodesStore.hasPermissions(node, 2)">
+ <hr style="margin: 2px 0" />
+ <button @click="action('delete')"><Icon name="delete" fill="red" /> Delete</button>
+ </template>
+ <hr style="margin: 2px 0" />
+ <div class="foot-menu">
+ <p style="display: flex; align-items: center; gap: 8px">
+ <img :src="useAvatar(user)" alt="Avatar" style="width: 20px; height: 20px; margin: 0; border-radius: 50%" />{{ user?.username }}
+ </p>
+ <p>Updated on {{ numericDate(node.updated_timestamp) }}</p>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Node, PublicUser } from '@/stores';
+import DeleteDocumentModal from '~/pages/dashboard/docs/_modals/DeleteDocumentModal.vue';
+const props = defineProps<{ node: Node }>();
+const emit = defineEmits(['close']);
+const user = ref<PublicUser | null>(null);
+
+const userStore = useUserStore();
+const nodesStore = useNodesStore();
+
+watchEffect(async () => {
+ if (props.node) user.value = await userStore.fetchPublicUser(props.node.user_id);
+});
+
+const numericDate = (timestamp: number): string => {
+ const date = new Date(timestamp);
+ return date.toLocaleDateString('en-US', {
+ year: 'numeric',
+ month: '2-digit',
+ day: '2-digit',
+ });
+};
+
+function action(actionName: string) {
+ if (actionName === 'open') useRouter().push(`/dashboard/docs/${props.node.id}`);
+ else if (actionName === 'edit') useRouter().push(`/dashboard/docs/edit/${props.node.id}`);
+ else if (actionName === 'copyLink') {
+ const link = `${window.location.origin}/dashboard/docs/${props.node.id}`;
+ navigator.clipboard.writeText(link);
+ } else if (actionName === 'copyId') {
+ navigator.clipboard.writeText(props.node.id);
+ } else if (actionName === 'duplicate') {
+ nodesStore.duplicate(props.node);
+ } else if (actionName === 'delete') {
+ useModal().add(new Modal(shallowRef(DeleteDocumentModal), { props: { documentId: props.node.id } }));
+ emit('close');
+ } else if (actionName === 'pin') {
+ nodesStore.update({ ...props.node, order: props.node.order === -1 ? 0 : -1 });
+ }
+ emit('close');
+}
+</script>
+
+<style scoped lang="scss">
+button {
+ display: flex;
+ width: 100%;
+ padding: 6px 8px;
+ border: none;
+ font-family: ui-sans-serif, sans-serif;
+ font-size: 14px;
+ color: var(--font-color);
+ background: none;
+ align-items: center;
+ cursor: pointer;
+ gap: 8px;
+
+ &:hover {
+ background-color: var(--bg-contrast);
+ }
+}
+
+.foot-menu {
+ display: flex;
+ padding: 4px 8px;
+ font-size: 0.85rem;
+ color: var(--font-color-light);
+ flex-direction: column;
+ gap: 5px;
+
+ p {
+ margin: 0;
+ }
+}
+</style>
diff --git a/frontend/app/components/Sidebar/Sidebar.vue b/frontend/app/components/Sidebar/Sidebar.vue
index a44d6f37..1ad7961e 100644
--- a/frontend/app/components/Sidebar/Sidebar.vue
+++ b/frontend/app/components/Sidebar/Sidebar.vue
@@ -109,7 +109,6 @@ onBeforeUnmount(() => {
max-height: 100%;
padding: 0.5rem;
background: var(--bg-color);
- transition: background-color $transition-duration;
overflow-y: scroll;
&::-webkit-scrollbar-thumb {
diff --git a/frontend/app/components/Sidebar/SidebarItem.vue b/frontend/app/components/Sidebar/SidebarItem.vue
index a5d0660e..b5b21b8e 100644
--- a/frontend/app/components/Sidebar/SidebarItem.vue
+++ b/frontend/app/components/Sidebar/SidebarItem.vue
@@ -8,6 +8,7 @@
@dragover.prevent="dragOver"
@drop="drop"
@dragleave="dragLeave"
+ @contextmenu.prevent="showContextMenu"
>
<Icon :name="icon" :class="customClass" />&nbsp;
@@ -22,12 +23,13 @@
<NuxtLink v-if="item.data.role === 2" :to="`/dashboard/docs/new?cat=${item.id}`" :prefetch="false" class="nav close">
<Icon name="plus" fill="var(--font-color)" />
</NuxtLink>
- <Icon v-if="item.data.role === 3 && item.data.order === -1" name="pin" fill="var(--font-color-light)" class="ni" />
+ <Icon v-if="item.data.role < 4 && item.data.order === -1" name="pin" fill="var(--font-color-light)" class="ni" />
<slot />
</span>
</template>
<script setup lang="ts">
+import NodeContextMenu from '../Node/NodeContextMenu.vue';
import { navigationItems, type DefaultItem } from './helpers';
import type { Node } from '~/stores';
@@ -52,6 +54,14 @@ const onClick = (m: MouseEvent) => {
if (isMobile() && (props.item.route || props.item.onClick)) isOpened.value = false;
};
+const contextMenu = useContextMenu();
+
+function showContextMenu(event: MouseEvent) {
+ if (props.item.data.role === -1) return; // Prevent context menu on nav items
+ contextMenu.open(shallowRef(NodeContextMenu), event, {
+ props: { node: props.item.data as Node },
+ });
+}
const dragStart = (event: DragEvent) => {
// Stocke l'ID de l'élément en cours de glissement
event.dataTransfer!.setData('text/plain', props.item.id.toString());
diff --git a/frontend/app/composables/useContextMenu.ts b/frontend/app/composables/useContextMenu.ts
new file mode 100644
index 00000000..4228fc39
--- /dev/null
+++ b/frontend/app/composables/useContextMenu.ts
@@ -0,0 +1,39 @@
+import { ref } from 'vue';
+
+type ContextMenuOptions = {
+ props?: Record<string, unknown>;
+};
+
+type ContextMenu = {
+ component: object;
+ x: number;
+ y: number;
+ options: ContextMenuOptions;
+};
+
+const menu = ref<ContextMenu | null>(null);
+
+export function useContextMenu() {
+ function open(component: object, event: MouseEvent, options: ContextMenuOptions = {}) {
+ console.log('Opening context menu', component, event, options);
+ // Fermer d’abord si un autre est déjà ouvert
+ close();
+
+ // Calcul position (éviter de dépasser l’écran)
+ const { clientX: x, clientY: y } = event;
+ menu.value = { component, x, y, options };
+
+ // Empêche le clic d’ouvrir un menu par défaut
+ event.preventDefault();
+ }
+
+ function close() {
+ menu.value = null;
+ }
+
+ return {
+ menu,
+ open,
+ close,
+ };
+}
diff --git a/frontend/app/composables/NotificationBus.ts b/frontend/app/composables/useNotifications.ts
similarity index 100%
rename from frontend/app/composables/NotificationBus.ts
rename to frontend/app/composables/useNotifications.ts
diff --git a/frontend/app/composables/utils.ts b/frontend/app/composables/utils.ts
index 24039e6f..17d015a8 100644
--- a/frontend/app/composables/utils.ts
+++ b/frontend/app/composables/utils.ts
@@ -8,7 +8,7 @@ export const isMobile = () => (import.meta.client ? window.innerWidth <= 768 : f
// Intermediate screen size
export const isTablet = () => (import.meta.client ? window.innerWidth <= 1280 : false);
-export function useAvatar(user?: User | PublicUser): string {
+export function useAvatar(user?: User | PublicUser | null): string {
return user?.avatar ? CDN + '/' + user.id + '/avatar' : '/default_avatar.avif';
}
diff --git a/frontend/app/helpers/icons.ts b/frontend/app/helpers/icons.ts
index 126e4da7..58ef48cc 100644
--- a/frontend/app/helpers/icons.ts
+++ b/frontend/app/helpers/icons.ts
@@ -15,6 +15,7 @@ const icons = {
delete: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="var(--font-color)"><path d="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z" /></svg>`,
dock: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm120-80v-560H200v560h120Zm80 0h360v-560H400v560Zm-80 0H200h120Z"/></svg>`,
draft: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path style="fill:var(--teal)" d="M240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>`,
+ duplicate: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M320-80q-33 0-56.5-23.5T240-160v-80h-80q-33 0-56.5-23.5T80-320v-80h80v80h80v-320q0-33 23.5-56.5T320-720h320v-80h-80v-80h80q33 0 56.5 23.5T720-800v80h80q33 0 56.5 23.5T880-640v480q0 33-23.5 56.5T800-80H320Zm0-80h480v-480H320v480ZM80-480v-160h80v160H80Zm0-240v-80q0-33 23.5-56.5T160-880h80v80h-80v80H80Zm240-80v-80h160v80H320Zm0 640v-480 480Z"/></svg>`,
edit: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960" fill="var(--font-color)"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>`,
edit_page: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h405l-60 60H180v600h600v-348l60-60v408q0 24-18 42t-42 18H180Zm300-360ZM360-360v-170l382-382q9-9 20-13t22-4q11 0 22.317 4.5T827-911l83 84q8.609 8.958 13.304 19.782Q928-796.394 928-785.197q0 11.197-4.5 22.697T910-742L530-360H360Zm508-425-84-84 84 84ZM420-420h85l253-253-43-42-43-42-252 251v86Zm295-295-43-42 43 42 43 42-43-42Z"/></svg>`,
expand: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M480-80 240-320l57-57 183 183 183-183 57 57L480-80ZM298-584l-58-56 240-240 240 240-58 56-182-182-182 182Z"/></svg>`,
diff --git a/frontend/app/pages/dashboard/categories/[id]/edit.vue b/frontend/app/pages/dashboard/categories/[id]/edit.vue
index cafdd95a..25e935e4 100644
--- a/frontend/app/pages/dashboard/categories/[id]/edit.vue
+++ b/frontend/app/pages/dashboard/categories/[id]/edit.vue
@@ -4,16 +4,15 @@
<form v-if="category" @submit.prevent>
<div class="form-row">
<div class="form-column">
- <label>ID</label>
- <input id="id" v-model="category.id" type="text" disabled />
+ <label>Name</label>
+ <input id="name" v-model="category.name" type="text" required />
</div>
<div class="form-column">
<label>Role</label>
<AppRadio v-model="category.role" :items="CATEGORY_ROLES" />
</div>
</div>
- <label>Name</label>
- <input id="name" v-model="category.name" type="text" required />
+
<div class="form-row">
<div class="form-column">
<label>Parent</label>
@@ -40,6 +39,9 @@
<AppButton type="primary" class="btn primary" @click="updateCategory">Update</AppButton>
</div>
</form>
+ <div v-if="category" class="infos">
+ <p>ID: {{ category.id }}</p>
+ </div>
</div>
</template>
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index 9c170035..7a51683c 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -233,7 +233,6 @@ export const useNodesStore = defineStore('nodes', {
return request.result as DB_Node;
} else throw request.message;
},
-
async update(node: Node) {
if (node.partial) {
console.log('[store/nodes] Node looks partial, cannot update it directly.');
@@ -247,6 +246,29 @@ export const useNodesStore = defineStore('nodes', {
return this.nodes;
} else throw request.message;
},
+ async duplicate(node: Node): Promise<DB_Node> {
+ if (!node) throw 'Node not found in store, cannot duplicate';
+ if (node.partial) {
+ console.log('[store/nodes] Node looks partial, cannot duplcate it directly.');
+ const full_node = await this.fetch({ id: node.id });
+ if (!full_node) throw 'Node not found';
+ node = mergeNode(node, full_node);
+ }
+ // use the post method to duplicate the node
+ const newNodeData: Partial<Node> = {
+ name: node.name,
+ description: node.description,
+ role: node.role,
+ parent_id: node.parent_id,
+ tags: node.tags,
+ accessibility: node.accessibility,
+ access: node.access,
+ content: node.content,
+ content_compiled: node.content_compiled,
+ };
+ const newNode = await this.post(newNodeData);
+ return newNode;
+ },
async delete(id: string) {
const request = await makeRequest(`nodes/${id}`, 'DELETE', {});
if (request.status == 'success') {