2021-11-23 01:27:32 +01:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
2022-03-31 15:39:49 +02:00
|
|
|
import type CodeMirrorLib from "codemirror";
|
2021-11-23 01:27:32 +01:00
|
|
|
import { createEventDispatcher } from "svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import type { Writable } from "svelte/store";
|
|
|
|
|
|
|
|
import DropdownMenu from "../../components/DropdownMenu.svelte";
|
|
|
|
import Shortcut from "../../components/Shortcut.svelte";
|
2022-01-08 02:46:01 +01:00
|
|
|
import { placeCaretAfter } from "../../domlib/place-caret";
|
2022-01-10 03:51:50 +01:00
|
|
|
import { pageTheme } from "../../sveltelib/theme";
|
2022-02-04 09:36:34 +01:00
|
|
|
import MathjaxButtons from "./MathjaxButtons.svelte";
|
|
|
|
import MathjaxEditor from "./MathjaxEditor.svelte";
|
2021-11-23 01:27:32 +01:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
export let element: Element;
|
2021-11-23 01:27:32 +01:00
|
|
|
export let code: Writable<string>;
|
2022-03-31 15:39:49 +02:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
export let selectAll: boolean;
|
2022-03-31 15:39:49 +02:00
|
|
|
export let position: CodeMirrorLib.Position | undefined;
|
2021-11-23 01:27:32 +01:00
|
|
|
|
|
|
|
const acceptShortcut = "Enter";
|
|
|
|
const newlineShortcut = "Shift+Enter";
|
|
|
|
|
|
|
|
export let updateSelection: () => Promise<void>;
|
|
|
|
let dropdownApi: any;
|
|
|
|
|
|
|
|
export async function update() {
|
|
|
|
await updateSelection?.();
|
|
|
|
dropdownApi.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
</script>
|
|
|
|
|
2022-01-10 03:51:50 +01:00
|
|
|
<div class="mathjax-menu" class:light-theme={!$pageTheme.isDark}>
|
2022-01-08 02:46:01 +01:00
|
|
|
<slot />
|
2021-11-23 01:27:32 +01:00
|
|
|
|
|
|
|
<DropdownMenu>
|
|
|
|
<MathjaxEditor
|
|
|
|
{acceptShortcut}
|
|
|
|
{newlineShortcut}
|
|
|
|
{code}
|
2022-01-08 02:46:01 +01:00
|
|
|
{selectAll}
|
2022-03-31 15:39:49 +02:00
|
|
|
{position}
|
2021-11-23 01:27:32 +01:00
|
|
|
on:blur={() => dispatch("reset")}
|
2022-01-08 02:46:01 +01:00
|
|
|
on:moveoutstart
|
|
|
|
on:moveoutend
|
2022-05-13 05:04:20 +02:00
|
|
|
let:editor={mathjaxEditor}
|
|
|
|
>
|
|
|
|
<Shortcut
|
|
|
|
keyCombination={acceptShortcut}
|
|
|
|
on:action={() => dispatch("moveoutend")}
|
|
|
|
/>
|
2021-11-23 01:27:32 +01:00
|
|
|
|
2022-05-13 05:04:20 +02:00
|
|
|
<MathjaxButtons
|
|
|
|
{element}
|
|
|
|
on:delete={() => {
|
|
|
|
placeCaretAfter(element);
|
|
|
|
element.remove();
|
|
|
|
dispatch("reset");
|
|
|
|
}}
|
|
|
|
on:surround={async ({ detail }) => {
|
|
|
|
const editor = await mathjaxEditor.editor;
|
|
|
|
const { prefix, suffix } = detail;
|
2021-11-23 01:27:32 +01:00
|
|
|
|
2022-05-13 05:04:20 +02:00
|
|
|
editor.replaceSelection(prefix + editor.getSelection() + suffix);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</MathjaxEditor>
|
2021-11-23 01:27:32 +01:00
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.mathjax-menu :global(.dropdown-menu) {
|
|
|
|
border-color: var(--border);
|
|
|
|
}
|
2022-01-10 03:51:50 +01:00
|
|
|
|
|
|
|
.light-theme {
|
|
|
|
:global(.dropdown-menu) {
|
|
|
|
background-color: var(--window-bg);
|
|
|
|
}
|
|
|
|
|
|
|
|
:global(.CodeMirror) {
|
|
|
|
border-width: 1px 0;
|
|
|
|
border-style: solid;
|
|
|
|
border-color: var(--border);
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 01:27:32 +01:00
|
|
|
</style>
|