Studio: more work on the base properties

This commit is contained in:
Pieter Vander Vennet 2023-06-21 17:13:09 +02:00
parent c229b92221
commit 84dee10201
46 changed files with 11462 additions and 37927 deletions

View file

@ -11,7 +11,7 @@
import {Utils} from "../../Utils";
export let type: ValidatorType
export let feedback: UIEventSource<Translation> | undefined = undefined
export let feedback: UIEventSource<Translation> | undefined
export let getCountry: () => string | undefined
export let placeholder: string | Translation | undefined
export let unit: Unit = undefined
@ -53,7 +53,7 @@
validator = Validators.get(type ?? "string")
_placeholder = placeholder ?? validator?.getPlaceholder() ?? type
feedback = feedback?.setData(validator?.getFeedback(_value.data, getCountry))
feedback?.setData(validator?.getFeedback(_value.data, getCountry))
initValueAndDenom()
}
@ -62,8 +62,8 @@
// Update the value stores
const v = _value.data
if (!validator?.isValid(v, getCountry) || v === "") {
value.setData(undefined)
feedback?.setData(validator?.getFeedback(v, getCountry))
value.setData("")
return
}

View file

@ -24,8 +24,7 @@
inline = config.freeform?.inline
}
export let feedback: UIEventSource<Translation> = new UIEventSource<Translation>(undefined)
export let feedback: UIEventSource<Translation>
let dispatch = createEventDispatcher<{ selected, submit }>()
onDestroy(
value.addCallbackD(() => {

View file

@ -47,4 +47,11 @@ export default class EditLayerState {
!path.some((part, i) => !(sch.path.length > path.length && sch.path[i] === part))
)
}
public getSchema(path: string[]) {
return this.schema.filter(
(sch) =>
!path.some((part, i) => !(sch.path.length == path.length && sch.path[i] === part))
)
}
}

View file

@ -0,0 +1,62 @@
<script lang="ts">
import EditLayerState from "./EditLayerState";
import type {ConfigMeta} from "./configMeta";
import {UIEventSource} from "../../Logic/UIEventSource";
import type {
QuestionableTagRenderingConfigJson
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson";
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte";
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
import {onDestroy} from "svelte";
import SchemaBasedInput from "./SchemaBasedInput.svelte";
/**
* If 'types' is defined: allow the user to pick one of the types to input.
*/
export let state: EditLayerState
export let path: (string | number)[] = []
export let schema: ConfigMeta
let value = new UIEventSource<string>(undefined)
const configJson: QuestionableTagRenderingConfigJson = {
id: "TYPE_OF:" + path.join("_"),
question: "Which subcategory is needed?",
questionHint: schema.description,
mappings: schema.hints.types.split(";").map(opt => opt.trim()).filter(opt => opt.length > 0).map((opt, i) => ({
if: "value=" + i,
then: opt
}))
}
const config = new TagRenderingConfig(configJson, "config based on " + schema.path.join("."))
let tags = new UIEventSource<Record<string, string>>({})
let chosenOption: number = undefined
let subSchemas: ConfigMeta[] = []
onDestroy(tags.addCallback(tags => {
chosenOption = Number(tags["value"])
const type = schema.type[chosenOption]
const cleanPath = <string[]> path.filter(p => typeof p === "string")
for (const crumble of Object.keys(type.properties)) {
console.log("Searching entries for", [...cleanPath, crumble])
subSchemas.push(...(state.getSchema([...cleanPath, crumble])))
}
}))
</script>
<div>
<TagRenderingEditable {config} showQuestionIfUnknown={true} {state} {tags}/>
</div>
{#if chosenOption !== undefined}
<div class="pl-2 border-2 border-dashed border-gray-300 flex flex-col gap-y-2">
{#each subSchemas as subschema}
{JSON.stringify(subschema)}
<SchemaBasedInput {state} schema={subschema} path={[...path]}></SchemaBasedInput>
{/each}
</div>
{/if}

View file

@ -1,7 +1,6 @@
<script lang="ts">
import {UIEventSource} from "../../Logic/UIEventSource";
import {Translation} from "../i18n/Translation";
import type {ConfigMeta} from "./configMeta";
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte";
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
@ -15,8 +14,8 @@
export let path: (string | number)[] = []
export let schema: ConfigMeta
let value = new UIEventSource<string>(undefined)
let feedback = new UIEventSource<Translation>(undefined)
const configJson: QuestionableTagRenderingConfigJson = {
id: path.join("_"),
render: schema.hints.inline ?? schema.path.at(-1) + ": <b>{value}</b>",
@ -29,7 +28,12 @@
}
}
if (!schema.required) {
if (schema.hints.default) {
configJson.mappings = [{
if: "value=", // +schema.hints.default,
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) {
configJson.mappings = [{
if: "value=",
then: schema.path.at(-1) + " is not set. " + (schema.hints.ifunset ?? ""),

View file

@ -3,15 +3,18 @@
import SchemaBasedField from "./SchemaBasedField.svelte";
import EditLayerState from "./EditLayerState";
import SchemaBasedArray from "./SchemaBasedArray.svelte";
import SchemaBaseMultiType from "./SchemaBaseMultiType.svelte";
export let schema: ConfigMeta
export let state: EditLayerState
export let path : (string | number)[] = []
export let path: (string | number)[] = []
</script>
{#if schema.type === "array"}
<SchemaBasedArray {path} {state} {schema}/>
{:else if schema.hints.types}
<SchemaBaseMultiType {path} {state} {schema}></SchemaBaseMultiType>
{:else}
<SchemaBasedField {path} {state} {schema}/>
{/if}

View file

@ -6,9 +6,14 @@ export interface ConfigMeta {
hints: {
group?: string
typehint?: string
/**
* If multiple subcategories can be chosen
*/
types?: string
question?: string
ifunset?: string
inline?: string
default?: string
}
required: boolean
description: string