π The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.
Vue dockergolangkanbanknowledge-baseknowledge-managementmarkdownnote-takingnotesnotes-appnotionnuxtnuxtjsoffline-firstoidcpwaselfhostedssovuevuejswiki
Init refactor command center
Smaug6739a4146a5cc646
diff --git a/backend/models/node.model.go b/backend/models/node.model.goindex e9ba2c83..a4202359 100644--- a/backend/models/node.model.go+++ b/backend/models/node.model.go@@ -39,6 +39,7 @@ type NodeSearchResult struct {Description *string `json:"description" db:"description"`Tags *string `json:"tags" db:"tags"`Role int `json:"role" db:"role"`+ Accessibility *int `json:"accessibility" db:"accessibility"`Icon *string `json:"icon" db:"icon"`Relevance float64 `json:"relevance" db:"relevance"`ContentSnippet *string `json:"content_snippet,omitempty" db:"content_snippet"`diff --git a/backend/repositories/node.repository.go b/backend/repositories/node.repository.goindex b0901f60..617740bb 100644--- a/backend/repositories/node.repository.go+++ b/backend/repositories/node.repository.go@@ -295,7 +295,7 @@ func (r *NodeRepositoryImpl) SearchFulltext(userId types.Snowflake, query stringif includeContent {// FULLTEXT search including content bodyerr = r.db.Select(&results, `- SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.icon,+ SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.accessibility, n.icon,MATCH(n.content) AGAINST(? IN NATURAL LANGUAGE MODE) AS relevance,SUBSTRING(n.content,GREATEST(1, LOCATE(?, LOWER(n.content)) - 50),@@ -310,7 +310,7 @@ func (r *NodeRepositoryImpl) SearchFulltext(userId types.Snowflake, query string} else {// FULLTEXT search on name, description, tags only (faster)err = r.db.Select(&results, `- SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.icon,+ SELECT n.id, n.user_id, n.parent_id, n.name, n.description, n.tags, n.role, n.accessibility, n.icon,MATCH(n.name, n.description, n.tags, n.content) AGAINST(? IN NATURAL LANGUAGE MODE) AS relevance,NULL AS content_snippet,n.created_timestamp,diff --git a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue b/frontend/app/components/CommandCenter/AdvancedSearchTab.vueindex c2c181fa..1e17987d 100644--- a/frontend/app/components/CommandCenter/AdvancedSearchTab.vue+++ b/frontend/app/components/CommandCenter/AdvancedSearchTab.vue@@ -68,6 +68,7 @@<script setup lang="ts">import SearchResultsList from './SearchResultsList.vue';+import { resolveIcon } from '~/helpers/node';import type { Node, NodeSearchResult } from '~/stores';const props = defineProps<{ query: string; selectedIndex: number }>();@@ -178,7 +179,7 @@ watch(const flattenedItems = computed(() => {return searchResults.value.map((doc, idx) => ({id: doc.id,- icon: getDocumentIcon(doc),+ icon: resolveIcon(doc),title: doc.name,description: buildDescription(doc),path: `/dashboard/docs/${doc.id}`,@@ -245,11 +246,6 @@ function clearFilters() {searchInContent.value = true;}-function getDocumentIcon(doc: NodeSearchResult | Node): string {- if ('order' in doc && doc.order == -1) return 'pin';- return 'files';-}-defineExpose({ flattenedItems });</script>diff --git a/frontend/app/components/CommandCenter/TabNavigation.vue b/frontend/app/components/CommandCenter/TabNavigation.vueindex 12a3fdb2..6bae9e03 100644--- a/frontend/app/components/CommandCenter/TabNavigation.vue+++ b/frontend/app/components/CommandCenter/TabNavigation.vue@@ -8,10 +8,10 @@</template><script setup lang="ts">-defineProps<{ activeTab: string }>();const emit = defineEmits<{ 'change-tab': [tabId: string] }>();const handleClick = (tabId: string) => emit('change-tab', tabId);+const { changeTab, activeTab } = useCommandCenter();interface Tab {id: string;@@ -31,6 +31,22 @@ const tabs: Tab[] = [icon: 'layers',},];++const handleKeydown = (e: KeyboardEvent) => {+ if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {+ e.stopImmediatePropagation();+ e.preventDefault();+ changeTab(activeTab.value === 'quick' ? 'advanced' : 'quick');+ }+};++// Add global keydown listener for tab switching (priority capture to override other handlers)+onMounted(() => {+ window.addEventListener('keydown', handleKeydown, { capture: true });+});+onUnmounted(() => {+ window.removeEventListener('keydown', handleKeydown, { capture: true });+});</script><style scoped lang="scss">diff --git a/frontend/app/components/CommandCenter/index.vue b/frontend/app/components/CommandCenter/index.vueindex 55dfb814..82ca09b2 100644--- a/frontend/app/components/CommandCenter/index.vue+++ b/frontend/app/components/CommandCenter/index.vue@@ -1,135 +1,83 @@<template>- <Teleport to="body">- <Transition name="modal" class="command-center-overlay">- <div v-if="isOpen" @click="closeSearch">- <div class="command-center-modal">- <!-- Header -->- <div class="search-header">- <div class="search-input-wrapper">- <Icon name="search" class="search-icon" />- <input- ref="searchInput"- v-model="searchQuery"- type="text"- placeholder="Search for a page, action, or document..."- class="search-input"- @keydown="handleSearchKeydown"- /><tag yellow style="height: fit-content">Beta</tag>- </div>- <button class="close-btn" @click="closeSearch">- <Icon name="close" />- </button>- </div>-- <!-- Tab Navigation -->- <TabNavigation :active-tab="activeTab" @change-tab="changeTab" />-- <!-- Tab Content -->- <div class="tab-content">- <QuickSearchTab- v-if="activeTab === 'quick'"- ref="quickSearchTab"- :search-query="searchQuery"- :selected-index="selectedIndex"- @select-item="handleQuickSelect"- @update-selected-index="updateSelectedIndex"- />-- <AdvancedSearchTab- v-else-if="activeTab === 'advanced'"- ref="advancedSearchTab"- :query="searchQuery"- :selected-index="selectedIndex"- @select-document="handleDocumentSelect"- @update-selected-index="updateSelectedIndex"- />- </div>-- <!-- Footer -->- <div class="search-footer">- <div class="shortcuts"><kbd>ββ</kbd> or <kbd>Tab</kbd>Navigate <kbd>Enter</kbd> Select <kbd>β</kbd> Switch tabs <kbd>Escape</kbd> Close</div>- </div>- </div>+ <div class="command-center-modal" @click="handleOverlayClick">+ <!-- Header -->+ <div class="search-header">+ <div class="search-input-wrapper">+ <Icon name="search" class="search-icon" />+ <input+ ref="searchInput"+ :value="searchQuery"+ type="text"+ placeholder="Search for a page, action, or document..."+ class="search-input"+ @input="handleSearchInput"+ @keydown="handleSearchKeydown"+ /><tag yellow class="tag">Beta</tag></div>- </Transition>- </Teleport>+ </div>++ <!-- Tab Navigation -->+ <TabNavigation @change-tab="handleTabChange" />++ <!-- Tab Content -->+ <div class="tab-content">+ <QuickSearchTab+ v-if="activeTab === 'quick'"+ ref="quickSearchTab"+ :search-query="searchQuery"+ :selected-index="selectedIndex"+ @select-item="handleQuickSelect"+ @update-selected-index="setSelectedIndex"+ />++ <AdvancedSearchTab+ v-else-if="activeTab === 'advanced'"+ ref="advancedSearchTab"+ :query="searchQuery"+ :selected-index="selectedIndex"+ @select-document="handleDocumentSelect"+ @update-selected-index="setSelectedIndex"+ />+ </div>++ <!-- Footer -->+ <div class="search-footer">+ <div class="shortcuts"><kbd>ββ</kbd> or <kbd>Tab</kbd>Navigate <kbd>Enter</kbd> Select <kbd>β</kbd> Switch tabs <kbd>Escape</kbd> Close</div>+ </div>+ </div></template><script setup lang="ts">-import CreateCategoryModal from '~/components/Node/Modals/CreateCategory.vue';import TabNavigation from './TabNavigation.vue';import QuickSearchTab from './QuickSearchTab.vue';import AdvancedSearchTab from './AdvancedSearchTab.vue';import type { Node } from '~/stores';-const router = useRouter();-const isOpen = ref(false);-const searchQuery = ref('');-const selectedIndex = ref(0);-const activeTab = ref('quick');+const { searchQuery, selectedIndex, activeTab, close, changeTab, setSearchQuery, setSelectedIndex } = useCommandCenter();+const searchInput = ref<HTMLInputElement>();const quickSearchTab = ref();const advancedSearchTab = ref();-const handleGlobalKeydown = (e: KeyboardEvent) => {- if (e.key === '/') {- const target = e.target as HTMLElement;- const isTyping = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;- if (isTyping) return;- e.preventDefault();- return openSearch();- }- if ((e.ctrlKey || e.metaKey) && e.key === 'k') {- e.preventDefault();- return openSearch();- }- if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'u') {- e.preventDefault();- return router.push('/dashboard/cdn');- }- if ((e.ctrlKey || e.metaKey) && e.altKey && e.key.toLowerCase() === 'c') {- e.preventDefault();- return router.push('/dashboard/docs/new');- }- if ((e.ctrlKey || e.metaKey) && e.altKey && e.key.toLowerCase() === 'n') {- e.preventDefault();- return useModal().add(new Modal(shallowRef(CreateCategoryModal), { props: { role: 1 } }));- }- if (e.key === 'Escape' && isOpen.value) {- return closeSearch();- }- if ((e.key === 'ArrowRight' || e.key === 'ArrowLeft') && isOpen.value) {- e.preventDefault();- e.stopImmediatePropagation();- return changeTab(activeTab.value === 'quick' ? 'advanced' : 'quick');- }-};-const openListener = () => openSearch();--// *********** Lifecycle ***********+// Focus input when openingonMounted(() => {- document.addEventListener('keydown', handleGlobalKeydown);- window.addEventListener('command-center-open', openListener as EventListener);-});--onBeforeUnmount(() => {- document.removeEventListener('keydown', handleGlobalKeydown);- window.removeEventListener('command-center-open', openListener as EventListener);+ nextTick(() => searchInput.value?.focus());});// --- Methods ----function openSearch() {- isOpen.value = true;- selectedIndex.value = 0;- searchQuery.value = '';- activeTab.value = 'quick';- nextTick(() => searchInput.value?.focus());- document.body.classList.add('modal-open');+function handleSearchInput(e: Event) {+ setSearchQuery((e.target as HTMLInputElement).value);+}++function handleTabChange(tabId: string) {+ changeTab(tabId as 'quick' | 'advanced');+ if (tabId === 'quick') {+ nextTick(() => searchInput.value?.focus());+ }}-function closeSearch(e?: MouseEvent) {+function handleOverlayClick(e: MouseEvent) {if (- e &&e.target &&(e.target as Element).closest('.command-center-modal') &&!(e.target as Element).closest('.close-btn') &&@@ -137,35 +85,20 @@ function closeSearch(e?: MouseEvent) {)return;- isOpen.value = false;- searchQuery.value = '';- selectedIndex.value = 0;- document.body.classList.remove('modal-open');-}--function changeTab(tabId: string) {- activeTab.value = tabId;- selectedIndex.value = 0;- if (tabId === 'quick') {- nextTick(() => searchInput.value?.focus());- }-}--function updateSelectedIndex(index: number) {- selectedIndex.value = index;+ close();}function handleQuickSelect() {- const selectedItem = quickSearchTab.value.flattenedItems[selectedIndex.value];+ const selectedItem = quickSearchTab.value?.flattenedItems?.[selectedIndex.value];if (selectedItem) {navigateTo(selectedItem.path);- closeSearch();+ close();}}function handleDocumentSelect(document: Node) {navigateTo(`/dashboard/docs/${document.id}`);- closeSearch();+ close();}function handleSearchKeydown(e: KeyboardEvent) {@@ -178,10 +111,10 @@ function handleSearchKeydown(e: KeyboardEvent) {const maxIndex = items.length - 1;if ((e.key === 'ArrowDown' || (e.key === 'Tab' && !e.shiftKey)) && selectedIndex.value < maxIndex) {e.preventDefault();- selectedIndex.value = (selectedIndex.value + 1) % Math.max(maxIndex + 1, 1);+ setSelectedIndex((selectedIndex.value + 1) % Math.max(maxIndex + 1, 1));} else if (e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey && selectedIndex.value > 0)) {e.preventDefault();- selectedIndex.value = (selectedIndex.value - 1 + Math.max(maxIndex + 1, 1)) % Math.max(maxIndex + 1, 1);+ setSelectedIndex((selectedIndex.value - 1 + Math.max(maxIndex + 1, 1)) % Math.max(maxIndex + 1, 1));} else if (e.key === 'Enter' && items.length > 0) {e.preventDefault();if (activeTab.value === 'quick') {@@ -194,48 +127,12 @@ function handleSearchKeydown(e: KeyboardEvent) {}}}--defineExpose({ openSearch, closeSearch });--watch(searchQuery, () => (selectedIndex.value = 0));</script><style scoped lang="scss">-.command-center-overlay {- position: fixed;- z-index: 500;- display: flex;- background: rgb(0 0 0 / 50%);- align-items: flex-start;- inset: 0;- justify-content: center;- padding-top: 8vh;-}--.modal-enter-active,-.modal-leave-active {- transition:- opacity 0.3s ease,- transform 0.3s ease;-}--.modal-enter-from,-.modal-leave-to {- opacity: 0;- transform: scale(1.1);-}-.command-center-modal {- position: relative;- z-index: 1000;display: flex;- width: 92%;- max-width: 720px;- max-height: 85vh;- border: 1px solid var(--border);border-radius: 16px;- background: var(--surface-base);- box-shadow: 0 20px 60px rgb(0 0 0 / 30%);flex-direction: column;overflow: auto;}@@ -274,16 +171,9 @@ watch(searchQuery, () => (selectedIndex.value = 0));outline: none;}-.close-btn {- padding: 8px;- border: none;- border-radius: 8px;- background: transparent;- cursor: pointer;-- &:hover {- background: var(--border);- }+.tag {+ height: fit-content;+ margin-right: 20px;}.tab-content {@@ -301,6 +191,7 @@ watch(searchQuery, () => (selectedIndex.value = 0));.shortcuts {display: flex;+ align-items: center;font-size: 13px;font-weight: 500;flex-wrap: wrap;diff --git a/frontend/app/composables/useCommandCenter.ts b/frontend/app/composables/useCommandCenter.tsnew file mode 100644index 00000000..9d938d7f--- /dev/null+++ b/frontend/app/composables/useCommandCenter.ts@@ -0,0 +1,117 @@+import CreateCategoryModal from '~/components/Node/Modals/CreateCategory.vue';+import CommandCenter from '~/components/CommandCenter/index.vue';++type TabType = 'quick' | 'advanced';++interface CommandCenterState {+ searchQuery: string;+ selectedIndex: number;+ activeTab: TabType;+}++// Singleton state shared across all component instances+const state = reactive<CommandCenterState>({+ searchQuery: '',+ selectedIndex: 0,+ activeTab: 'quick',+});++let isInitialized = false;++export function useCommandCenter() {+ const router = useRouter();+ const modalManager = useModal();+ const modal = new Modal(shallowRef(CommandCenter), { noPadding: true, onClose: afterClose });++ // --- Methods ---+ function open() {+ state.selectedIndex = 0;+ state.searchQuery = '';+ state.activeTab = 'quick';+ modalManager.add(modal);+ }++ function close() {+ modalManager.close(modal);+ }++ function afterClose() {+ state.searchQuery = '';+ state.selectedIndex = 0;+ }++ function changeTab(tabId: TabType) {+ state.activeTab = tabId;+ state.selectedIndex = 0;+ }++ function setSearchQuery(query: string) {+ state.searchQuery = query;+ state.selectedIndex = 0;+ }++ function setSelectedIndex(index: number) {+ state.selectedIndex = index;+ }++ // --- Global keyboard shortcuts handler ---+ function handleGlobalKeydown(e: KeyboardEvent) {+ if (e.key === '/') {+ const target = e.target as HTMLElement;+ const isTyping = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;+ if (isTyping) return;+ e.preventDefault();+ return open();+ }+ if ((e.ctrlKey || e.metaKey) && e.key === 'k') {+ e.preventDefault();+ return open();+ }+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'u') {+ e.preventDefault();+ return router.push('/dashboard/cdn');+ }+ if ((e.ctrlKey || e.metaKey) && e.altKey && e.key.toLowerCase() === 'c') {+ e.preventDefault();+ return router.push('/dashboard/docs/new');+ }+ if ((e.ctrlKey || e.metaKey) && e.altKey && e.key.toLowerCase() === 'n') {+ e.preventDefault();+ return useModal().add(new Modal(shallowRef(CreateCategoryModal), { props: { role: 1 } }));+ }+ }++ // --- Initialize global listeners (called once) ---+ function initGlobalListeners() {+ if (isInitialized) return;+ isInitialized = true;++ document.addEventListener('keydown', handleGlobalKeydown);+ window.addEventListener('command-center-open', open as EventListener);+ }++ // --- Cleanup global listeners ---+ function destroyGlobalListeners() {+ isInitialized = false;+ document.removeEventListener('keydown', handleGlobalKeydown);+ window.removeEventListener('command-center-open', open as EventListener);+ }++ return {+ // State (readonly for external access)+ searchQuery: computed(() => state.searchQuery),+ selectedIndex: computed(() => state.selectedIndex),+ activeTab: computed(() => state.activeTab),++ // Methods+ open,+ close,+ changeTab,+ setSearchQuery,+ setSelectedIndex,++ // Lifecycle+ initGlobalListeners,+ destroyGlobalListeners,+ };+}diff --git a/frontend/app/composables/useModal.ts b/frontend/app/composables/useModal.tsindex e1ff8954..1abcd137 100644--- a/frontend/app/composables/useModal.ts+++ b/frontend/app/composables/useModal.ts@@ -16,6 +16,7 @@ function close(modal: Modal) {const index = modals.value.indexOf(modal);if (index !== -1) {modals.value.splice(index, 1);+ if (modal.options.onClose) modal.options.onClose();}if (modals.value.length === 0) {document.body.classList.remove('modal-open');@@ -30,6 +31,9 @@ function closeLast() {/** Close all modals in the stack */function closeAll() {+ modals.value.forEach(modal => {+ if (modal.options.onClose) modal.options.onClose();+ });modals.value = [];document.body.classList.remove('modal-open');}@@ -42,6 +46,7 @@ interface ModalOptions {size?: 'small' | 'medium' | 'large';noPadding?: boolean;props?: object;+ onClose?: () => void;}export class Modal {diff --git a/frontend/app/helpers/navigation.ts b/frontend/app/helpers/navigation.tsindex 5c5348f2..31214023 100644--- a/frontend/app/helpers/navigation.ts+++ b/frontend/app/helpers/navigation.ts@@ -88,7 +88,7 @@ export const quickActions: QuickAction[] = [title: 'Search in docs',description: 'Search in your documents',icon: 'search',- shortcut: 'Ctrl+q',+ shortcut: 'Ctrl+K or / ',path: '/dashboard/docs',},{diff --git a/frontend/app/helpers/node.ts b/frontend/app/helpers/node.tsindex eb5f2bfe..8856bd0d 100644--- a/frontend/app/helpers/node.ts+++ b/frontend/app/helpers/node.ts@@ -2,10 +2,10 @@* Node utilities - centralized helpers for working with nodes (documents, categories, workspaces, resources)* Roles: 1 = Workspace, 2 = Category, 3 = Document, 4 = Resource*/-import type { DB_Node, Node } from '~/stores';+import type { DB_Node, Node, NodeSearchResult } from '~/stores';/** Resolve the appropriate icon for a node based on its role and properties */-export const resolveIcon = (item: Node | DB_Node): string => {+export const resolveIcon = (item: Node | DB_Node | NodeSearchResult): string => {if (item.icon) return item.icon;if (item.role === 1) return 'workspace';if (item.role === 2 && 'shared' in item) return item.shared ? 'shared_folder' : 'folder';diff --git a/frontend/app/pages/dashboard.vue b/frontend/app/pages/dashboard.vueindex 82ae213e..bab7fcc2 100644--- a/frontend/app/pages/dashboard.vue+++ b/frontend/app/pages/dashboard.vue@@ -4,7 +4,6 @@<BackToTop /></ClientOnly><Sidebar />- <CommandCenter /><MediumView><Navbar /><div style="width: 100%; height: calc(100% - 65px)"><NuxtPage /></div>@@ -20,4 +19,13 @@ const userStore = useUserStore();nodesStore.init();userStore.fetch();++const { initGlobalListeners, destroyGlobalListeners } = useCommandCenter();++onMounted(() => {+ initGlobalListeners();+});+onBeforeUnmount(() => {+ destroyGlobalListeners();+});</script>diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.tsindex 28152b9a..11383c82 100644--- a/frontend/app/stores/db_strustures.d.ts+++ b/frontend/app/stores/db_strustures.d.ts@@ -73,8 +73,10 @@ export interface NodeSearchResult {description?: string;tags?: string;role: number;+ accessibility: number;icon?: string;relevance: number;+ metadata?: undefined;content_snippet?: string;created_timestamp: number;updated_timestamp: number;