900 lines
38 KiB
Vue
900 lines
38 KiB
Vue
<script setup>
|
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import { useCampaignService } from '~/services/Campaign.js';
|
|
import { AnchorMap, AnchoredMap, ClearAnchoredMap, SetActivePane } from '~/services/Content.js';
|
|
import { emitter } from '~/services/Emitter';
|
|
import { BuildColorMenu } from '~/services/EntryColors';
|
|
import { BuildItemRows } from '~/services/ItemFolders';
|
|
import Server, { getBaseUrl } from '~/services/Server';
|
|
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
|
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
|
|
import { ACTOR_DRAG_TYPE } from '~/services/MapTokens';
|
|
import EntryFolderRow from './EntryFolderRow.vue';
|
|
import NestedNoteList from './NestedNoteList.vue';
|
|
|
|
const { Campaign } = useCampaignService();
|
|
const { t } = useI18n();
|
|
const notes = ref([]);
|
|
const folders = ref([]);
|
|
const actors = ref([]);
|
|
const items = ref([]);
|
|
const maps = ref([]);
|
|
const entryLists = { actor: actors, item: items, map: maps };
|
|
// Every sidebar section files its rows into folders of its own (see models/Folder.js), so
|
|
// each entry list keeps the tree `/actor|item|map/list` sends along. Folders are open by
|
|
// default: a folder synced from Foundry should show what stands in it, not hide it.
|
|
const entryFolders = { actor: ref([]), item: ref([]), map: ref([]) };
|
|
const collapsedFolderIds = ref([]);
|
|
const loadingNotes = ref(false);
|
|
const loadingEntries = ref(false);
|
|
const notesError = ref('');
|
|
const entriesError = ref('');
|
|
const sidebarCollapsed = ref(false);
|
|
const activeSection = ref('notes');
|
|
const isDragOverSidebar = ref(false);
|
|
const expandedFolderIds = ref([]);
|
|
const nestedNoteListRef = ref(null);
|
|
let entryRefreshInterval;
|
|
|
|
async function handleSidebarDrop(event) {
|
|
if (activeSection.value !== 'notes') return;
|
|
const noteKey = event.dataTransfer.getData('text/plain');
|
|
if (!noteKey) return;
|
|
try {
|
|
await Server().post('/note/update', { id: noteKey, folder: null });
|
|
if (nestedNoteListRef.value) {
|
|
nestedNoteListRef.value.clearCacheAndReloadExpanded();
|
|
} else {
|
|
fetchCampaignNotes();
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
|
|
// An actor row is dragged out of the sidebar onto a map, where it stands as a token. The map viewer
|
|
// reads that type back on its drop (see MapViewerPane.vue); a note drag carries 'text/plain'
|
|
// instead, so the two never land where the other belongs.
|
|
function startActorDrag(event, actor) {
|
|
event.dataTransfer.setData(ACTOR_DRAG_TYPE, String(actor._id));
|
|
event.dataTransfer.effectAllowed = 'copyMove';
|
|
}
|
|
|
|
function toggleExpandedFolder(folderId) {
|
|
const arr = expandedFolderIds.value;
|
|
const idx = arr.indexOf(folderId);
|
|
if (idx !== -1) {
|
|
arr.splice(idx, 1);
|
|
} else {
|
|
arr.push(folderId);
|
|
}
|
|
}
|
|
|
|
function isFolderExpanded(folderId) {
|
|
return expandedFolderIds.value.includes(folderId);
|
|
}
|
|
|
|
function openNote(note) {
|
|
emitter.emit('push-note', note);
|
|
}
|
|
|
|
function handleNoteCreated(note) {
|
|
if (!note) return;
|
|
|
|
const noteCampaignId = note.campaign?._id ?? note.campaign ?? null;
|
|
if (campaignId.value && noteCampaignId && noteCampaignId !== campaignId.value) return;
|
|
|
|
const createdNote = {
|
|
key: note._id,
|
|
title: note.title,
|
|
text: note.content ?? '',
|
|
date: note.date
|
|
};
|
|
|
|
notes.value = notes.value.filter((currentNote) => currentNote.key !== createdNote.key);
|
|
|
|
// Notes created inside a folder are added by NestedNoteList's own cache handler
|
|
const noteFolderId = note.folder?._id ?? note.folder ?? null;
|
|
if (!noteFolderId) {
|
|
notes.value.unshift(createdNote);
|
|
}
|
|
|
|
openNote(createdNote);
|
|
}
|
|
|
|
function handleNoteRenamed(data) {
|
|
const note = notes.value.find(n => n.key === data.key);
|
|
if (note) {
|
|
note.title = data.title;
|
|
}
|
|
emitter.emit('title-updated', { key: data.key, title: data.title });
|
|
}
|
|
|
|
function handleNoteDeleted(noteKey) {
|
|
notes.value = notes.value.filter(n => n.key !== noteKey);
|
|
}
|
|
|
|
function sectionForTarget(target) {
|
|
if (target === 'actor') return 'actors';
|
|
if (target === 'item') return 'items';
|
|
if (target === 'map') return 'maps';
|
|
return null;
|
|
}
|
|
|
|
function handleFolderSaved(folder) {
|
|
// A folder only shows up once the list it belongs to reads it back: the notes refetch
|
|
// their tree, an entry list refetches its own (silently, its rows are already there).
|
|
const section = sectionForTarget(folder?.target ?? 'note');
|
|
if (!section) {
|
|
fetchCampaignNotes();
|
|
return;
|
|
}
|
|
fetchCampaignEntries(section, true);
|
|
}
|
|
|
|
function handleFolderDeleted(folderId) {
|
|
expandedFolderIds.value = expandedFolderIds.value.filter((id) => id !== folderId);
|
|
collapsedFolderIds.value = collapsedFolderIds.value.filter((id) => id !== folderId);
|
|
}
|
|
|
|
function handleCampaignEntryCreated({ entityType, entry }) {
|
|
if (!entry || (entry.campaign && String(entry.campaign) !== String(campaignId.value))) return;
|
|
const list = entryLists[entityType];
|
|
if (!list) return;
|
|
list.value = [...list.value.filter((current) => current._id !== entry._id), entry]
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
}
|
|
|
|
function handleCampaignEntryUpdated({ entityType, entry }) {
|
|
if (!entry) return;
|
|
const list = entryLists[entityType];
|
|
if (!list) return;
|
|
list.value = list.value.map((current) => current._id === entry._id ? entry : current)
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
// The anchored map is this very entry (its pins changed, say): write it back without touching
|
|
// the pane, so switching back from the notes still shows what is on the map.
|
|
if (entityType === 'map' && AnchoredMap.value?._id === entry._id) AnchoredMap.value = entry;
|
|
}
|
|
|
|
const campaignId = computed(() => {
|
|
return Campaign.value?._id ?? Campaign.value?.id ?? null;
|
|
});
|
|
|
|
async function fetchCampaignNotes() {
|
|
if (!campaignId.value) {
|
|
notes.value = [];
|
|
folders.value = [];
|
|
notesError.value = '';
|
|
return;
|
|
}
|
|
|
|
loadingNotes.value = true;
|
|
notesError.value = '';
|
|
|
|
try {
|
|
const response = await Server().get('/note/list', { params: { campaign: campaignId.value } });
|
|
|
|
if (response.data.status !== 'ok') {
|
|
notes.value = [];
|
|
folders.value = [];
|
|
notesError.value = response.data.msg ?? 'Unable to load notes.';
|
|
return;
|
|
}
|
|
|
|
folders.value = response.data.folders.map((folder) => ({
|
|
_id: folder._id, name: folder.name, date: folder.date, color: folder.color
|
|
}));
|
|
|
|
notes.value = response.data.notes.map((note) => {
|
|
return { key: note._id, title: note.title, text: note.content ?? '', date: note.date, color: note.color };
|
|
});
|
|
} catch (error) {
|
|
notes.value = [];
|
|
folders.value = [];
|
|
notesError.value = 'Unable to load notes.';
|
|
} finally {
|
|
loadingNotes.value = false;
|
|
}
|
|
}
|
|
|
|
function entryEntityType(section) {
|
|
if (section === 'actors') return 'actor';
|
|
if (section === 'items') return 'item';
|
|
if (section === 'maps') return 'map';
|
|
return null;
|
|
}
|
|
|
|
function isEntrySection(section) {
|
|
return entryEntityType(section) !== null;
|
|
}
|
|
|
|
async function fetchCampaignEntries(entityType = activeSection.value, silent = false) {
|
|
const kind = entryEntityType(entityType);
|
|
const list = entryLists[kind];
|
|
if (!campaignId.value || !list) return;
|
|
if (!silent) {
|
|
loadingEntries.value = true;
|
|
entriesError.value = '';
|
|
}
|
|
try {
|
|
const response = await Server().get(`/${kind}/list`, { params: { campaign: campaignId.value } });
|
|
if (response.data.status !== 'ok') {
|
|
if (!silent) entriesError.value = response.data.msg ?? t('campaigns.errors.load');
|
|
return;
|
|
}
|
|
|
|
const previousById = new Map(list.value.map((entry) => [entry._id, entry]));
|
|
list.value = response.data[entityType] ?? [];
|
|
// Every entry list comes with the folders its rows stand in, so the sidebar can
|
|
// group them the way the note tree does (and the way the Foundry item directory
|
|
// arrives for items).
|
|
entryFolders[kind].value = response.data.folders ?? [];
|
|
// Tell open windows about Foundry changes landing behind them.
|
|
for (const entry of list.value) {
|
|
const previous = previousById.get(entry._id);
|
|
if (previous && JSON.stringify(previous) !== JSON.stringify(entry)) {
|
|
emitter.emit('campaign-entry-updated', { entityType: kind, entry });
|
|
}
|
|
}
|
|
} catch (error) {
|
|
if (!silent) entriesError.value = t('campaigns.errors.load');
|
|
} finally {
|
|
if (!silent) loadingEntries.value = false;
|
|
}
|
|
}
|
|
|
|
function selectSection(section) {
|
|
activeSection.value = section;
|
|
if (isEntrySection(section)) fetchCampaignEntries(section);
|
|
// Only the notes and maps buttons say something about the note container: they switch it between
|
|
// the notes that are open and the anchored map. Actors and items open windows of their own, so
|
|
// their buttons leave whatever the note container was showing untouched.
|
|
if (section === 'notes') SetActivePane('notes');
|
|
else if (section === 'maps' && AnchoredMap.value) SetActivePane('map');
|
|
}
|
|
|
|
function createEntry(entityType) {
|
|
if (!campaignId.value) return;
|
|
if (entityType === 'map') {
|
|
CreateWindow('create_map', { campaign: campaignId.value });
|
|
return;
|
|
}
|
|
CreateWindow('create_campaign_entry', { entityType, campaign: campaignId.value });
|
|
}
|
|
|
|
// Every section files its rows into folders of its own: the window passes along which
|
|
// list the folder belongs to, so the notes, the actors, the items and the maps each keep
|
|
// a tree the others never show.
|
|
function createFolder(target = 'note') {
|
|
if (!campaignId.value) return;
|
|
CreateWindow('new_folder', { campaign: campaignId.value, target });
|
|
}
|
|
|
|
function entrySummary(actor) {
|
|
const bits = [t(`campaigns.actor.types.${actor.type}`)];
|
|
if (actor.species) bits.push(actor.species);
|
|
if (actor.className) bits.push(actor.className);
|
|
if (actor.level) bits.push(`${t('campaigns.actor.level-short')} ${actor.level}`);
|
|
if (actor.challengeRating) bits.push(`${t('campaigns.actor.cr-short')} ${actor.challengeRating}`);
|
|
return bits.join(' · ');
|
|
}
|
|
|
|
function itemSummary(item) {
|
|
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
|
|
}
|
|
|
|
// An item's icon in the sidebar: an uploaded filename served from /api/public, or a full URL
|
|
// (Foundry sends its own icon as one) — the same rule the item window uses.
|
|
function itemImageUrl(image) {
|
|
if (!image) return '';
|
|
return /^(https?:|data:|\/\/)/i.test(image) ? image : `${getBaseUrl()}/public/${image}`;
|
|
}
|
|
|
|
function mapSummary(map) {
|
|
return t('campaigns.map.summary', { size: map.gridSize, scale: map.scale });
|
|
}
|
|
|
|
function editItem(entry) {
|
|
if (!campaignId.value) return;
|
|
CreateWindow('create_campaign_entry', { entityType: 'item', campaign: campaignId.value, entry });
|
|
}
|
|
|
|
function editMap(map) {
|
|
if (!campaignId.value) return;
|
|
CreateWindow('create_map', { campaign: campaignId.value, entry: map });
|
|
}
|
|
|
|
function showEntryMenu(entry, entityType) {
|
|
const list = entryLists[entityType];
|
|
const menuItems = [];
|
|
|
|
// Characters are edited in their sheet; items and maps get their window in edit mode.
|
|
if (entityType === 'item') {
|
|
menuItems.push({
|
|
name: t('campaigns.actions.edit'),
|
|
icon: '/icons/iconoir/regular/edit.svg',
|
|
action: () => { HideContextMenu(); editItem(entry); }
|
|
});
|
|
} else if (entityType === 'map') {
|
|
menuItems.push({
|
|
name: t('campaigns.actions.edit'),
|
|
icon: '/icons/iconoir/regular/edit.svg',
|
|
action: () => { HideContextMenu(); editMap(entry); }
|
|
});
|
|
}
|
|
|
|
// Rows of every section can be filed into a folder of their own list, like a note
|
|
// into a folder of the note tree.
|
|
menuItems.push({
|
|
name: t('campaigns.folders.move-to'),
|
|
icon: '/icons/iconoir/regular/folder.svg',
|
|
context: moveToFolderMenu(entityType, entry)
|
|
});
|
|
|
|
menuItems.push({
|
|
name: t('campaigns.actions.delete'),
|
|
icon: '/icons/iconoir/regular/trash.svg',
|
|
action: async () => {
|
|
try {
|
|
const response = await Server().post(`/${entityType}/delete`, { id: entry._id });
|
|
if (response.data.status === 'ok' && list) {
|
|
list.value = list.value.filter((current) => current._id !== entry._id);
|
|
if (entityType === 'map' && isAnchoredMap(entry)) ClearAnchoredMap();
|
|
}
|
|
} catch (error) {} finally { HideContextMenu(); }
|
|
}
|
|
});
|
|
ShowContextMenu(menuItems);
|
|
}
|
|
|
|
// The menu of a folder row: rename it, colour it, delete it. The notes' folders are
|
|
// renamed and coloured the same way, through the same `/folder/*` routes.
|
|
function folderMenuItems(folder) {
|
|
return [
|
|
{
|
|
name: t('campaigns.folders.rename'), icon: '/icons/iconoir/regular/edit-pencil.svg',
|
|
action: () => {
|
|
HideContextMenu();
|
|
CreateWindow('new_folder', { folderId: folder._id, campaign: campaignId.value, name: folder.name });
|
|
}
|
|
},
|
|
{
|
|
name: t('campaigns.folders.color'), icon: '/icons/iconoir/regular/palette.svg',
|
|
context: BuildColorMenu((color) => setFolderColor(folder, color), { defaultLabel: t('campaigns.folders.default') })
|
|
},
|
|
{ divider: true },
|
|
{ name: t('campaigns.folders.delete'), icon: '/icons/iconoir/regular/trash.svg', action: () => deleteEntryFolder(folder) }
|
|
];
|
|
}
|
|
|
|
async function setFolderColor(folder, color) {
|
|
try {
|
|
const response = await Server().post('/folder/update', { id: folder._id, color });
|
|
if (response.data.status === 'ok') folder.color = color;
|
|
} catch (error) {} finally {
|
|
HideContextMenu();
|
|
}
|
|
}
|
|
|
|
async function deleteEntryFolder(folder) {
|
|
try {
|
|
const response = await Server().post('/folder/delete', { id: folder._id });
|
|
if (response.data.status !== 'ok') return;
|
|
collapsedFolderIds.value = collapsedFolderIds.value.filter((id) => id !== folder._id);
|
|
// Whatever stood in the folder moved to the root of the list along with it.
|
|
await fetchCampaignEntries(activeSection.value, true);
|
|
} catch (error) {} finally {
|
|
HideContextMenu();
|
|
}
|
|
}
|
|
|
|
// The 'move to folder' submenu of an entry: the folders of its own list and its root.
|
|
function moveToFolderMenu(entityType, entry) {
|
|
const menuItems = entryFolders[entityType].value.map((folder) => ({
|
|
name: folder.name, icon: '/icons/iconoir/regular/folder.svg',
|
|
action: () => moveEntryToFolder(entityType, entry, folder._id)
|
|
}));
|
|
|
|
if (menuItems.length > 0) menuItems.push({ divider: true });
|
|
menuItems.push({
|
|
name: t('campaigns.folders.root'), icon: '/icons/iconoir/regular/xmark-circle.svg',
|
|
action: () => moveEntryToFolder(entityType, entry, null)
|
|
});
|
|
return menuItems;
|
|
}
|
|
|
|
async function moveEntryToFolder(entityType, entry, folderId) {
|
|
try {
|
|
const response = await Server().post(`/${entityType}/update`, { id: entry._id, folder: folderId });
|
|
if (response.data.status !== 'ok') return;
|
|
// The row walks over to its new folder. This is the event a Foundry sync of the
|
|
// entry sends, so the list regroups and a window open on it sees the change.
|
|
emitter.emit('campaign-entry-updated', { entityType, entry: response.data[entityType] });
|
|
} catch (error) {} finally {
|
|
HideContextMenu();
|
|
}
|
|
}
|
|
|
|
async function openCharacterSheet(actor) {
|
|
const existingWindowId = GetFirstWindowId('character_sheet');
|
|
if (existingWindowId !== undefined) {
|
|
ClearWindow({ id: existingWindowId });
|
|
await nextTick();
|
|
}
|
|
CreateWindow('character_sheet', { actor });
|
|
}
|
|
|
|
// Clicking an item opens its window, like a character does with its sheet.
|
|
async function openItemSheet(item) {
|
|
const existingWindowId = GetFirstWindowId('item_sheet');
|
|
if (existingWindowId !== undefined) {
|
|
ClearWindow({ id: existingWindowId });
|
|
await nextTick();
|
|
}
|
|
CreateWindow('item_sheet', { item });
|
|
}
|
|
|
|
// Maps are anchored on the note container instead of opening a window: the notes that were open
|
|
// stay open, and the sidebar's notes/maps buttons switch between the two.
|
|
function openMapViewer(map) {
|
|
if (!map) return;
|
|
const floatingViewer = GetFirstWindowId('map_viewer');
|
|
if (floatingViewer !== undefined) ClearWindow({ id: floatingViewer });
|
|
AnchorMap(map);
|
|
}
|
|
|
|
function isAnchoredMap(map) {
|
|
return AnchoredMap.value?._id === map._id;
|
|
}
|
|
|
|
function createNote() {
|
|
if (!Campaign.value) return;
|
|
|
|
CreateWindow('new_note', { campaign: campaignId.value });
|
|
}
|
|
|
|
function toggleSidebar() {
|
|
sidebarCollapsed.value = !sidebarCollapsed.value;
|
|
}
|
|
|
|
const rootNotes = computed(() => notes.value.filter(n => !n._folder));
|
|
|
|
// The rows of each entry list: every folder followed by what stands in it, deeper and
|
|
// deeper, the way the item list has done since its folders arrived from the linked world
|
|
// (services/ItemFolders.js builds them from the list and the folders the API sends).
|
|
// Without any folder this is the plain list, and `row.item` is the entry of the section
|
|
// the row belongs to: its actor, item or map.
|
|
const entryRows = {
|
|
actor: computed(() => BuildItemRows(actors.value, entryFolders.actor.value, collapsedFolderIds.value)),
|
|
item: computed(() => BuildItemRows(items.value, entryFolders.item.value, collapsedFolderIds.value)),
|
|
map: computed(() => BuildItemRows(maps.value, entryFolders.map.value, collapsedFolderIds.value))
|
|
};
|
|
|
|
// Rows one step deeper per folder level; the sidebar list's own padding is the base.
|
|
function rowIndent(depth) {
|
|
return { paddingLeft: `${10 + depth * 14}px` };
|
|
}
|
|
|
|
function toggleFolder(folderId) {
|
|
collapsedFolderIds.value = collapsedFolderIds.value.includes(folderId)
|
|
? collapsedFolderIds.value.filter((id) => id !== folderId)
|
|
: [...collapsedFolderIds.value, folderId];
|
|
}
|
|
|
|
watch(campaignId, (newVal) => {
|
|
if (newVal) {
|
|
actors.value = [];
|
|
items.value = [];
|
|
maps.value = [];
|
|
for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = [];
|
|
collapsedFolderIds.value = [];
|
|
ClearAnchoredMap();
|
|
fetchCampaignNotes();
|
|
if (isEntrySection(activeSection.value)) fetchCampaignEntries(activeSection.value);
|
|
} else {
|
|
notes.value = [];
|
|
folders.value = [];
|
|
actors.value = [];
|
|
items.value = [];
|
|
maps.value = [];
|
|
for (const sectionFolders of Object.values(entryFolders)) sectionFolders.value = [];
|
|
collapsedFolderIds.value = [];
|
|
notesError.value = '';
|
|
entriesError.value = '';
|
|
ClearAnchoredMap();
|
|
}
|
|
});
|
|
|
|
onMounted(() => {
|
|
emitter.on('note-created', handleNoteCreated);
|
|
emitter.on('note-renamed', handleNoteRenamed);
|
|
emitter.on('delete-note', handleNoteDeleted);
|
|
emitter.on('folder-saved', handleFolderSaved);
|
|
emitter.on('folder-deleted', handleFolderDeleted);
|
|
emitter.on('campaign-entry-created', handleCampaignEntryCreated);
|
|
emitter.on('campaign-entry-updated', handleCampaignEntryUpdated);
|
|
|
|
if (campaignId.value) {
|
|
fetchCampaignNotes();
|
|
}
|
|
entryRefreshInterval = setInterval(() => {
|
|
// Synced Foundry entries land in the background for both lists.
|
|
if ((activeSection.value === 'actors' || activeSection.value === 'items') && campaignId.value) {
|
|
fetchCampaignEntries(activeSection.value, true);
|
|
}
|
|
}, 5000);
|
|
});
|
|
|
|
onBeforeUnmount(() => {
|
|
clearInterval(entryRefreshInterval);
|
|
emitter.off('note-created', handleNoteCreated);
|
|
emitter.off('note-renamed', handleNoteRenamed);
|
|
emitter.off('delete-note', handleNoteDeleted);
|
|
emitter.off('folder-saved', handleFolderSaved);
|
|
emitter.off('folder-deleted', handleFolderDeleted);
|
|
emitter.off('campaign-entry-created', handleCampaignEntryCreated);
|
|
emitter.off('campaign-entry-updated', handleCampaignEntryUpdated);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="sidebar-shell">
|
|
<nav class="sidebar-actions" aria-label="Campaign tools">
|
|
<button
|
|
class="sidebar-action"
|
|
type="button"
|
|
@click="toggleSidebar"
|
|
:aria-expanded="(!sidebarCollapsed).toString()"
|
|
aria-controls="campaign-section-list"
|
|
:title="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
|
|
:aria-label="sidebarCollapsed ? t('campaigns.actions.expand-sidebar') : t('campaigns.actions.collapse-sidebar')"
|
|
>
|
|
<img
|
|
class="sidebar-action-icon"
|
|
:src="sidebarCollapsed ? '/icons/iconoir/regular/nav-arrow-right.svg' : '/icons/iconoir/regular/nav-arrow-left.svg'"
|
|
alt=""
|
|
aria-hidden="true"
|
|
>
|
|
</button>
|
|
|
|
<button
|
|
class="sidebar-action"
|
|
:class="{ selected: activeSection === 'notes' }"
|
|
type="button" @click="selectSection('notes')"
|
|
:title="t('campaigns.sections.notes')" :aria-label="t('campaigns.sections.notes')"
|
|
:aria-pressed="(activeSection === 'notes').toString()"
|
|
>
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/book.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
|
|
<button
|
|
class="sidebar-action"
|
|
:class="{ selected: activeSection === 'actors' }"
|
|
type="button" @click="selectSection('actors')"
|
|
:title="t('campaigns.sections.actors')" :aria-label="t('campaigns.sections.actors')"
|
|
:aria-pressed="(activeSection === 'actors').toString()"
|
|
>
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/user.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
|
|
<button
|
|
class="sidebar-action"
|
|
:class="{ selected: activeSection === 'items' }"
|
|
type="button" @click="selectSection('items')"
|
|
:title="t('campaigns.sections.items')" :aria-label="t('campaigns.sections.items')"
|
|
:aria-pressed="(activeSection === 'items').toString()"
|
|
>
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/box.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
|
|
<button
|
|
class="sidebar-action"
|
|
:class="{ selected: activeSection === 'maps' }"
|
|
type="button" @click="selectSection('maps')"
|
|
:title="t('campaigns.sections.maps')" :aria-label="t('campaigns.sections.maps')"
|
|
:aria-pressed="(activeSection === 'maps').toString()"
|
|
>
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/map.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
</nav>
|
|
|
|
<aside class="notes-sidebar" :class="{ collapsed: sidebarCollapsed }">
|
|
<div class="sidebar-header">
|
|
<div class="sidebar-copy">
|
|
<span class="sidebar-eyebrow">{{ t('campaigns.sidebar-label') }}</span>
|
|
<strong class="sidebar-title">{{ t(`campaigns.sections.${activeSection}`) }}</strong>
|
|
</div>
|
|
<div class="sidebar-header-actions">
|
|
<template v-if="activeSection === 'notes'">
|
|
<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="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>
|
|
<button class="sidebar-action" type="button" @click="fetchCampaignNotes" :disabled="!Campaign || loadingNotes" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
</template>
|
|
<template v-else>
|
|
<button class="sidebar-action" type="button" @click="createEntry(entryEntityType(activeSection))" :disabled="!Campaign" :title="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })" :aria-label="t('campaigns.actions.create', { section: t(`campaigns.sections.${activeSection}`).toLowerCase() })">
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/plus.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
<button class="sidebar-action" type="button" @click="createFolder(entryEntityType(activeSection))" :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>
|
|
<button class="sidebar-action" type="button" @click="fetchCampaignEntries(activeSection)" :disabled="!Campaign || loadingEntries" :title="t('campaigns.actions.refresh')" :aria-label="t('campaigns.actions.refresh')">
|
|
<img class="sidebar-action-icon" src="/icons/iconoir/regular/refresh.svg" alt="" aria-hidden="true">
|
|
</button>
|
|
</template>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-list-drop-wrap" :class="{ 'drag-over': activeSection === 'notes' && isDragOverSidebar }" id="campaign-section-list" @dragenter.self="isDragOverSidebar = true" @dragleave.self="isDragOverSidebar = false" @dragover.prevent @drop.stop="handleSidebarDrop">
|
|
<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>
|
|
<NestedNoteList v-else ref="nestedNoteListRef"
|
|
:parent-folder-id="null" :folders="folders" :notes="rootNotes" :campaign-id="campaignId"
|
|
:expanded-folder-ids="expandedFolderIds" @open-note="openNote"
|
|
@reload-notes="fetchCampaignNotes" @toggle-expanded-folder="toggleExpandedFolder" />
|
|
</template>
|
|
|
|
<template v-else-if="activeSection === 'actors'">
|
|
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
|
|
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
|
|
<div v-else-if="actors.length === 0 && entryFolders.actor.value.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-actors') }}</div>
|
|
<template v-for="row in entryRows.actor.value" :key="row.key">
|
|
<EntryFolderRow
|
|
v-if="row.kind === 'folder'"
|
|
:folder="row.folder"
|
|
:collapsed="collapsedFolderIds.includes(row.folder._id)"
|
|
:indent="rowIndent(row.depth)"
|
|
:menu="folderMenuItems(row.folder)"
|
|
:toggle-label="t('campaigns.folders.toggle', { name: row.folder.name })"
|
|
@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-meta">{{ entrySummary(row.item) }}</span>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
<template v-else-if="activeSection === 'items'">
|
|
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
|
|
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
|
|
<div v-else-if="items.length === 0 && entryFolders.item.value.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-items') }}</div>
|
|
<template v-for="row in entryRows.item.value" :key="row.key">
|
|
<EntryFolderRow
|
|
v-if="row.kind === 'folder'"
|
|
:folder="row.folder"
|
|
:collapsed="collapsedFolderIds.includes(row.folder._id)"
|
|
:indent="rowIndent(row.depth)"
|
|
:menu="folderMenuItems(row.folder)"
|
|
:toggle-label="t('campaigns.folders.toggle', { name: row.folder.name })"
|
|
@toggle="toggleFolder(row.folder._id)"
|
|
/>
|
|
<div v-else class="entity-entry" :style="rowIndent(row.depth)" role="button" tabindex="0" @click="openItemSheet(row.item)" @keydown.enter="openItemSheet(row.item)" @keydown.space.prevent="openItemSheet(row.item)" @contextmenu.prevent="showEntryMenu(row.item, 'item')">
|
|
<span class="entity-entry-title">
|
|
<span v-if="row.item.image" class="entity-entry-image" aria-hidden="true">
|
|
<img :src="itemImageUrl(row.item.image)" alt="">
|
|
</span>
|
|
<span class="entity-entry-name">{{ row.item.name }}</span>
|
|
</span>
|
|
<span class="entity-entry-meta">{{ itemSummary(row.item) }}</span>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
<template v-else>
|
|
<div v-if="loadingEntries" class="sidebar-state">{{ t('campaigns.states.loading') }}</div>
|
|
<div v-else-if="entriesError" class="sidebar-state error">{{ entriesError }}</div>
|
|
<div v-else-if="maps.length === 0 && entryFolders.map.value.length === 0" class="sidebar-state">{{ t('campaigns.states.empty-maps') }}</div>
|
|
<template v-for="row in entryRows.map.value" :key="row.key">
|
|
<EntryFolderRow
|
|
v-if="row.kind === 'folder'"
|
|
:folder="row.folder"
|
|
:collapsed="collapsedFolderIds.includes(row.folder._id)"
|
|
:indent="rowIndent(row.depth)"
|
|
:menu="folderMenuItems(row.folder)"
|
|
:toggle-label="t('campaigns.folders.toggle', { name: row.folder.name })"
|
|
@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>
|
|
<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>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.sidebar-shell {
|
|
min-height: 0;
|
|
display: flex;
|
|
flex-direction: row;
|
|
}
|
|
|
|
.sidebar-actions {
|
|
width: 46px;
|
|
min-width: 46px;
|
|
padding: 8px 6px;
|
|
border-right: 1px solid var(--color-border);
|
|
background-color: var(--color-background-light);
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.sidebar-action {
|
|
width: 34px;
|
|
height: 34px;
|
|
margin: 0;
|
|
padding: 0;
|
|
border: 1px solid var(--color-border);
|
|
border-radius: 8px;
|
|
background: var(--color-background-soft);
|
|
box-shadow: none;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.sidebar-action.selected {
|
|
background: var(--color-button-hover);
|
|
border-color: var(--color-link);
|
|
}
|
|
|
|
.sidebar-action:hover {
|
|
background: var(--color-button-hover);
|
|
}
|
|
|
|
.sidebar-action:disabled {
|
|
opacity: 0.45;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.sidebar-action-icon {
|
|
width: 18px;
|
|
height: 18px;
|
|
filter: invert(var(--color-icon-invert));
|
|
}
|
|
|
|
.notes-sidebar {
|
|
min-width: 280px;
|
|
width: 280px;
|
|
border-right: 1px solid var(--color-border);
|
|
background-color: var(--color-background-light);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
transition: width 0.2s ease, min-width 0.2s ease, border-color 0.2s ease;
|
|
}
|
|
|
|
.notes-sidebar.collapsed {
|
|
width: 0;
|
|
min-width: 0;
|
|
border-right-color: transparent;
|
|
}
|
|
|
|
.sidebar-header {
|
|
width: 280px;
|
|
min-width: 280px;
|
|
box-sizing: border-box;
|
|
padding: 12px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 8px;
|
|
border-bottom: 1px solid var(--color-border);
|
|
}
|
|
|
|
.sidebar-header-actions { display: flex; align-items: center; gap: 4px; }
|
|
.sidebar-header-actions .sidebar-action { width: 30px; height: 30px; }
|
|
.sidebar-header-actions .sidebar-action-icon { width: 16px; height: 16px; }
|
|
|
|
.sidebar-copy {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 2px;
|
|
min-width: 0;
|
|
}
|
|
|
|
.sidebar-eyebrow,
|
|
.sidebar-meta {
|
|
font-size: 12px;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.sidebar-title {
|
|
line-height: 1.2;
|
|
word-break: break-word;
|
|
}
|
|
|
|
.sidebar-list-drop-wrap {
|
|
width: 280px;
|
|
min-width: 280px;
|
|
box-sizing: border-box;
|
|
padding: 10px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow-y: auto;
|
|
gap: 2px;
|
|
transition: background-color 0.15s ease;
|
|
flex: 1;
|
|
min-height: 0;
|
|
}
|
|
|
|
.sidebar-list-drop-wrap.drag-over {
|
|
background: var(--color-button-hover);
|
|
}
|
|
|
|
.sidebar-state {
|
|
padding: 12px;
|
|
border-radius: 10px;
|
|
background: var(--color-background-soft);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.sidebar-state.error {
|
|
color: #9e2a2b;
|
|
}
|
|
|
|
.entity-entry {
|
|
/* These rows are divs (the note and folder rows are buttons) and there is no global box-sizing
|
|
reset, so without border-box the padding and border add onto the 100% width and the entry
|
|
sticks out of the sidebar. */
|
|
width: 100%; min-width: 0; box-sizing: border-box; padding: 9px 10px; border: 1px solid transparent;
|
|
border-radius: 8px;
|
|
background: transparent; color: var(--color-text); text-align: left; display: flex; flex-direction: column;
|
|
gap: 3px; cursor: pointer;
|
|
}
|
|
.entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); }
|
|
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
|
|
/* The map currently anchored on the note container. */
|
|
.entity-entry.anchored { border-color: var(--color-link); background: var(--color-background-soft); }
|
|
.entity-entry-name-row { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
|
|
.entity-entry-name { font-weight: bold; min-width: 0; word-break: break-word; }
|
|
.entity-entry-sync {
|
|
font-size: 10px;
|
|
letter-spacing: 0.04em;
|
|
text-transform: uppercase;
|
|
opacity: 0.6;
|
|
}
|
|
.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; }
|
|
/* 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; }
|
|
.entity-entry-image {
|
|
flex: 0 0 30px; width: 30px; height: 30px; box-sizing: border-box;
|
|
display: grid; place-items: center; overflow: hidden;
|
|
border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-background-soft);
|
|
}
|
|
.entity-entry-image img { width: 100%; height: 100%; object-fit: contain; }
|
|
|
|
@media (max-width: 900px) {
|
|
.notes-sidebar {
|
|
width: 220px;
|
|
min-width: 220px;
|
|
}
|
|
|
|
.sidebar-header,
|
|
.sidebar-list-drop-wrap {
|
|
width: 220px;
|
|
min-width: 220px;
|
|
}
|
|
}
|
|
</style>
|