2021-08-04 22:01:03 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2021-08-06 04:59:33 +02:00
|
|
|
import WithDropdown from "components/WithDropdown.svelte";
|
|
|
|
import ButtonDropdown from "components/ButtonDropdown.svelte";
|
2021-08-06 16:52:34 +02:00
|
|
|
import DropdownMenu from "components/DropdownMenu.svelte";
|
2021-08-06 04:59:33 +02:00
|
|
|
import Item from "components/Item.svelte";
|
|
|
|
|
2021-08-05 23:34:26 +02:00
|
|
|
import HandleSelection from "./HandleSelection.svelte";
|
2021-08-05 23:45:45 +02:00
|
|
|
import HandleBackground from "./HandleBackground.svelte";
|
|
|
|
import HandleControl from "./HandleControl.svelte";
|
2021-08-06 00:59:52 +02:00
|
|
|
import MathjaxHandleInlineBlock from "./MathjaxHandleInlineBlock.svelte";
|
2021-08-06 16:52:34 +02:00
|
|
|
import MathjaxHandleEditor from "./MathjaxHandleEditor.svelte";
|
2021-08-05 23:34:26 +02:00
|
|
|
|
|
|
|
export let activeImage: HTMLImageElement | null = null;
|
|
|
|
export let container: HTMLElement;
|
2021-08-06 00:59:52 +02:00
|
|
|
export let isRtl: boolean;
|
|
|
|
|
2021-08-07 01:30:26 +02:00
|
|
|
const resizeObserver = new ResizeObserver(() => {
|
|
|
|
if (activeImage) {
|
|
|
|
updateSelection();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
resizeObserver.observe(container);
|
|
|
|
|
2021-08-06 00:59:52 +02:00
|
|
|
let updateSelection: () => void;
|
2021-08-06 16:52:34 +02:00
|
|
|
let edit = false;
|
2021-08-06 17:40:27 +02:00
|
|
|
|
|
|
|
function onUpdate(event: CustomEvent) {
|
|
|
|
activeImage!.parentElement!.dataset.mathjax = event.detail.mathjax;
|
|
|
|
setTimeout(updateSelection);
|
|
|
|
}
|
2021-08-04 22:01:03 +02:00
|
|
|
</script>
|
2021-08-05 23:34:26 +02:00
|
|
|
|
2021-08-06 04:59:33 +02:00
|
|
|
<WithDropdown
|
|
|
|
placement="bottom"
|
|
|
|
autoOpen={true}
|
|
|
|
autoClose={false}
|
|
|
|
let:createDropdown
|
|
|
|
let:dropdownObject
|
|
|
|
>
|
|
|
|
{#if activeImage}
|
|
|
|
<HandleSelection
|
|
|
|
image={activeImage}
|
|
|
|
{container}
|
|
|
|
offsetX={2}
|
|
|
|
offsetY={2}
|
|
|
|
bind:updateSelection
|
|
|
|
on:mount={(event) => createDropdown(event.detail.selection)}
|
2021-08-06 00:59:52 +02:00
|
|
|
>
|
2021-08-06 16:52:34 +02:00
|
|
|
<HandleBackground
|
|
|
|
on:click={(event) => event.stopPropagation()}
|
2021-08-06 17:40:27 +02:00
|
|
|
on:dblclick={() => (edit = !edit)}
|
2021-08-06 16:52:34 +02:00
|
|
|
/>
|
2021-08-06 04:59:33 +02:00
|
|
|
|
|
|
|
<HandleControl offsetX={1} offsetY={1} />
|
|
|
|
</HandleSelection>
|
|
|
|
|
2021-08-06 16:52:34 +02:00
|
|
|
{#if !edit}
|
|
|
|
<DropdownMenu>
|
|
|
|
<MathjaxHandleEditor
|
|
|
|
initialValue={activeImage.parentElement?.dataset.mathjax ?? ""}
|
2021-08-07 01:23:54 +02:00
|
|
|
on:update={(event) => {
|
|
|
|
onUpdate(event);
|
|
|
|
setTimeout(dropdownObject.update);
|
|
|
|
}}
|
2021-08-06 16:52:34 +02:00
|
|
|
/>
|
|
|
|
</DropdownMenu>
|
|
|
|
{:else}
|
|
|
|
<ButtonDropdown>
|
|
|
|
<div
|
|
|
|
on:click={() => {
|
|
|
|
updateSelection();
|
|
|
|
dropdownObject.update();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Item>
|
|
|
|
<MathjaxHandleInlineBlock {activeImage} {isRtl} />
|
|
|
|
</Item>
|
|
|
|
</div>
|
|
|
|
</ButtonDropdown>
|
|
|
|
{/if}
|
2021-08-06 04:59:33 +02:00
|
|
|
{/if}
|
|
|
|
</WithDropdown>
|