forked from MapComplete/MapComplete
Fix: correctly flatten special cases
This commit is contained in:
parent
e731c677b9
commit
593d7bd07a
2 changed files with 27 additions and 10 deletions
|
@ -35,6 +35,8 @@ export default class Constants {
|
||||||
"current_view",
|
"current_view",
|
||||||
"import_candidate",
|
"import_candidate",
|
||||||
"usersettings",
|
"usersettings",
|
||||||
|
"icons",
|
||||||
|
"filters"
|
||||||
] as const
|
] as const
|
||||||
/**
|
/**
|
||||||
* Layer IDs of layers which have special properties through built-in hooks
|
* Layer IDs of layers which have special properties through built-in hooks
|
||||||
|
|
|
@ -32,7 +32,6 @@ import { ConfigMeta } from "../../../UI/Studio/configMeta"
|
||||||
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
|
import LineRenderingConfigJson from "../Json/LineRenderingConfigJson"
|
||||||
import { ConversionContext } from "./ConversionContext"
|
import { ConversionContext } from "./ConversionContext"
|
||||||
import { ExpandRewrite } from "./ExpandRewrite"
|
import { ExpandRewrite } from "./ExpandRewrite"
|
||||||
import { ALL } from "node:dns"
|
|
||||||
|
|
||||||
class ExpandFilter extends DesugaringStep<LayerConfigJson> {
|
class ExpandFilter extends DesugaringStep<LayerConfigJson> {
|
||||||
private static readonly predefinedFilters = ExpandFilter.load_filters()
|
private static readonly predefinedFilters = ExpandFilter.load_filters()
|
||||||
|
@ -700,6 +699,15 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static escapeStr(v: string): string{
|
||||||
|
return v
|
||||||
|
.replace(/,/g, "&COMMA")
|
||||||
|
.replace(/\{/g, "&LBRACE")
|
||||||
|
.replace(/}/g, "&RBRACE")
|
||||||
|
.replace(/\(/g, "&LPARENS")
|
||||||
|
.replace(/\)/g, "&RPARENS")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the heavy lifting and conversion
|
* Does the heavy lifting and conversion
|
||||||
*
|
*
|
||||||
|
@ -756,6 +764,19 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
* const context = ConversionContext.test()
|
* const context = ConversionContext.test()
|
||||||
* RewriteSpecial.convertIfNeeded(special, context) // => {"en": "<h3>Entrances</h3>This building has {_entrances_count} entrances:{multi(_entrance_properties_with_width,An <a href='#&LBRACEid&RBRACE'>entrance</a> of &LBRACEcanonical&LPARENSwidth&RPARENS&RBRACE)}{_entrances_count_without_width_count} entrances don't have width information yet"}
|
* RewriteSpecial.convertIfNeeded(special, context) // => {"en": "<h3>Entrances</h3>This building has {_entrances_count} entrances:{multi(_entrance_properties_with_width,An <a href='#&LBRACEid&RBRACE'>entrance</a> of &LBRACEcanonical&LPARENSwidth&RPARENS&RBRACE)}{_entrances_count_without_width_count} entrances don't have width information yet"}
|
||||||
* context.getAll("error") // => []
|
* context.getAll("error") // => []
|
||||||
|
*
|
||||||
|
* // another actual test
|
||||||
|
* const special = {
|
||||||
|
* "special":{
|
||||||
|
* "type": "multi",
|
||||||
|
* "key": "_nearby_bicycle_parkings:props",
|
||||||
|
* "tagrendering": {
|
||||||
|
* "*": "<b>{id}</b> ({distance}m) {tagApply(a,b,c)}"
|
||||||
|
* }
|
||||||
|
* }}
|
||||||
|
* const context = ConversionContext.test()
|
||||||
|
* RewriteSpecial.convertIfNeeded(special, context) // => {"*": "{multi(_nearby_bicycle_parkings:props,<b>&LBRACEid&RBRACE</b> &LPARENS&LBRACEdistance&RBRACEm&RPARENS &LBRACEtagApply&LPARENSa&COMMAb&COMMAc&RPARENS&RBRACE)}"}
|
||||||
|
* context.getAll("error") // => []
|
||||||
*/
|
*/
|
||||||
private static convertIfNeeded(
|
private static convertIfNeeded(
|
||||||
input:
|
input:
|
||||||
|
@ -838,7 +859,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
const translatedArgs = argNamesList
|
const translatedArgs = argNamesList
|
||||||
.map((nm) => special[nm])
|
.map((nm) => special[nm])
|
||||||
.filter((v) => v !== undefined)
|
.filter((v) => v !== undefined)
|
||||||
.filter((v) => Translations.isProbablyATranslation(v))
|
.filter((v) => Translations.isProbablyATranslation(v) || v["*"] !== undefined)
|
||||||
for (const translatedArg of translatedArgs) {
|
for (const translatedArg of translatedArgs) {
|
||||||
for (const ln of Object.keys(translatedArg)) {
|
for (const ln of Object.keys(translatedArg)) {
|
||||||
foundLanguages.add(ln)
|
foundLanguages.add(ln)
|
||||||
|
@ -856,7 +877,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (foundLanguages.size === 0) {
|
if (foundLanguages.size === 0) {
|
||||||
const args = argNamesList.map((nm) => special[nm] ?? "").join(",")
|
const args = argNamesList.map((nm) => RewriteSpecial.escapeStr(special[nm] ?? "")).join(",")
|
||||||
return {
|
return {
|
||||||
"*": `{${type}(${args})}`,
|
"*": `{${type}(${args})}`,
|
||||||
}
|
}
|
||||||
|
@ -874,13 +895,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof v === "string") {
|
if (typeof v === "string") {
|
||||||
const txt = v
|
args.push(RewriteSpecial.escapeStr(v))
|
||||||
.replace(/,/g, "&COMMA")
|
|
||||||
.replace(/\{/g, "&LBRACE")
|
|
||||||
.replace(/}/g, "&RBRACE")
|
|
||||||
.replace(/\(/g, "&LPARENS")
|
|
||||||
.replace(/\)/g, "&RPARENS")
|
|
||||||
args.push(txt)
|
|
||||||
} else if (typeof v === "object") {
|
} else if (typeof v === "object") {
|
||||||
args.push(JSON.stringify(v))
|
args.push(JSON.stringify(v))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue