forked from MapComplete/MapComplete
		
	Studio: first working version for basic layer properties
This commit is contained in:
		
							parent
							
								
									5a49677d5a
								
							
						
					
					
						commit
						f18a2b9184
					
				
					 41 changed files with 4446 additions and 852 deletions
				
			
		|  | @ -4,10 +4,12 @@ | |||
|     import type {ConfigMeta} from "./configMeta"; | ||||
|     import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte"; | ||||
|     import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"; | ||||
|     import nmd from "nano-markdown" | ||||
|     import type { | ||||
|         QuestionableTagRenderingConfigJson | ||||
|     } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"; | ||||
|     import EditLayerState from "./EditLayerState"; | ||||
|     import { onDestroy } from "svelte"; | ||||
| 
 | ||||
| 
 | ||||
|     export let state: EditLayerState | ||||
|  | @ -15,22 +17,21 @@ | |||
|     export let schema: ConfigMeta | ||||
|     let value = new UIEventSource<string>(undefined) | ||||
| 
 | ||||
| 
 | ||||
|     const configJson: QuestionableTagRenderingConfigJson = { | ||||
|         id: path.join("_"), | ||||
|         render: schema.hints.inline ?? schema.path.at(-1) + ": <b>{value}</b>", | ||||
|         render: schema.type === "boolean" ? undefined : schema.hints.inline ?? schema.path.at(-1) + ": <b>{value}</b>", | ||||
|         question: schema.hints.question, | ||||
|         questionHint: schema.description, | ||||
|         freeform: { | ||||
|         questionHint: nmd(schema.description), | ||||
|         freeform: schema.type === "boolean" ? undefined : { | ||||
|             key: "value", | ||||
|             type: schema.hints.typehint ?? "string", | ||||
|             inline: schema.hints.inline !== undefined | ||||
|         } | ||||
|         }, | ||||
|     } | ||||
| 
 | ||||
|     if (schema.hints.default) { | ||||
|         configJson.mappings = [{ | ||||
|             if: "value=", // +schema.hints.default, | ||||
|             if: "value=", // We leave this blank | ||||
|             then: schema.path.at(-1) + " is not set. The default value <b>" + schema.hints.default + "</b> will be used. " + (schema.hints.ifunset ?? ""), | ||||
|         }] | ||||
|     } else if (!schema.required) { | ||||
|  | @ -39,22 +40,58 @@ | |||
|             then: schema.path.at(-1) + " is not set. " + (schema.hints.ifunset ?? ""), | ||||
|         }] | ||||
|     } | ||||
| 
 | ||||
|     if (schema.type === "boolean" || (Array.isArray(schema.type) && schema.type.some(t => t["type"] === "boolean") >= 0)) { | ||||
|         configJson.mappings = configJson.mappings ?? [] | ||||
|         configJson.mappings.push( | ||||
|             { | ||||
|                 if: "value=true", | ||||
|                 then: "Yes "+(schema.hints?.iftrue??"") | ||||
|             }, | ||||
|             { | ||||
|                 if: "value=false", | ||||
|                 then: "No "+(schema.hints?.iffalse??"") | ||||
|             } | ||||
|         ) | ||||
|     } | ||||
| 
 | ||||
|     if (schema.hints.suggestions) { | ||||
|         if (!configJson.mappings) { | ||||
|             configJson.mappings = [] | ||||
|         } | ||||
|         configJson.mappings.push(...schema.hints.suggestions) | ||||
|     } | ||||
|     let config: TagRenderingConfig | ||||
|     let err: string = undefined | ||||
|     try { | ||||
|         config = new TagRenderingConfig(configJson, "config based on " + schema.path.join(".")) | ||||
|     } catch (e) { | ||||
|         console.error(e, config) | ||||
|         err = e | ||||
|         err = path.join(".") + " " + e | ||||
|     } | ||||
|     let tags = new UIEventSource<Record<string, string>>({}) | ||||
|     state.register(path, tags.map(tgs => tgs["value"])) | ||||
|     let startValue = state.getCurrentValueFor(path) | ||||
|     if (startValue?.["en"]) { | ||||
|         startValue = startValue["en"] | ||||
|     } | ||||
|     console.log("Startvalue for", path.join("."), "is", startValue) | ||||
|     let tags = new UIEventSource<Record<string, string>>({value: startValue ?? ""}) | ||||
|     onDestroy(state.register(path, tags.map(tgs => { | ||||
|         const v = tgs["value"]; | ||||
|         if (schema.type === "boolan") { | ||||
|             return v === "true" || v === "yes" || v === "1" | ||||
|         } | ||||
|         if (schema.type === "number") { | ||||
|             return Number(v) | ||||
|         } | ||||
|         return v | ||||
|     }))) | ||||
| </script> | ||||
| 
 | ||||
| {#if err !== undefined} | ||||
|     <span class="alert">{err}</span> | ||||
|     {JSON.stringify(schema)} | ||||
| {:else} | ||||
|     <div> | ||||
|         <TagRenderingEditable {config} showQuestionIfUnknown={true} {state} {tags}/> | ||||
|         <TagRenderingEditable {config} selectedElement={undefined} showQuestionIfUnknown={true} {state} {tags}/> | ||||
|     </div> | ||||
| {/if} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue