MapComplete/src/UI/Studio/ArrayMultiAnswer.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.3 KiB
Svelte
Raw Normal View History

<script lang="ts">
2023-11-09 16:30:26 +01:00
import type { ConfigMeta } from "./configMeta"
import EditLayerState from "./EditLayerState"
import type { QuestionableTagRenderingConfigJson } from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson"
import { UIEventSource } from "../../Logic/UIEventSource"
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte"
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
2023-11-09 16:30:26 +01:00
export let schema: ConfigMeta
export let state: EditLayerState
export let path: (string | number)[] = []
const configJson: QuestionableTagRenderingConfigJson = {
mappings: schema.hints.suggestions,
multiAnswer: true,
2023-11-09 16:30:26 +01:00
id: "multi_anwser_" + path.join("_"),
question: schema.hints.question,
}
const tags = new UIEventSource({})
{
// Setting the initial value
2023-11-09 16:30:26 +01:00
const v = <string[]>state.getCurrentValueFor(path)
if (v && v.length > 0) {
tags.setData({ value: v.join(";") })
}
}
2023-11-09 16:30:26 +01:00
tags.addCallbackD((tags) => {
const values = tags["value"]?.split(";")
2023-11-09 16:30:26 +01:00
if (!values) {
return
}
state.setValueAt(path, values)
})
2023-11-09 16:30:26 +01:00
const config = new TagRenderingConfig(configJson)
</script>
<div>
2023-11-09 16:30:26 +01:00
<TagRenderingEditable
{config}
selectedElement={undefined}
{state}
{tags}
/>
</div>