forked from MapComplete/MapComplete
Docs: improve comments, error checking and defaults
This commit is contained in:
parent
65da7155fa
commit
ac9792ac43
6 changed files with 47 additions and 3 deletions
|
@ -535,7 +535,7 @@ export class PrepareTheme extends Fuse<LayoutConfigJson> {
|
||||||
new SetDefault("socialImage", "assets/SocialImage.png", true),
|
new SetDefault("socialImage", "assets/SocialImage.png", true),
|
||||||
// We expand all tagrenderings first...
|
// We expand all tagrenderings first...
|
||||||
new On("layers", new Each(new PrepareLayer(state))),
|
new On("layers", new Each(new PrepareLayer(state))),
|
||||||
// Then we apply the override all
|
// Then we apply the override all. We must first expand everything in case that we override something in an expanded tag
|
||||||
new ApplyOverrideAll(),
|
new ApplyOverrideAll(),
|
||||||
// And then we prepare all the layers _again_ in case that an override all contained unexpanded tagrenderings!
|
// And then we prepare all the layers _again_ in case that an override all contained unexpanded tagrenderings!
|
||||||
new On("layers", new Each(new PrepareLayer(state))),
|
new On("layers", new Each(new PrepareLayer(state))),
|
||||||
|
|
|
@ -882,6 +882,10 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(json.icon?.["size"]){
|
||||||
|
context.enters("icon","size").err("size is not a valid attribute. Did you mean 'class'? Class can be one of `small`, `medium` or `large`")
|
||||||
|
}
|
||||||
|
|
||||||
if (json.freeform) {
|
if (json.freeform) {
|
||||||
if (json.render === undefined) {
|
if (json.render === undefined) {
|
||||||
context
|
context
|
||||||
|
|
|
@ -153,7 +153,7 @@ export default class TagRenderingConfig {
|
||||||
this.renderIconClass = "small"
|
this.renderIconClass = "small"
|
||||||
} else if (typeof json.icon === "object") {
|
} else if (typeof json.icon === "object") {
|
||||||
this.renderIcon = json.icon.path
|
this.renderIcon = json.icon.path
|
||||||
this.renderIconClass = json.icon.class
|
this.renderIconClass = json.icon.class ?? "small"
|
||||||
}
|
}
|
||||||
this.metacondition = TagUtils.Tag(
|
this.metacondition = TagUtils.Tag(
|
||||||
json.metacondition ?? { and: [] },
|
json.metacondition ?? { and: [] },
|
||||||
|
|
|
@ -27,6 +27,7 @@ import IconValidator from "./Validators/IconValidator"
|
||||||
import TagValidator from "./Validators/TagValidator"
|
import TagValidator from "./Validators/TagValidator"
|
||||||
import IdValidator from "./Validators/IdValidator"
|
import IdValidator from "./Validators/IdValidator"
|
||||||
import SlopeValidator from "./Validators/SlopeValidator"
|
import SlopeValidator from "./Validators/SlopeValidator"
|
||||||
|
import VeloparkValidator from "./Validators/VeloparkValidator"
|
||||||
|
|
||||||
export type ValidatorType = (typeof Validators.availableTypes)[number]
|
export type ValidatorType = (typeof Validators.availableTypes)[number]
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ export default class Validators {
|
||||||
"fediverse",
|
"fediverse",
|
||||||
"id",
|
"id",
|
||||||
"slope",
|
"slope",
|
||||||
|
"velopark"
|
||||||
] as const
|
] as const
|
||||||
|
|
||||||
public static readonly AllValidators: ReadonlyArray<Validator> = [
|
public static readonly AllValidators: ReadonlyArray<Validator> = [
|
||||||
|
@ -86,6 +88,7 @@ export default class Validators {
|
||||||
new FediverseValidator(),
|
new FediverseValidator(),
|
||||||
new IdValidator(),
|
new IdValidator(),
|
||||||
new SlopeValidator(),
|
new SlopeValidator(),
|
||||||
|
new VeloparkValidator()
|
||||||
]
|
]
|
||||||
|
|
||||||
private static _byType = Validators._byTypeConstructor()
|
private static _byType = Validators._byTypeConstructor()
|
||||||
|
|
37
src/UI/InputElement/Validators/VeloparkValidator.ts
Normal file
37
src/UI/InputElement/Validators/VeloparkValidator.ts
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import { Translation } from "../../i18n/Translation"
|
||||||
|
import UrlValidator from "./UrlValidator"
|
||||||
|
|
||||||
|
export default class VeloparkValidator extends UrlValidator {
|
||||||
|
constructor() {
|
||||||
|
super("velopark", "A custom element to allow copy-pasting velopark-pages")
|
||||||
|
}
|
||||||
|
|
||||||
|
getFeedback(s: string): Translation {
|
||||||
|
const superF = super.getFeedback(s)
|
||||||
|
if (superF) {
|
||||||
|
return superF
|
||||||
|
}
|
||||||
|
const url = new URL(s)
|
||||||
|
if (url.hostname !== "velopark.be" && url.hostname !== "www.velopark.be" && url.hostname !== "data.velopark.be") {
|
||||||
|
return new Translation({ "*": "Invalid hostname, expected velopark.be" })
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!s.startsWith("https://data.velopark.be/data/") && !s.startsWith("https://www.velopark.be/static/data/")){
|
||||||
|
return new Translation({"*":"A valid URL should either start with https://data.velopark.be/data/ or https://www.velopark.be/static/data/"})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public isValid(str: string) {
|
||||||
|
return super.isValid(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
reformat(str: string): string {
|
||||||
|
const url = new URL(super.reformat(str))
|
||||||
|
if(url.pathname.startsWith("/static/data/")){
|
||||||
|
const id = str.substring(str.lastIndexOf("/")+1)
|
||||||
|
return "https://data.velopark.be/data/"+id
|
||||||
|
}
|
||||||
|
return super.reformat(str)
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,7 +29,7 @@
|
||||||
|
|
||||||
{#if mapping.icon !== undefined}
|
{#if mapping.icon !== undefined}
|
||||||
<div class="inline-flex items-center">
|
<div class="inline-flex items-center">
|
||||||
<Icon icon={mapping.icon} clss={twJoin(`mapping-icon-${mapping.iconClass}`, "mr-2")} />
|
<Icon icon={mapping.icon} clss={twJoin(`mapping-icon-${mapping.iconClass ?? "small"}`, "mr-2")} />
|
||||||
<SpecialTranslation t={mapping.then} {tags} {state} {layer} feature={selectedElement} />
|
<SpecialTranslation t={mapping.then} {tags} {state} {layer} feature={selectedElement} />
|
||||||
</div>
|
</div>
|
||||||
{:else if mapping.then !== undefined}
|
{:else if mapping.then !== undefined}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue