anki/ts/editor/NoteCreator.svelte
Matthias Metelka d902b00d0e
Fix reduce motion bottom border issues (#2185)
* Fix reduce motion bottom border issues

* Disable show/hide on hover with reduce motion setting

for purists.
2022-11-08 22:57:10 +10:00

52 lines
1.4 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
import { onDestroy, onMount } from "svelte";
import { bridgeCommand } from "../lib/bridgecommand";
import { registerShortcut } from "../lib/shortcuts";
import type { NoteEditorAPI } from "./NoteEditor.svelte";
import NoteEditor from "./NoteEditor.svelte";
import StickyBadge from "./StickyBadge.svelte";
const api: Partial<NoteEditorAPI> = {};
let noteEditor: NoteEditor;
export let uiResolve: (api: NoteEditorAPI) => void;
$: if (noteEditor) {
uiResolve(api as NoteEditorAPI);
}
let stickies: boolean[] = [];
function setSticky(stckies: boolean[]): void {
stickies = stckies;
}
function toggleStickyAll(): void {
bridgeCommand("toggleStickyAll", (values: boolean[]) => (stickies = values));
}
let deregisterSticky: () => void;
export function activateStickyShortcuts() {
deregisterSticky = registerShortcut(toggleStickyAll, "Shift+F9");
}
onMount(() => {
Object.assign(globalThis, {
setSticky,
});
});
onDestroy(() => deregisterSticky);
</script>
<NoteEditor bind:this={noteEditor} {api}>
<svelte:fragment slot="field-state" let:index let:show>
<StickyBadge bind:active={stickies[index]} {index} {show} />
</svelte:fragment>
</NoteEditor>