2021-10-18 14:01:15 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2022-01-08 02:46:01 +01:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
export type { ContentEditableAPI } from "./content-editable";
|
|
|
|
</script>
|
|
|
|
|
2021-10-18 14:01:15 +02:00
|
|
|
<script lang="ts">
|
2022-06-22 01:53:10 +02:00
|
|
|
import type { Writable } from "svelte/store";
|
2022-02-04 09:36:34 +01:00
|
|
|
|
2021-10-18 14:01:15 +02:00
|
|
|
import { updateAllState } from "../components/WithState.svelte";
|
2022-01-08 02:46:01 +01:00
|
|
|
import actionList from "../sveltelib/action-list";
|
2022-02-25 01:59:06 +01:00
|
|
|
import type { MirrorAction } from "../sveltelib/dom-mirror";
|
|
|
|
import type { SetupInputHandlerAction } from "../sveltelib/input-handler";
|
2022-02-04 09:36:34 +01:00
|
|
|
import type { ContentEditableAPI } from "./content-editable";
|
2022-11-15 02:14:18 +01:00
|
|
|
import {
|
|
|
|
fixRTLKeyboardNav,
|
|
|
|
preventBuiltinShortcuts,
|
|
|
|
useFocusHandler,
|
|
|
|
} from "./content-editable";
|
2021-10-18 14:01:15 +02:00
|
|
|
|
|
|
|
export let resolve: (editable: HTMLElement) => void;
|
2021-11-18 10:18:39 +01:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
export let mirrors: MirrorAction[];
|
|
|
|
export let nodes: Writable<DocumentFragment>;
|
2021-11-09 03:53:39 +01:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
const mirrorAction = actionList(mirrors);
|
|
|
|
const mirrorOptions = { store: nodes };
|
2021-11-09 03:53:39 +01:00
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
export let inputHandlers: SetupInputHandlerAction[];
|
2021-11-23 01:27:32 +01:00
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
const inputHandlerAction = actionList(inputHandlers);
|
2021-11-09 03:53:39 +01:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
export let api: Partial<ContentEditableAPI>;
|
2021-11-18 10:18:39 +01:00
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
const [focusHandler, setupFocusHandling] = useFocusHandler();
|
2022-01-19 01:17:53 +01:00
|
|
|
|
2022-02-25 01:59:06 +01:00
|
|
|
Object.assign(api, { focusHandler });
|
2021-10-18 14:01:15 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<anki-editable
|
|
|
|
contenteditable="true"
|
2023-07-01 08:21:53 +02:00
|
|
|
role="textbox"
|
|
|
|
tabindex="0"
|
2021-10-18 14:01:15 +02:00
|
|
|
use:resolve
|
2022-01-19 01:17:53 +01:00
|
|
|
use:setupFocusHandling
|
2022-02-22 13:17:22 +01:00
|
|
|
use:preventBuiltinShortcuts
|
2022-11-15 02:14:18 +01:00
|
|
|
use:fixRTLKeyboardNav
|
2022-01-08 02:46:01 +01:00
|
|
|
use:mirrorAction={mirrorOptions}
|
2022-02-25 01:59:06 +01:00
|
|
|
use:inputHandlerAction={{}}
|
2021-11-18 10:18:39 +01:00
|
|
|
on:focus
|
|
|
|
on:blur
|
2021-10-18 14:01:15 +02:00
|
|
|
on:click={updateAllState}
|
|
|
|
on:keyup={updateAllState}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
anki-editable {
|
|
|
|
display: block;
|
2022-06-17 03:02:30 +02:00
|
|
|
position: relative;
|
2022-06-22 01:53:10 +02:00
|
|
|
|
2022-01-08 02:46:01 +01:00
|
|
|
overflow: auto;
|
2022-01-25 01:35:13 +01:00
|
|
|
overflow-wrap: anywhere;
|
|
|
|
/* fallback for iOS */
|
|
|
|
word-break: break-word;
|
2021-10-18 14:01:15 +02:00
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* editable-base.scss contains styling targeting user HTML */
|
|
|
|
</style>
|