forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
6bc8760adf
commit
0ad881316b
359 changed files with 2049 additions and 938 deletions
|
|
@ -32,22 +32,26 @@ export class PruneFilters extends DesugaringStep<LayerConfigJson> {
|
|||
filter: FilterConfigJson,
|
||||
context: ConversionContext
|
||||
): FilterConfigJson {
|
||||
|
||||
if (filter.options.length === 1) {
|
||||
const option = filter.options[0]
|
||||
const tags = TagUtils.Tag(option.osmTags)
|
||||
const optimized = TagUtils.removeKnownParts(tags, sourceTags, true)
|
||||
if (optimized === true) {
|
||||
context.warn("Removing filter as always known: ", new Translation(option.question).textFor("en"))
|
||||
context.warn(
|
||||
"Removing filter as always known: ",
|
||||
new Translation(option.question).textFor("en")
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
if (optimized === false) {
|
||||
context.warn("Removing filter as not possible: ", new Translation(option.question).textFor("en"))
|
||||
context.warn(
|
||||
"Removing filter as not possible: ",
|
||||
new Translation(option.question).textFor("en")
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!filter.strict) {
|
||||
return filter
|
||||
}
|
||||
|
|
@ -85,7 +89,6 @@ export class PruneFilters extends DesugaringStep<LayerConfigJson> {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
return { ...filter, options: newOptions, strict: undefined }
|
||||
}
|
||||
|
||||
|
|
@ -99,9 +102,9 @@ export class PruneFilters extends DesugaringStep<LayerConfigJson> {
|
|||
const sourceTags = TagUtils.Tag(json.source["osmTags"])
|
||||
return {
|
||||
...json,
|
||||
filter: Utils.NoNull(json.filter?.map((obj) =>
|
||||
this.prune(sourceTags, <FilterConfigJson>obj, context)
|
||||
)),
|
||||
filter: Utils.NoNull(
|
||||
json.filter?.map((obj) => this.prune(sourceTags, <FilterConfigJson>obj, context))
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,9 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
|
||||
public convert(
|
||||
spec: string | { "builtin": string | string[] } | (TagRenderingConfigJson),
|
||||
spec: string | { builtin: string | string[] } | TagRenderingConfigJson,
|
||||
ctx: ConversionContext
|
||||
): QuestionableTagRenderingConfigJson[] {
|
||||
|
||||
const trs = this.convertOnce(<any>spec, ctx)?.map((tr) =>
|
||||
this.pruneMappings<TagRenderingConfigJson & { id: string }>(tr, ctx)
|
||||
)
|
||||
|
|
@ -124,7 +123,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
return {
|
||||
...mapping,
|
||||
if: newIf.asJson()
|
||||
if: newIf.asJson(),
|
||||
}
|
||||
})
|
||||
const after = newMappings?.length ?? 0
|
||||
|
|
@ -137,7 +136,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
const tr = {
|
||||
...tagRendering,
|
||||
mappings: newMappings
|
||||
mappings: newMappings,
|
||||
}
|
||||
delete tr["strict"]
|
||||
return tr
|
||||
|
|
@ -249,7 +248,7 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
|
||||
private convertOnce(
|
||||
tr: string | { "builtin": string } | TagRenderingConfigJson,
|
||||
tr: string | { builtin: string } | TagRenderingConfigJson,
|
||||
ctx: ConversionContext
|
||||
): TagRenderingConfigJson[] {
|
||||
const state = this._state
|
||||
|
|
@ -273,25 +272,25 @@ export class ExpandTagRendering extends Conversion<
|
|||
ctx.warn(
|
||||
`A literal rendering was detected: ${tr}
|
||||
Did you perhaps forgot to add a layer name as 'layername.${tr}'? ` +
|
||||
Array.from(state.sharedLayers.keys()).join(", ")
|
||||
Array.from(state.sharedLayers.keys()).join(", ")
|
||||
)
|
||||
}
|
||||
|
||||
if (this._options?.noHardcodedStrings && this._state?.sharedLayers?.size > 0) {
|
||||
ctx.err(
|
||||
"Detected an invocation to a builtin tagRendering, but this tagrendering was not found: " +
|
||||
tr +
|
||||
" \n Did you perhaps forget to add the layer as prefix, such as `icons." +
|
||||
tr +
|
||||
"`? "
|
||||
tr +
|
||||
" \n Did you perhaps forget to add the layer as prefix, such as `icons." +
|
||||
tr +
|
||||
"`? "
|
||||
)
|
||||
}
|
||||
|
||||
return [
|
||||
<TagRenderingConfigJson & { id: string }>{
|
||||
render: tr,
|
||||
id: tr.replace(/[^a-zA-Z0-9]/g, "")
|
||||
}
|
||||
id: tr.replace(/[^a-zA-Z0-9]/g, ""),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -316,9 +315,9 @@ export class ExpandTagRendering extends Conversion<
|
|||
}
|
||||
ctx.err(
|
||||
"An object calling a builtin can only have keys `builtin` or `override`, but a key with name `" +
|
||||
key +
|
||||
"` was found. This won't be picked up! The full object is: " +
|
||||
JSON.stringify(tr)
|
||||
key +
|
||||
"` was found. This won't be picked up! The full object is: " +
|
||||
JSON.stringify(tr)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -345,19 +344,19 @@ export class ExpandTagRendering extends Conversion<
|
|||
if (state.sharedLayers.size === 0) {
|
||||
ctx.warn(
|
||||
"BOOTSTRAPPING. Rerun generate layeroverview. While reusing tagrendering: " +
|
||||
name +
|
||||
": layer " +
|
||||
layerName +
|
||||
" not found for now, but ignoring as this is a bootstrapping run. "
|
||||
name +
|
||||
": layer " +
|
||||
layerName +
|
||||
" not found for now, but ignoring as this is a bootstrapping run. "
|
||||
)
|
||||
} else {
|
||||
ctx.err(
|
||||
": While reusing tagrendering: " +
|
||||
name +
|
||||
": layer " +
|
||||
layerName +
|
||||
" not found. Maybe you meant one of " +
|
||||
candidates.slice(0, 3).join(", ")
|
||||
name +
|
||||
": layer " +
|
||||
layerName +
|
||||
" not found. Maybe you meant one of " +
|
||||
candidates.slice(0, 3).join(", ")
|
||||
)
|
||||
}
|
||||
continue
|
||||
|
|
@ -369,10 +368,10 @@ export class ExpandTagRendering extends Conversion<
|
|||
candidates = Utils.sortedByLevenshteinDistance(name, candidates, (i) => i)
|
||||
ctx.err(
|
||||
"The tagRendering with identifier " +
|
||||
name +
|
||||
" was not found.\n\tDid you mean one of " +
|
||||
candidates.join(", ") +
|
||||
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first"
|
||||
name +
|
||||
" was not found.\n\tDid you mean one of " +
|
||||
candidates.join(", ") +
|
||||
"?\n(Hint: did you add a new label and are you trying to use this label at the same time? Run 'reset:layeroverview' first"
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,18 @@
|
|||
import { Concat, DesugaringContext, DesugaringStep, Each, FirstOf, Fuse, On, SetDefault } from "./Conversion"
|
||||
import {
|
||||
Concat,
|
||||
DesugaringContext,
|
||||
DesugaringStep,
|
||||
Each,
|
||||
FirstOf,
|
||||
Fuse,
|
||||
On,
|
||||
SetDefault,
|
||||
} from "./Conversion"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import { MinimalTagRenderingConfigJson, TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import {
|
||||
MinimalTagRenderingConfigJson,
|
||||
TagRenderingConfigJson,
|
||||
} from "../Json/TagRenderingConfigJson"
|
||||
import { Utils } from "../../../Utils"
|
||||
import RewritableConfigJson from "../Json/RewritableConfigJson"
|
||||
import SpecialVisualizations from "../../../UI/SpecialVisualizations"
|
||||
|
|
@ -24,7 +36,7 @@ import { ExpandTagRendering } from "./ExpandTagRendering"
|
|||
class AddFiltersFromTagRenderings extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super(
|
||||
"Inspects all the tagRenderings. If some tagRenderings have the `filter` attribute set, introduce those filters. This step might introduce shorthand filter names, thus 'ExpandFilter' should be run afterwards. Can be disabled with \"#filter\":\"no-auto\"",
|
||||
'Inspects all the tagRenderings. If some tagRenderings have the `filter` attribute set, introduce those filters. This step might introduce shorthand filter names, thus \'ExpandFilter\' should be run afterwards. Can be disabled with "#filter":"no-auto"',
|
||||
["filter"],
|
||||
"AddFiltersFromTagRenderings"
|
||||
)
|
||||
|
|
@ -127,7 +139,7 @@ class DetectInline extends DesugaringStep<QuestionableTagRenderingConfigJson> {
|
|||
if (json.freeform.inline === true) {
|
||||
context.err(
|
||||
"'inline' is set, but the rendering contains a special visualisation...\n " +
|
||||
spec[key]
|
||||
spec[key]
|
||||
)
|
||||
}
|
||||
json = JSON.parse(JSON.stringify(json))
|
||||
|
|
@ -226,20 +238,20 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
if (blacklisted?.length > 0 && used?.length > 0) {
|
||||
context.err(
|
||||
"The {questions()}-special rendering only supports either a blacklist OR a whitelist, but not both." +
|
||||
"\n Whitelisted: " +
|
||||
used.join(", ") +
|
||||
"\n Blacklisted: " +
|
||||
blacklisted.join(", ")
|
||||
"\n Whitelisted: " +
|
||||
used.join(", ") +
|
||||
"\n Blacklisted: " +
|
||||
blacklisted.join(", ")
|
||||
)
|
||||
}
|
||||
for (const usedLabel of used) {
|
||||
if (!allLabels.has(usedLabel)) {
|
||||
context.err(
|
||||
"This layers specifies a special question element for label `" +
|
||||
usedLabel +
|
||||
"`, but this label doesn't exist.\n" +
|
||||
" Available labels are " +
|
||||
Array.from(allLabels).join(", ")
|
||||
usedLabel +
|
||||
"`, but this label doesn't exist.\n" +
|
||||
" Available labels are " +
|
||||
Array.from(allLabels).join(", ")
|
||||
)
|
||||
}
|
||||
seen.add(usedLabel)
|
||||
|
|
@ -253,8 +265,8 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
const question: QuestionableTagRenderingConfigJson = {
|
||||
id: "leftover-questions",
|
||||
render: {
|
||||
"*": `{questions( ,${Array.from(seen).join(";")})}`
|
||||
}
|
||||
"*": `{questions( ,${Array.from(seen).join(";")})}`,
|
||||
},
|
||||
}
|
||||
json.tagRenderings.push(question)
|
||||
}
|
||||
|
|
@ -336,13 +348,13 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
|||
if (json.allowMove && !usedSpecialFunctions.has("move_button")) {
|
||||
json.tagRenderings.push({
|
||||
id: "move-button",
|
||||
render: { "*": "{move_button()}" }
|
||||
render: { "*": "{move_button()}" },
|
||||
})
|
||||
}
|
||||
if (json.deletion && !usedSpecialFunctions.has("delete_button")) {
|
||||
json.tagRenderings.push({
|
||||
id: "delete-button",
|
||||
render: { "*": "{delete_button()}" }
|
||||
render: { "*": "{delete_button()}" },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -357,9 +369,9 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
|
|||
or: [
|
||||
"__featureSwitchIsDebugging=true",
|
||||
"mapcomplete-show_tags=full",
|
||||
"mapcomplete-show_debug=yes"
|
||||
]
|
||||
}
|
||||
"mapcomplete-show_debug=yes",
|
||||
],
|
||||
},
|
||||
}
|
||||
json.tagRenderings?.push(trc)
|
||||
}
|
||||
|
|
@ -467,10 +479,10 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
private static convertIfNeeded(
|
||||
input:
|
||||
| (object & {
|
||||
special: {
|
||||
type: string
|
||||
}
|
||||
})
|
||||
special: {
|
||||
type: string
|
||||
}
|
||||
})
|
||||
| any,
|
||||
context: ConversionContext
|
||||
): any {
|
||||
|
|
@ -568,7 +580,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
.map((nm) => RewriteSpecial.escapeStr(special[nm] ?? "", context))
|
||||
.join(",")
|
||||
return {
|
||||
"*": `{${type}(${args})${clss}}`
|
||||
"*": `{${type}(${args})${clss}}`,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -666,14 +678,14 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
|
|||
}[] = []
|
||||
|
||||
for (let i = 0; i < badgesJson.length; i++) {
|
||||
const iconBadge: string | ({
|
||||
if: TagConfigJson
|
||||
then: string | MinimalTagRenderingConfigJson
|
||||
}) = badgesJson[i]
|
||||
|
||||
const iconBadge:
|
||||
| string
|
||||
| {
|
||||
if: TagConfigJson
|
||||
then: string | MinimalTagRenderingConfigJson
|
||||
} = badgesJson[i]
|
||||
|
||||
if (typeof iconBadge === "string") {
|
||||
|
||||
const expanded: QuestionableTagRenderingConfigJson[] = this._expand.convert(
|
||||
iconBadge,
|
||||
context.enters("iconBadges", i)
|
||||
|
|
@ -683,16 +695,18 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
|
|||
const condition = tr.condition
|
||||
for (const trElement of tr.mappings) {
|
||||
const showIf = TagUtils.optimzeJson({
|
||||
and: Utils.NoNull([condition,
|
||||
and: Utils.NoNull([
|
||||
condition,
|
||||
{
|
||||
or: Utils.NoNull([
|
||||
trElement.alsoShowIf, trElement.if
|
||||
])
|
||||
}
|
||||
])
|
||||
or: Utils.NoNull([trElement.alsoShowIf, trElement.if]),
|
||||
},
|
||||
]),
|
||||
})
|
||||
if (showIf === true) {
|
||||
context.warn("Dropping iconBadge that would be _always_ shown: " + (trElement.icon ?? trElement.then))
|
||||
context.warn(
|
||||
"Dropping iconBadge that would be _always_ shown: " +
|
||||
(trElement.icon ?? trElement.then)
|
||||
)
|
||||
continue
|
||||
}
|
||||
if (showIf === false) {
|
||||
|
|
@ -700,11 +714,9 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
|
|||
}
|
||||
iconBadges.push({
|
||||
if: showIf,
|
||||
then: trElement.icon ?? trElement.then
|
||||
then: trElement.icon ?? trElement.then,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
|
@ -721,7 +733,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
|
|||
iconBadges.push(
|
||||
...expanded.map((resolved) => ({
|
||||
if: iconBadge.if,
|
||||
then: <MinimalTagRenderingConfigJson>resolved
|
||||
then: <MinimalTagRenderingConfigJson>resolved,
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
|
@ -734,7 +746,7 @@ class PreparePointRendering extends Fuse<PointRenderingConfigJson> {
|
|||
constructor(state: DesugaringContext, layer: LayerConfigJson) {
|
||||
super(
|
||||
"Prepares point renderings by expanding 'icon' and 'iconBadges'." +
|
||||
" A tagRendering from the host tagRenderings will be substituted in",
|
||||
" A tagRendering from the host tagRenderings will be substituted in",
|
||||
new On(
|
||||
"marker",
|
||||
new Each(
|
||||
|
|
@ -861,7 +873,7 @@ export class AddRatingBadge extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
const specialVis: Exclude<RenderingSpecification, string>[] = <
|
||||
Exclude<RenderingSpecification, string>[]
|
||||
>ValidationUtils.getAllSpecialVisualisations(<any>json.tagRenderings).filter(
|
||||
>ValidationUtils.getAllSpecialVisualisations(<any>json.tagRenderings).filter(
|
||||
(rs) => typeof rs !== "string"
|
||||
)
|
||||
const funcs = new Set<string>(specialVis.map((rs) => rs.func.funcName))
|
||||
|
|
@ -897,7 +909,7 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
|
|||
}
|
||||
return <TagRenderingConfigJson>{
|
||||
id: "title_icon_auto_" + tr.id,
|
||||
mappings
|
||||
mappings,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -942,8 +954,8 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
|
|||
.enters("titleIcons", i)
|
||||
.warn(
|
||||
"TagRendering with id " +
|
||||
trId +
|
||||
" does not have any icons, not generating an icon for this"
|
||||
trId +
|
||||
" does not have any icons, not generating an icon for this"
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
|
@ -1006,7 +1018,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
|
|||
(layer) =>
|
||||
new Concat(
|
||||
new ExpandTagRendering(state, layer, {
|
||||
addToContext: options?.addTagRenderingsToContext ?? false
|
||||
addToContext: options?.addTagRenderingsToContext ?? false,
|
||||
})
|
||||
)
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,14 @@
|
|||
import { Concat, Conversion, DesugaringContext, DesugaringStep, Each, Fuse, On, Pass, SetDefault } from "./Conversion"
|
||||
import {
|
||||
Concat,
|
||||
Conversion,
|
||||
DesugaringContext,
|
||||
DesugaringStep,
|
||||
Each,
|
||||
Fuse,
|
||||
On,
|
||||
Pass,
|
||||
SetDefault,
|
||||
} from "./Conversion"
|
||||
import { ThemeConfigJson } from "../Json/ThemeConfigJson"
|
||||
import { PrepareLayer } from "./PrepareLayer"
|
||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue