2022-01-24 02:43:09 +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">
|
|
|
|
import ButtonGroup from "../../components/ButtonGroup.svelte";
|
2022-02-03 05:52:11 +01:00
|
|
|
import ButtonGroupItem, {
|
|
|
|
createProps,
|
|
|
|
setSlotHostContext,
|
2022-02-04 09:36:34 +01:00
|
|
|
updatePropsList,
|
2022-02-03 05:52:11 +01:00
|
|
|
} from "../../components/ButtonGroupItem.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import DynamicallySlottable from "../../components/DynamicallySlottable.svelte";
|
2022-01-24 02:43:09 +01:00
|
|
|
import IconButton from "../../components/IconButton.svelte";
|
|
|
|
import Shortcut from "../../components/Shortcut.svelte";
|
|
|
|
import { bridgeCommand } from "../../lib/bridgecommand";
|
2022-02-04 09:36:34 +01:00
|
|
|
import * as tr from "../../lib/ftl";
|
2022-02-25 01:59:06 +01:00
|
|
|
import { promiseWithResolver } from "../../lib/promise";
|
|
|
|
import { registerPackage } from "../../lib/runtime-require";
|
2022-01-24 02:43:09 +01:00
|
|
|
import { getPlatformString } from "../../lib/shortcuts";
|
2022-02-03 05:52:11 +01:00
|
|
|
import { context } from "../NoteEditor.svelte";
|
2022-02-25 01:59:06 +01:00
|
|
|
import { setFormat } from "../old-editor-adapter";
|
2022-10-27 01:11:36 +02:00
|
|
|
import { editingInputIsRichText, RichTextInputAPI } from "../rich-text-input";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { micIcon, paperclipIcon } from "./icons";
|
|
|
|
import LatexButton from "./LatexButton.svelte";
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
const { focusedInput } = context.get();
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
const attachmentCombination = "F3";
|
|
|
|
|
|
|
|
let mediaPromise: Promise<string>;
|
|
|
|
let resolve: (media: string) => void;
|
|
|
|
|
2022-03-16 01:29:06 +01:00
|
|
|
function resolveMedia(media: string): void {
|
|
|
|
resolve?.(media);
|
2022-02-25 01:59:06 +01:00
|
|
|
}
|
|
|
|
|
2022-03-16 01:29:06 +01:00
|
|
|
function attachMediaOnFocus(): void {
|
2022-10-27 01:11:36 +02:00
|
|
|
if (disabled) {
|
2022-02-25 01:59:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[mediaPromise, resolve] = promiseWithResolver<string>();
|
2022-10-27 01:11:36 +02:00
|
|
|
($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
|
2022-02-25 01:59:06 +01:00
|
|
|
async () => setFormat("inserthtml", await mediaPromise),
|
|
|
|
{ once: true },
|
|
|
|
);
|
|
|
|
|
2022-01-24 02:43:09 +01:00
|
|
|
bridgeCommand("attach");
|
|
|
|
}
|
|
|
|
|
2022-03-16 01:29:06 +01:00
|
|
|
registerPackage("anki/TemplateButtons", {
|
|
|
|
resolveMedia,
|
|
|
|
});
|
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
const recordCombination = "F5";
|
|
|
|
|
2022-03-16 01:29:06 +01:00
|
|
|
function attachRecordingOnFocus(): void {
|
2022-10-27 01:11:36 +02:00
|
|
|
if (disabled) {
|
2022-02-25 01:59:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[mediaPromise, resolve] = promiseWithResolver<string>();
|
2022-10-27 01:11:36 +02:00
|
|
|
($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
|
2022-02-25 01:59:06 +01:00
|
|
|
async () => setFormat("inserthtml", await mediaPromise),
|
|
|
|
{ once: true },
|
|
|
|
);
|
|
|
|
|
2022-01-24 02:43:09 +01:00
|
|
|
bridgeCommand("record");
|
|
|
|
}
|
|
|
|
|
2022-10-27 01:11:36 +02:00
|
|
|
$: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
|
2022-02-03 05:52:11 +01:00
|
|
|
|
|
|
|
export let api = {};
|
2022-01-24 02:43:09 +01:00
|
|
|
</script>
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<ButtonGroup>
|
|
|
|
<DynamicallySlottable
|
|
|
|
slotHost={ButtonGroupItem}
|
|
|
|
{createProps}
|
|
|
|
{updatePropsList}
|
|
|
|
{setSlotHostContext}
|
|
|
|
{api}
|
|
|
|
>
|
|
|
|
<ButtonGroupItem>
|
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingAttachPicturesaudiovideo()} ({getPlatformString(
|
2022-02-25 01:59:06 +01:00
|
|
|
attachmentCombination,
|
2022-02-03 05:52:11 +01:00
|
|
|
)})"
|
|
|
|
iconSize={70}
|
|
|
|
{disabled}
|
2022-03-16 01:29:06 +01:00
|
|
|
on:click={attachMediaOnFocus}
|
2022-02-03 05:52:11 +01:00
|
|
|
>
|
|
|
|
{@html paperclipIcon}
|
|
|
|
</IconButton>
|
2022-03-16 01:29:06 +01:00
|
|
|
<Shortcut
|
|
|
|
keyCombination={attachmentCombination}
|
|
|
|
on:action={attachMediaOnFocus}
|
|
|
|
/>
|
2022-02-03 05:52:11 +01:00
|
|
|
</ButtonGroupItem>
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<ButtonGroupItem>
|
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingRecordAudio()} ({getPlatformString(
|
2022-02-25 01:59:06 +01:00
|
|
|
recordCombination,
|
2022-02-03 05:52:11 +01:00
|
|
|
)})"
|
|
|
|
iconSize={70}
|
|
|
|
{disabled}
|
2022-03-16 01:29:06 +01:00
|
|
|
on:click={attachRecordingOnFocus}
|
2022-02-03 05:52:11 +01:00
|
|
|
>
|
|
|
|
{@html micIcon}
|
|
|
|
</IconButton>
|
2022-03-16 01:29:06 +01:00
|
|
|
<Shortcut
|
|
|
|
keyCombination={recordCombination}
|
|
|
|
on:action={attachRecordingOnFocus}
|
|
|
|
/>
|
2022-02-03 05:52:11 +01:00
|
|
|
</ButtonGroupItem>
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<ButtonGroupItem>
|
|
|
|
<LatexButton />
|
|
|
|
</ButtonGroupItem>
|
|
|
|
</DynamicallySlottable>
|
2022-01-24 02:43:09 +01:00
|
|
|
</ButtonGroup>
|