2021-07-21 16:48:02 +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-10-18 14:01:15 +02:00
|
|
|
import { getContext } from "svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { createEventDispatcher } from "svelte";
|
|
|
|
import type { Readable } from "svelte/store";
|
2021-07-21 16:48:02 +02:00
|
|
|
|
2021-10-18 14:01:15 +02:00
|
|
|
import ButtonGroup from "../../components/ButtonGroup.svelte";
|
|
|
|
import IconButton from "../../components/IconButton.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { directionKey } from "../../lib/context-keys";
|
|
|
|
import * as tr from "../../lib/ftl";
|
2022-09-05 09:20:00 +02:00
|
|
|
import { removeStyleProperties } from "../../lib/styling";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { floatLeftIcon, floatNoneIcon, floatRightIcon } from "./icons";
|
2021-07-21 16:48:02 +02:00
|
|
|
|
2021-08-06 02:19:36 +02:00
|
|
|
export let image: HTMLImageElement;
|
2021-07-21 16:48:02 +02:00
|
|
|
|
2022-09-05 09:20:00 +02:00
|
|
|
$: floatStyle = getComputedStyle(image).float;
|
|
|
|
|
2021-10-18 14:01:15 +02:00
|
|
|
const direction = getContext<Readable<"ltr" | "rtl">>(directionKey);
|
|
|
|
const [inlineStartIcon, inlineEndIcon] =
|
|
|
|
$direction === "ltr"
|
|
|
|
? [floatLeftIcon, floatRightIcon]
|
|
|
|
: [floatRightIcon, floatLeftIcon];
|
2021-08-06 03:53:44 +02:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
2021-07-21 16:48:02 +02:00
|
|
|
</script>
|
|
|
|
|
2021-09-02 21:01:29 +02:00
|
|
|
<ButtonGroup size={1.6} wrap={false}>
|
2022-02-03 05:52:11 +01:00
|
|
|
<IconButton
|
|
|
|
tooltip={tr.editingFloatLeft()}
|
2022-09-05 09:20:00 +02:00
|
|
|
active={floatStyle === "left"}
|
2022-02-03 05:52:11 +01:00
|
|
|
flipX={$direction === "rtl"}
|
|
|
|
on:click={() => {
|
|
|
|
image.style.float = "left";
|
|
|
|
setTimeout(() => dispatch("update"));
|
|
|
|
}}
|
|
|
|
--border-left-radius="5px">{@html inlineStartIcon}</IconButton
|
|
|
|
>
|
2021-07-21 16:48:02 +02:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<IconButton
|
|
|
|
tooltip={tr.editingFloatNone()}
|
2022-09-05 09:20:00 +02:00
|
|
|
active={floatStyle === "none"}
|
2022-02-03 05:52:11 +01:00
|
|
|
flipX={$direction === "rtl"}
|
|
|
|
on:click={() => {
|
2022-09-05 09:20:00 +02:00
|
|
|
// We shortly set to none, because simply unsetting float will not
|
|
|
|
// trigger floatStyle being reset
|
|
|
|
image.style.float = "none";
|
|
|
|
removeStyleProperties(image, "float");
|
2022-02-03 05:52:11 +01:00
|
|
|
setTimeout(() => dispatch("update"));
|
|
|
|
}}>{@html floatNoneIcon}</IconButton
|
|
|
|
>
|
2021-07-21 16:48:02 +02:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<IconButton
|
|
|
|
tooltip={tr.editingFloatRight()}
|
2022-09-05 09:20:00 +02:00
|
|
|
active={floatStyle === "right"}
|
2022-02-03 05:52:11 +01:00
|
|
|
flipX={$direction === "rtl"}
|
|
|
|
on:click={() => {
|
|
|
|
image.style.float = "right";
|
|
|
|
setTimeout(() => dispatch("update"));
|
|
|
|
}}
|
|
|
|
--border-right-radius="5px">{@html inlineEndIcon}</IconButton
|
|
|
|
>
|
2021-07-21 16:48:02 +02:00
|
|
|
</ButtonGroup>
|