68fa661b53
* Move up MathjaxOverlay to be initialized only once * Move ImageOverlay to NoteEditor root * Move Symbols Overlay to NoteEditor root * Refactor image overlay to not require second mutation observer * Use elevation + overflow:hidden in Editorfield * Make it possible to show input next to each other again * Set handle background color to code bg * Make Collapsible unmount the component * Simplify how decorated elements are mounted * Set RichTextInput background to frame-bg again * Strip out FocusTrap code * Revert "Make Collapsible unmount the component" This reverts commit 52722065ea199fa57ae750fa34bf47ee1c5aab3c. * Allow clicking on label container to unfocus field * Fix mathjax overlay resetting too its api too soon * Allow scrolling on overlays * Set focus-border border-color in focused field * Fix background color of fields * Add back grid-gap removed it during merge to see if margin-top would behave any differently - which is not the case. * Fix double border issue within Collapsible.svelte * Format * Edit appearance of focused fields a bit * Remove unused properties * Include elevation in button_mixins_lib * Give label-container a background color Co-authored-by: Henrik Giesel <hengiesel@gmail.com>
115 lines
3.1 KiB
Svelte
115 lines
3.1 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">
|
|
import type { Writable } from "svelte/store";
|
|
|
|
import contextProperty from "../sveltelib/context-property";
|
|
|
|
export interface FocusableInputAPI {
|
|
readonly name: string;
|
|
focusable: boolean;
|
|
/**
|
|
* The reaction to a user-initiated focus, e.g. by clicking on the
|
|
* editor label, or pressing Tab.
|
|
*/
|
|
focus(): void;
|
|
/**
|
|
* Behaves similar to a refresh, e.g. sync with content, put the caret
|
|
* into a neutral position, and/or clear selections.
|
|
*/
|
|
refocus(): void;
|
|
}
|
|
|
|
export interface EditingInputAPI extends FocusableInputAPI {
|
|
/**
|
|
* Check whether blurred target belongs to an editing input.
|
|
* The editing area can then restore focus to this input.
|
|
*
|
|
* @returns An editing input api that is associated with the event target.
|
|
*/
|
|
getInputAPI(target: EventTarget): Promise<FocusableInputAPI | null>;
|
|
}
|
|
|
|
export interface EditingAreaAPI {
|
|
content: Writable<string>;
|
|
editingInputs: Writable<EditingInputAPI[]>;
|
|
focus(): void;
|
|
refocus(): void;
|
|
}
|
|
|
|
const key = Symbol("editingArea");
|
|
const [context, setContextProperty] = contextProperty<EditingAreaAPI>(key);
|
|
|
|
export { context };
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import { setContext as svelteSetContext } from "svelte";
|
|
import { writable } from "svelte/store";
|
|
|
|
import { fontFamilyKey, fontSizeKey } from "../lib/context-keys";
|
|
|
|
export let fontFamily: string;
|
|
const fontFamilyStore = writable(fontFamily);
|
|
$: $fontFamilyStore = fontFamily;
|
|
svelteSetContext(fontFamilyKey, fontFamilyStore);
|
|
|
|
export let fontSize: number;
|
|
const fontSizeStore = writable(fontSize);
|
|
$: $fontSizeStore = fontSize;
|
|
svelteSetContext(fontSizeKey, fontSizeStore);
|
|
|
|
export let content: Writable<string>;
|
|
|
|
let editingArea: HTMLElement;
|
|
|
|
const inputsStore = writable<EditingInputAPI[]>([]);
|
|
$: editingInputs = $inputsStore;
|
|
|
|
function getAvailableInput(): EditingInputAPI | undefined {
|
|
return editingInputs.find((input) => input.focusable);
|
|
}
|
|
|
|
function focus(): void {
|
|
editingArea.contains(document.activeElement);
|
|
}
|
|
|
|
function refocus(): void {
|
|
const availableInput = getAvailableInput();
|
|
|
|
if (availableInput) {
|
|
availableInput.refocus();
|
|
}
|
|
}
|
|
|
|
let apiPartial: Partial<EditingAreaAPI>;
|
|
export { apiPartial as api };
|
|
|
|
const api = Object.assign(apiPartial, {
|
|
content,
|
|
editingInputs: inputsStore,
|
|
focus,
|
|
refocus,
|
|
});
|
|
|
|
setContextProperty(api);
|
|
</script>
|
|
|
|
<div bind:this={editingArea} class="editing-area">
|
|
<slot />
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
.editing-area {
|
|
display: grid;
|
|
/* TODO allow configuration of grid #1503 */
|
|
/* grid-template-columns: repeat(2, 1fr); */
|
|
|
|
/* This defines the border between inputs */
|
|
grid-gap: 1px;
|
|
background-color: var(--border);
|
|
}
|
|
</style>
|