d110c4916c
* Introduce setting to collapse field by default * Fix schema order * Change wording from adjective to imperative sounds a bit less clunky * Update rslib/src/notetype/schema11.rs (dae) * Keep settings in single column * Add back Toggle Visual Editor string * Add RichTextBadge component and show it conditionally * Reverse input order depending on default setting * Make PlainTextInput border-radius responsive to toggle states * Prevent first Collapsible transition differently * Focus inputs after Collapsible transition The double tick calls are just a temporary solution until I find the exact moment an input is focusable again. * Use requestAnimationFrame to await focusable state Note: Svelte tick doesn't seem to work in this scenario.
60 lines
1.5 KiB
Svelte
60 lines
1.5 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 { createEventDispatcher, onMount } from "svelte";
|
|
|
|
import Badge from "../components/Badge.svelte";
|
|
import * as tr from "../lib/ftl";
|
|
import { getPlatformString, registerShortcut } from "../lib/shortcuts";
|
|
import { context as editorFieldContext } from "./EditorField.svelte";
|
|
import { richTextIcon } from "./icons";
|
|
|
|
const editorField = editorFieldContext.get();
|
|
const keyCombination = "Control+Shift+X";
|
|
const dispatch = createEventDispatcher();
|
|
|
|
export let visible = false;
|
|
export let off = false;
|
|
|
|
function toggle() {
|
|
dispatch("toggle");
|
|
}
|
|
|
|
function shortcut(target: HTMLElement): () => void {
|
|
return registerShortcut(toggle, keyCombination, { target });
|
|
}
|
|
|
|
onMount(() => editorField.element.then(shortcut));
|
|
</script>
|
|
|
|
<span
|
|
class="plain-text-badge"
|
|
class:visible
|
|
class:highlighted={!off}
|
|
on:click|stopPropagation={toggle}
|
|
>
|
|
<Badge
|
|
tooltip="{tr.editingToggleVisualEditor()} ({getPlatformString(keyCombination)})"
|
|
iconSize={80}>{@html richTextIcon}</Badge
|
|
>
|
|
</span>
|
|
|
|
<style lang="scss">
|
|
span {
|
|
cursor: pointer;
|
|
opacity: 0;
|
|
|
|
&.visible {
|
|
opacity: 0.4;
|
|
&:hover {
|
|
opacity: 0.8;
|
|
}
|
|
}
|
|
&.highlighted {
|
|
opacity: 1;
|
|
}
|
|
}
|
|
</style>
|