Deploy deepseek 2
This commit is contained in:
302
frontend/app/components/viewer/content/EmbeddedEntry.vue
Normal file
302
frontend/app/components/viewer/content/EmbeddedEntry.vue
Normal file
@@ -0,0 +1,302 @@
|
||||
<script setup>
|
||||
// `![[Name]]` in a note mounts this card where the token was written. It resolves the label against
|
||||
// the campaign's lists and draws the character's sheet or the item's description inline; the button
|
||||
// opens the full sheet window, the same one the sidebar uses. Mounted like a widget: its only prop
|
||||
// is the label the note wrote, and it talks to the services on its own.
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { getBaseUrl } from '~/services/Server';
|
||||
import { FindLinkTarget } from '~/services/LinkAutocomplete';
|
||||
import { LoadLinkEntry, LoadLinkTargets } from '~/services/LinkTargets';
|
||||
import { useCampaignService } from '~/services/Campaign';
|
||||
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
||||
|
||||
// `t` comes from the note as a prop: a card mounted with its own `createApp` is not inside the
|
||||
// app's plugin tree, so it cannot call `useI18n()` the way the note can.
|
||||
const props = defineProps(['href', 't']);
|
||||
const { Campaign } = useCampaignService();
|
||||
const translate = (key) => (props.t ? props.t(key) : key);
|
||||
|
||||
const target = ref(null);
|
||||
const entry = ref(null);
|
||||
const loading = ref(true);
|
||||
|
||||
const campaignId = computed(() => Campaign.value?._id ?? Campaign.value?.id ?? null);
|
||||
const isActor = computed(() => target.value?.type === 'actor');
|
||||
const isItem = computed(() => target.value?.type === 'item');
|
||||
|
||||
onMounted(async () => {
|
||||
const targets = await LoadLinkTargets(campaignId.value);
|
||||
const found = FindLinkTarget(targets, props.href);
|
||||
if (!found) {
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
target.value = found;
|
||||
entry.value = await LoadLinkEntry(campaignId.value, found.type, found.id);
|
||||
loading.value = false;
|
||||
});
|
||||
|
||||
// --- The character sheet, in the small ---
|
||||
const abilityStats = [
|
||||
{ key: 'str', label: 'STR' }, { key: 'dex', label: 'DEX' }, { key: 'con', label: 'CON' },
|
||||
{ key: 'int', label: 'INT' }, { key: 'wis', label: 'WIS' }, { key: 'cha', label: 'CHA' }
|
||||
];
|
||||
|
||||
function abilityModifier(score) {
|
||||
const modifier = Math.floor((Number(score ?? 10) - 10) / 2);
|
||||
return modifier >= 0 ? `+${modifier}` : String(modifier);
|
||||
}
|
||||
|
||||
function barPercent(current, max) {
|
||||
const top = Number(max) || 0;
|
||||
return top > 0 ? Math.min(100, Math.max(0, ((Number(current) || 0) / top) * 100)) : 0;
|
||||
}
|
||||
|
||||
const hitPointsPercent = computed(() => barPercent(entry.value?.hitPoints?.current, entry.value?.hitPoints?.max));
|
||||
|
||||
const actorLine = computed(() => {
|
||||
const parts = [];
|
||||
if (entry.value?.className) parts.push(entry.value.className);
|
||||
if (entry.value?.species) parts.push(entry.value.species);
|
||||
if (entry.value?.level) parts.push(`${translate('campaigns.character-sheet.level')} ${entry.value.level}`);
|
||||
return parts.join(' · ');
|
||||
});
|
||||
|
||||
// Uploaded images are served by `/api/public`; a synced world hands over full URLs.
|
||||
function resolveImage(image) {
|
||||
if (!image) return '';
|
||||
return /^(https?:|data:|\/\/)/i.test(image)
|
||||
? image
|
||||
: `${getBaseUrl()}/public/${image}`;
|
||||
}
|
||||
|
||||
const imageUrl = computed(() => resolveImage(entry.value?.image));
|
||||
const initial = computed(() => String(entry.value?.name ?? '?').slice(0, 1).toUpperCase());
|
||||
|
||||
// --- The item's sheet, in the small ---
|
||||
const itemTags = computed(() => {
|
||||
const parts = [];
|
||||
if (entry.value?.category) parts.push(translate(`campaigns.item.categories.${entry.value.category}`));
|
||||
if (entry.value?.rarity) parts.push(translate(`campaigns.item.rarities.${entry.value.rarity}`));
|
||||
return parts;
|
||||
});
|
||||
|
||||
const weight = computed(() => {
|
||||
if (entry.value?.weight === undefined || entry.value?.weight === '') return '';
|
||||
return Number(entry.value.weight).toFixed(1);
|
||||
});
|
||||
|
||||
async function openSheet() {
|
||||
const type = target.value?.type;
|
||||
if ((type !== 'actor' && type !== 'item') || !entry.value) return;
|
||||
|
||||
const windowType = type === 'actor' ? 'character_sheet' : 'item_sheet';
|
||||
const existingWindowId = GetFirstWindowId(windowType);
|
||||
if (existingWindowId !== undefined) {
|
||||
ClearWindow({ id: existingWindowId });
|
||||
await nextTick();
|
||||
}
|
||||
CreateWindow(windowType, type === 'actor' ? { actor: entry.value } : { item: entry.value });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span v-if="loading" class="embedded-entry embedded-loading">{{ href }}</span>
|
||||
|
||||
<span v-else-if="entry && isActor" class="embedded-entry embedded-actor">
|
||||
<span class="embed-head">
|
||||
<span class="embed-mark" :class="{ empty: !imageUrl }">
|
||||
<img v-if="imageUrl" :src="imageUrl" alt="">
|
||||
<span v-else aria-hidden="true">{{ initial }}</span>
|
||||
</span>
|
||||
<span class="embed-identity">
|
||||
<strong class="embed-name">{{ entry.name }}</strong>
|
||||
<span class="embed-line">{{ actorLine }}</span>
|
||||
</span>
|
||||
<button class="embed-open" type="button" @click="openSheet">
|
||||
{{ translate('campaigns.link-preview.open-character') }}
|
||||
</button>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span v-else-if="entry && isItem" class="embedded-entry embedded-item">
|
||||
<span class="embed-head">
|
||||
<span class="embed-mark" :class="{ empty: !imageUrl }">
|
||||
<img v-if="imageUrl" :src="imageUrl" alt="">
|
||||
<span v-else aria-hidden="true">{{ initial }}</span>
|
||||
</span>
|
||||
<span class="embed-identity">
|
||||
<strong class="embed-name">{{ entry.name }}</strong>
|
||||
<span class="embed-tags">
|
||||
<span v-for="tag in itemTags" :key="tag" class="embed-tag">{{ tag }}</span>
|
||||
</span>
|
||||
</span>
|
||||
<button class="embed-open" type="button" @click="openSheet">
|
||||
{{ translate('campaigns.link-preview.open-item') }}
|
||||
</button>
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span v-else class="embedded-entry embedded-missing" :title="translate('campaigns.link-preview.not-found')">{{ href }}</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* A card written between paragraphs: it takes the note's width but is still inline content, so the
|
||||
markdown paragraph around it does not turn into an invalid block. */
|
||||
.embedded-entry {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
margin: 8px 0;
|
||||
padding: 13px 14px;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 10px;
|
||||
background: var(--color-background-light);
|
||||
box-shadow: 0 3px 12px var(--color-window-shadow);
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.embedded-loading,
|
||||
.embedded-missing {
|
||||
color: var(--color-gray);
|
||||
font-size: 12px;
|
||||
opacity: .75;
|
||||
}
|
||||
|
||||
.embed-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.embed-mark {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
flex: 0 0 52px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 9px;
|
||||
background: var(--color-background-soft);
|
||||
color: var(--color-link);
|
||||
font: 24px MrEavesRemake;
|
||||
}
|
||||
|
||||
.embed-mark.empty { border-style: dashed; }
|
||||
.embed-mark img { width: 100%; height: 100%; object-fit: contain; }
|
||||
|
||||
.embed-identity { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
|
||||
|
||||
.embed-name {
|
||||
font: 21px MrEavesRemake;
|
||||
letter-spacing: .02em;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.embed-line { font-size: 11px; opacity: .72; overflow-wrap: anywhere; }
|
||||
.embed-weight { display: block; margin: 0 0 10px; }
|
||||
|
||||
.embed-tags { display: flex; flex-wrap: wrap; gap: 5px; }
|
||||
|
||||
.embed-tag {
|
||||
padding: 2px 8px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 999px;
|
||||
background: var(--color-background-soft);
|
||||
font-size: 11px;
|
||||
opacity: .9;
|
||||
}
|
||||
|
||||
.embed-open {
|
||||
flex: 0 0 auto;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid var(--color-link);
|
||||
border-radius: 7px;
|
||||
background: transparent;
|
||||
color: var(--color-link);
|
||||
font: inherit;
|
||||
font-size: 11px;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.embed-open:hover { background: var(--color-button-hover); }
|
||||
|
||||
.embed-vitals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
|
||||
|
||||
.embed-stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 7px 4px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 7px;
|
||||
background: var(--color-background-soft);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.embed-stat span { font-size: 9px; text-transform: uppercase; letter-spacing: .05em; opacity: .68; }
|
||||
.embed-stat strong { font: 16px MrEavesRemake; white-space: nowrap; }
|
||||
|
||||
.embed-hp-track {
|
||||
display: block;
|
||||
height: 6px;
|
||||
margin: 8px 0 10px;
|
||||
overflow: hidden;
|
||||
border-radius: 999px;
|
||||
background: var(--color-background-soft);
|
||||
}
|
||||
|
||||
.embed-hp-fill { display: block; height: 100%; border-radius: inherit; background: var(--color-red); }
|
||||
|
||||
.embed-abilities { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 5px; }
|
||||
|
||||
.embed-ability {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1px;
|
||||
padding: 6px 3px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 7px;
|
||||
background: var(--color-background-soft);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.embed-ability > span:first-child { font-size: 9px; font-weight: 700; letter-spacing: .06em; opacity: .68; }
|
||||
.embed-ability strong { font: 17px MrEavesRemake; }
|
||||
.embed-ability em { font-style: normal; font-size: 10px; opacity: .72; }
|
||||
|
||||
.embed-section { display: block; margin-top: 10px; }
|
||||
|
||||
.embed-section-title {
|
||||
display: block;
|
||||
padding-bottom: 5px;
|
||||
margin-bottom: 5px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
font: 14px MrEavesRemake;
|
||||
letter-spacing: .03em;
|
||||
}
|
||||
|
||||
.embed-copy {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.45;
|
||||
opacity: .85;
|
||||
}
|
||||
|
||||
@media (max-width: 520px) {
|
||||
.embed-head { align-items: flex-start; flex-wrap: wrap; }
|
||||
.embed-open { margin-left: auto; }
|
||||
.embed-abilities { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
}
|
||||
</style>
|
||||
227
frontend/app/components/viewer/content/LinkPreview.vue
Normal file
227
frontend/app/components/viewer/content/LinkPreview.vue
Normal file
@@ -0,0 +1,227 @@
|
||||
<script setup>
|
||||
// The small card a note shows when the pointer rests on a `[[…]]` link to a character or an item.
|
||||
// It only reads what the sidebar lists already answer with; pressing the card's button opens the
|
||||
// full sheet window, the same one clicking the sidebar row opens.
|
||||
import { computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getBaseUrl } from '~/services/Server';
|
||||
|
||||
const props = defineProps(['preview']);
|
||||
const emit = defineEmits(['enter', 'leave', 'close', 'open']);
|
||||
const { t } = useI18n();
|
||||
|
||||
const target = computed(() => props.preview?.target ?? {});
|
||||
const entry = computed(() => props.preview?.entry ?? {});
|
||||
const isActor = computed(() => target.value.type === 'actor');
|
||||
const isItem = computed(() => target.value.type === 'item');
|
||||
|
||||
const position = computed(() => ({
|
||||
left: `${props.preview?.x ?? 0}px`,
|
||||
top: `${props.preview?.y ?? 0}px`
|
||||
}));
|
||||
|
||||
// Uploaded images are served by `/api/public`; a synced world hands over full URLs.
|
||||
function resolveImage(image) {
|
||||
if (!image) return '';
|
||||
return /^(https?:|data:|\/\/)/i.test(image)
|
||||
? image
|
||||
: `${getBaseUrl()}/public/${image}`;
|
||||
}
|
||||
|
||||
const imageUrl = computed(() => resolveImage(entry.value.image));
|
||||
const initial = computed(() => String(entry.value.name ?? '?').slice(0, 1).toUpperCase());
|
||||
|
||||
const actorLine = computed(() => {
|
||||
const parts = [];
|
||||
if (entry.value.className) parts.push(entry.value.className);
|
||||
if (entry.value.species) parts.push(entry.value.species);
|
||||
if (entry.value.level) parts.push(`${t('campaigns.character-sheet.level')} ${entry.value.level}`);
|
||||
return parts.join(' · ');
|
||||
});
|
||||
|
||||
const itemLine = computed(() => {
|
||||
const parts = [];
|
||||
if (entry.value.category) parts.push(t(`campaigns.item.categories.${entry.value.category}`));
|
||||
if (entry.value.rarity) parts.push(t(`campaigns.item.rarities.${entry.value.rarity}`));
|
||||
return parts.join(' · ');
|
||||
});
|
||||
|
||||
const hitPoints = computed(() => {
|
||||
const hp = entry.value.hitPoints;
|
||||
if (!hp) return '';
|
||||
return `${Number(hp.current ?? 0)} / ${Number(hp.max ?? 0)}`;
|
||||
});
|
||||
|
||||
const description = computed(() => String(entry.value.description ?? '').trim());
|
||||
|
||||
const openLabel = computed(() => t(isActor.value
|
||||
? 'campaigns.link-preview.open-character'
|
||||
: 'campaigns.link-preview.open-item'));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
class="link-preview"
|
||||
:style="position"
|
||||
role="dialog"
|
||||
:aria-label="entry.name"
|
||||
@mouseenter="emit('enter')"
|
||||
@mouseleave="emit('leave')"
|
||||
>
|
||||
<div class="preview-head">
|
||||
<div class="preview-mark" :class="{ empty: !imageUrl }">
|
||||
<img v-if="imageUrl" :src="imageUrl" :alt="''">
|
||||
<span v-else aria-hidden="true">{{ initial }}</span>
|
||||
</div>
|
||||
<div class="preview-identity">
|
||||
<strong class="preview-name">{{ entry.name }}</strong>
|
||||
<span class="preview-line">{{ isActor ? actorLine : itemLine }}</span>
|
||||
</div>
|
||||
<button class="preview-close" type="button" :aria-label="$t('campaigns.link-preview.close')" @click="emit('close')">×</button>
|
||||
</div>
|
||||
|
||||
<div v-if="isActor" class="preview-stats">
|
||||
<div class="preview-stat">
|
||||
<span>{{ $t('campaigns.character-sheet.armor-class') }}</span>
|
||||
<strong>{{ entry.armorClass ?? '—' }}</strong>
|
||||
</div>
|
||||
<div class="preview-stat">
|
||||
<span>{{ $t('campaigns.character-sheet.hit-points') }}</span>
|
||||
<strong>{{ hitPoints || '—' }}</strong>
|
||||
</div>
|
||||
<div class="preview-stat">
|
||||
<span>{{ $t('campaigns.character-sheet.speed') }}</span>
|
||||
<strong>{{ entry.speed ?? '—' }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-else-if="isItem">
|
||||
<p class="preview-copy">{{ description || $t('campaigns.link-preview.no-description') }}</p>
|
||||
<p v-if="entry.weight !== undefined && entry.weight !== ''" class="preview-weight">
|
||||
{{ $t('campaigns.item.weight') }}: {{ Number(entry.weight).toFixed(1) }}
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<button class="preview-open" type="button" @click="emit('open')">{{ openLabel }}</button>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* The card floats above the notes, which scroll under it, so it is fixed to the viewport and
|
||||
positioned from the link's rectangle by Note.vue. */
|
||||
.link-preview {
|
||||
position: fixed;
|
||||
z-index: 4000;
|
||||
width: 320px;
|
||||
max-height: min(70vh, 420px);
|
||||
overflow: auto;
|
||||
padding: 13px 14px 12px;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 10px;
|
||||
background: var(--color-background-light);
|
||||
box-shadow: 0 10px 30px var(--color-window-shadow);
|
||||
color: var(--color-text);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.preview-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.preview-mark {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
flex: 0 0 44px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
overflow: hidden;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 9px;
|
||||
background: var(--color-background-soft);
|
||||
color: var(--color-link);
|
||||
font: 21px MrEavesRemake;
|
||||
}
|
||||
|
||||
.preview-mark.empty { border-style: dashed; }
|
||||
.preview-mark img { width: 100%; height: 100%; object-fit: contain; }
|
||||
|
||||
.preview-identity { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
|
||||
|
||||
.preview-name {
|
||||
font: 18px MrEavesRemake;
|
||||
letter-spacing: .02em;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
.preview-line { font-size: 11px; opacity: .72; overflow-wrap: anywhere; }
|
||||
|
||||
.preview-close {
|
||||
flex: 0 0 auto;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: 5px;
|
||||
background: transparent;
|
||||
color: var(--color-text);
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.preview-close:hover { background: var(--color-button-hover); }
|
||||
|
||||
.preview-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
|
||||
|
||||
.preview-stat {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 7px 4px;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 7px;
|
||||
background: var(--color-background-soft);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.preview-stat span { font-size: 9px; text-transform: uppercase; letter-spacing: .05em; opacity: .68; }
|
||||
.preview-stat strong { font: 15px MrEavesRemake; white-space: nowrap; }
|
||||
|
||||
.preview-copy {
|
||||
margin: 0;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
line-height: 1.45;
|
||||
opacity: .85;
|
||||
}
|
||||
|
||||
.preview-weight { margin: 7px 0 0; font-size: 11px; opacity: .68; }
|
||||
|
||||
.preview-open {
|
||||
width: 100%;
|
||||
margin-top: 11px;
|
||||
padding: 7px 10px;
|
||||
border: 1px solid var(--color-link);
|
||||
border-radius: 7px;
|
||||
background: transparent;
|
||||
color: var(--color-link);
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.preview-open:hover { background: var(--color-button-hover); }
|
||||
</style>
|
||||
@@ -1,12 +1,21 @@
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted, ref, createApp } from 'vue';
|
||||
import { onMounted, onUnmounted, ref, nextTick, createApp } from 'vue';
|
||||
import ToastManager from '~/components/managers/ToastManager.vue';
|
||||
import { emitter } from '~/services/Emitter';
|
||||
import { GetWidget, ParseMarkdown } from '~/services/Marker';
|
||||
import { GetWidget, GetWidgetRegistry, ParseMarkdown } from '~/services/Marker';
|
||||
import { BuildWidgetSuggestions, FilterWidgetSuggestions, FindWidgetTrigger, InsertWidgetSuggestion } from '~/services/WidgetAutocomplete';
|
||||
import { FilterLinkSuggestions, FindLinkTarget, FindLinkTrigger, InsertLinkSuggestion } from '~/services/LinkAutocomplete';
|
||||
import { LoadLinkEntry, LoadLinkTargets } from '~/services/LinkTargets';
|
||||
import { AnchorMap } from '~/services/Content';
|
||||
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
||||
import { useCampaignService } from '~/services/Campaign';
|
||||
import Server from '~/services/Server';
|
||||
import { DisplayToast } from '~/services/Toaster';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import TestWidget from '../widgets/TestWidget.vue';
|
||||
import EmbeddedEntry from './EmbeddedEntry.vue';
|
||||
import LinkPreview from './LinkPreview.vue';
|
||||
import SuggestionMenu from './SuggestionMenu.vue';
|
||||
|
||||
// import { GetNote, GetContent } from '@/services/Content';
|
||||
const props = defineProps(['text', 'title', 'noteKey']);
|
||||
@@ -24,6 +33,228 @@ const showClose = ref(false);
|
||||
|
||||
let savedState = { text: '', title: '' };
|
||||
|
||||
// --- Autocompletat de la nota ---
|
||||
// Mentre s'edita, escriure `@` ofereix els widgets de la nota (els de Marker.js) i `[[` els
|
||||
// enllacos de la campanya (notes, actors, objectes i mapes). La llista es calcula sobre el text i
|
||||
// el cursor reals, no sobre el model, perque l'esdeveniment d'entrada arriba abans que Vue
|
||||
// actualitzi `sourceText`.
|
||||
const editor = ref(null);
|
||||
const suggestions = ref([]);
|
||||
const selectedSuggestion = ref(0);
|
||||
const suggestionStyle = ref({});
|
||||
|
||||
const allWidgetSuggestions = BuildWidgetSuggestions(GetWidgetRegistry());
|
||||
const { Campaign } = useCampaignService();
|
||||
const linkTargets = ref([]);
|
||||
let linkTargetsLoaded = false;
|
||||
let linkTargetsRequest = null;
|
||||
const campaignId = computed(() => Campaign.value?._id ?? Campaign.value?.id ?? null);
|
||||
|
||||
// Les destinacions d'enllac venen del servidor una sola vegada: tant el desplegable d'edicio com la
|
||||
// vista previa dels enllacos ja escrits fan servir la mateixa llista.
|
||||
function ensureLinkTargets() {
|
||||
if (linkTargetsLoaded) return Promise.resolve(linkTargets.value);
|
||||
if (!linkTargetsRequest) {
|
||||
linkTargetsRequest = LoadLinkTargets(campaignId.value).then((targets) => {
|
||||
linkTargets.value = targets;
|
||||
linkTargetsLoaded = true;
|
||||
return targets;
|
||||
}).catch(() => []);
|
||||
}
|
||||
return linkTargetsRequest;
|
||||
}
|
||||
|
||||
// Estils que el mirall ha de copiar del textarea per mesurar-hi el cursor.
|
||||
const MIRROR_STYLES = [
|
||||
'direction', 'boxSizing', 'width', 'height',
|
||||
'overflowX', 'overflowY',
|
||||
'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth',
|
||||
'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
|
||||
'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust',
|
||||
'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent',
|
||||
'textDecoration', 'letterSpacing', 'wordSpacing', 'tabSize'
|
||||
];
|
||||
|
||||
// Posicio (en px, relativa al contenidor de la nota) del cursor del textarea. Un element mirall
|
||||
// invisible copia els estils i el text fins al cursor i ens diu on cau.
|
||||
function caretCoordinates(textarea, position) {
|
||||
const style = window.getComputedStyle(textarea);
|
||||
const mirror = document.createElement('div');
|
||||
mirror.style.position = 'absolute';
|
||||
mirror.style.top = '0';
|
||||
mirror.style.left = '0';
|
||||
mirror.style.visibility = 'hidden';
|
||||
mirror.style.whiteSpace = 'pre-wrap';
|
||||
mirror.style.wordWrap = 'break-word';
|
||||
for (const property of MIRROR_STYLES) {
|
||||
if (style[property] != null) mirror.style[property] = style[property];
|
||||
}
|
||||
|
||||
const value = textarea.value;
|
||||
mirror.textContent = value.substring(0, position);
|
||||
const marker = document.createElement('span');
|
||||
marker.textContent = value.substring(position) || '.';
|
||||
mirror.appendChild(marker);
|
||||
document.body.appendChild(mirror);
|
||||
|
||||
const lineHeight = parseFloat(style.lineHeight) || parseFloat(style.fontSize) * 1.2 || 20;
|
||||
const coordinates = {
|
||||
top: marker.offsetTop + textarea.offsetTop - textarea.scrollTop,
|
||||
left: marker.offsetLeft + textarea.offsetLeft - textarea.scrollLeft,
|
||||
lineHeight
|
||||
};
|
||||
|
||||
document.body.removeChild(mirror);
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
// Cada entrada del desplegable porta ja el seu text i la seva pista traduida; `value` es el widget o
|
||||
// l'objectiu d'enllac cru que s'inserirà en triar-la.
|
||||
function widgetEntry(widget) {
|
||||
return {
|
||||
key: `widget:${widget.type}:${widget.name}`,
|
||||
kind: 'widget',
|
||||
value: widget,
|
||||
label: `@${widget.name}`,
|
||||
hint: t('general.widgets.' + widget.type)
|
||||
};
|
||||
}
|
||||
|
||||
function linkEntry(target) {
|
||||
return {
|
||||
key: `link:${target.type}:${target.id}`,
|
||||
kind: 'link',
|
||||
value: target,
|
||||
label: `[[${target.label}]]`,
|
||||
hint: t(`campaigns.sections.${target.type}s`)
|
||||
};
|
||||
}
|
||||
|
||||
function closeSuggestions() {
|
||||
suggestions.value = [];
|
||||
}
|
||||
|
||||
// Dibuixa el desplegable sota el cursor, girant-lo cap amunt si no hi cap.
|
||||
function showSuggestions(matches, caret) {
|
||||
if (!matches.length || !editor.value) {
|
||||
closeSuggestions();
|
||||
return;
|
||||
}
|
||||
|
||||
suggestions.value = matches;
|
||||
selectedSuggestion.value = 0;
|
||||
|
||||
const coordinates = caretCoordinates(editor.value, caret);
|
||||
const container = editor.value.parentElement;
|
||||
const containerHeight = container ? container.clientHeight : 0;
|
||||
let top = coordinates.top + coordinates.lineHeight;
|
||||
if (containerHeight && top + 150 > containerHeight) top = Math.max(0, coordinates.top - 150);
|
||||
suggestionStyle.value = { top: `${top}px`, left: `${coordinates.left}px` };
|
||||
}
|
||||
|
||||
function updateSuggestions(text, caret) {
|
||||
const widgetTrigger = FindWidgetTrigger(text, caret);
|
||||
if (widgetTrigger) {
|
||||
showSuggestions(FilterWidgetSuggestions(allWidgetSuggestions, widgetTrigger.query).map(widgetEntry), caret);
|
||||
return;
|
||||
}
|
||||
|
||||
const linkTrigger = FindLinkTrigger(text, caret);
|
||||
if (linkTrigger) {
|
||||
// Les destinacions d'enllac vénen del servidor: la primera vegada que es tecleja `[[` es
|
||||
// demanen, i en arribar es torna a calcular el desplegable sobre el que hi ha ara al cursor.
|
||||
if (!linkTargetsLoaded) {
|
||||
closeSuggestions();
|
||||
ensureLinkTargets().then(() => {
|
||||
const el = editor.value;
|
||||
if (el) updateSuggestions(el.value, el.selectionStart ?? el.value.length);
|
||||
});
|
||||
return;
|
||||
}
|
||||
showSuggestions(FilterLinkSuggestions(linkTargets.value, linkTrigger.query).map(linkEntry), caret);
|
||||
return;
|
||||
}
|
||||
|
||||
closeSuggestions();
|
||||
}
|
||||
|
||||
function onEditorInput(event) {
|
||||
const el = event.target;
|
||||
updateSuggestions(el.value, el.selectionStart ?? el.value.length);
|
||||
}
|
||||
|
||||
function onEditorClick(event) {
|
||||
if (!suggestions.value.length) return;
|
||||
const el = event.target;
|
||||
updateSuggestions(el.value, el.selectionStart ?? el.value.length);
|
||||
}
|
||||
|
||||
function onEditorKeydown(event) {
|
||||
if (!suggestions.value.length) return;
|
||||
|
||||
if (event.key === 'ArrowDown') {
|
||||
event.preventDefault();
|
||||
selectedSuggestion.value = (selectedSuggestion.value + 1) % suggestions.value.length;
|
||||
} else if (event.key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
selectedSuggestion.value = (selectedSuggestion.value - 1 + suggestions.value.length) % suggestions.value.length;
|
||||
} else if (event.key === 'Enter' || event.key === 'Tab') {
|
||||
event.preventDefault();
|
||||
applySuggestion(suggestions.value[selectedSuggestion.value]);
|
||||
} else if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
closeSuggestions();
|
||||
}
|
||||
}
|
||||
|
||||
function onSuggestionHover(index) {
|
||||
selectedSuggestion.value = index;
|
||||
}
|
||||
|
||||
function applySuggestion(entry) {
|
||||
if (!entry) return;
|
||||
if (entry.kind === 'link') applyLinkSuggestion(entry.value);
|
||||
else applyWidgetSuggestion(entry.value);
|
||||
}
|
||||
|
||||
// Escriu el text inserit i deixa el cursor on el widget o l'enllac el volen.
|
||||
function writeSuggestion(result) {
|
||||
sourceText.value = result.text;
|
||||
closeSuggestions();
|
||||
const el = editor.value;
|
||||
if (!el) return;
|
||||
nextTick(() => {
|
||||
el.focus();
|
||||
el.setSelectionRange(result.caret, result.caret);
|
||||
});
|
||||
}
|
||||
|
||||
function applyWidgetSuggestion(suggestion) {
|
||||
const el = editor.value;
|
||||
if (!el || !suggestion) return;
|
||||
|
||||
const trigger = FindWidgetTrigger(el.value, el.selectionStart ?? el.value.length);
|
||||
if (!trigger) {
|
||||
closeSuggestions();
|
||||
return;
|
||||
}
|
||||
|
||||
writeSuggestion(InsertWidgetSuggestion(el.value, trigger, suggestion));
|
||||
}
|
||||
|
||||
function applyLinkSuggestion(target) {
|
||||
const el = editor.value;
|
||||
if (!el || !target) return;
|
||||
|
||||
const trigger = FindLinkTrigger(el.value, el.selectionStart ?? el.value.length);
|
||||
if (!trigger) {
|
||||
closeSuggestions();
|
||||
return;
|
||||
}
|
||||
|
||||
writeSuggestion(InsertLinkSuggestion(el.value, trigger, target));
|
||||
}
|
||||
|
||||
function markDirty() {
|
||||
isDirty.value = sourceText.value !== savedState.text || title.value !== savedState.title;
|
||||
}
|
||||
@@ -81,6 +312,195 @@ function mountComponents() {
|
||||
});
|
||||
});
|
||||
}
|
||||
// --- Enllacos `[[…]]` de la vista previa ---
|
||||
// Cada enllac porta el nom de l'entrada. En muntar la nota el resolem contra les llistes de la
|
||||
// campanya: un personatge o un objecte mostra una fitxa resumida en passar-hi el ratoli i s'obre
|
||||
// sencer en fer-hi clic; una nota s'obre a la columna i un mapa s'ancora com des de la barra.
|
||||
const linkPreview = ref(null);
|
||||
const PREVIEW_DELAY = 180;
|
||||
const PREVIEW_HIDE_DELAY = 140;
|
||||
let previewTimer = null;
|
||||
let previewHideTimer = null;
|
||||
let hoveredLink = null;
|
||||
let previewHovered = false;
|
||||
|
||||
function resolveLink(el) {
|
||||
return FindLinkTarget(linkTargets.value, el?.dataset?.href);
|
||||
}
|
||||
|
||||
function hideLinkPreview() {
|
||||
clearTimeout(previewTimer);
|
||||
clearTimeout(previewHideTimer);
|
||||
previewHovered = false;
|
||||
hoveredLink = null;
|
||||
linkPreview.value = null;
|
||||
}
|
||||
|
||||
function scheduleHideLinkPreview() {
|
||||
clearTimeout(previewTimer);
|
||||
clearTimeout(previewHideTimer);
|
||||
previewHideTimer = setTimeout(() => {
|
||||
if (!previewHovered) hideLinkPreview();
|
||||
}, PREVIEW_HIDE_DELAY);
|
||||
}
|
||||
|
||||
function keepLinkPreview() {
|
||||
previewHovered = true;
|
||||
clearTimeout(previewHideTimer);
|
||||
}
|
||||
|
||||
async function showLinkPreview(el) {
|
||||
await ensureLinkTargets();
|
||||
if (hoveredLink !== el) return;
|
||||
|
||||
const target = resolveLink(el);
|
||||
if (!target || (target.type !== 'actor' && target.type !== 'item')) return;
|
||||
|
||||
const entry = await LoadLinkEntry(campaignId.value, target.type, target.id);
|
||||
if (!entry || hoveredLink !== el) return;
|
||||
|
||||
// The card is fixed to the viewport, so it is placed from the link's rectangle and kept
|
||||
// inside the window; a link near the bottom gets the card above it instead.
|
||||
const rect = el.getBoundingClientRect();
|
||||
const width = 320;
|
||||
const estimatedHeight = 260;
|
||||
const x = Math.min(Math.max(8, rect.left), Math.max(8, window.innerWidth - width - 12));
|
||||
const y = rect.bottom + estimatedHeight + 12 > window.innerHeight
|
||||
? Math.max(8, rect.top - estimatedHeight - 8)
|
||||
: rect.bottom + 8;
|
||||
|
||||
linkPreview.value = { target, entry, x, y };
|
||||
}
|
||||
|
||||
function onLinkEnter(el) {
|
||||
hoveredLink = el;
|
||||
clearTimeout(previewTimer);
|
||||
clearTimeout(previewHideTimer);
|
||||
previewTimer = setTimeout(() => showLinkPreview(el), PREVIEW_DELAY);
|
||||
}
|
||||
|
||||
// Marks every link of the rendered note with the type it points at, so the CSS can tell a character
|
||||
// from an item and a target that is gone can be dimmed. It runs after the lists arrive.
|
||||
async function annotateLinks(root) {
|
||||
const links = Array.from(root.querySelectorAll('.vue-link'));
|
||||
if (!links.length) return;
|
||||
|
||||
await ensureLinkTargets();
|
||||
if (!root.isConnected) return;
|
||||
|
||||
for (const el of links) {
|
||||
const target = resolveLink(el);
|
||||
if (target) {
|
||||
el.dataset.linkType = target.type;
|
||||
el.classList.add('is-resolved');
|
||||
} else {
|
||||
el.classList.add('is-unresolved');
|
||||
el.title = t('campaigns.link-preview.not-found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function bindLinks(root) {
|
||||
root.querySelectorAll('.vue-link').forEach((el) => {
|
||||
if (el.dataset.linkBound) return;
|
||||
el.dataset.linkBound = '1';
|
||||
el.addEventListener('mouseenter', () => onLinkEnter(el));
|
||||
el.addEventListener('mouseleave', scheduleHideLinkPreview);
|
||||
el.addEventListener('focus', () => onLinkEnter(el));
|
||||
el.addEventListener('blur', scheduleHideLinkPreview);
|
||||
el.addEventListener('click', (event) => {
|
||||
event.stopPropagation();
|
||||
openLink(el);
|
||||
});
|
||||
el.addEventListener('keydown', (event) => {
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
openLink(el);
|
||||
});
|
||||
});
|
||||
|
||||
annotateLinks(root);
|
||||
}
|
||||
|
||||
async function openLink(el) {
|
||||
await ensureLinkTargets();
|
||||
const target = resolveLink(el);
|
||||
if (!target) return;
|
||||
hideLinkPreview();
|
||||
openLinkTarget(target);
|
||||
}
|
||||
|
||||
async function openLinkTarget(target) {
|
||||
if (target.type === 'actor' || target.type === 'item') {
|
||||
const entry = await LoadLinkEntry(campaignId.value, target.type, target.id);
|
||||
if (entry) await openEntrySheet(target.type, entry);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.type === 'note') {
|
||||
try {
|
||||
const response = await Server().get(`/note/retrieve/${target.id}`);
|
||||
if (response.data.status !== 'ok' || !response.data.note) return;
|
||||
const note = response.data.note;
|
||||
emitter.emit('push-note', { key: note._id, title: note.title, text: note.content ?? '', date: note.date });
|
||||
} catch (error) {}
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.type === 'map') {
|
||||
const map = await LoadLinkEntry(campaignId.value, 'map', target.id);
|
||||
if (map) AnchorMap(map);
|
||||
}
|
||||
}
|
||||
|
||||
// The same window the sidebar opens: replace the sheet that is already up instead of stacking a
|
||||
// second one.
|
||||
async function openEntrySheet(type, entry) {
|
||||
const windowType = type === 'actor' ? 'character_sheet' : 'item_sheet';
|
||||
const existingWindowId = GetFirstWindowId(windowType);
|
||||
if (existingWindowId !== undefined) {
|
||||
ClearWindow({ id: existingWindowId });
|
||||
await nextTick();
|
||||
}
|
||||
CreateWindow(windowType, type === 'actor' ? { actor: entry } : { item: entry });
|
||||
}
|
||||
|
||||
function openPreviewedEntry() {
|
||||
const target = linkPreview.value?.target;
|
||||
hideLinkPreview();
|
||||
if (target) openLinkTarget(target);
|
||||
}
|
||||
|
||||
function setupLinks() {
|
||||
const root = renderedContent.value;
|
||||
if (!root) return;
|
||||
bindLinks(root);
|
||||
}
|
||||
|
||||
// --- `![[…]]` embeddings ---
|
||||
// An embedded token mounts a card of its own, the way widgets do: the placeholder left by Marker is
|
||||
// the app's container, and `EmbeddedEntry.vue` resolves the label and draws the sheet inline.
|
||||
function mountEmbeds() {
|
||||
const root = renderedContent.value;
|
||||
if (!root) return;
|
||||
|
||||
root.querySelectorAll('.vue-embed').forEach(el => {
|
||||
if (el.dataset.embedMounted) return;
|
||||
el.dataset.embedMounted = '1';
|
||||
try {
|
||||
const app = createApp(EmbeddedEntry, { href: el.dataset.href, t });
|
||||
app.config.errorHandler = (err) => {
|
||||
console.error('Embed error', el.dataset.href, err);
|
||||
};
|
||||
app.mount(el);
|
||||
mountedApps.push(app);
|
||||
} catch (err) {
|
||||
console.error('Failed to mount embed', el.dataset.href, err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
function update(){
|
||||
@@ -88,11 +508,14 @@ function update(){
|
||||
// la reassignacio de displayText (v-html) eliminaria els contenidors i
|
||||
// desmuntar-les despres fallaria sobre nodes desaccelats.
|
||||
unmountComponents();
|
||||
hideLinkPreview();
|
||||
displayText.value = compiledMarkdown.value;
|
||||
setTimeout(() => {
|
||||
setupHeadings();
|
||||
setupCallout()
|
||||
setupLinks();
|
||||
mountComponents();
|
||||
mountEmbeds();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@@ -107,6 +530,9 @@ onMounted(() => {
|
||||
savedState = { text: props.text, title: props.title };
|
||||
emitter.on('title-updated', handleTitleUpdate);
|
||||
// window.addEventListener('keydown', handleKeydown);
|
||||
// The preview is pinned to the viewport, so any scroll (the note column, another note) leaves
|
||||
// it behind: dismiss it instead of letting it float over the wrong place.
|
||||
window.addEventListener('scroll', hideLinkPreview, true);
|
||||
setTimeout(() => setupCallout(), 0);
|
||||
update();
|
||||
});
|
||||
@@ -120,6 +546,8 @@ function handleTitleUpdate(data) {
|
||||
onUnmounted(() => {
|
||||
emitter.off('title-updated', handleTitleUpdate);
|
||||
// window.removeEventListener('keydown', handleKeydown);
|
||||
window.removeEventListener('scroll', hideLinkPreview, true);
|
||||
hideLinkPreview();
|
||||
unmountComponents();
|
||||
});
|
||||
|
||||
@@ -128,6 +556,8 @@ function handleKeydown(e) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'e') {
|
||||
e.preventDefault(); // prevent browser default behavior
|
||||
editingMode.value = !editingMode.value;
|
||||
closeSuggestions();
|
||||
hideLinkPreview();
|
||||
if(!editingMode.value){
|
||||
update();
|
||||
SaveNote(); // Save when switching to display mode
|
||||
@@ -280,7 +710,7 @@ function renderFoldTree(items, target) {
|
||||
|
||||
function handleFoldClick(e) {
|
||||
// No plegar quan es fa clic en un enllaç o se selecciona text
|
||||
if (e.target.closest('a')) return;
|
||||
if (e.target.closest('a, .vue-link')) return;
|
||||
const selection = window.getSelection();
|
||||
if (selection && selection.toString()) return;
|
||||
|
||||
@@ -325,13 +755,39 @@ function setupHeadings() {
|
||||
<span>{{ title }}</span>
|
||||
</div>
|
||||
<div class="note-content-container">
|
||||
<textarea v-model="sourceText" class="full-editor" v-if="editingMode"></textarea>
|
||||
<template v-if="editingMode">
|
||||
<textarea
|
||||
ref="editor"
|
||||
v-model="sourceText"
|
||||
class="full-editor"
|
||||
@input="onEditorInput"
|
||||
@click="onEditorClick"
|
||||
@keydown="onEditorKeydown"
|
||||
@blur="closeSuggestions"
|
||||
></textarea>
|
||||
<SuggestionMenu
|
||||
v-if="suggestions.length"
|
||||
:suggestions="suggestions"
|
||||
:selected="selectedSuggestion"
|
||||
:position="suggestionStyle"
|
||||
@select="applySuggestion"
|
||||
@hover="onSuggestionHover"
|
||||
/>
|
||||
</template>
|
||||
<div v-else class="note-content" ref="noteContent">
|
||||
<h1>{{ title }}</h1>
|
||||
<div ref="renderedContent" v-html="displayText"></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<LinkPreview
|
||||
v-if="linkPreview"
|
||||
:preview="linkPreview"
|
||||
@enter="keepLinkPreview"
|
||||
@leave="scheduleHideLinkPreview"
|
||||
@close="hideLinkPreview"
|
||||
@open="openPreviewedEntry"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -439,6 +895,7 @@ width: 100%;
|
||||
|
||||
.note-content-container {
|
||||
width: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.note-content :deep(img) {
|
||||
@@ -446,4 +903,29 @@ width: 100%;
|
||||
height: auto;
|
||||
display: block; /* optional: avoids inline spacing issues */
|
||||
}
|
||||
|
||||
/* Els `[[enllacos]]` de la nota: es llegeixen com a text subratllat i obren la fitxa de
|
||||
l'entrada. El tipus el marca el servei d'enllacos en resoldre'l. */
|
||||
.note-content :deep(.vue-link) {
|
||||
color: var(--color-link);
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-decoration-style: dotted;
|
||||
text-underline-offset: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.note-content :deep(.vue-link:hover),
|
||||
.note-content :deep(.vue-link:focus-visible) {
|
||||
text-decoration-style: solid;
|
||||
background: var(--color-button-hover);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.note-content :deep(.vue-link.is-unresolved) {
|
||||
color: var(--color-gray);
|
||||
cursor: help;
|
||||
text-decoration-style: dashed;
|
||||
opacity: .7;
|
||||
}
|
||||
</style>
|
||||
|
||||
73
frontend/app/components/viewer/content/SuggestionMenu.vue
Normal file
73
frontend/app/components/viewer/content/SuggestionMenu.vue
Normal file
@@ -0,0 +1,73 @@
|
||||
<script setup>
|
||||
// The dropdown the note editor shows while a widget name or a wiki link is being typed. It only
|
||||
// draws what it is handed: each entry carries its own `label` and `hint`, and the parent decides
|
||||
// when it is open, where it sits and what is selected.
|
||||
defineProps(['suggestions', 'selected', 'position']);
|
||||
const emit = defineEmits(['select', 'hover']);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="suggestion-menu" :style="position" role="listbox">
|
||||
<div
|
||||
v-for="(suggestion, index) in suggestions"
|
||||
:key="suggestion.key"
|
||||
class="suggestion"
|
||||
:class="{ selected: index === selected }"
|
||||
role="option"
|
||||
:aria-selected="index === selected"
|
||||
@mousedown.prevent="emit('select', suggestion)"
|
||||
@mouseenter="emit('hover', index)"
|
||||
>
|
||||
<span class="suggestion-label">{{ suggestion.label }}</span>
|
||||
<span class="suggestion-hint">{{ suggestion.hint }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.suggestion-menu {
|
||||
position: absolute;
|
||||
z-index: 40;
|
||||
min-width: 190px;
|
||||
max-width: 320px;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
padding: 4px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 6px;
|
||||
background-color: var(--color-background-light);
|
||||
box-shadow: 0 6px 18px var(--color-container-shadow);
|
||||
}
|
||||
|
||||
.suggestion {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 4px 8px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.suggestion.selected {
|
||||
background-color: var(--color-selected);
|
||||
}
|
||||
|
||||
.suggestion-label {
|
||||
font-family: monospace;
|
||||
color: var(--color-text);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.suggestion-hint {
|
||||
font-size: 11px;
|
||||
color: var(--color-gray);
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user