Allow drag-dropping into plaintext editor (#3902)

* expose field index as data attr on container

* allow drag/dropping into fields' plaintext editors
This commit is contained in:
llama 2025-04-11 17:34:47 +08:00 committed by GitHub
parent 0f9216c127
commit d9c71a54cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View file

@ -60,6 +60,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export let collapsed = false;
export let flipInputs = false;
export let dupe = false;
export let index;
const directionStore = writable<"ltr" | "rtl">();
setContext(directionKey, directionStore);
@ -95,6 +96,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
on:mouseenter
on:mouseleave
role="presentation"
data-index={index}
>
<slot name="field-label" />

View file

@ -45,6 +45,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { bridgeCommand } from "@tslib/bridgecommand";
import { onMount, tick } from "svelte";
import { get, writable } from "svelte/store";
import { nodeIsCommonElement } from "@tslib/dom";
import Absolute from "$lib/components/Absolute.svelte";
import Badge from "$lib/components/Badge.svelte";
@ -322,15 +323,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
export function focusIfField(x: number, y: number): boolean {
const elements = document.elementsFromPoint(x, y);
const first = elements[0];
const first = elements[0].closest(".field-container");
if (first.shadowRoot) {
const richTextInput = first.shadowRoot.lastElementChild! as HTMLElement;
richTextInput.focus();
return true;
if (!first || !nodeIsCommonElement(first)) {
return false;
}
return false;
const index = parseInt(first.dataset?.index ?? "");
if (Number.isNaN(index) || !fields[index] || fieldsCollapsed[index]) {
return false;
}
if (richTextsHidden[index]) {
toggleRichTextInput(index);
} else {
richTextInputs[index].api.refocus();
}
return true;
}
let richTextInputs: RichTextInput[] = [];
@ -668,6 +679,7 @@ the AddCards dialog) should be implemented in the user of this component.
<EditorField
{field}
{content}
{index}
flipInputs={plainTextDefaults[index]}
api={fields[index]}
on:focusin={() => {