2023-10-25 00:03:51 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import type { ConfigMeta } from "./configMeta";
|
|
|
|
import EditLayerState from "./EditLayerState";
|
|
|
|
import * as questions from "../../assets/generated/layers/questions.json";
|
|
|
|
import { ImmutableStore, Store } from "../../Logic/UIEventSource";
|
|
|
|
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte";
|
|
|
|
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
|
2023-11-02 04:35:32 +01:00
|
|
|
import nmd from "nano-markdown";
|
2023-10-25 00:03:51 +02:00
|
|
|
import type {
|
|
|
|
QuestionableTagRenderingConfigJson
|
|
|
|
} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.js";
|
|
|
|
import type { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson";
|
|
|
|
import FromHtml from "../Base/FromHtml.svelte";
|
2023-11-02 04:35:32 +01:00
|
|
|
import { Utils } from "../../Utils";
|
2023-11-03 02:04:42 +01:00
|
|
|
import ShowConversionMessage from "./ShowConversionMessage.svelte";
|
|
|
|
import NextButton from "../Base/NextButton.svelte";
|
2023-10-25 00:03:51 +02:00
|
|
|
|
|
|
|
export let state: EditLayerState;
|
|
|
|
export let path: ReadonlyArray<string | number>;
|
|
|
|
export let schema: ConfigMeta;
|
|
|
|
let value = state.getStoreFor(path);
|
|
|
|
|
|
|
|
let perId: Record<string, TagRenderingConfigJson[]> = {};
|
|
|
|
for (const tagRendering of questions.tagRenderings) {
|
|
|
|
if (tagRendering.labels) {
|
|
|
|
for (const label of tagRendering.labels) {
|
|
|
|
perId[label] = (perId[label] ?? []).concat(tagRendering);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
perId[tagRendering.id] = [tagRendering];
|
|
|
|
}
|
|
|
|
|
|
|
|
let configJson: Store<QuestionableTagRenderingConfigJson[]> = value.map(x => {
|
|
|
|
if (typeof x === "string") {
|
|
|
|
return perId[x];
|
|
|
|
} else {
|
|
|
|
return [x];
|
|
|
|
}
|
|
|
|
});
|
2023-11-02 04:35:32 +01:00
|
|
|
let configs: Store<TagRenderingConfig[]> =configJson.mapD(configs => Utils.NoNull( configs.map(config => {
|
|
|
|
try{
|
|
|
|
return new TagRenderingConfig(config);
|
|
|
|
}catch (e) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
})));
|
2023-10-25 00:03:51 +02:00
|
|
|
let id: Store<string> = value.mapD(c => {
|
2023-11-02 04:35:32 +01:00
|
|
|
if (c?.id) {
|
2023-10-25 00:03:51 +02:00
|
|
|
return c.id;
|
|
|
|
}
|
|
|
|
if (typeof c === "string") {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
let tags = state.testTags;
|
|
|
|
|
|
|
|
let messages = state.messagesFor(path);
|
|
|
|
|
2023-11-02 04:35:32 +01:00
|
|
|
let description = schema.description
|
|
|
|
if(description){
|
|
|
|
try{
|
|
|
|
description = nmd(description)
|
|
|
|
}catch (e) {
|
|
|
|
console.error("Could not convert description to markdown", {description})
|
|
|
|
}
|
|
|
|
}
|
2023-10-25 00:03:51 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="flex">
|
|
|
|
|
|
|
|
<div class="flex flex-col interactive border-interactive m-4 w-full">
|
|
|
|
|
|
|
|
{#if $id}
|
|
|
|
TagRendering {$id}
|
|
|
|
{/if}
|
2023-11-03 02:04:42 +01:00
|
|
|
<NextButton clss="primary" on:click={() => state.highlightedItem.setData({path, schema})}>
|
2023-10-25 00:03:51 +02:00
|
|
|
{#if schema.hints.question}
|
|
|
|
{schema.hints.question}
|
|
|
|
{/if}
|
2023-11-03 02:04:42 +01:00
|
|
|
</NextButton>
|
2023-11-02 04:35:32 +01:00
|
|
|
{#if description}
|
|
|
|
<FromHtml src={description} />
|
2023-10-25 00:03:51 +02:00
|
|
|
{/if}
|
|
|
|
{#each $messages as message}
|
2023-11-03 02:04:42 +01:00
|
|
|
<ShowConversionMessage {message}/>
|
2023-10-25 00:03:51 +02:00
|
|
|
{/each}
|
|
|
|
|
|
|
|
<slot class="self-end my-4"></slot>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex flex-col w-full m-4">
|
2023-11-03 02:04:42 +01:00
|
|
|
<h3>Preview of this question</h3>
|
2023-10-25 00:03:51 +02:00
|
|
|
{#each $configs as config}
|
|
|
|
<TagRenderingEditable
|
|
|
|
selectedElement={state.exampleFeature}
|
|
|
|
config={config} editingEnabled={new ImmutableStore(true)} showQuestionIfUnknown={true}
|
|
|
|
{state}
|
|
|
|
{tags}></TagRenderingEditable>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|