Image support!
This commit is contained in:
@@ -23,6 +23,8 @@ 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');
|
||||
const isMedia = computed(() => target.value?.type === 'media');
|
||||
const isImage = computed(() => String(entry.value?.mimeType ?? '').startsWith('image/'));
|
||||
|
||||
onMounted(async () => {
|
||||
const targets = await LoadLinkTargets(campaignId.value);
|
||||
@@ -71,6 +73,7 @@ function resolveImage(image) {
|
||||
}
|
||||
|
||||
const imageUrl = computed(() => resolveImage(entry.value?.image));
|
||||
const mediaUrl = computed(() => entry.value?.file ? `${getBaseUrl()}/public/${entry.value.file}` : '');
|
||||
const initial = computed(() => String(entry.value?.name ?? '?').slice(0, 1).toUpperCase());
|
||||
|
||||
// --- The item's sheet, in the small ---
|
||||
@@ -137,6 +140,11 @@ async function openSheet() {
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<span v-else-if="entry && isMedia" class="embedded-media">
|
||||
<img v-if="isImage" class="embed-image" :src="mediaUrl" :alt="entry.name">
|
||||
<a v-else class="embed-file" :href="mediaUrl" target="_blank" rel="noopener">{{ entry.name }}</a>
|
||||
</span>
|
||||
|
||||
<span v-else class="embedded-entry embedded-missing" :title="translate('campaigns.link-preview.not-found')">{{ href }}</span>
|
||||
</template>
|
||||
|
||||
@@ -226,6 +234,19 @@ async function openSheet() {
|
||||
|
||||
.embed-open:hover { background: var(--color-button-hover); }
|
||||
|
||||
/* An embedded upload: an image fills the note's width, any other file is offered as a link. */
|
||||
.embedded-media { display: inline-block; max-width: 100%; margin: 8px 0; vertical-align: top; }
|
||||
|
||||
.embed-image {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.embed-file { color: var(--color-link); word-break: break-word; }
|
||||
|
||||
.embed-vitals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
|
||||
|
||||
.embed-stat {
|
||||
|
||||
@@ -126,7 +126,7 @@ function linkEntry(target) {
|
||||
kind: 'link',
|
||||
value: target,
|
||||
label: `[[${target.label}]]`,
|
||||
hint: t(`campaigns.sections.${target.type}s`)
|
||||
hint: t(target.type === 'media' ? 'campaigns.sections.media' : `campaigns.sections.${target.type}s`)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -451,6 +451,12 @@ async function openLinkTarget(target) {
|
||||
if (target.type === 'map') {
|
||||
const map = await LoadLinkEntry(campaignId.value, 'map', target.id);
|
||||
if (map) AnchorMap(map);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.type === 'media') {
|
||||
const media = await LoadLinkEntry(campaignId.value, 'media', target.id);
|
||||
if (media) CreateWindow('media_viewer', { media });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,12 @@ the way a file explorer does. Clicking a row opens the file in a window of its o
|
||||
moves into a folder like a note — drag it there, or use **Move to Folder…** in its right-click menu.
|
||||
Right-clicking a media row also deletes it, file included.
|
||||
|
||||
A note can point at an uploaded file by its name, the same way it links to the rest of the campaign.
|
||||
Write `![[harbour.png]]` and an image is drawn in the note at that spot — the picture fills the note's
|
||||
width. A sound, a video or a PDF written this way is shown as a link to the file. Without the **!** the
|
||||
file's name is a normal link that opens the media window when clicked: `[[harbour.png]]`. Typing `[[`
|
||||
while editing offers the uploaded files in the same menu as notes, characters, items and maps.
|
||||
|
||||
## Markdown
|
||||
|
||||
Headings, **bold**, *italic*, lists, quotes, tables, code and links all work:
|
||||
@@ -78,9 +84,10 @@ species, armour class, hit points, speed and ability scores, with the traits, pr
|
||||
spells below. An item arrives with its icon, category, rarity, weight, properties and description.
|
||||
|
||||
The embedded card is part of the note in display mode, and its **Open** button opens the full sheet,
|
||||
the same window the sidebar opens. Only characters and items can be embedded; a note or a map written
|
||||
with the **!** stays as plain text. Name resolution works exactly like a normal link, so an embed of
|
||||
an entry that has been renamed is shown dimmed.
|
||||
the same window the sidebar opens. An uploaded image can be embedded the same way (`![[harbour.png]]`,
|
||||
see [Images and media](#images-and-media)). A note or a map written with the **!** stays as plain text.
|
||||
Name resolution works exactly like a normal link, so an embed of an entry that has been renamed is
|
||||
shown dimmed.
|
||||
|
||||
## Rolling dice in a note
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// The rules behind the note editor's wiki-link autocomplete (type `[[` while editing a note and the
|
||||
// campaign's notes, actors, items and maps are offered to link to). These helpers hold no state,
|
||||
// campaign's notes, actors, items, maps and uploaded files are offered to link to). These helpers
|
||||
// hold no state,
|
||||
// touch no DOM and import nothing, so tests can load them straight from source. Marker.js renders
|
||||
// `[[target]]` as a link, so the target written here is the entry's label.
|
||||
|
||||
@@ -30,10 +31,10 @@ function FindLinkTrigger(text, caret) {
|
||||
return { start, query };
|
||||
}
|
||||
|
||||
// One `{ id, label, type }` per linkable entry, from the campaign's four lists. Entries without a
|
||||
// name are left out (they would show as an empty menu row), the rest are sorted by label so the menu
|
||||
// One `{ id, label, type }` per linkable entry, from the campaign's lists. Entries without a name
|
||||
// are left out (they would show as an empty menu row), the rest are sorted by label so the menu
|
||||
// reads alphabetically whatever order the API answered with.
|
||||
function BuildLinkSuggestions({ notes, actors, items, maps } = {}) {
|
||||
function BuildLinkSuggestions({ notes, actors, items, maps, media } = {}) {
|
||||
const suggestions = [];
|
||||
const seen = new Set();
|
||||
|
||||
@@ -52,6 +53,7 @@ function BuildLinkSuggestions({ notes, actors, items, maps } = {}) {
|
||||
push('actor', actors, (actor) => actor.name);
|
||||
push('item', items, (item) => item.name);
|
||||
push('map', maps, (map) => map.name);
|
||||
push('media', media, (file) => file.name);
|
||||
|
||||
return suggestions.sort((a, b) => a.label.localeCompare(b.label));
|
||||
}
|
||||
|
||||
@@ -9,14 +9,15 @@ import { BuildLinkSuggestions } from './LinkAutocomplete';
|
||||
const CACHE_TTL = 30 * 1000;
|
||||
const cache = new Map(); // campaignId → { at, promise }
|
||||
|
||||
// The campaign's four lists as the API answers them. The note preview needs the entry itself (a
|
||||
// The campaign's lists as the API answers them. The note preview needs the entry itself (a
|
||||
// character sheet, an item), not only the label the suggestion carries, so the lists are kept as
|
||||
// they arrive and both readers resolve from the same round of requests.
|
||||
const LIST_PATHS = {
|
||||
note: { path: '/note/all', key: 'notes' },
|
||||
actor: { path: '/actor/list', key: 'actors' },
|
||||
item: { path: '/item/list', key: 'items' },
|
||||
map: { path: '/map/list', key: 'maps' }
|
||||
map: { path: '/map/list', key: 'maps' },
|
||||
media: { path: '/media/list', key: 'media' }
|
||||
};
|
||||
|
||||
async function fetchList(campaignId, path, key) {
|
||||
@@ -32,7 +33,7 @@ async function fetchList(campaignId, path, key) {
|
||||
function LoadCampaignEntries(campaignId) {
|
||||
const id = campaignId ? String(campaignId) : '';
|
||||
if (!id) {
|
||||
return Promise.resolve({ notes: [], actors: [], items: [], maps: [] });
|
||||
return Promise.resolve({ notes: [], actors: [], items: [], maps: [], media: [] });
|
||||
}
|
||||
|
||||
const cached = cache.get(id);
|
||||
@@ -40,7 +41,7 @@ function LoadCampaignEntries(campaignId) {
|
||||
|
||||
const promise = Promise.all(
|
||||
Object.values(LIST_PATHS).map(({ path, key }) => fetchList(id, path, key))
|
||||
).then(([notes, actors, items, maps]) => ({ notes, actors, items, maps }));
|
||||
).then(([notes, actors, items, maps, media]) => ({ notes, actors, items, maps, media }));
|
||||
|
||||
cache.set(id, { at: Date.now(), promise });
|
||||
return promise;
|
||||
|
||||
Reference in New Issue
Block a user