Image support!
This commit is contained in:
@@ -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