From 21563e4dc2f6a5d9dbbc48bb5eb7842aae224984 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 3 Jan 2024 14:57:26 +0100 Subject: [PATCH] More fixes to studio, move error message to validation step, fix #1710 --- .../ThemeConfig/Conversion/Validation.ts | 16 ++++++++ src/Models/ThemeConfig/LayerConfig.ts | 8 ---- src/UI/Studio/EditLayer.svelte | 41 ++++++++++++++----- src/UI/Studio/SchemaBasedField.svelte | 2 +- src/UI/StudioGUI.svelte | 4 +- 5 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/Models/ThemeConfig/Conversion/Validation.ts b/src/Models/ThemeConfig/Conversion/Validation.ts index 1b9142083..0a267fc08 100644 --- a/src/Models/ThemeConfig/Conversion/Validation.ts +++ b/src/Models/ThemeConfig/Conversion/Validation.ts @@ -421,6 +421,7 @@ export class DetectNonErasedKeysInMappings extends DesugaringStep void) => void }, addTo: Set) { keys?.forEach((k) => addTo.add(k)) } @@ -1359,6 +1360,7 @@ export class PrevalidateLayer extends DesugaringStep { export class ValidateLayerConfig extends DesugaringStep { private readonly validator: ValidateLayer + constructor( path: string, isBuiltin: boolean, @@ -1385,6 +1387,7 @@ export class ValidateLayerConfig extends DesugaringStep { return prepared?.raw } } + export class ValidateLayer extends Conversion< LayerConfigJson, { parsed: LayerConfig; raw: LayerConfigJson } @@ -1462,6 +1465,19 @@ export class ValidateLayer extends Conversion< } } + for (let i = 0; i < json.presets.length; i++) { + const preset = json.presets[i] + if ( + preset.snapToLayer === undefined && + preset.maxSnapDistance !== undefined && + preset.maxSnapDistance !== null + ) { + context + .enters("presets", i, "maxSnapDistance") + .err("A maxSnapDistance is given, but there is no layer given to snap to") + } + } + return { raw: json, parsed: layerConfig } } } diff --git a/src/Models/ThemeConfig/LayerConfig.ts b/src/Models/ThemeConfig/LayerConfig.ts index 60813b15b..7b2feacd0 100644 --- a/src/Models/ThemeConfig/LayerConfig.ts +++ b/src/Models/ThemeConfig/LayerConfig.ts @@ -184,14 +184,6 @@ export default class LayerConfig extends WithContextLoader { snapToLayers, maxSnapDistance: pr.maxSnapDistance ?? 10, } - } else if (pr.maxSnapDistance !== undefined) { - throw ( - "Layer " + - this.id + - " defines a maxSnapDistance, but does not include a `snapToLayer` (at " + - context + - ")" - ) } const config: PresetConfig = { diff --git a/src/UI/Studio/EditLayer.svelte b/src/UI/Studio/EditLayer.svelte index b4af91434..5d9aedbaf 100644 --- a/src/UI/Studio/EditLayer.svelte +++ b/src/UI/Studio/EditLayer.svelte @@ -24,7 +24,7 @@ export let backToStudio: () => void let messages = state.messages let hasErrors = messages.mapD( - (m: ConversionMessage[]) => m.filter((m) => m.level === "error").length + (m: ConversionMessage[]) => m.filter((m) => m.level === "error").length, ) const configuration = state.configuration @@ -73,6 +73,7 @@ }) let highlightedItem: UIEventSource = state.highlightedItem + function deleteLayer() { state.delete() backToStudio() @@ -93,15 +94,32 @@ {:else if $hasErrors > 0}
{$hasErrors} errors detected
{:else} - - Try it out - - + {/if} @@ -120,7 +138,8 @@
diff --git a/src/UI/Studio/SchemaBasedField.svelte b/src/UI/Studio/SchemaBasedField.svelte index b7b67e6d6..dd87e9af8 100644 --- a/src/UI/Studio/SchemaBasedField.svelte +++ b/src/UI/Studio/SchemaBasedField.svelte @@ -158,7 +158,7 @@ } } if (schema.type === "number") { - if (v === "") { + if (v === "" || v === null || isNaN(Number(v))) { return undefined } return Number(v) diff --git a/src/UI/StudioGUI.svelte b/src/UI/StudioGUI.svelte index 48fa7a8d7..67f97fd3d 100644 --- a/src/UI/StudioGUI.svelte +++ b/src/UI/StudioGUI.svelte @@ -95,7 +95,7 @@ const version = meta.version async function editLayer(event: Event) { - const layerId: { owner: number; id: string } = event.detail + const layerId: { owner: number; id: string } = event["detail"] state = "loading" editLayerState.startSavingUpdates(false) editLayerState.configuration.setData(await studio.fetch(layerId.id, "layers", layerId.owner)) @@ -104,7 +104,7 @@ } async function editTheme(event: Event) { - const id: { id: string; owner: number } = event.detail + const id: { id: string; owner: number } = event["detail"] state = "loading" editThemeState.startSavingUpdates(false) editThemeState.configuration.setData(await studio.fetch(id.id, "themes", id.owner))