This commit is contained in:
@@ -7,7 +7,7 @@ import { AnchorMap, AnchoredMap, ClearAnchoredMap, SetActivePane } from '~/servi
|
|||||||
import { emitter } from '~/services/Emitter';
|
import { emitter } from '~/services/Emitter';
|
||||||
import { BuildColorMenu } from '~/services/EntryColors';
|
import { BuildColorMenu } from '~/services/EntryColors';
|
||||||
import { BuildItemRows } from '~/services/ItemFolders';
|
import { BuildItemRows } from '~/services/ItemFolders';
|
||||||
import Server from '~/services/Server';
|
import Server, { getBaseUrl } from '~/services/Server';
|
||||||
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
import { ClearWindow, CreateWindow, GetFirstWindowId } from '~/services/Windows';
|
||||||
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
|
import { HideContextMenu, ShowContextMenu } from '~/services/ContextMenu';
|
||||||
import { ACTOR_DRAG_TYPE } from '~/services/MapTokens';
|
import { ACTOR_DRAG_TYPE } from '~/services/MapTokens';
|
||||||
@@ -283,6 +283,13 @@ function itemSummary(item) {
|
|||||||
return `${t(`campaigns.item.categories.${item.category}`)} · ${t(`campaigns.item.rarities.${item.rarity}`)} · ${t('campaigns.item.quantity-short')} ${item.quantity}`;
|
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) {
|
function mapSummary(map) {
|
||||||
return t('campaigns.map.summary', { size: map.gridSize, scale: map.scale });
|
return t('campaigns.map.summary', { size: map.gridSize, scale: map.scale });
|
||||||
}
|
}
|
||||||
@@ -670,9 +677,11 @@ onBeforeUnmount(() => {
|
|||||||
@toggle="toggleFolder(row.folder._id)"
|
@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')">
|
<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-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 class="entity-entry-name">{{ row.item.name }}</span>
|
||||||
<span v-if="row.item.foundryItemId" class="entity-entry-sync">{{ t('campaigns.synced') }}</span>
|
|
||||||
</span>
|
</span>
|
||||||
<span class="entity-entry-meta">{{ itemSummary(row.item) }}</span>
|
<span class="entity-entry-meta">{{ itemSummary(row.item) }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -865,6 +874,15 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
.entity-entry-meta, .entity-entry-description { font-size: 12px; opacity: 0.72; }
|
.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; }
|
.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) {
|
@media (max-width: 900px) {
|
||||||
.notes-sidebar {
|
.notes-sidebar {
|
||||||
|
|||||||
69
tests/item-entry-display.test.js
Normal file
69
tests/item-entry-display.test.js
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
// Tests for Syndria98/dragonroll#53: the item row in the campaign sidebar dropped its "SYNCED"
|
||||||
|
// text badge and now leads with the item's own icon on the left of the entry.
|
||||||
|
//
|
||||||
|
// The repository root installs no dependencies, so these read the sidebar component the way
|
||||||
|
// tests/sidebar-entity-entry.test.js does — the checks are about the markup and style of the row.
|
||||||
|
//
|
||||||
|
// Run with `npm test` from the repository root, or `node --test tests/`.
|
||||||
|
|
||||||
|
const { test } = require("node:test");
|
||||||
|
const assert = require("node:assert/strict");
|
||||||
|
const fs = require("node:fs");
|
||||||
|
const path = require("node:path");
|
||||||
|
|
||||||
|
const source = fs.readFileSync(
|
||||||
|
path.join(__dirname, "..", "frontend", "app", "components", "partials", "ContentSidebar.vue"),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
|
||||||
|
// The block that renders the item rows, from the items section down to its closing template. The
|
||||||
|
// items section is followed by the maps section (`v-else`), so the first `</template>` that leads
|
||||||
|
// there ends it; the inner `v-for` close is followed by another close, not by `v-else`.
|
||||||
|
const itemSection =
|
||||||
|
/<template v-else-if="activeSection === 'items'">([\s\S]*?)<\/template>\s*\n\s*<template v-else>/.exec(source)?.[1] ?? "";
|
||||||
|
|
||||||
|
// `selector` is inserted verbatim, so escape the `.` of a class combination. Comments are dropped:
|
||||||
|
// they explain a rule, they are not part of it.
|
||||||
|
function ruleFor(selector) {
|
||||||
|
const rule = new RegExp(`\\.${selector}\\s*\\{([^}]*)\\}`).exec(source)?.[0];
|
||||||
|
return rule?.replace(/\/\*[\s\S]*?\*\//g, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
test("the item entry no longer shows the SYNCED text", () => {
|
||||||
|
assert.ok(itemSection, "expected to find the items section of the sidebar");
|
||||||
|
assert.doesNotMatch(itemSection, /campaigns\.synced/, "the item row must not render the synced text");
|
||||||
|
assert.doesNotMatch(itemSection, /entity-entry-sync/, "the item row must not render the synced badge");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the item entry shows the item's image on the left when it has one", () => {
|
||||||
|
// the icon renders only for an item that carries an image, resolved through the helper...
|
||||||
|
assert.match(
|
||||||
|
itemSection,
|
||||||
|
/<span v-if="row\.item\.image" class="entity-entry-image"[\s\S]*?<img :src="itemImageUrl\(row\.item\.image\)"/
|
||||||
|
);
|
||||||
|
// ...and on the left: it stands before the name in the row markup.
|
||||||
|
assert.ok(
|
||||||
|
itemSection.indexOf("entity-entry-image") < itemSection.indexOf("entity-entry-name"),
|
||||||
|
"the item image must stand to the left of the name"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("the item entry lays the icon out beside the name", () => {
|
||||||
|
const title = ruleFor("entity-entry-title");
|
||||||
|
assert.ok(title, "expected a .entity-entry-title style rule");
|
||||||
|
assert.match(title, /display:\s*flex/, "the icon and the name sit side by side");
|
||||||
|
|
||||||
|
const image = ruleFor("entity-entry-image");
|
||||||
|
assert.ok(image, "expected a .entity-entry-image style rule");
|
||||||
|
assert.match(image, /overflow:\s*hidden/, "the icon is clipped to its box");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an item image resolves like the item window: uploads from /public, full URLs as they are", () => {
|
||||||
|
assert.match(source, /import Server, \{ getBaseUrl \} from ['"]~\/services\/Server['"]/);
|
||||||
|
|
||||||
|
const resolver = /function itemImageUrl\(image\)\s*\{[\s\S]*?\n\}/.exec(source)?.[0] ?? "";
|
||||||
|
assert.ok(resolver, "expected an itemImageUrl helper");
|
||||||
|
assert.match(resolver, /https\?:/, "a full http(s) URL loads as it is");
|
||||||
|
assert.match(resolver, /data:/, "a data URI loads as it is");
|
||||||
|
assert.match(resolver, /\$\{getBaseUrl\(\)\}\/public\//, "an uploaded filename resolves as a /public file");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user