2021-04-13 10:57:08 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-02-09 04:38:04 +01:00
|
|
|
|
2022-08-31 15:34:39 +02:00
|
|
|
import type { PlainTextInputAPI } from "./plain-text-input";
|
|
|
|
import type { RichTextInputAPI } from "./rich-text-input";
|
|
|
|
|
2022-02-22 13:17:22 +01:00
|
|
|
function isFontElement(element: Element): element is HTMLFontElement {
|
|
|
|
return element.tagName === "FONT";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Avoid both HTMLFontElement and .color, as they are both deprecated
|
|
|
|
*/
|
|
|
|
export function withFontColor(
|
|
|
|
element: Element,
|
|
|
|
callback: (color: string) => void,
|
|
|
|
): boolean {
|
|
|
|
if (isFontElement(element)) {
|
|
|
|
callback(element.color);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2022-08-31 15:34:39 +02:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Required for field inputs wrapped in Collapsible
|
|
|
|
*/
|
|
|
|
export async function refocusInput(
|
|
|
|
api: RichTextInputAPI | PlainTextInputAPI,
|
|
|
|
): Promise<void> {
|
|
|
|
do {
|
|
|
|
await new Promise(window.requestAnimationFrame);
|
|
|
|
} while (!api.focusable);
|
|
|
|
api.refocus();
|
|
|
|
}
|