Merge branch 'master' into ai/issue-47
Some checks failed
Test / test (push) Failing after 2s

This commit is contained in:
2026-10-15 11:08:48 +00:00
14 changed files with 981 additions and 23 deletions

View File

@@ -5,6 +5,7 @@ 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 { BuildItemRows } from '~/services/ItemFolders';
import Server from '~/services/Server';
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
@@ -17,6 +18,10 @@ const notes = ref([]);
const folders = ref([]);
const actors = ref([]);
const items = ref([]);
// The folders items stand in, and which of them the list has collapsed. Folders are
// open by default: a folder synced from Foundry should show its items, not hide them.
const itemFolders = ref([]);
const collapsedItemFolderIds = ref([]);
const maps = ref([]);
const entryLists = { actor: actors, item: items, map: maps };
const loadingNotes = ref(false);
@@ -202,6 +207,9 @@ async function fetchCampaignEntries(entityType = activeSection.value, silent = f
const previousById = new Map(list.value.map((entry) => [entry._id, entry]));
list.value = response.data[entityType] ?? [];
// Items come with the folder tree their world synced over, so the list can
// group them the way the Foundry item directory does.
if (kind === 'item') itemFolders.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);
@@ -345,10 +353,27 @@ function toggleSidebar() {
const rootNotes = computed(() => notes.value.filter(n => !n._folder));
// The items of the campaign, each under the folder it stands in (see
// services/ItemFolders.js). Without any folder this is the plain item list.
const itemRows = computed(() => BuildItemRows(items.value, itemFolders.value, collapsedItemFolderIds.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 toggleItemFolder(folderId) {
collapsedItemFolderIds.value = collapsedItemFolderIds.value.includes(folderId)
? collapsedItemFolderIds.value.filter((id) => id !== folderId)
: [...collapsedItemFolderIds.value, folderId];
}
watch(campaignId, (newVal) => {
if (newVal) {
actors.value = [];
items.value = [];
itemFolders.value = [];
collapsedItemFolderIds.value = [];
maps.value = [];
ClearAnchoredMap();
fetchCampaignNotes();
@@ -358,6 +383,8 @@ watch(campaignId, (newVal) => {
folders.value = [];
actors.value = [];
items.value = [];
itemFolders.value = [];
collapsedItemFolderIds.value = [];
maps.value = [];
notesError.value = '';
entriesError.value = '';
@@ -512,13 +539,33 @@ onBeforeUnmount(() => {
<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" class="sidebar-state">{{ t('campaigns.states.empty-items') }}</div>
<div v-for="item in items" :key="item._id" class="entity-entry" role="button" tabindex="0" @click="openItemSheet(item)" @keydown.enter="openItemSheet(item)" @keydown.space.prevent="openItemSheet(item)" @contextmenu.prevent="showEntryMenu(item, 'item')">
<span class="entity-entry-name-row">
<span class="entity-entry-name">{{ item.name }}</span>
<span v-if="item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
</span>
<span class="entity-entry-meta">{{ itemSummary(item) }}</span>
</div>
<template v-for="row in itemRows" :key="row.key">
<button
v-if="row.kind === 'folder'"
class="item-folder-entry"
type="button"
:style="rowIndent(row.depth)"
:aria-expanded="(!collapsedItemFolderIds.includes(row.folder._id)).toString()"
:aria-label="t('campaigns.item.folder-toggle', { name: row.folder.name })"
@click="toggleItemFolder(row.folder._id)"
>
<img
class="item-folder-arrow"
:src="collapsedItemFolderIds.includes(row.folder._id) ? '/icons/iconoir/regular/nav-arrow-right.svg' : '/icons/iconoir/regular/nav-arrow-down.svg'"
alt=""
aria-hidden="true"
>
<img class="item-folder-icon" src="/icons/iconoir/regular/folder.svg" alt="" aria-hidden="true">
<span class="item-folder-name">{{ row.folder.name }}</span>
</button>
<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-name-row">
<span class="entity-entry-name">{{ row.item.name }}</span>
<span v-if="row.item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
</span>
<span class="entity-entry-meta">{{ itemSummary(row.item) }}</span>
</div>
</template>
</template>
<template v-else>
@@ -684,6 +731,18 @@ onBeforeUnmount(() => {
}
.entity-entry:hover { border-color: var(--color-border); background: var(--color-background-soft); }
.entity-entry:focus-visible { outline: 1px solid var(--color-link); }
/* Item folders, synced from the linked world's item directory: the same row box as
an entry, since they share the sidebar list and its width rules. */
.item-folder-entry {
width: 100%; min-width: 0; box-sizing: border-box; margin: 0; padding: 8px 10px; border: 1px solid transparent;
border-radius: 8px; background: transparent; color: var(--color-text); text-align: left; display: flex;
align-items: center; gap: 6px; cursor: pointer; font: inherit;
}
.item-folder-entry:hover { background: var(--color-background-soft); }
.item-folder-entry:focus-visible { outline: 1px solid var(--color-link); }
.item-folder-arrow { width: 12px; height: 12px; flex: 0 0 12px; filter: invert(var(--color-icon-invert)); opacity: 0.6; }
.item-folder-icon { width: 15px; height: 15px; flex: 0 0 15px; filter: invert(var(--color-icon-invert)); }
.item-folder-name { min-width: 0; font-weight: bold; word-break: break-word; }
/* 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; }