дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-29 05:52:23 +02:00
Tab on a database result tab stepped through every toolbar control (7 to 11 stops) before reaching the grid, and the grid then had no active cell. Now: - a new WAI-ARIA Toolbar (src/ui/Toolbar.tsx) makes the result, plan, Output and pager toolbars one Tab stop with roving focus on arrows/Home/End; - Tabs gets an optional focusContent prop, called on plain Tab, so Tab from a result tab focuses the grid (or plan tree / Output log); - the grid selects its first cell when focused from the keyboard, Tab / Shift+Tab move between cells row by row and leave the grid past either end, and Tab in the cell editor commits and moves on. Co-authored-by: Mr0Bread <[email protected]>
81 рядки
2.4 KiB
TypeScript
81 рядки
2.4 KiB
TypeScript
import { registerActions, type ActionContext } from "@/platform/actions";
|
|
import { setContext } from "@/platform/context";
|
|
|
|
export interface CellActions {
|
|
canToggle(): boolean;
|
|
canSetNull(): boolean;
|
|
canSetDefault(): boolean;
|
|
canFilter(): boolean;
|
|
toggle(): void;
|
|
setNull(): void;
|
|
setDefault(): void;
|
|
/** Opens the local filter of the selected cell's column. */
|
|
filter(): void;
|
|
}
|
|
|
|
const grids = new WeakMap<Element, CellActions>();
|
|
let active: CellActions | null = null;
|
|
|
|
export function registerCellGrid(root: Element, actions: CellActions): () => void {
|
|
grids.set(root, actions);
|
|
return () => {
|
|
grids.delete(root);
|
|
if (active === actions) {
|
|
active = null;
|
|
setContext("dbCellGridFocus", false);
|
|
}
|
|
};
|
|
}
|
|
|
|
export function installCellActions(): () => void {
|
|
const onFocus = (event: FocusEvent) => {
|
|
const target = event.target instanceof Element ? event.target : null;
|
|
const root = target?.closest("[data-db-cell-grid]");
|
|
active =
|
|
root && !target?.closest("input, textarea, select, [contenteditable='true']") ? (grids.get(root) ?? null) : null;
|
|
setContext("dbCellGridFocus", !!active);
|
|
};
|
|
document.addEventListener("focusin", onFocus);
|
|
const handle = ({ arg }: ActionContext) => (arg as CellActions | undefined) ?? active;
|
|
const dispose = registerActions([
|
|
{
|
|
id: "db.toggleBooleanCell",
|
|
title: "Toggle Boolean Cell",
|
|
category: "Database",
|
|
keyWhen: "dbCellGridFocus",
|
|
enabled: (c) => handle(c)?.canToggle() ?? false,
|
|
run: (c) => handle(c)?.toggle(),
|
|
},
|
|
{
|
|
id: "db.setCellNull",
|
|
title: "Set NULL",
|
|
category: "Database",
|
|
keyWhen: "dbCellGridFocus",
|
|
enabled: (c) => handle(c)?.canSetNull() ?? false,
|
|
run: (c) => handle(c)?.setNull(),
|
|
},
|
|
{
|
|
id: "db.setCellDefault",
|
|
title: "Set DEFAULT",
|
|
category: "Database",
|
|
keyWhen: "dbCellGridFocus",
|
|
enabled: (c) => handle(c)?.canSetDefault() ?? false,
|
|
run: (c) => handle(c)?.setDefault(),
|
|
},
|
|
{
|
|
id: "db.localFilter",
|
|
title: "Local Filter",
|
|
category: "Database",
|
|
keyWhen: "dbCellGridFocus",
|
|
enabled: (c) => handle(c)?.canFilter() ?? false,
|
|
run: (c) => handle(c)?.filter(),
|
|
},
|
|
]);
|
|
return () => {
|
|
dispose();
|
|
document.removeEventListener("focusin", onFocus);
|
|
active = null;
|
|
setContext("dbCellGridFocus", false);
|
|
};
|
|
}
|