0d83581ab0
* Move Trigger into its own file * Try implement HandlerList * Implement new input handler and handler-list * Use new refocus HandlerList in TextColorButton * Fix TextColorButton on windows * Move ColorPicker to editor-toolbar * Change trigger behavior of overwriteSurround * Fix mathjax-overlay flushCaret * Insert image via bridgeCommand return value * Fix invoking color picker with F8 * Have remove format work even when collapsed * Satisfy formatter * Insert media via callback resolved from python * Replace print with web.eval * Fix python formatting * remove unused function (dae)
67 lines
1.8 KiB
Svelte
67 lines
1.8 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script context="module" lang="ts">
|
|
export type { ContentEditableAPI } from "./content-editable";
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import type { Writable } from "svelte/store";
|
|
|
|
import { updateAllState } from "../components/WithState.svelte";
|
|
import actionList from "../sveltelib/action-list";
|
|
import type { MirrorAction } from "../sveltelib/dom-mirror";
|
|
import type { SetupInputHandlerAction } from "../sveltelib/input-handler";
|
|
import type { ContentEditableAPI } from "./content-editable";
|
|
import { preventBuiltinShortcuts, useFocusHandler } from "./content-editable";
|
|
|
|
export let resolve: (editable: HTMLElement) => void;
|
|
|
|
export let mirrors: MirrorAction[];
|
|
export let nodes: Writable<DocumentFragment>;
|
|
|
|
const mirrorAction = actionList(mirrors);
|
|
const mirrorOptions = { store: nodes };
|
|
|
|
export let inputHandlers: SetupInputHandlerAction[];
|
|
|
|
const inputHandlerAction = actionList(inputHandlers);
|
|
|
|
export let api: Partial<ContentEditableAPI>;
|
|
|
|
const [focusHandler, setupFocusHandling] = useFocusHandler();
|
|
|
|
Object.assign(api, { focusHandler });
|
|
</script>
|
|
|
|
<anki-editable
|
|
contenteditable="true"
|
|
use:resolve
|
|
use:setupFocusHandling
|
|
use:preventBuiltinShortcuts
|
|
use:mirrorAction={mirrorOptions}
|
|
use:inputHandlerAction={{}}
|
|
on:focus
|
|
on:blur
|
|
on:click={updateAllState}
|
|
on:keyup={updateAllState}
|
|
/>
|
|
|
|
<style lang="scss">
|
|
anki-editable {
|
|
display: block;
|
|
padding: 6px;
|
|
overflow: auto;
|
|
overflow-wrap: anywhere;
|
|
/* fallback for iOS */
|
|
word-break: break-word;
|
|
|
|
&:focus {
|
|
outline: none;
|
|
}
|
|
}
|
|
|
|
/* editable-base.scss contains styling targeting user HTML */
|
|
</style>
|