Many UI improvements

This commit is contained in:
Pieter Vander Vennet 2024-06-18 03:33:11 +02:00
parent ef158ec914
commit 1098d71aa6
30 changed files with 5601 additions and 569 deletions

View file

@ -7,12 +7,12 @@ import {
FirstOf,
Fuse,
On,
SetDefault,
SetDefault
} from "./Conversion"
import { LayerConfigJson } from "../Json/LayerConfigJson"
import {
MinimalTagRenderingConfigJson,
TagRenderingConfigJson,
TagRenderingConfigJson
} from "../Json/TagRenderingConfigJson"
import { Utils } from "../../../Utils"
import RewritableConfigJson from "../Json/RewritableConfigJson"
@ -85,17 +85,17 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
}
const options = matchingTr.mappings.map((mapping) => ({
question: mapping.then,
osmTags: mapping.if,
osmTags: mapping.if
}))
options.unshift({
question: {
en: "All types",
en: "All types"
},
osmTags: undefined,
osmTags: undefined
})
newFilters.push({
id: filter,
options,
options
})
continue
}
@ -134,9 +134,9 @@ class ExpandFilter extends DesugaringStep<LayerConfigJson> {
.enter(filter)
.err(
"While searching for predefined filter " +
filter +
": this filter is not found. Perhaps you meant one of: " +
suggestions
filter +
": this filter is not found. Perhaps you meant one of: " +
suggestions
)
}
newFilters.push(found)
@ -149,9 +149,9 @@ class ExpandTagRendering extends Conversion<
| string
| TagRenderingConfigJson
| {
builtin: string | string[]
override: any
},
builtin: string | string[]
override: any
},
TagRenderingConfigJson[]
> {
private readonly _state: DesugaringContext
@ -340,25 +340,25 @@ 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 [
<any>{
render: tr,
id: tr.replace(/[^a-zA-Z0-9]/g, ""),
},
id: tr.replace(/[^a-zA-Z0-9]/g, "")
}
]
}
return lookup
@ -385,9 +385,9 @@ 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)
)
}
@ -411,19 +411,19 @@ 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
@ -435,10 +435,10 @@ 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
}
@ -492,7 +492,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))
@ -578,20 +578,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)
@ -605,8 +605,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)
}
@ -625,9 +625,13 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
"favourite_state",
"all_tags",
"qr_code",
"nearby_images",
"linked_open_data"
]
private readonly _desugaring: DesugaringContext
private readonly _desugaring: DesugaringContext
private readonly _addedByDefaultAtTop : QuestionableTagRenderingConfigJson[]
private readonly _addedByDefault: QuestionableTagRenderingConfigJson[]
constructor(desugaring: DesugaringContext) {
super(
"Add some editing elements, such as the delete button or the move button if they are configured. These used to be handled by the feature info box, but this has been replaced by special visualisation elements",
@ -635,6 +639,21 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
"AddEditingElements"
)
this._desugaring = desugaring
const builtinQuestions = Array.from(this._desugaring.tagRenderings?.values() ?? [])
function getAddedByDefaultIds(key: string): QuestionableTagRenderingConfigJson[] {
const addByDefault = builtinQuestions.filter(tr => tr.labels?.indexOf(key) >= 0)
const ids = new Set(addByDefault.map(tr => tr.id))
const idsInOrder = desugaring.tagRenderingOrder.filter(id => ids.has(id))
return Utils.NoNull(idsInOrder.map(id => desugaring.tagRenderings.get(id)))
}
this._addedByDefaultAtTop = getAddedByDefaultIds("added_by_default_top")
this._addedByDefault = getAddedByDefaultIds("added_by_default")
}
convert(json: LayerConfigJson, _: ConversionContext): LayerConfigJson {
@ -662,78 +681,40 @@ export class AddEditingElements extends DesugaringStep<LayerConfigJson> {
/***** ADD TO TOP ****/
if (
this._desugaring.tagRenderings.has("just_created") &&
!json.tagRenderings.some((tr) => tr === "just_created" || tr["id"] === "just_created")
) {
json.tagRenderings.unshift(this._desugaring.tagRenderings.get("just_created"))
}
if (!allIds.has("nothing_known")) {
const indexFirstQuestion = json.tagRenderings.findIndex(tr => tr["question"] !== undefined)
json.tagRenderings.splice(indexFirstQuestion,
0,
this._desugaring.tagRenderings.get("nothing_known"))
console.log("aDDING",this._desugaring.tagRenderings.get("nothing_known"))
}
json.tagRenderings.unshift(...this._addedByDefaultAtTop.filter(tr => !allIds.has(tr.id)))
/***** ADD TO BOTTOM ****/
if (!allIds.has("lod")) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("lod"))
}
if (!usedSpecialFunctions.has("minimap")) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("minimap"))
}
if(usedSpecialFunctions.has("image_upload") &&
!usedSpecialFunctions.has("nearby_images")){
json.tagRenderings.push(this._desugaring.tagRenderings.get("nearby_images"))
}
if (json.allowSplit && !usedSpecialFunctions.has("split_button")) {
json.tagRenderings.push({
id: "split-button",
render: { "*": "{split_button()}" },
})
json.tagRenderings.push(this._desugaring.tagRenderings.get("split_button"))
delete json.allowSplit
}
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()}" }
})
}
if (!usedSpecialFunctions.has("favourite_status")) {
json.tagRenderings.push({
id: "favourite_status",
render: { "*": "{favourite_status()}" },
})
}
if (!allIds.has("share")) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("share"))
}
if (!allIds.has("qr_code")) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("qr_code"))
}
if (
json.source !== "special" &&
json.source !== "special:library" &&
json.tagRenderings &&
this._desugaring.tagRenderings.has("last_edit") &&
!json.tagRenderings.some((tr) => tr["id"] === "last_edit")
) {
json.tagRenderings.push(this._desugaring.tagRenderings.get("last_edit"))
}
json.tagRenderings.push(...this._addedByDefault.filter(tr => !allIds.has(tr.id)))
if (!usedSpecialFunctions.has("all_tags")) {
const trc: QuestionableTagRenderingConfigJson = {
@ -744,9 +725,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)
}
@ -850,10 +831,10 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
private static convertIfNeeded(
input:
| (object & {
special: {
type: string
}
})
special: {
type: string
}
})
| any,
context: ConversionContext
): any {
@ -937,7 +918,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
const before = Translations.T(input.before)
const after = Translations.T(input.after)
const clss: string = input.class !== undefined ? ":"+input.class : ""
const clss: string = input.class !== undefined ? ":" + input.class : ""
for (const ln of Object.keys(before?.translations ?? {})) {
@ -952,7 +933,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
.map((nm) => RewriteSpecial.escapeStr(special[nm] ?? ""))
.join(",")
return {
"*": `{${type}(${args})${clss}}`,
"*": `{${type}(${args})${clss}}`
}
}
@ -1064,7 +1045,7 @@ class ExpandIconBadges extends DesugaringStep<PointRenderingConfigJson> {
iconBadges.push(
...expanded.map((resolved) => ({
if: iconBadge.if,
then: <MinimalTagRenderingConfigJson>resolved,
then: <MinimalTagRenderingConfigJson>resolved
}))
)
}
@ -1201,7 +1182,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))
@ -1237,7 +1218,7 @@ export class AutoTitleIcon extends DesugaringStep<LayerConfigJson> {
}
return <TagRenderingConfigJson>{
id: "title_icon_auto_" + tr.id,
mappings,
mappings
}
}
@ -1282,8 +1263,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
}
@ -1307,7 +1288,7 @@ export class PrepareLayer extends Fuse<LayerConfigJson> {
(layer) =>
new Concat(
new ExpandTagRendering(state, layer, {
addToContext: options?.addTagRenderingsToContext ?? false,
addToContext: options?.addTagRenderingsToContext ?? false
})
)
),