Chore: simplify code

This commit is contained in:
Pieter Vander Vennet 2025-04-15 16:46:45 +02:00
parent b06ed4c6ff
commit 84bfb955d8

View file

@ -24,8 +24,8 @@ export class WebAndCommunicationSpecialVisualisations {
{ {
name: "key", name: "key",
doc: "The attribute-name containing the link", doc: "The attribute-name containing the link",
required: true, required: true
}, }
], ],
constr( constr(
@ -35,7 +35,7 @@ export class WebAndCommunicationSpecialVisualisations {
): BaseUIElement { ): BaseUIElement {
const key = argument[0] const key = argument[0]
return new SvelteUIElement(FediverseLink, { key, tags, state }) return new SvelteUIElement(FediverseLink, { key, tags, state })
}, }
}, },
{ {
funcName: "wikipedia", funcName: "wikipedia",
@ -45,8 +45,8 @@ export class WebAndCommunicationSpecialVisualisations {
{ {
name: "keyToShowWikipediaFor", name: "keyToShowWikipediaFor",
doc: "Use the wikidata entry from this key to show the wikipedia article for. Multiple keys can be given (separated by ';'), in which case the first matching value is used", doc: "Use the wikidata entry from this key to show the wikipedia article for. Multiple keys can be given (separated by ';'), in which case the first matching value is used",
defaultValue: "wikidata;wikipedia", defaultValue: "wikidata;wikipedia"
}, }
], ],
needsUrls: [...Wikidata.neededUrls, ...Wikipedia.neededUrls], needsUrls: [...Wikidata.neededUrls, ...Wikipedia.neededUrls],
@ -59,9 +59,9 @@ export class WebAndCommunicationSpecialVisualisations {
return tags[key]?.split(";")?.map((id) => id.trim()) ?? [] return tags[key]?.split(";")?.map((id) => id.trim()) ?? []
}) })
return new SvelteUIElement(WikipediaPanel, { return new SvelteUIElement(WikipediaPanel, {
wikiIds, wikiIds
}) })
}, }
}, },
{ {
funcName: "wikidata_label", funcName: "wikidata_label",
@ -72,32 +72,32 @@ export class WebAndCommunicationSpecialVisualisations {
{ {
name: "keyToShowWikidataFor", name: "keyToShowWikidataFor",
doc: "Use the wikidata entry from this key to show the label", doc: "Use the wikidata entry from this key to show the label",
defaultValue: "wikidata", defaultValue: "wikidata"
}, }
], ],
needsUrls: Wikidata.neededUrls, needsUrls: Wikidata.neededUrls,
example: example:
"`{wikidata_label()}` is a basic example, `{wikipedia(name:etymology:wikidata)}` to show the label itself", "`{wikidata_label()}` is a basic example, `{wikipedia(name:etymology:wikidata)}` to show the label itself",
constr: (_, tagsSource, args) => constr: (_, tagsSource, args) => {
new VariableUiElement( const id = tagsSource
tagsSource .map((tags) => tags[args[0]])
.map((tags) => tags[args[0]]) .map((wikidata) => {
.map((wikidata) => { const wikidataIds = Utils.NoEmpty(
wikidata = Utils.NoEmpty( wikidata?.split(";")?.map((wd) => wd.trim()) ?? []
wikidata?.split(";")?.map((wd) => wd.trim()) ?? [] )
)[0] return wikidataIds?.[0]
const entry = Wikidata.LoadWikidataEntry(wikidata) })
return new VariableUiElement( const entry = id.bind(id => Wikidata.LoadWikidataEntry(id))
entry.map((e) => {
if (e === undefined || e["success"] === undefined) { return new VariableUiElement(
return wikidata entry.map((e) => {
} if (e === undefined || e["success"] === undefined) {
const response = <WikidataResponse>e["success"] return id.data
return Translation.fromMap(response.labels) }
}) const response = <WikidataResponse>e["success"]
) return Translation.fromMap(response.labels)
}) }))
), }
}, },
new MapillaryLinkVis(), new MapillaryLinkVis(),
{ {
@ -108,29 +108,29 @@ export class WebAndCommunicationSpecialVisualisations {
{ {
name: "to", name: "to",
doc: "Who to send the email to?", doc: "Who to send the email to?",
required: true, required: true
}, },
{ {
name: "subject", name: "subject",
doc: "The subject of the email", doc: "The subject of the email",
required: true, required: true
}, },
{ {
name: "body", name: "body",
doc: "The text in the email", doc: "The text in the email",
required: true, required: true
}, },
{ {
name: "button_text", name: "button_text",
doc: "The text shown on the button in the UI", doc: "The text shown on the button in the UI",
required: true, required: true
}, }
], ],
constr(__, tags, args) { constr(__, tags, args) {
return new SvelteUIElement(SendEmail, { args, tags }) return new SvelteUIElement(SendEmail, { args, tags })
}, }
}, },
{ {
funcName: "link", funcName: "link",
@ -140,29 +140,29 @@ export class WebAndCommunicationSpecialVisualisations {
{ {
name: "text", name: "text",
doc: "Text to be shown", doc: "Text to be shown",
required: true, required: true
}, },
{ {
name: "href", name: "href",
doc: "The URL to link to. Note that this will be URI-encoded before ", doc: "The URL to link to. Note that this will be URI-encoded before ",
required: true, required: true
}, },
{ {
name: "class", name: "class",
doc: "CSS-classes to add to the element", doc: "CSS-classes to add to the element"
}, },
{ {
name: "download", name: "download",
doc: "Expects a string which denotes the filename to download the contents of `href` into. If set, this link will act as a download-button.", doc: "Expects a string which denotes the filename to download the contents of `href` into. If set, this link will act as a download-button."
}, },
{ {
name: "arialabel", name: "arialabel",
doc: "If set, this text will be used as aria-label", doc: "If set, this text will be used as aria-label"
}, },
{ {
name: "icon", name: "icon",
doc: "If set, show this icon next to the link. You might want to combine this with `class: button`", doc: "If set, show this icon next to the link. You might want to combine this with `class: button`"
}, }
], ],
constr( constr(
@ -184,10 +184,10 @@ export class WebAndCommunicationSpecialVisualisations {
download: tagSource.map((tags) => Utils.SubstituteKeys(download, tags)), download: tagSource.map((tags) => Utils.SubstituteKeys(download, tags)),
ariaLabel: tagSource.map((tags) => Utils.SubstituteKeys(ariaLabel, tags)), ariaLabel: tagSource.map((tags) => Utils.SubstituteKeys(ariaLabel, tags)),
newTab: new ImmutableStore(newTab), newTab: new ImmutableStore(newTab),
icon: tagSource.map((tags) => Utils.SubstituteKeys(icon, tags)), icon: tagSource.map((tags) => Utils.SubstituteKeys(icon, tags))
}).setSpan() }).setSpan()
}, }
}, }
] ]
} }
} }