chore: automated housekeeping...

This commit is contained in:
Pieter Vander Vennet 2024-08-14 13:53:56 +02:00
parent f77570589d
commit 9b8a9337fd
111 changed files with 2911 additions and 1280 deletions

View file

@ -1,5 +1,4 @@
<script lang="ts">
import Translations from "../i18n/Translations"
import type { ConfigMeta } from "./configMeta"
import Icon from "../Map/Icon.svelte"
@ -11,9 +10,7 @@
import QuestionPreview from "./QuestionPreview.svelte"
import SchemaBasedMultiType from "./SchemaBasedMultiType.svelte"
import { EditJsonState } from "./EditLayerState"
import type {
QuestionableTagRenderingConfigJson,
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import { AccordionItem } from "flowbite-svelte"
export let state: EditJsonState<any>
@ -86,10 +83,10 @@
} catch (e) {
console.log(
"Warning: could not translate a title for " +
`${singular} ${i} with function ` +
schema.hints.title +
" and value " +
JSON.stringify(value),
`${singular} ${i} with function ` +
schema.hints.title +
" and value " +
JSON.stringify(value)
)
}
return Translations.T(`${singular} ${i}`)
@ -111,11 +108,10 @@
}
</script>
<AccordionItem open={$expanded} paddingDefault="p-0" inactiveClass="text-black m-0" >
<div slot="header" class="p-1 text-base w-full m-0 text-black">
<AccordionItem open={$expanded} paddingDefault="p-0" inactiveClass="text-black m-0">
<div slot="header" class="m-0 w-full p-1 text-base text-black">
{#if !isTagRenderingBlock}
<div class="flex items-center justify-between w-full">
<div class="flex w-full items-center justify-between">
<div class="m-0 flex">
{#if schema.hints.icon}
<Icon clss="w-6 h-6" icon={genIcon(value)} color={genColor(value)} />
@ -134,30 +130,30 @@
<button
class="h-fit w-fit rounded-full border border-black p-1"
on:click={() => {
del(i)
}}
del(i)
}}
>
<TrashIcon class="h-4 w-4" />
</button>
</div>
{:else if typeof value === "string"}
Builtin: <b>{value}</b>
{:else if value["builtin"]}
{:else if value["builtin"]}
reused tagrendering <span class="font-bold">{JSON.stringify(value["builtin"])}</span>
{:else}
<Tr cls="font-bold" t={Translations.T(value?.question ?? value?.render)} />
{/if}
</div>
<div class="normal-background p-2 border border-gray-300">
<div class="normal-background border border-gray-300 p-2">
{#if usesOverride}
This block uses an builtin/override construction and cannot be edited in Studio.
Edit the code directly
This block uses an builtin/override construction and cannot be edited in Studio. Edit the code
directly
{:else if isTagRenderingBlock}
<QuestionPreview {state} {path} {schema}>
<button
on:click={() => {
del(i)
}}
del(i)
}}
>
<TrashIcon class="h-4 w-4" />
Delete this question
@ -166,16 +162,16 @@
{#if i > 0}
<button
on:click={() => {
moveTo(i, 0)
}}
moveTo(i, 0)
}}
>
Move to front
</button>
<button
on:click={() => {
swap(i, i - 1)
}}
swap(i, i - 1)
}}
>
Move up
</button>
@ -183,29 +179,25 @@
{#if i + 1 < $currentValue.length}
<button
on:click={() => {
swap(i, i + 1)
}}
swap(i, i + 1)
}}
>
Move down
</button>
<button
on:click={() => {
moveTo(i, $currentValue.length - 1)
}}
moveTo(i, $currentValue.length - 1)
}}
>
Move to back
</button>
{/if}
</QuestionPreview>
{:else if schema.hints.types}
<SchemaBasedMultiType {state} path={[...path,i]} schema={schemaForMultitype()} />
<SchemaBasedMultiType {state} path={[...path, i]} schema={schemaForMultitype()} />
{:else}
{#each subparts as subpart}
<SchemaBasedInput
{state}
path={fusePath(subpart.path)}
schema={subpart}
/>
<SchemaBasedInput {state} path={fusePath(subpart.path)} schema={subpart} />
{/each}
{/if}
</div>

View file

@ -23,10 +23,9 @@
<div class="flex flex-col">
<div>
Deleting this layer will delete your version. If you clicked a layer made by someone else, their version will
remain.
If you ever accidentally delete a layer, contact Pietervdvn. He might have a backup
Deleting this layer will delete your version. If you clicked a layer made by someone else,
their version will remain. If you ever accidentally delete a layer, contact Pietervdvn. He
might have a backup
</div>
<NextButton clss="primary" on:click={() => deleteLayer()}>
@ -35,8 +34,5 @@
Do delete this {objectType}
</div>
</NextButton>
</div>
</AccordionSingle>

View file

@ -82,7 +82,7 @@
let highlightedItem: UIEventSource<HighlightedTagRendering> = state.highlightedItem
</script>
<div class="flex h-screen flex-col link-underline">
<div class="link-underline flex h-screen flex-col">
<div class="my-2 flex w-full flex-wrap justify-between">
<slot />
{#if $title === undefined}

View file

@ -54,7 +54,7 @@ export abstract class EditJsonState<T> {
* The EditLayerUI shows a 'schemaBasedInput' for this path to pop advanced questions out
*/
public readonly highlightedItem: UIEventSource<HighlightedTagRendering> = new UIEventSource(
undefined,
undefined
)
private sendingUpdates = false
private readonly _stores = new Map<string, UIEventSource<any>>()
@ -66,7 +66,7 @@ export abstract class EditJsonState<T> {
osmConnection: OsmConnection,
options?: {
expertMode?: UIEventSource<boolean>
},
}
) {
this.osmConnection = osmConnection
this.schema = schema
@ -93,14 +93,20 @@ export abstract class EditJsonState<T> {
await this.server.update(id, config, this.category)
})
this.messages = this.createMessagesStore()
}
public startSavingUpdates(enabled = true) {
this.sendingUpdates = enabled
this.register(["credits"], this.osmConnection.userDetails.mapD(u => u.name), false)
this.register(["credits:uid"], this.osmConnection.userDetails.mapD(u => u.uid), false)
this.register(
["credits"],
this.osmConnection.userDetails.mapD((u) => u.name),
false
)
this.register(
["credits:uid"],
this.osmConnection.userDetails.mapD((u) => u.uid),
false
)
if (enabled) {
this.configuration.ping()
}
@ -141,7 +147,7 @@ export abstract class EditJsonState<T> {
public register(
path: ReadonlyArray<string | number>,
value: Store<any>,
noInitialSync: boolean = true,
noInitialSync: boolean = true
): () => void {
const unsync = value.addCallback((v) => {
this.setValueAt(path, v)
@ -155,7 +161,7 @@ export abstract class EditJsonState<T> {
public getSchemaStartingWith(path: string[]) {
return this.schema.filter(
(sch) =>
!path.some((part, i) => !(sch.path.length > path.length && sch.path[i] === part)),
!path.some((part, i) => !(sch.path.length > path.length && sch.path[i] === part))
)
}
@ -173,11 +179,11 @@ export abstract class EditJsonState<T> {
}
public getSchema(path: (string | number)[]): ConfigMeta[] {
path = path.filter(p => typeof p === "string")
path = path.filter((p) => typeof p === "string")
const schemas = this.schema.filter(
(sch) =>
sch !== undefined &&
!path.some((part, i) => !(sch.path.length == path.length && sch.path[i] === part)),
!path.some((part, i) => !(sch.path.length == path.length && sch.path[i] === part))
)
if (schemas.length == 0) {
console.warn("No schemas found for path", path.join("."))
@ -267,12 +273,12 @@ class ContextRewritingStep<T> extends Conversion<LayerConfigJson, T> {
constructor(
state: DesugaringContext,
step: Conversion<LayerConfigJson, T>,
getTagRenderings: (t: T) => TagRenderingConfigJson[],
getTagRenderings: (t: T) => TagRenderingConfigJson[]
) {
super(
"When validating a layer, the tagRenderings are first expanded. Some builtin tagRendering-calls (e.g. `contact`) will introduce _multiple_ tagRenderings, causing the count to be off. This class rewrites the error messages to fix this",
[],
"ContextRewritingStep",
"ContextRewritingStep"
)
this._state = state
this._step = step
@ -282,7 +288,7 @@ class ContextRewritingStep<T> extends Conversion<LayerConfigJson, T> {
convert(json: LayerConfigJson, context: ConversionContext): T {
const converted = this._step.convert(json, context)
const originalIds = json.tagRenderings?.map(
(tr) => (<QuestionableTagRenderingConfigJson>tr)["id"],
(tr) => (<QuestionableTagRenderingConfigJson>tr)["id"]
)
if (!originalIds) {
return converted
@ -344,7 +350,7 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
schema: ConfigMeta[],
server: StudioServer,
osmConnection: OsmConnection,
options: { expertMode: UIEventSource<boolean> },
options: { expertMode: UIEventSource<boolean> }
) {
super(schema, server, "layers", osmConnection, options)
this.layout = {
@ -401,7 +407,7 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
return new ContextRewritingStep(
state,
new Pipe(new PrepareLayer(state), new ValidateLayer("dynamic", false, undefined, true)),
(t) => <TagRenderingConfigJson[]>t.raw.tagRenderings,
(t) => <TagRenderingConfigJson[]>t.raw.tagRenderings
)
}
@ -435,7 +441,7 @@ export default class EditLayerState extends EditJsonState<LayerConfigJson> {
}
protected async validate(
configuration: Partial<LayerConfigJson>,
configuration: Partial<LayerConfigJson>
): Promise<ConversionMessage[]> {
const layers = AllSharedLayers.getSharedLayersConfigs()
@ -465,18 +471,20 @@ export class EditThemeState extends EditJsonState<LayoutConfigJson> {
schema: ConfigMeta[],
server: StudioServer,
osmConnection: OsmConnection,
options: { expertMode: UIEventSource<boolean> },
options: { expertMode: UIEventSource<boolean> }
) {
super(schema, server, "themes", osmConnection, options)
this.setupFixers()
}
protected buildValidation(state: DesugaringContext): Conversion<LayoutConfigJson, any> {
return new Pipe(new PrevalidateTheme(),
return new Pipe(
new PrevalidateTheme(),
new Pipe(
new PrepareTheme(state),
new ValidateTheme(undefined, "", false, new Set(state.tagRenderings.keys())),
), true,
new ValidateTheme(undefined, "", false, new Set(state.tagRenderings.keys()))
),
true
)
}

View file

@ -5,9 +5,7 @@
import { ImmutableStore, Store } from "../../Logic/UIEventSource"
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte"
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
import type {
QuestionableTagRenderingConfigJson,
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.js"
import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.js"
import type { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson"
import FromHtml from "../Base/FromHtml.svelte"
import ShowConversionMessage from "./ShowConversionMessage.svelte"
@ -44,11 +42,12 @@
if (config["builtin"]) {
let override = ""
if (config["override"]) {
override = ". Some items are changed with an override. Editing this is not yet supported with Studio."
override =
". Some items are changed with an override. Editing this is not yet supported with Studio."
}
return new TagRenderingConfig({
render: {
"en": "This question reuses <b>" + JSON.stringify(config["builtin"]) + "</b>" + override,
en: "This question reuses <b>" + JSON.stringify(config["builtin"]) + "</b>" + override,
},
})
}
@ -69,10 +68,10 @@
<div class="flex">
<div class="m-4 flex w-full flex-col">
{#if $configJson.some(config => config["builtin"] !== undefined)}
<div class="interactive p-2 rounded-2xl">
This question uses an advanced 'builtin'+'override' construction in the source code.
Editing this with Studio is not supported.
{#if $configJson.some((config) => config["builtin"] !== undefined)}
<div class="interactive rounded-2xl p-2">
This question uses an advanced 'builtin'+'override' construction in the source code. Editing
this with Studio is not supported.
</div>
{:else}
<NextButton clss="primary" on:click={() => state.highlightedItem.setData({ path, schema })}>

View file

@ -9,14 +9,18 @@
export let state: EditLayerState | EditThemeState
let rawConfig = state.configuration.sync(f => JSON.stringify(f, null, " "), [], json => {
try {
return JSON.parse(json)
} catch (e) {
console.error("Could not parse", json)
return undefined
let rawConfig = state.configuration.sync(
(f) => JSON.stringify(f, null, " "),
[],
(json) => {
try {
return JSON.parse(json)
} catch (e) {
console.error("Could not parse", json)
return undefined
}
}
})
)
let container: HTMLDivElement
let monaco: typeof Monaco
@ -88,7 +92,7 @@
model = monaco?.editor?.createModel(
JSON.stringify(state.configuration.data, null, " "),
"json",
modelUri,
modelUri
)
} catch (e) {
console.error("Could not create model in MOnaco Editor", e)
@ -126,7 +130,7 @@
{:else}
<div bind:this={container} class="h-full w-full">
{#if !isLoaded}
<div class="h-full w-full flex items-center align-center">
<div class="align-center flex h-full w-full items-center">
<Loading />
</div>
{/if}

View file

@ -5,9 +5,7 @@
import { TrashIcon } from "@babeard/svelte-heroicons/mini"
import ShowConversionMessage from "./ShowConversionMessage.svelte"
import Markdown from "../Base/Markdown.svelte"
import type {
QuestionableTagRenderingConfigJson,
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import CollapsedTagRenderingPreview from "./CollapsedTagRenderingPreview.svelte"
import { Accordion } from "flowbite-svelte"
@ -63,8 +61,6 @@
currentValue.data.splice(i, 1)
currentValue.ping()
}
</script>
<div class="pl-2">
@ -76,7 +72,9 @@
{#if $currentValue === undefined}
No array defined
{:else if !Array.isArray($currentValue)}
Not an array: {typeof $currentValue} {JSON.stringify(path)} {JSON.stringify($currentValue).slice(0,120)}
Not an array: {typeof $currentValue}
{JSON.stringify(path)}
{JSON.stringify($currentValue).slice(0, 120)}
{:else if $currentValue?.length === 0}
No values are defined
{#if $messages.length > 0}
@ -102,7 +100,16 @@
{:else}
<Accordion>
{#each $currentValue as value, i (value)}
<CollapsedTagRenderingPreview {state} {isTagRenderingBlock} {schema} {currentValue} {value} {i} {singular} path={fusePath(i)} />
<CollapsedTagRenderingPreview
{state}
{isTagRenderingBlock}
{schema}
{currentValue}
{value}
{i}
{singular}
path={fusePath(i)}
/>
{/each}
</Accordion>
{/if}

View file

@ -8,9 +8,10 @@
export let state: EditJsonState<any>
export let path: (string | number)[] = []
export let schema: ConfigMeta = state.getSchema(<any> path)[0]
export let schema: ConfigMeta = state.getSchema(<any>path)[0]
let expertMode = state.expertMode
</script>
{#if schema === undefined}
<div>ERROR: no schema found for {path.join(".")}</div>
{:else if (schema.hints?.group !== "expert" || $expertMode) && schema.hints.group !== "hidden"}

View file

@ -220,10 +220,7 @@
{#if chosenOption !== undefined}
{#each subSchemas as subschema}
{#if $expertMode || subschema.hints?.group !== "expert"}
<SchemaBasedInput
{state}
path={[...subpath, subschema?.path?.at(-1) ?? "???"]}
/>
<SchemaBasedInput {state} path={[...subpath, subschema?.path?.at(-1) ?? "???"]} />
{:else if window.location.hostname === "127.0.0.1"}
<span class="subtle">Omitted expert question {subschema.path.join(".")}</span>
{/if}

View file

@ -29,7 +29,7 @@
const store = state.getStoreFor(path)
let value = store.data
let hasSeenIntro = UIEventSource.asBoolean(
LocalStorageSource.Get("studio-seen-tagrendering-tutorial", "false"),
LocalStorageSource.Get("studio-seen-tagrendering-tutorial", "false")
)
onMount(() => {
if (!hasSeenIntro.data) {
@ -42,24 +42,24 @@
* Should only be enabled for 'tagrenderings' in the theme, if the source is OSM
*/
let allowQuestions: Store<boolean> = state.configuration.mapD(
(config) => path.at(0) === "tagRenderings" && config.source?.["geoJson"] === undefined,
(config) => path.at(0) === "tagRenderings" && config.source?.["geoJson"] === undefined
)
let mappingsBuiltin: MappingConfigJson[] = []
let perLabel: Record<string, MappingConfigJson> = {}
{ // Build the list of options that one can choose for builtin questions
const forbidden = new Set( ["ignore_docs","all_tags"])
{
// Build the list of options that one can choose for builtin questions
const forbidden = new Set(["ignore_docs", "all_tags"])
for (const tr of questions.tagRenderings) {
if(forbidden.has(tr.id)){
if (forbidden.has(tr.id)) {
continue
}
let description = tr["description"] ?? tr["question"] ?? "No description available"
description = description["en"] ?? description
if (tr["labels"]) {
const labels: string[] = tr["labels"]
if(labels.some(l => forbidden.has(l))){
if (labels.some((l) => forbidden.has(l))) {
continue
}
for (const label of labels) {
@ -129,7 +129,7 @@
const freeformSchemaAll = <ConfigMeta[]>(
questionableTagRenderingSchemaRaw.filter(
(schema) => schema.path.length == 2 && schema.path[0] === "freeform" && $allowQuestions,
(schema) => schema.path.length == 2 && schema.path[0] === "freeform" && $allowQuestions
)
)
let freeformSchema = $expertMode
@ -138,7 +138,7 @@
const missing: string[] = questionableTagRenderingSchemaRaw
.filter(
(schema) =>
schema.path.length >= 1 && !items.has(schema.path[0]) && !ignored.has(schema.path[0]),
schema.path.length >= 1 && !items.has(schema.path[0]) && !ignored.has(schema.path[0])
)
.map((schema) => schema.path.join("."))
console.log({ state })
@ -146,7 +146,14 @@
{#if typeof $store === "string"}
<div class="low-interaction flex">
<TagRenderingEditable config={configBuiltin} selectedElement={undefined} {state} {tags} editMode={true} clss="w-full" />
<TagRenderingEditable
config={configBuiltin}
selectedElement={undefined}
{state}
{tags}
editMode={true}
clss="w-full"
/>
<slot name="upper-right" />
</div>
{:else}