Move ImageOverlay to NoteEditor root

This commit is contained in:
Henrik Giesel 2022-09-13 23:04:12 +02:00
parent 36eea447d1
commit f25f5d1461
8 changed files with 52 additions and 25 deletions

View file

@ -67,7 +67,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
}); });
} }
$: disabled = !editingInputIsRichText($focusedInput); $: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
const incrementKeyCombination = "Control+Shift+C"; const incrementKeyCombination = "Control+Shift+C";
const sameKeyCombination = "Control+Alt+Shift+C"; const sameKeyCombination = "Control+Alt+Shift+C";

View file

@ -57,7 +57,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import Fields from "./Fields.svelte"; import Fields from "./Fields.svelte";
import FrameElement from "./FrameElement.svelte"; import FrameElement from "./FrameElement.svelte";
import { alertIcon } from "./icons"; import { alertIcon } from "./icons";
import ImageHandle from "./image-overlay"; import ImageOverlay from "./image-overlay";
import MathjaxOverlay from "./mathjax-overlay"; import MathjaxOverlay from "./mathjax-overlay";
import MathjaxElement from "./MathjaxElement.svelte"; import MathjaxElement from "./MathjaxElement.svelte";
import Notification from "./Notification.svelte"; import Notification from "./Notification.svelte";
@ -447,7 +447,6 @@ the AddCards dialog) should be implemented in the user of this component.
}} }}
bind:this={richTextInputs[index]} bind:this={richTextInputs[index]}
> >
<ImageHandle maxWidth={250} maxHeight={125} />
{#if insertSymbols} {#if insertSymbols}
<SymbolsOverlay /> <SymbolsOverlay />
{/if} {/if}
@ -483,6 +482,7 @@ the AddCards dialog) should be implemented in the user of this component.
</Fields> </Fields>
<MathjaxOverlay /> <MathjaxOverlay />
<ImageOverlay maxWidth={250} maxHeight={125} />
<div class="note-editor-tag-editor"> <div class="note-editor-tag-editor">
<TagEditor {tags} on:tagsupdate={saveTags} /> <TagEditor {tags} on:tagsupdate={saveTags} />

View file

@ -56,7 +56,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const { focusedInput } = context.get(); const { focusedInput } = context.get();
$: disabled = !editingInputIsRichText($focusedInput); $: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
let showFloating = false; let showFloating = false;
</script> </script>

View file

@ -25,7 +25,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
execCommand(key); execCommand(key);
} }
$: disabled = !editingInputIsRichText($focusedInput); $: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
</script> </script>
{#if withoutState} {#if withoutState}

View file

@ -66,7 +66,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
[onLatexMathEnv, "Control+T, M", tr.editingLatexMathEnv()], [onLatexMathEnv, "Control+T, M", tr.editingLatexMathEnv()],
]; ];
$: disabled = !editingInputIsRichText($focusedInput); $: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
let showFloating = false; let showFloating = false;
</script> </script>

View file

@ -19,7 +19,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { getPlatformString } from "../../lib/shortcuts"; import { getPlatformString } from "../../lib/shortcuts";
import { context } from "../NoteEditor.svelte"; import { context } from "../NoteEditor.svelte";
import { setFormat } from "../old-editor-adapter"; import { setFormat } from "../old-editor-adapter";
import { editingInputIsRichText } from "../rich-text-input"; import { editingInputIsRichText, RichTextInputAPI } from "../rich-text-input";
import { micIcon, paperclipIcon } from "./icons"; import { micIcon, paperclipIcon } from "./icons";
import LatexButton from "./LatexButton.svelte"; import LatexButton from "./LatexButton.svelte";
@ -35,12 +35,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
} }
function attachMediaOnFocus(): void { function attachMediaOnFocus(): void {
if (!editingInputIsRichText($focusedInput)) { if (disabled) {
return; return;
} }
[mediaPromise, resolve] = promiseWithResolver<string>(); [mediaPromise, resolve] = promiseWithResolver<string>();
$focusedInput.editable.focusHandler.focus.on( ($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
async () => setFormat("inserthtml", await mediaPromise), async () => setFormat("inserthtml", await mediaPromise),
{ once: true }, { once: true },
); );
@ -55,12 +55,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const recordCombination = "F5"; const recordCombination = "F5";
function attachRecordingOnFocus(): void { function attachRecordingOnFocus(): void {
if (!editingInputIsRichText($focusedInput)) { if (disabled) {
return; return;
} }
[mediaPromise, resolve] = promiseWithResolver<string>(); [mediaPromise, resolve] = promiseWithResolver<string>();
$focusedInput.editable.focusHandler.focus.on( ($focusedInput as RichTextInputAPI).editable.focusHandler.focus.on(
async () => setFormat("inserthtml", await mediaPromise), async () => setFormat("inserthtml", await mediaPromise),
{ once: true }, { once: true },
); );
@ -68,7 +68,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
bridgeCommand("record"); bridgeCommand("record");
} }
$: disabled = !editingInputIsRichText($focusedInput); $: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
export let api = {}; export let api = {};
</script> </script>

View file

@ -3,7 +3,7 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { onMount, tick } from "svelte"; import { tick } from "svelte";
import ButtonToolbar from "../../components/ButtonToolbar.svelte"; import ButtonToolbar from "../../components/ButtonToolbar.svelte";
import Popover from "../../components/Popover.svelte"; import Popover from "../../components/Popover.svelte";
@ -12,17 +12,52 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { on } from "../../lib/events"; import { on } from "../../lib/events";
import * as tr from "../../lib/ftl"; import * as tr from "../../lib/ftl";
import { removeStyleProperties } from "../../lib/styling"; import { removeStyleProperties } from "../../lib/styling";
import type { Callback } from "../../lib/typing";
import type { EditingInputAPI } from "../EditingArea.svelte";
import HandleBackground from "../HandleBackground.svelte"; import HandleBackground from "../HandleBackground.svelte";
import HandleControl from "../HandleControl.svelte"; import HandleControl from "../HandleControl.svelte";
import HandleLabel from "../HandleLabel.svelte"; import HandleLabel from "../HandleLabel.svelte";
import { context } from "../rich-text-input"; import { context } from "../NoteEditor.svelte";
import type { RichTextInputAPI } from "../rich-text-input";
import {
editingInputIsRichText,
lifecycle as richTextLifecycle,
} from "../rich-text-input";
import FloatButtons from "./FloatButtons.svelte"; import FloatButtons from "./FloatButtons.svelte";
import SizeSelect from "./SizeSelect.svelte"; import SizeSelect from "./SizeSelect.svelte";
export let maxWidth: number; export let maxWidth: number;
export let maxHeight: number; export let maxHeight: number;
const { element } = context.get(); richTextLifecycle.onMount(({ element }: RichTextInputAPI): void => {
(async () => {
const container = await element;
container.style.setProperty("--editor-shrink-max-width", `${maxWidth}px`);
container.style.setProperty("--editor-shrink-max-height", `${maxHeight}px`);
})();
});
const { focusedInput } = context.get();
let cleanup: Callback;
let richTextInput: RichTextInputAPI | null = null;
async function initialize(input: EditingInputAPI | null): Promise<void> {
cleanup?.();
if (!input || !editingInputIsRichText(input)) {
richTextInput = null;
return;
}
const container = await input.element;
cleanup = on(container, "click", maybeShowHandle);
richTextInput = input;
}
$: initialize($focusedInput);
let activeImage: HTMLImageElement | null = null; let activeImage: HTMLImageElement | null = null;
@ -101,7 +136,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
$: observes = Boolean(activeImage); $: observes = Boolean(activeImage);
async function toggleResizeObserver(observes: boolean) { async function toggleResizeObserver(observes: boolean) {
const container = await element; const container = await richTextInput!.element;
if (observes) { if (observes) {
resizeObserver.observe(container); resizeObserver.observe(container);
@ -193,15 +228,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
activeImage!.removeAttribute("width"); activeImage!.removeAttribute("width");
} }
onMount(async () => {
const container = await element;
container.style.setProperty("--editor-shrink-max-width", `${maxWidth}px`);
container.style.setProperty("--editor-shrink-max-height", `${maxHeight}px`);
return on(container, "click", maybeShowHandle);
});
let shrinkingDisabled: boolean; let shrinkingDisabled: boolean;
$: shrinkingDisabled = $: shrinkingDisabled =
Number(actualWidth) <= maxWidth && Number(actualHeight) <= maxHeight; Number(actualWidth) <= maxWidth && Number(actualHeight) <= maxHeight;

View file

@ -54,6 +54,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
context, context,
editingInputIsRichText, editingInputIsRichText,
globalInputHandler as inputHandler, globalInputHandler as inputHandler,
lifecycle,
surrounder, surrounder,
}; };
</script> </script>