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.

4.8 KB
Raw Blame
<template>
  <div class="context-menu">
    <div class="menu-header">
      <UserAvatar :user="user" square />
      <div class="header-info">
        <span class="header-name">{{ node.name }}</span>
        <span class="header-meta">{{ user?.username }} · {{ shortDate(node.updated_timestamp) }}</span>
      </div>
    </div>

    <div class="menu-group">
      <button class="menu-item" @click="action('open')"><Icon name="file_open" />{{ t('common.actions.open') }}</button>
      <button class="menu-item" @click="action('edit')"><Icon name="edit_page" />{{ t('common.actions.edit') }}</button>
    </div>

    <div class="menu-group">
      <button class="menu-item" @click="action('copyLink')"><Icon name="link" />{{ t('common.actions.copyLink') }}</button>
      <button class="menu-item" @click="action('copyMd')"><Icon name="link" />{{ t('common.actions.copy') }} {{ t('common.labels.content') }}</button>
    </div>

    <div v-if="nodesPermissionsStore.hasPermissions(node, 4)" class="menu-group">
      <button class="menu-item" @click="action('manageAccess')"><Icon name="manage_access" />{{ t('nodes.actions.managePermissions') }}</button>
    </div>

    <div class="menu-group">
      <button class="menu-item delete" @click="action('delete')"><Icon name="delete" />{{ t('common.actions.delete') }}</button>
    </div>

    <div v-if="developerMode" class="menu-group">
      <button class="menu-item" @click="action('copyId')"><Icon name="snippets" />{{ t('common.actions.copy') }} {{ t('common.labels.id') }}</button>
    </div>
  </div>
</template>

<script setup lang="ts">
import NodePermissions from '../Modals/Permissions.vue';
import NodeDeleteModal from '../Modals/Delete.vue';
import type { Node } from '~/stores';

const props = defineProps<{ node: Node }>();
const emit = defineEmits(['close']);

const nodesPermissionsStore = useNodesPermissionsStore();
const userStore = useUserStore();

const preferences = usePreferencesStore();
const { t } = useI18nT();
const { shortDate } = useDateFormatters();
const { resourceURL } = useApi();
const modal = useModal();
const notifications = useNotifications();
const router = useRouter();

userStore.fetchPublicUser(props.node.user_id);
const user = computed(() => userStore.getById(props.node.user_id || ''));
const developerMode = preferences.get('developerMode');

async function action(name: string) {
  switch (name) {
    case 'open':
      router.push(`/dashboard/docs/${props.node.id}`);
      break;
    case 'edit':
      router.push(`/dashboard/cdn/${props.node.id}`);
      break;
    case 'delete':
      modal.add(new Modal(shallowRef(NodeDeleteModal), { props: { node: props.node }, size: 'small' }));
      break;
    case 'copyLink':
      navigator.clipboard.writeText(resourceURL(props.node));
      notifications.add({ type: 'success', title: 'Link copied to clipboard' });
      break;
    case 'copyMd':
      navigator.clipboard.writeText(`![${props.node.name}](${resourceURL(props.node)})`);
      notifications.add({ type: 'success', title: 'Markdown link copied to clipboard' });
      break;
    case 'manageAccess':
      modal.add(new Modal(shallowRef(NodePermissions), { props: { node: props.node }, size: 'small' }));
      break;
    case 'copyId':
      navigator.clipboard.writeText(props.node.id);
      notifications.add({ type: 'success', title: 'ID copied to clipboard' });
      break;
  }
  emit('close');
}
</script>

<style scoped lang="scss">
.context-menu {
  padding: 6px;
}

.menu-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding: 8px 10px 12px;
  border-bottom: 1px solid var(--border);

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    object-fit: cover;
  }
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.header-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.header-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.menu-group {
  padding: 2px 0;

  & + & {
    margin-top: 2px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 4px 10px;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  color: var(--text-body);
  text-align: left;
  background: none;
  cursor: pointer;
  transition: background 0.1s;

  &:hover {
    background: var(--surface-raised);
  }

  &.delete {
    color: var(--red);

    :deep(svg) {
      fill: var(--red);
    }
  }
}

@media screen and (width <= 768px) {
  .context-menu {
    width: 100%;
    border: none;
    box-shadow: none;

    .menu-item {
      padding: 12px 16px;
      font-size: 16px;
    }
  }
}
</style>