Studio: more work on studio

This commit is contained in:
Pieter Vander Vennet 2023-10-07 03:07:32 +02:00
parent 81876fc5ed
commit 4e8dfc0026
20 changed files with 1842 additions and 94 deletions

View file

@ -7,10 +7,12 @@
import { Store, UIEventSource } from "../../Logic/UIEventSource";
import type { ConfigMeta } from "./configMeta";
import { Utils } from "../../Utils";
import type { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson";
const layerSchema: ConfigMeta[] = <any>layerSchemaRaw;
let state = new EditLayerState(layerSchema);
state.configuration.setData({});
export let initialLayerConfig: Partial<LayerConfigJson> = {}
state.configuration.setData(initialLayerConfig);
const configuration = state.configuration;
new LayerStateSender("http://localhost:1235", state);
/**

View file

@ -129,7 +129,7 @@ export default class EditLayerState {
}
entry = entry[breadcrumb]
}
if (v) {
if (v !== undefined && v !== null && v !== "") {
entry[path.at(-1)] = v
} else if (entry) {
delete entry[path.at(-1)]

View file

@ -72,11 +72,11 @@
configJson.mappings.push(
{
if: "value=true",
then: "Yes "+(schema.hints?.iftrue??"")
then: "Yes: "+(schema.hints?.iftrue??"")
},
{
if: "value=false",
then: "No "+(schema.hints?.iffalse??"")
then: "No: "+(schema.hints?.iffalse??"")
}
)
}
@ -106,6 +106,15 @@
if (schema.type === "boolan") {
return v === "true" || v === "yes" || v === "1"
}
if(mightBeBoolean(schema.type)){
if(v === "true" || v === "yes" || v === "1"){
return true
}
if(v === "false" || v === "no" || v === "0"){
console.log("Setting false...")
return false
}
}
if (schema.type === "number") {
return Number(v)
}

View file

@ -4,9 +4,8 @@
import EditLayerState from "./EditLayerState";
import SchemaBasedArray from "./SchemaBasedArray.svelte";
import SchemaBasedMultiType from "./SchemaBasedMultiType.svelte";
import SchemaBasedTranslationInput from "./SchemaBasedTranslationInput.svelte";
import { ConfigMetaUtils } from "./configMeta.ts"
import ArrayMultiAnswer from "./ArrayMultiAnswer.svelte";
export let schema: ConfigMeta;
export let state: EditLayerState;
export let path: (string | number)[] = [];

View file

@ -13,6 +13,7 @@
import type { JsonSchemaType } from "./jsonSchema";
// @ts-ignore
import nmd from "nano-markdown";
import { writable } from "svelte/store";
/**
* If 'types' is defined: allow the user to pick one of the types to input.
@ -84,7 +85,7 @@
);
}
const config = new TagRenderingConfig(configJson, "config based on " + schema.path.join("."));
let chosenOption: number = defaultOption;
let chosenOption: number = writable(defaultOption);
const existingValue = state.getCurrentValueFor(path);
@ -126,8 +127,11 @@
}
possibleTypes.sort((a, b) => b.optionalMatches - a.optionalMatches);
possibleTypes.sort((a, b) => b.matchingPropertiesCount - a.matchingPropertiesCount);
console.log("Possible types are", possibleTypes)
if (possibleTypes.length > 0) {
tags.setData({ chosen_type_index: "" + possibleTypes[0].index });
chosenOption = possibleTypes[0].index
tags.setData({ chosen_type_index: "" + chosenOption});
}
} else if (defaultOption !== undefined) {
tags.setData({ chosen_type_index: "" + defaultOption });
@ -150,13 +154,14 @@
let subSchemas: ConfigMeta[] = [];
let subpath = path;
console.log("Initial chosen option is", chosenOption);
console.log("Initial chosen option for",path.join("."),"is", chosenOption);
onDestroy(tags.addCallbackAndRun(tags => {
if (tags["value"] !== "") {
chosenOption = undefined;
return;
}
const oldOption = chosenOption;
console.log("Updating chosenOption based on", tags, oldOption)
chosenOption = tags["chosen_type_index"] ? Number(tags["chosen_type_index"]) : defaultOption;
const type = schema.type[chosenOption];
if (chosenOption !== oldOption) {
@ -209,4 +214,5 @@
path={[...subpath, (subschema?.path?.at(-1) ?? "???")]}></SchemaBasedInput>
{/each}
{/if}
{chosenOption}
</div>