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
|
|
|
|
-->
|
|
|
|
<script lang="typescript">
|
|
|
|
import Detachable from "components/Detachable.svelte";
|
|
|
|
|
|
|
|
import type { ButtonGroupRegistration } from "./buttons";
|
|
|
|
import type { Register } from "./registration";
|
|
|
|
|
|
|
|
import { getContext, hasContext } from "svelte";
|
|
|
|
import { buttonToolbarKey } from "./contextKeys";
|
|
|
|
|
|
|
|
export let id: string | undefined = undefined;
|
|
|
|
export let registration: ButtonGroupRegistration | undefined = undefined;
|
|
|
|
|
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-06 19:26:50 +02:00
|
|
|
} else if (hasContext(buttonToolbarKey)) {
|
|
|
|
const registerComponent = getContext<Register<ButtonGroupRegistration>>(
|
|
|
|
buttonToolbarKey
|
|
|
|
);
|
|
|
|
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>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
div {
|
|
|
|
display: contents;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<!-- div is necessary to preserve item position -->
|
|
|
|
<div {id}>
|
2021-05-07 14:31:08 +02:00
|
|
|
<Detachable {detached}>
|
2021-05-06 19:26:50 +02:00
|
|
|
<slot />
|
|
|
|
</Detachable>
|
|
|
|
</div>
|