diff --git a/src/UI/Studio/EditLayer.svelte b/src/UI/Studio/EditLayer.svelte index 0920b030d..e8fa9168d 100644 --- a/src/UI/Studio/EditLayer.svelte +++ b/src/UI/Studio/EditLayer.svelte @@ -13,24 +13,15 @@ import SchemaBasedInput from "./SchemaBasedInput.svelte" import FloatOver from "../Base/FloatOver.svelte" import TagRenderingInput from "./TagRenderingInput.svelte" - import FromHtml from "../Base/FromHtml.svelte" import AllTagsPanel from "../Popup/AllTagsPanel.svelte" import QuestionPreview from "./QuestionPreview.svelte" import ShowConversionMessages from "./ShowConversionMessages.svelte" - import loader from "@monaco-editor/loader" - import type * as Monaco from "monaco-editor/esm/vs/editor/editor.api" - import { onMount } from "svelte" - import layerSchemaJSON from "../../../Docs/Schemas/LayerConfigJson.schema.json" + import RawEditor from "./RawEditor.svelte" const layerSchema: ConfigMeta[] = layerSchemaRaw export let state: EditLayerState - // Throw error if we don't have a state - if (!state) { - throw new Error("No state provided") - } - export let backToStudio: () => void let messages = state.messages let hasErrors = messages.mapD( @@ -69,7 +60,7 @@ } let requiredFields = ["id", "name", "description", "source"] - let currentlyMissing = state.configuration.map((config) => { + let currentlyMissing = configuration.map((config) => { if (!config) { return [] } @@ -88,61 +79,6 @@ state.delete() backToStudio() } - - let tabbedGroup: TabbedGroup - let openTab: UIEventSource = new UIEventSource(0) - - let monaco: typeof Monaco - let editorContainer: HTMLDivElement - let layerEditor: Monaco.editor.IStandaloneCodeEditor - let model: Monaco.editor.ITextModel - - onMount(async () => { - openTab = tabbedGroup.getTab() - - const monacoEditor = await import("monaco-editor") - loader.config({ monaco: monacoEditor.default }) - - monaco = await loader.init() - - // Prepare the Monaco editor (language settings) - // A.K.A. The schemas for the Monaco editor - monaco.languages.json.jsonDefaults.setDiagnosticsOptions({ - validate: true, - schemas: [ - { - uri: "https://mapcomplete.org/schemas/layerconfig.json", - fileMatch: ["layer.json"], - schema: layerSchemaJSON, - }, - ], - }) - let modelUri = monaco.Uri.parse("inmemory://inmemory/layer.json") - model = monaco.editor.createModel( - JSON.stringify(state.configuration.data, null, " "), - "json", - modelUri - ) - - layerEditor = monaco.editor.create(editorContainer, { - model: model, - automaticLayout: true, - }) - - // When the editor is changed, update the configuration, but only if the user hasn't typed for 500ms and the JSON is valid - let timeout: number - layerEditor.onDidChangeModelContent(() => { - clearTimeout(timeout) - timeout = setTimeout(() => { - try { - const newConfig = JSON.parse(layerEditor.getValue()) - state.configuration.setData(newConfig) - } catch (e) { - console.error(e) - } - }, 500) - }) - })
@@ -191,7 +127,7 @@ {/each} {:else}
- +
General properties @@ -254,7 +190,9 @@ Below, you'll find the raw configuration file in `.json`-format. This is mostly for debugging purposes, but you can also edit the file directly if you want.
-
+
+ +
diff --git a/src/UI/Studio/EditTheme.svelte b/src/UI/Studio/EditTheme.svelte index 34eff126e..16f9e0a36 100644 --- a/src/UI/Studio/EditTheme.svelte +++ b/src/UI/Studio/EditTheme.svelte @@ -6,6 +6,7 @@ import TabbedGroup from "../Base/TabbedGroup.svelte" import ShowConversionMessages from "./ShowConversionMessages.svelte" import Region from "./Region.svelte" + import RawEditor from "./RawEditor.svelte" export let state: EditThemeState let schema: ConfigMeta[] = state.schema.filter((schema) => schema.path.length > 0) @@ -20,7 +21,7 @@ const perRegion: Record = {} for (const schemaElement of schema) { - if(schemaElement.path.length > 1 && schemaElement.path[0] === "layers"){ + if (schemaElement.path.length > 1 && schemaElement.path[0] === "layers") { continue } const key = schemaElement.hints.group ?? "no-group" @@ -73,9 +74,13 @@
Configuration file
-
-
- {JSON.stringify($config)} +
+
+ Below, you'll find the raw configuration file in `.json`-format. This is mostly for + debugging purposes, but you can also edit the file directly if you want. +
+
+
diff --git a/src/UI/Studio/RawEditor.svelte b/src/UI/Studio/RawEditor.svelte new file mode 100644 index 000000000..679f2f314 --- /dev/null +++ b/src/UI/Studio/RawEditor.svelte @@ -0,0 +1,101 @@ + + +