MapComplete/src/UI/BigComponents/SelectedElementView.svelte

60 lines
2 KiB
Svelte
Raw Normal View History

2023-03-28 05:13:48 +02:00
<script lang="ts">
import type { Feature } from "geojson"
2023-12-19 22:08:00 +01:00
import { Store, UIEventSource } from "../../Logic/UIEventSource"
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
import type { SpecialVisualizationState } from "../SpecialVisualization"
import TagRenderingEditable from "../Popup/TagRendering/TagRenderingEditable.svelte"
import { onDestroy } from "svelte"
import Translations from "../i18n/Translations"
import Tr from "../Base/Tr.svelte"
2023-12-19 22:08:00 +01:00
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
2023-03-28 05:13:48 +02:00
export let state: SpecialVisualizationState
export let layer: LayerConfig
export let selectedElement: Feature
export let highlightedRendering: UIEventSource<string> = undefined
2023-04-07 02:13:57 +02:00
2023-12-19 22:08:00 +01:00
export let tags: UIEventSource<Record<string, string>> = state.featureProperties.getStore(
selectedElement.properties.id
)
let _metatags: Record<string, string>
onDestroy(
state.userRelatedState.preferencesAsTags.addCallbackAndRun((tags) => {
_metatags = tags
})
)
2023-11-23 15:47:16 +01:00
2023-12-19 22:08:00 +01:00
let knownTagRenderings: Store<TagRenderingConfig[]> = tags.mapD((tgs) =>
layer.tagRenderings.filter(
(config) =>
(config.condition?.matchesProperties(tgs) ?? true) &&
(config.metacondition?.matchesProperties({ ...tgs, ..._metatags }) ?? true) &&
config.IsKnown(tgs)
)
)
2023-03-28 05:13:48 +02:00
</script>
{#if $tags._deleted === "yes"}
<Tr t={Translations.t.delete.isDeleted} />
<button class="w-full" on:click={() => state.selectedElement.setData(undefined)}>
<Tr t={Translations.t.general.returnToTheMap} />
</button>
{:else}
<div class="flex h-full w-full flex-col gap-y-2 overflow-y-auto p-1 px-2" tabindex="-1">
{#each $knownTagRenderings as config (config.id)}
2023-11-23 15:47:16 +01:00
<TagRenderingEditable
{tags}
{config}
{state}
{selectedElement}
{layer}
{highlightedRendering}
2023-12-19 22:08:00 +01:00
clss={$knownTagRenderings.length === 1
? "h-full"
: "tr-length-" + $knownTagRenderings.length}
2023-11-23 15:47:16 +01:00
/>
{/each}
</div>
{/if}