Merge develop

This commit is contained in:
Pieter Vander Vennet 2023-12-03 04:44:59 +01:00
commit d959b6b40b
290 changed files with 37178 additions and 2200 deletions

View file

@ -168,8 +168,18 @@ export class UpdateLegacyLayer extends DesugaringStep<
const pr = rendering
if (pr["icon"]) {
try {
const icon = Utils.NoEmpty(pr["icon"].split(";"))
let iconConfig = pr["icon"]
if (
Object.keys(iconConfig).length === 1 &&
iconConfig["render"] !== undefined
) {
iconConfig = iconConfig.render
}
const icon = Utils.NoEmpty(iconConfig.split(";"))
pr.marker = icon.map((i) => {
if (i.startsWith("http")) {
return { icon: i }
}
const [iconPath, color] = i.split(":")
return { icon: iconPath, color }
})
@ -243,10 +253,6 @@ class UpdateLegacyTheme extends DesugaringStep<LayoutConfigJson> {
delete oldThemeConfig.socialImage
}
if (oldThemeConfig.defaultBackgroundId === "osm") {
console.log("Removing old background in", json.id)
}
if (typeof oldThemeConfig.credits === "string") {
oldThemeConfig.credits = [oldThemeConfig.credits]
}

View file

@ -1266,6 +1266,59 @@ export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
return json
}
}
export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
constructor() {
super(
"The auto-icon creates a (non-clickable) title icon based on a tagRendering which has icons",
["titleIcons"],
"AutoTitleIcon"
)
}
convert(json: LayerConfigJson, context: ConversionContext): LayerConfigJson {
json = { ...json }
json.titleIcons = [...json.titleIcons]
for (let i = 0; i < json.titleIcons.length; i++) {
const titleIcon = json.titleIcons[i]
if (typeof titleIcon !== "string") {
continue
}
if (!titleIcon.startsWith("auto:")) {
continue
}
const trId = titleIcon.substring("auto:".length)
const tr = <QuestionableTagRenderingConfigJson>(
json.tagRenderings.find((tr) => tr["id"] === trId)
)
if (tr === undefined) {
context.enters("titleIcons", i).err("TagRendering with id " + trId + " not found")
continue
}
const mappings: { if: TagConfigJson; then: string }[] = tr.mappings
?.filter((m) => m.icon !== undefined)
.map((m) => {
const path: string = typeof m.icon === "string" ? m.icon : m.icon.path
const img = `<img class="m-1 h-6 w-6 low-interaction rounded" src='${path}'/>`
return { if: m.if, then: img }
})
if (mappings.length === 0) {
context
.enters("titleIcons", i)
.warn(
"TagRendering with id " +
trId +
" does not have any icons, not generating an icon for this"
)
continue
}
json.titleIcons[i] = <TagRenderingConfigJson>{
id: "title_icon_auto_" + trId,
mappings,
}
}
return json
}
}
export class PrepareLayer extends Fuse<LayerConfigJson> {
constructor(state: DesugaringContext) {
@ -1294,6 +1347,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
new SetDefault("titleIcons", ["icons.defaults"]),
new AddRatingBadge(),
new AddFavouriteBadges(),
new AutoTitleIcon(),
new On(
"titleIcons",
(layer) =>

View file

@ -814,6 +814,12 @@ class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
)
}
if (Object.keys(json).length === 1 && typeof json["render"] === "string") {
context.warn(
`use the content directly instead of {render: ${JSON.stringify(json["render"])}}`
)
}
{
for (const key of ["question", "questionHint", "render"]) {
CheckTranslation.allowUndefined.convert(json[key], context.enter(key))

View file

@ -240,6 +240,8 @@ export interface LayerConfigJson {
* Use an empty array to hide them.
* Note that "defaults" will insert all the default titleIcons (which are added automatically)
*
* Use `auto:<tagrenderingId>` to automatically create an icon based on a tagRendering which has icons
*
* Type: icon[]
* group: infobox
*/

View file

@ -3,18 +3,15 @@ import TagRenderingConfig from "./TagRenderingConfig"
import { TagsFilter } from "../../Logic/Tags/TagsFilter"
import { TagUtils } from "../../Logic/Tags/TagUtils"
import { Utils } from "../../Utils"
import Svg from "../../Svg"
import WithContextLoader from "./WithContextLoader"
import { ImmutableStore, Store } from "../../Logic/UIEventSource"
import BaseUIElement from "../../UI/BaseUIElement"
import { FixedUiElement } from "../../UI/Base/FixedUiElement"
import Img from "../../UI/Base/Img"
import Combine from "../../UI/Base/Combine"
import { VariableUiElement } from "../../UI/Base/VariableUIElement"
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
import SvelteUIElement from "../../UI/Base/SvelteUIElement"
import DynamicMarker from "../../UI/Map/DynamicMarker.svelte"
import { html } from "svelte/types/compiler/utils/namespaces"
export class IconConfig extends WithContextLoader {
public static readonly defaultIcon = new IconConfig({ icon: "pin", color: "#ff9939" })

View file

@ -27,11 +27,6 @@ export default class WithContextLoader {
`${translationContext ?? this._context}.${key}.default value`
)
}
if (Object.keys(v).length === 1 && typeof v["render"] === "string") {
throw `At ${
translationContext ?? "<unknown>"
}: use the content directly instead of {${key}: ${JSON.stringify(v)}}`
}
return new TagRenderingConfig(
<QuestionableTagRenderingConfigJson>v,