forked from MapComplete/MapComplete
Chore: typing, formatting
This commit is contained in:
parent
244c976af6
commit
add464f58f
1 changed files with 40 additions and 35 deletions
|
|
@ -59,10 +59,11 @@ export class ExpandTagRendering extends Conversion<
|
||||||
}
|
}
|
||||||
|
|
||||||
public convert(
|
public convert(
|
||||||
spec: string | any,
|
spec: string | { "builtin": string | string[] } | (TagRenderingConfigJson),
|
||||||
ctx: ConversionContext
|
ctx: ConversionContext
|
||||||
): QuestionableTagRenderingConfigJson[] {
|
): QuestionableTagRenderingConfigJson[] {
|
||||||
const trs = this.convertOnce(spec, ctx)?.map((tr) =>
|
|
||||||
|
const trs = this.convertOnce(<any>spec, ctx)?.map((tr) =>
|
||||||
this.pruneMappings<TagRenderingConfigJson & { id: string }>(tr, ctx)
|
this.pruneMappings<TagRenderingConfigJson & { id: string }>(tr, ctx)
|
||||||
)
|
)
|
||||||
if (!Array.isArray(trs)) {
|
if (!Array.isArray(trs)) {
|
||||||
|
|
@ -123,7 +124,7 @@ export class ExpandTagRendering extends Conversion<
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...mapping,
|
...mapping,
|
||||||
if: newIf.asJson(),
|
if: newIf.asJson()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const after = newMappings?.length ?? 0
|
const after = newMappings?.length ?? 0
|
||||||
|
|
@ -136,7 +137,7 @@ export class ExpandTagRendering extends Conversion<
|
||||||
}
|
}
|
||||||
const tr = {
|
const tr = {
|
||||||
...tagRendering,
|
...tagRendering,
|
||||||
mappings: newMappings,
|
mappings: newMappings
|
||||||
}
|
}
|
||||||
delete tr["strict"]
|
delete tr["strict"]
|
||||||
return tr
|
return tr
|
||||||
|
|
@ -155,17 +156,17 @@ export class ExpandTagRendering extends Conversion<
|
||||||
for (const tagRenderingConfigJson of direct) {
|
for (const tagRenderingConfigJson of direct) {
|
||||||
const nm: string | string[] | undefined = tagRenderingConfigJson["builtin"]
|
const nm: string | string[] | undefined = tagRenderingConfigJson["builtin"]
|
||||||
if (nm !== undefined) {
|
if (nm !== undefined) {
|
||||||
let indirect: TagRenderingConfigJson[]
|
let indirect: (TagRenderingConfigJson & { id: string })[]
|
||||||
if (typeof nm === "string") {
|
if (typeof nm === "string") {
|
||||||
indirect = this.lookup(nm, ctx)
|
indirect = this.lookup(nm, ctx)
|
||||||
} else {
|
} else {
|
||||||
indirect = [].concat(...nm.map((n) => this.lookup(n, ctx)))
|
indirect = [].concat(...nm.map((n) => this.lookup(n, ctx)))
|
||||||
}
|
}
|
||||||
for (let foundTr of indirect) {
|
for (let foundTr of indirect) {
|
||||||
foundTr = Utils.Clone<any>(foundTr)
|
foundTr = Utils.Clone(foundTr)
|
||||||
ctx.MergeObjectsForOverride(tagRenderingConfigJson["override"] ?? {}, foundTr)
|
ctx.MergeObjectsForOverride(tagRenderingConfigJson["override"] ?? {}, foundTr)
|
||||||
foundTr["id"] = tagRenderingConfigJson["id"] ?? foundTr["id"]
|
foundTr["id"] = tagRenderingConfigJson["id"] ?? foundTr["id"]
|
||||||
result.push(<any>foundTr)
|
result.push(foundTr)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.push(tagRenderingConfigJson)
|
result.push(tagRenderingConfigJson)
|
||||||
|
|
@ -248,11 +249,15 @@ export class ExpandTagRendering extends Conversion<
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertOnce(
|
private convertOnce(
|
||||||
tr: string | any,
|
tr: string | { "builtin": string } | TagRenderingConfigJson,
|
||||||
ctx: ConversionContext
|
ctx: ConversionContext
|
||||||
): (TagRenderingConfigJson & { id: string })[] {
|
): TagRenderingConfigJson[] {
|
||||||
const state = this._state
|
const state = this._state
|
||||||
|
|
||||||
|
if (tr === undefined) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof tr === "string") {
|
if (typeof tr === "string") {
|
||||||
if (this._state.tagRenderings !== null) {
|
if (this._state.tagRenderings !== null) {
|
||||||
const lookup = this.lookup(tr, ctx)
|
const lookup = this.lookup(tr, ctx)
|
||||||
|
|
@ -283,10 +288,10 @@ export class ExpandTagRendering extends Conversion<
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
<any>{
|
<TagRenderingConfigJson & { id: string }>{
|
||||||
render: tr,
|
render: tr,
|
||||||
id: tr.replace(/[^a-zA-Z0-9]/g, ""),
|
id: tr.replace(/[^a-zA-Z0-9]/g, "")
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,7 +377,7 @@ export class ExpandTagRendering extends Conversion<
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let foundTr of lookup) {
|
for (let foundTr of lookup) {
|
||||||
foundTr = Utils.Clone<any>(foundTr)
|
foundTr = Utils.Clone(foundTr)
|
||||||
ctx.MergeObjectsForOverride(tr["override"] ?? {}, foundTr)
|
ctx.MergeObjectsForOverride(tr["override"] ?? {}, foundTr)
|
||||||
if (names.length == 1) {
|
if (names.length == 1) {
|
||||||
foundTr["id"] = tr["id"] ?? foundTr["id"]
|
foundTr["id"] = tr["id"] ?? foundTr["id"]
|
||||||
|
|
@ -383,6 +388,6 @@ export class ExpandTagRendering extends Conversion<
|
||||||
return trs
|
return trs
|
||||||
}
|
}
|
||||||
|
|
||||||
return [tr]
|
return [<TagRenderingConfigJson & { id: string }>tr]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue