More things
Some checks failed
Test / test (push) Failing after 5s
Build and Deploy Nuxt / build (push) Successful in 2m3s

This commit is contained in:
2026-11-20 18:59:01 +01:00
parent b83f64ff9e
commit d61659cfdd
51 changed files with 1777 additions and 3817 deletions

View File

@@ -18,6 +18,7 @@ import NestedNoteList from './NestedNoteList.vue';
const { Campaign } = useCampaignService();
const { t } = useI18n();
const notes = ref([]);
const media = ref([]);
const folders = ref([]);
const actors = ref([]);
const items = ref([]);
@@ -40,14 +41,16 @@ const activeSection = ref('notes');
const isDragOverSidebar = ref(false);
const expandedFolderIds = ref([]);
const nestedNoteListRef = ref(null);
const mediaInput = ref(null);
let entryRefreshInterval;
async function handleSidebarDrop(event) {
if (activeSection.value !== 'notes') return;
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey) return;
const row = event.dataTransfer.getData('text/plain');
if (!row) return;
const mediaId = row.startsWith('media:') ? row.slice(6) : null;
try {
await Server().post('/note/update', { id: noteKey, folder: null });
await Server().post(mediaId ? '/media/update' : '/note/update', { id: mediaId ?? row, folder: null });
if (nestedNoteListRef.value) {
nestedNoteListRef.value.clearCacheAndReloadExpanded();
} else {
@@ -118,6 +121,11 @@ function handleNoteDeleted(noteKey) {
notes.value = notes.value.filter(n => n.key !== noteKey);
}
// A media row deleted from the tree anywhere under the sidebar.
function handleMediaDeleted(mediaId) {
media.value = media.value.filter((item) => item._id !== mediaId);
}
function sectionForTarget(target) {
if (target === 'actor') return 'actors';
if (target === 'item') return 'items';
@@ -167,6 +175,7 @@ const campaignId = computed(() => {
async function fetchCampaignNotes() {
if (!campaignId.value) {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = '';
return;
@@ -180,6 +189,7 @@ async function fetchCampaignNotes() {
if (response.data.status !== 'ok') {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = response.data.msg ?? 'Unable to load notes.';
return;
@@ -192,8 +202,10 @@ async function fetchCampaignNotes() {
notes.value = response.data.notes.map((note) => {
return { key: note._id, title: note.title, text: note.content ?? '', date: note.date, color: note.color };
});
media.value = response.data.media ?? [];
} catch (error) {
notes.value = [];
media.value = [];
folders.value = [];
notesError.value = 'Unable to load notes.';
} finally {
@@ -503,6 +515,34 @@ function createNote() {
CreateWindow('new_note', { campaign: campaignId.value });
}
function chooseMedia() {
mediaInput.value?.click();
}
// The picked files are uploaded to the root of the note tree, one request per file, and their
// rows join the list as each lands.
async function uploadMedia(event) {
const files = Array.from(event.target.files ?? []);
event.target.value = '';
if (!campaignId.value) return;
for (const file of files) {
const body = new FormData();
body.append('file', file);
body.append('campaign', campaignId.value);
try {
const response = await Server().post('/media/upload', body);
if (response.data.status !== 'ok') {
DisplayToast('red', t(response.data.msg || 'campaigns.media.upload-error'), 3000);
continue;
}
media.value = [response.data.media, ...media.value];
} catch (error) {
DisplayToast('red', t('campaigns.media.upload-error'), 3000);
}
}
}
function toggleSidebar() {
sidebarCollapsed.value = !sidebarCollapsed.value;
}
@@ -536,6 +576,7 @@ watch(campaignId, (newVal) => {
actors.value = [];
items.value = [];
maps.value = [];
media.value = [];
for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = [];
collapsedFolderIds.value = [];
ClearAnchoredMap();
@@ -543,6 +584,7 @@ watch(campaignId, (newVal) => {
if (isEntrySection(activeSection.value)) fetchCampaignEntries(activeSection.value);
} else {
notes.value = [];
media.value = [];
folders.value = [];
actors.value = [];
items.value = [];
@@ -559,6 +601,7 @@ onMounted(() => {
emitter.on('note-created', handleNoteCreated);
emitter.on('note-renamed', handleNoteRenamed);
emitter.on('delete-note', handleNoteDeleted);
emitter.on('media-deleted', handleMediaDeleted);
emitter.on('folder-saved', handleFolderSaved);
emitter.on('folder-deleted', handleFolderDeleted);
emitter.on('campaign-entry-created', handleCampaignEntryCreated);
@@ -580,6 +623,7 @@ onBeforeUnmount(() => {
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
emitter.off('media-deleted', handleMediaDeleted);
emitter.off('folder-saved', handleFolderSaved);
emitter.off('folder-deleted', handleFolderDeleted);
emitter.off('campaign-entry-created', handleCampaignEntryCreated);
@@ -659,6 +703,10 @@ onBeforeUnmount(() => {
<button class="sidebar-action" type="button" @click="createNote" :disabled="!Campaign" :title="t('campaigns.actions.new-note')" :aria-label="t('campaigns.actions.new-note')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
</button>
<button class="sidebar-action" type="button" @click="chooseMedia" :disabled="!Campaign" :title="t('campaigns.media.upload')" :aria-label="t('campaigns.media.upload')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/media-image-plus.svg" alt="" aria-hidden="true">
</button>
<input ref="mediaInput" class="media-input" type="file" multiple @change="uploadMedia">
<button class="sidebar-action" type="button" @click="createFolder()" :disabled="!Campaign" :title="t('campaigns.actions.new-folder')" :aria-label="t('campaigns.actions.new-folder')">
<img class="sidebar-action-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
</button>
@@ -684,9 +732,9 @@ onBeforeUnmount(() => {
<template v-if="activeSection === 'notes'">
<div v-if="loadingNotes" class="sidebar-state">{{ t('campaigns.states.loading-notes') }}</div>
<div v-else-if="notesError" class="sidebar-state error">{{ notesError }}</div>
<div v-else-if="folders.length === 0 && notes.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-notes') }}</div>
<div v-else-if="folders.length === 0 && notes.length === 0 && media.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-notes') }}</div>
<NestedNoteList v-else ref="nestedNoteListRef"
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :campaign-id="campaignId"
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :media="media" :campaign-id="campaignId"
:expanded-folder-ids="expandedFolderIds" @open-note="openNote"
@reload-notes="fetchCampaignNotes" @toggle-expanded-folder="toggleExpandedFolder" />
</template>
@@ -706,7 +754,10 @@ onBeforeUnmount(() => {
@toggle="toggleFolder(row.folder._id)"
/>
<div v-else class="entity-entry" :style="rowIndent(row.depth)" role="button" tabindex="0" draggable="true" :title="t('campaigns.map.tokens.drag')" @click="openCharacterSheet(row.item)" @keydown.enter="openCharacterSheet(row.item)" @keydown.space.prevent="openCharacterSheet(row.item)" @dragstart="startActorDrag($event, row.item)" @contextmenu.prevent="showEntryMenu(row.item, 'actor')">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span class="entity-entry-title">
<img class="entity-entry-icon" src="/icons/iconoir/regular/user.svg" alt="" aria-hidden="true">
<span class="entity-entry-name">{{ row.item.name }}</span>
</span>
<span class="entity-entry-meta">{{ entrySummary(row.item) }}</span>
</div>
</template>
@@ -731,6 +782,7 @@ onBeforeUnmount(() => {
<span v-if="row.item.image" class="entity-entry-image" aria-hidden="true">
<img :src="itemImageUrl(row.item.image)" alt="">
</span>
<img v-else class="entity-entry-icon" src="/icons/iconoir/regular/box.svg" alt="" aria-hidden="true">
<span class="entity-entry-name" :class="rarityClass(row.item)">{{ row.item.name }}</span>
</span>
</div>
@@ -752,9 +804,12 @@ onBeforeUnmount(() => {
@toggle="toggleFolder(row.folder._id)"
/>
<div v-else class="entity-entry" :style="rowIndent(row.depth)" :class="{ anchored: isAnchoredMap(row.item) }" role="button" tabindex="0" @click="openMapViewer(row.item)" @keydown.enter="openMapViewer(row.item)" @keydown.space.prevent="openMapViewer(row.item)" @contextmenu.prevent="showEntryMenu(row.item, 'map')">
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span v-if="isAnchoredMap(row.item)" class="entity-entry-sync">{{ t('campaigns.map.anchored') }}</span>
<span class="entity-entry-title">
<img class="entity-entry-icon" src="/icons/iconoir/regular/map.svg" alt="" aria-hidden="true">
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span v-if="isAnchoredMap(row.item)" class="entity-entry-sync">{{ t('campaigns.map.anchored') }}</span>
</span>
</span>
<span class="entity-entry-meta">{{ mapSummary(row.item) }}</span>
<span v-if="!row.item.image" class="entity-entry-description">{{ t('campaigns.map.no-image') }}</span>
@@ -850,6 +905,7 @@ onBeforeUnmount(() => {
}
.sidebar-header-actions { display: flex; align-items: center; gap: 4px; }
.media-input { display: none; }
.sidebar-header-actions .sidebar-action { width: 30px; height: 30px; }
.sidebar-header-actions .sidebar-action-icon { width: 16px; height: 16px; }
@@ -923,6 +979,8 @@ onBeforeUnmount(() => {
}
.entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; }
.entity-entry-description { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
/* Every entry row leads with an icon of what it is: an actor, an item, a map. */
.entity-entry-icon { width: 16px; height: 16px; flex: 0 0 16px; filter: invert(var(--color-icon-invert)); }
/* An item row leads with the item's own icon on the left of its name, standing in for the
"SYNCED" text it used to show (Syndria98/dragonroll#53). */
.entity-entry-title { display: flex; align-items: center; gap: 9px; min-width: 0; }

View File

@@ -2,13 +2,15 @@
import { ref, onBeforeUnmount, onMounted, watch } from 'vue';
import { emitter } from '~/services/Emitter';
import { BuildColorMenu } from '~/services/EntryColors';
import Server from '~/services/Server';
import Server, { getBaseUrl } from '~/services/Server';
import { CreateWindow } from '~/services/Windows';
import { ShowContextMenu, HideContextMenu } from '~/services/ContextMenu';
const props = defineProps({
folders: Array,
notes: Array,
// Media files standing beside the notes at this level of the tree.
media: { type: Array, default: () => [] },
campaignId: String,
level: { type: Number, default: 0 },
parentFolderId: String,
@@ -44,6 +46,7 @@ onMounted(() => {
emitter.on('note-created', handleNoteCreated);
emitter.on('note-renamed', handleNoteRenamed);
emitter.on('delete-note', handleNoteDeleted);
emitter.on('media-deleted', handleMediaDeleted);
emitter.on('folder-saved', handleFolderSaved);
});
@@ -51,6 +54,7 @@ onBeforeUnmount(() => {
emitter.off('note-created', handleNoteCreated);
emitter.off('note-renamed', handleNoteRenamed);
emitter.off('delete-note', handleNoteDeleted);
emitter.off('media-deleted', handleMediaDeleted);
emitter.off('folder-saved', handleFolderSaved);
});
@@ -80,6 +84,12 @@ function handleNoteDeleted(noteKey) {
}
}
function handleMediaDeleted(mediaId) {
for (const entry of Object.values(folderContentCache.value)) {
entry.media = entry.media.filter((m) => m._id !== mediaId);
}
}
function handleFolderSaved(folder) {
const folderId = folder?._id ?? folder?.id;
if (!folderId) return;
@@ -98,6 +108,7 @@ function loadFolderContents(folderId) {
if (res.data.status !== 'ok') return;
folderContentCache.value[folderId] = {
notes: res.data.notes.map(n => ({ key: n._id, title: n.title, text: n.content || '', color: n.color })),
media: res.data.media || [],
subfolders: res.data.subfolders || []
};
}).catch(() => {}).finally(() => {
@@ -113,6 +124,10 @@ function getFolderSubfolders(folderId) {
return folderContentCache.value[folderId]?.subfolders || [];
}
function getFolderMedia(folderId) {
return folderContentCache.value[folderId]?.media || [];
}
// Load contents for all currently-expanded folders
function loadExpandedFolders() {
const idsToLoad = props.level === 0
@@ -125,26 +140,32 @@ function loadExpandedFolders() {
}
}
// A row dragged into a folder is either a note (its key) or a media file ("media:<id>").
async function moveDraggedRow(payload, folderId) {
const mediaId = payload.startsWith('media:') ? payload.slice(6) : null;
await Server().post(mediaId ? '/media/update' : '/note/update', { id: mediaId ?? payload, folder: folderId });
}
async function handleDropNoteOnFolder(folderId, event) {
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey || !folderId) return;
const row = event.dataTransfer.getData('text/plain');
if (!row || !folderId) return;
dragHoveredFolderId.value = null;
try {
await Server().post('/note/update', { id: noteKey, folder: folderId });
await moveDraggedRow(row, folderId);
clearCacheAndReloadExpanded();
} catch (e) {}
}
async function handleDropNoteOnRoot(event) {
const noteKey = event.dataTransfer.getData('text/plain');
if (!noteKey) return;
const row = event.dataTransfer.getData('text/plain');
if (!row) return;
dragHoveredFolderId.value = null;
try {
await Server().post('/note/update', { id: noteKey, folder: null });
await moveDraggedRow(row, null);
clearCacheAndReloadExpanded();
} catch (e) {}
}
@@ -172,6 +193,31 @@ function startDragNote(event, note) {
event.dataTransfer.effectAllowed = 'move';
}
// A media row drags into a folder like a note does, under a prefixed key so the drop knows
// which of the two lists it is moving.
function startDragMedia(event, media) {
event.dataTransfer.setData('text/plain', `media:${media._id}`);
event.dataTransfer.effectAllowed = 'move';
}
// The icon a media row leads with, the way the sidebar tells a picture from a sound at a glance.
function mediaIcon(media) {
const type = media?.mimeType ?? '';
if (type.startsWith('image/')) return '/icons/iconoir/regular/media-image.svg';
if (type.startsWith('audio/')) return '/icons/iconoir/regular/music-note.svg';
if (type.startsWith('video/')) return '/icons/iconoir/regular/media-video.svg';
if (type === 'application/pdf') return '/icons/iconoir/regular/page.svg';
return '/icons/iconoir/regular/attachment.svg';
}
function mediaUrl(media) {
return media?.file ? `${getBaseUrl()}/public/${media.file}` : '';
}
function openMedia(media) {
CreateWindow('media_viewer', { media });
}
function setDragHover(id) {
dragHoveredFolderId.value = id;
}
@@ -194,6 +240,18 @@ function buildNoteContextMenu(note) {
];
}
function buildMediaContextMenu(media) {
return [
{ name: 'Open', icon: '/icons/iconoir/regular/attachment.svg', action: () => openMedia(media) },
{
name: 'Move to Folder...', icon: '/icons/iconoir/regular/folder.svg',
context: buildMediaMoveToMenu(media)
},
{ divider: true },
{ name: 'Delete', icon: '/icons/iconoir/regular/trash.svg', action: () => deleteMedia(media) }
];
}
function buildFolderContextMenu(folder) {
if (!folder || !folder._id) return [];
return [
@@ -262,6 +320,35 @@ async function deleteFolder(folderId) {
HideContextMenu();
}
function buildMediaMoveToMenu(media) {
const moveItems = (props.folders || []).map(folder => ({
name: folder.name, icon: '/icons/iconoir/regular/folder.svg', action: () => moveMediaToFolder(media, folder._id)
}));
if (moveItems.length > 0) moveItems.push({ divider: true });
moveItems.push({ name: '(Root)', icon: '/icons/iconoir/regular/attachment.svg', action: () => moveMediaToFolder(media, null) });
return moveItems;
}
async function moveMediaToFolder(media, folderId) {
try {
const response = await Server().post('/media/update', { id: media._id, folder: folderId || null });
if (response.data.status !== 'ok') return;
clearCacheAndReloadExpanded();
} catch (e) {}
HideContextMenu();
}
async function deleteMedia(media) {
try {
const response = await Server().post('/media/delete', { id: media._id });
if (response.data.status === 'ok') emitter.emit('media-deleted', media._id);
} catch (error) {} finally {
HideContextMenu();
}
}
async function moveNoteToFolder(note, folderId) {
try {
const response = await Server().post('/note/update', { id: note.key, folder: folderId || null });
@@ -308,6 +395,7 @@ function createNoteInFolder(folderId) {
v-if="expandedFolderIds.includes(folder._id)"
:folders="getFolderSubfolders(folder._id)"
:notes="getFolderNotes(folder._id)"
:media="getFolderMedia(folder._id)"
:campaign-id="campaignId"
:level="level + 1"
:parent-folder-id="folder._id"
@@ -323,15 +411,24 @@ function createNoteInFolder(folderId) {
<!-- Notes at this level -->
<template v-for="note in notes" :key="note.key">
<button type="button" class="note-link" :class="{ 'has-color': !!note.color }" :style="entryColorStyle(note)" draggable="true" @dragstart="startDragNote($event, note)" @click.stop="$emit('open-note', note)" @contextmenu.prevent="ShowContextMenu(buildNoteContextMenu(note))">
<img class="note-link-icon" src="/icons/iconoir/regular/journal-page.svg" alt="" aria-hidden="true">
<span class="note-link-title">{{ note.title }}</span>
</button>
</template>
<!-- Media files at this level, VSCode-explorer style: the type's icon, then the file name -->
<template v-for="item in media" :key="item._id">
<button type="button" class="note-link media-link" draggable="true" :title="item.name" @dragstart="startDragMedia($event, item)" @click.stop="openMedia(item)" @contextmenu.prevent="ShowContextMenu(buildMediaContextMenu(item))">
<img class="media-link-icon" :src="mediaIcon(item)" alt="" aria-hidden="true">
<span class="media-link-name">{{ item.name }}</span>
</button>
</template>
<!-- Drop zone for root-level notes -->
<div v-if="level === 0" class="root-drop-zone" :class="{ 'drag-over': dragHoveredFolderId === 'root' }" @drop.stop="handleDropNoteOnRoot($event)">
</div>
<div v-if="folders.length === 0 && (!notes || notes.length === 0) && level === 0" class="sidebar-state">Empty</div>
<div v-if="folders.length === 0 && (!notes || notes.length === 0) && (!media || media.length === 0) && level === 0" class="sidebar-state">Empty</div>
</div>
</template>
@@ -353,10 +450,17 @@ function createNoteInFolder(folderId) {
.folder-children { padding-left: 20px; margin-top: 2px; cursor: default; }
.folder-children.drag-over { background: #ffffff22; border-radius: 10px; }
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: column; align-items: flex-start; text-align: left; cursor: grab; border-radius: 8px; }
.note-link { width: 100%; padding: 6px; margin: 0; box-shadow: none; border: none; display: flex; flex-direction: row; align-items: center; gap: 8px; text-align: left; cursor: grab; border-radius: 8px; }
.note-link.has-color { background: color-mix(in srgb, var(--entry-color) 32%, transparent); }
.note-link.has-color:hover { background: color-mix(in srgb, var(--entry-color) 50%, transparent); }
.note-link-title { font-weight: 600; word-break: break-word; }
/* Every note row leads with the page icon, like a media row with the icon of its type. */
.note-link-icon { width: 15px; height: 15px; flex: 0 0 15px; filter: invert(var(--color-icon-invert)); }
.note-link-title { flex: 1; min-width: 0; font-weight: 600; word-break: break-word; }
/* Media rows share the note row's box, with the file type's icon where a note has none. */
.media-link { flex-direction: row; align-items: center; gap: 8px; }
.media-link-icon { width: 15px; height: 15px; flex: 0 0 15px; filter: invert(var(--color-icon-invert)); }
.media-link-name { min-width: 0; font-weight: 500; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-state { padding: 12px; border-radius: 10px; background: var(--color-background-soft); font-size: 14px; }