mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-07 08:54:42 +00:00
Apply prettier-compatible formatting across the repo to match the incoming oxfmt configuration. Mechanical reformat only — no logic changes. Covers YAML quote normalization, package.json key sorting, Markdown/TOML formatting, and minor TS whitespace tweaks.
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import type { KeyboardFocusScope } from "@/keyboard/actions";
|
|
|
|
function isElement(value: unknown): value is Element {
|
|
return typeof Element !== "undefined" && value instanceof Element;
|
|
}
|
|
|
|
function getFocusCandidateElements(target: EventTarget | null): Element[] {
|
|
const candidates: Element[] = [];
|
|
const pushUnique = (element: Element | null) => {
|
|
if (!element || candidates.includes(element)) {
|
|
return;
|
|
}
|
|
candidates.push(element);
|
|
};
|
|
|
|
if (isElement(target)) {
|
|
pushUnique(target);
|
|
}
|
|
|
|
if (typeof Node !== "undefined" && target instanceof Node) {
|
|
pushUnique(isElement(target.parentElement) ? target.parentElement : null);
|
|
}
|
|
|
|
if (typeof document !== "undefined" && isElement(document.activeElement)) {
|
|
pushUnique(document.activeElement);
|
|
}
|
|
|
|
return candidates;
|
|
}
|
|
|
|
export function resolveKeyboardFocusScope(input: {
|
|
target: EventTarget | null;
|
|
commandCenterOpen: boolean;
|
|
}): KeyboardFocusScope {
|
|
const { target, commandCenterOpen } = input;
|
|
const candidates = getFocusCandidateElements(target);
|
|
if (candidates.length === 0) {
|
|
return commandCenterOpen ? "command-center" : "other";
|
|
}
|
|
|
|
if (
|
|
candidates.some((element) =>
|
|
Boolean(element.closest("[data-testid='terminal-surface']") || element.closest(".xterm")),
|
|
)
|
|
) {
|
|
return "terminal";
|
|
}
|
|
|
|
if (
|
|
commandCenterOpen &&
|
|
candidates.some((element) =>
|
|
Boolean(
|
|
element.closest("[data-testid='command-center-panel']") ||
|
|
element.closest("[data-testid='command-center-input']"),
|
|
),
|
|
)
|
|
) {
|
|
return "command-center";
|
|
}
|
|
|
|
if (
|
|
candidates.some((element) => Boolean(element.closest("[data-testid='message-input-root']")))
|
|
) {
|
|
return "message-input";
|
|
}
|
|
|
|
if (
|
|
candidates.some((element) => {
|
|
const editable = element as HTMLElement;
|
|
if (editable.isContentEditable) {
|
|
return true;
|
|
}
|
|
const tag = element.tagName.toLowerCase();
|
|
return tag === "input" || tag === "textarea" || tag === "select";
|
|
})
|
|
) {
|
|
return commandCenterOpen ? "command-center" : "editable";
|
|
}
|
|
|
|
return commandCenterOpen ? "command-center" : "other";
|
|
}
|