2021-05-06 19:26:50 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-10-26 00:43:02 +02:00
|
|
|
<script lang="ts">
|
2021-07-09 16:50:12 +02:00
|
|
|
import Detachable from "./Detachable.svelte";
|
2021-05-06 19:26:50 +02:00
|
|
|
|
2021-05-27 13:55:13 +02:00
|
|
|
import type { Register, Registration } from "./registration";
|
2021-05-06 19:26:50 +02:00
|
|
|
|
|
|
|
import { getContext, hasContext } from "svelte";
|
2021-06-30 19:55:56 +02:00
|
|
|
import { sectionKey } from "./context-keys";
|
2021-05-06 19:26:50 +02:00
|
|
|
|
|
|
|
export let id: string | undefined = undefined;
|
2021-05-27 13:55:13 +02:00
|
|
|
export let registration: Registration | undefined = undefined;
|
2021-05-06 19:26:50 +02:00
|
|
|
|
2021-05-07 14:31:08 +02:00
|
|
|
let detached: boolean;
|
2021-05-06 19:26:50 +02:00
|
|
|
|
|
|
|
if (registration) {
|
|
|
|
const { detach } = registration;
|
2021-05-07 14:31:08 +02:00
|
|
|
detach.subscribe((value: boolean) => (detached = value));
|
2021-05-27 13:55:13 +02:00
|
|
|
} else if (hasContext(sectionKey)) {
|
|
|
|
const registerComponent = getContext<Register<Registration>>(sectionKey);
|
2021-05-06 19:26:50 +02:00
|
|
|
const { detach } = registerComponent();
|
2021-05-07 14:31:08 +02:00
|
|
|
detach.subscribe((value: boolean) => (detached = value));
|
2021-05-06 19:26:50 +02:00
|
|
|
} else {
|
2021-05-07 14:31:08 +02:00
|
|
|
detached = false;
|
2021-05-06 19:26:50 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- div is necessary to preserve item position -->
|
2021-10-18 14:01:15 +02:00
|
|
|
<div class="item" {id}>
|
2021-05-07 14:31:08 +02:00
|
|
|
<Detachable {detached}>
|
2021-05-06 19:26:50 +02:00
|
|
|
<slot />
|
|
|
|
</Detachable>
|
|
|
|
</div>
|
2021-05-26 01:21:33 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
2021-10-28 11:37:52 +02:00
|
|
|
.item {
|
|
|
|
display: contents;
|
|
|
|
}
|
2021-05-26 01:21:33 +02:00
|
|
|
</style>
|