mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-02 13:04:08 +01:00
Merge origin/main into stetta/tk_mwaz7asqhsi6jowm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
a14fc18b4b
44 files changed
+2715
-348
No files matched your search
@@ -78,8 +78,18 @@ export type DropdownItemDefault = {
|
||||
*/
|
||||
submenuTrigger?: "row" | "button";
|
||||
icon?: IconProps["icon"];
|
||||
/** Buttons over the row's right end, shown while it is hovered, each acting without selecting it */
|
||||
actions?: DropdownItemAction[];
|
||||
};
|
||||
|
||||
export interface DropdownItemAction {
|
||||
icon: IconProps["icon"];
|
||||
title: string;
|
||||
onSelect: () => void;
|
||||
/** Closes the menu after, as one opening a dialog does; the menu stays open otherwise */
|
||||
closeMenu?: boolean;
|
||||
}
|
||||
|
||||
export type DropdownItem = DropdownItemDefault | DropdownItemSeparator | DropdownItemContent;
|
||||
|
||||
export interface DropdownProps {
|
||||
@@ -819,6 +829,7 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
||||
onSelect={handleSelect}
|
||||
onHover={handleItemHover}
|
||||
onOpenSubmenu={(item, el) => setActiveSubmenu({ item, parent: el })}
|
||||
onCloseAll={handleCloseAll}
|
||||
// oxlint-disable-next-line no-array-index-key -- It's fine
|
||||
key={i}
|
||||
item={item}
|
||||
@@ -891,10 +902,15 @@ interface MenuItemProps {
|
||||
onFocus: (item: DropdownItemDefault) => void;
|
||||
onHover: (item: DropdownItemDefault, el: HTMLButtonElement) => void;
|
||||
onOpenSubmenu: (item: DropdownItemDefault, el: HTMLButtonElement) => void;
|
||||
/** Closes the whole menu, for an action that asks to */
|
||||
onCloseAll?: () => void;
|
||||
focused: boolean;
|
||||
isParentOfActiveSubmenu?: boolean;
|
||||
}
|
||||
|
||||
/** Room the row leaves at its right for the buttons over it, by how many there are */
|
||||
const ROW_BUTTONS_PADDING = ["", "pr-8", "pr-14", "pr-20"];
|
||||
|
||||
function MenuItem({
|
||||
className,
|
||||
focused,
|
||||
@@ -903,6 +919,7 @@ function MenuItem({
|
||||
item,
|
||||
onSelect,
|
||||
onOpenSubmenu,
|
||||
onCloseAll,
|
||||
isParentOfActiveSubmenu,
|
||||
...props
|
||||
}: MenuItemProps) {
|
||||
@@ -939,6 +956,9 @@ function MenuItem({
|
||||
};
|
||||
|
||||
const hasButtonSubmenu = item.submenu != null && item.submenuTrigger === "button";
|
||||
const actions = item.actions ?? [];
|
||||
// Buttons over the row: its actions, then its submenu's trigger
|
||||
const overlaid = actions.length + (hasButtonSubmenu ? 1 : 0);
|
||||
|
||||
const rightSlot =
|
||||
item.submenu && !hasButtonSubmenu ? (
|
||||
@@ -952,8 +972,8 @@ function MenuItem({
|
||||
ref={initRef}
|
||||
size="sm"
|
||||
tabIndex={-1}
|
||||
onMouseEnter={hasButtonSubmenu ? undefined : handleMouseEnter}
|
||||
onMouseLeave={hasButtonSubmenu ? undefined : (e) => e.currentTarget.blur()}
|
||||
onMouseEnter={overlaid > 0 ? undefined : handleMouseEnter}
|
||||
onMouseLeave={overlaid > 0 ? undefined : (e) => e.currentTarget.blur()}
|
||||
disabled={item.disabled}
|
||||
onFocus={handleFocus}
|
||||
onClick={handleClick}
|
||||
@@ -974,7 +994,7 @@ function MenuItem({
|
||||
"min-w-32 outline-hidden px-2 mx-1.5 flex whitespace-nowrap",
|
||||
"focus:bg-surface-highlight focus:text rounded-sm focus:outline-hidden focus-visible:outline-1",
|
||||
isParentOfActiveSubmenu && "bg-surface-highlight text rounded-sm",
|
||||
hasButtonSubmenu && "pr-8",
|
||||
ROW_BUTTONS_PADDING[overlaid],
|
||||
item.color === "danger" && "text-danger!",
|
||||
item.color === "primary" && "text-primary!",
|
||||
item.color === "success" && "text-success!",
|
||||
@@ -988,13 +1008,13 @@ function MenuItem({
|
||||
</Button>
|
||||
);
|
||||
|
||||
if (!hasButtonSubmenu) {
|
||||
if (overlaid === 0) {
|
||||
return button;
|
||||
}
|
||||
|
||||
// The submenu trigger overlays the row as a sibling (not a child) because the row is
|
||||
// itself a button and buttons cannot nest. Hover handling lives on this wrapper so the
|
||||
// row keeps its focus highlight while the mouse is over the trigger.
|
||||
// The actions and submenu trigger overlay the row as siblings (not children) because the row
|
||||
// is itself a button and buttons cannot nest. Hover handling lives on this wrapper so the
|
||||
// row keeps its focus highlight while the mouse is over them.
|
||||
return (
|
||||
<div
|
||||
className="relative grid group/menuitem"
|
||||
@@ -1013,23 +1033,44 @@ function MenuItem({
|
||||
"opacity-0 group-hover/menuitem:opacity-100 group-focus-within/menuitem:opacity-100",
|
||||
)}
|
||||
>
|
||||
<IconButton
|
||||
color="custom"
|
||||
size="2xs"
|
||||
tabIndex={-1}
|
||||
icon="ellipsis_vertical"
|
||||
iconColor="secondary"
|
||||
title="More actions"
|
||||
className="h-full! w-7!"
|
||||
onMouseDown={(e) => {
|
||||
// Prevent the trigger from stealing focus, which would unhighlight the row
|
||||
e.preventDefault();
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onOpenSubmenu(item, e.currentTarget);
|
||||
}}
|
||||
/>
|
||||
{actions.map((action) => (
|
||||
<IconButton
|
||||
key={action.title}
|
||||
color="custom"
|
||||
size="2xs"
|
||||
tabIndex={-1}
|
||||
icon={action.icon}
|
||||
iconColor="secondary"
|
||||
title={action.title}
|
||||
className="h-full! w-6!"
|
||||
// Prevent the button from stealing focus, which would unhighlight the row
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
action.onSelect();
|
||||
if (action.closeMenu) onCloseAll?.();
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
{hasButtonSubmenu && (
|
||||
<IconButton
|
||||
color="custom"
|
||||
size="2xs"
|
||||
tabIndex={-1}
|
||||
icon="ellipsis_vertical"
|
||||
iconColor="secondary"
|
||||
title="More actions"
|
||||
className="h-full! w-7!"
|
||||
onMouseDown={(e) => {
|
||||
// Prevent the trigger from stealing focus, which would unhighlight the row
|
||||
e.preventDefault();
|
||||
}}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onOpenSubmenu(item, e.currentTarget);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -34,6 +34,11 @@ export interface QueryFilterOptions {
|
||||
* searches. `typed` is the word, and the completions replace it.
|
||||
*/
|
||||
moreCompletions?: (typed: string) => Completion[];
|
||||
/**
|
||||
* Completions above the engine's while the box is empty, such as recent searches, each
|
||||
* replacing the whole text
|
||||
*/
|
||||
leadCompletions?: () => Completion[];
|
||||
/** The terms of a query the search cannot run, underlined as typing settles */
|
||||
problems?: (text: string) => Promise<QueryProblem[]>;
|
||||
/**
|
||||
@@ -139,6 +144,7 @@ function completionSource({
|
||||
values,
|
||||
loadValues,
|
||||
moreCompletions,
|
||||
leadCompletions,
|
||||
fieldsOnly,
|
||||
}: QueryFilterOptions) {
|
||||
return async (ctx: CompletionContext): Promise<CompletionResult | null> => {
|
||||
@@ -179,11 +185,14 @@ function completionSource({
|
||||
if (from === word.from) options.push(...more);
|
||||
}
|
||||
}
|
||||
if (options.length === 0) return null;
|
||||
|
||||
// Field names pop up for something typed; on an empty spot, only when asked for
|
||||
const onlyFields = options.every((o) => o.type === "field");
|
||||
if (onlyFields && from === to && !ctx.explicit) return null;
|
||||
if (onlyFields && from === to && !ctx.explicit) options.length = 0;
|
||||
|
||||
// In an empty box, both they and the leading ones start at its start
|
||||
const lead = text === "" ? (leadCompletions?.() ?? []) : [];
|
||||
options.unshift(...lead);
|
||||
if (options.length === 0) return null;
|
||||
|
||||
// The engine has already filtered and ranked the options
|
||||
return { from, to, options, filter: false };
|
||||
|
||||
@@ -114,6 +114,8 @@ export interface HttpRequestPaneViewProps {
|
||||
* request doesn't carry to the next
|
||||
*/
|
||||
defaultTab?: string;
|
||||
/** The tab to show over any remembered, while this request offers it */
|
||||
activeTab?: string;
|
||||
/** A tab was chosen */
|
||||
onTabChange?: (tab: string) => void;
|
||||
}
|
||||
@@ -165,6 +167,7 @@ export function HttpRequestPaneView({
|
||||
extraTabs,
|
||||
urlLine,
|
||||
defaultTab,
|
||||
activeTab,
|
||||
onTabChange,
|
||||
}: HttpRequestPaneViewProps) {
|
||||
const { ErrorBoundary } = useEditorHost();
|
||||
@@ -284,6 +287,7 @@ export function HttpRequestPaneView({
|
||||
storageKey={tabsStorageKey}
|
||||
activeTabKey={request.id}
|
||||
defaultValue={defaultTab}
|
||||
value={activeTab}
|
||||
keyedDefault={defaultTab != null}
|
||||
onChangeValue={onTabChange}
|
||||
>
|
||||
|
||||
@@ -85,6 +85,8 @@ export interface HttpResponsePaneViewProps {
|
||||
* doesn't carry to the next
|
||||
*/
|
||||
defaultTab?: string;
|
||||
/** The tab to show over any remembered, while this response offers it */
|
||||
activeTab?: string;
|
||||
/** A tab was chosen */
|
||||
onTabChange?: (tab: string) => void;
|
||||
}
|
||||
@@ -116,6 +118,7 @@ export function HttpResponsePaneView({
|
||||
requestShownApart = false,
|
||||
bare = false,
|
||||
defaultTab,
|
||||
activeTab,
|
||||
onTabChange,
|
||||
}: HttpResponsePaneViewProps) {
|
||||
const { ErrorBoundary } = useEditorHost();
|
||||
@@ -264,6 +267,7 @@ export function HttpResponsePaneView({
|
||||
storageKey={tabsStorageKey}
|
||||
activeTabKey={activeTabKey}
|
||||
defaultValue={defaultTab}
|
||||
value={activeTab}
|
||||
keyedDefault={defaultTab != null}
|
||||
onChangeValue={onTabChange}
|
||||
>
|
||||
|
||||
@@ -75,6 +75,11 @@ export interface TabsProps {
|
||||
label: string;
|
||||
/** Default tab value. If not provided, defaults to first tab. */
|
||||
defaultValue?: string;
|
||||
/**
|
||||
* The tab shown, over the one stored or last chosen, while it is offered. Choosing another
|
||||
* still calls `onChangeValue`, for the owner to pass it back.
|
||||
*/
|
||||
value?: string;
|
||||
/** Called when active tab changes */
|
||||
onChangeValue?: (value: string) => void;
|
||||
tabs: TabItem[];
|
||||
@@ -99,6 +104,7 @@ export interface TabsProps {
|
||||
export const Tabs = forwardRef<TabsRef, TabsProps>(function Tabs(
|
||||
{
|
||||
defaultValue,
|
||||
value: controlledValue,
|
||||
onChangeValue: onChangeValueProp,
|
||||
label,
|
||||
children,
|
||||
@@ -142,7 +148,12 @@ export const Tabs = forwardRef<TabsRef, TabsProps>(function Tabs(
|
||||
keyedDefault && internal?.key !== activeTabKey ? undefined : internal?.value;
|
||||
const offered = (v: string | undefined) =>
|
||||
v != null && (!keyedDefault || originalTabs.some((t) => t.value === v));
|
||||
const value = [storedActiveTab, internalValue, defaultValue].find(offered) ?? originalTabs[0]?.value;
|
||||
const controlled = originalTabs.some((t) => t.value === controlledValue)
|
||||
? controlledValue
|
||||
: undefined;
|
||||
const value =
|
||||
[controlled, storedActiveTab, internalValue, defaultValue].find(offered) ??
|
||||
originalTabs[0]?.value;
|
||||
|
||||
// Helper to normalize storage (handle migration from old format)
|
||||
const normalizeStorage = useCallback(
|
||||
|
||||
@@ -28,7 +28,13 @@ import { useAtomValue, useStore } from "jotai";
|
||||
import { draggingIdsFamily, focusIdsFamily, hoveredParentFamily, selectedIdsFamily } from "./atoms";
|
||||
import { type CollapsedAtom, CollapsedAtomContext } from "./context";
|
||||
import type { ContextMenuRenderer, TreeNode } from "./common";
|
||||
import { closestVisibleNode, equalSubtree, getSelectedItems, hasAncestor } from "./common";
|
||||
import {
|
||||
closestVisibleNode,
|
||||
equalSubtree,
|
||||
getSelectedItems,
|
||||
hasAncestor,
|
||||
tabbableSelection,
|
||||
} from "./common";
|
||||
import { TreeDragOverlay } from "./TreeDragOverlay";
|
||||
import type { TreeItemClickEvent, TreeItemHandle, TreeItemProps } from "./TreeItem";
|
||||
import type { TreeItemListProps } from "./TreeItemList";
|
||||
@@ -222,9 +228,12 @@ function TreeInner<T extends { id: string }>(
|
||||
}
|
||||
|
||||
const closest = closestVisibleNode(store, collapsedAtom, lastSelectedItem.node);
|
||||
if (closest != null) {
|
||||
if (closest != null && lastSelectedId != null) {
|
||||
const id = closest.item.id;
|
||||
store.set(selectedIdsFamily(treeId), [id]);
|
||||
const selected = store.get(selectedIdsFamily(treeId));
|
||||
const next = tabbableSelection(selected, lastSelectedId, id);
|
||||
if (next == null) return;
|
||||
store.set(selectedIdsFamily(treeId), next);
|
||||
store.set(focusIdsFamily(treeId), { anchorId: id, lastId: id });
|
||||
}
|
||||
}, [selectableItems, treeId]);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { tabbableSelection } from "./common";
|
||||
|
||||
describe("tabbableSelection", () => {
|
||||
test("leaves several selected rows alone while the last one focused is in view", () => {
|
||||
// As the tree renders again, say for new counts, the selection stands.
|
||||
expect(tabbableSelection(["a", "b", "c"], "b", "b")).toBeNull();
|
||||
expect(tabbableSelection(["b"], "b", "b")).toBeNull();
|
||||
});
|
||||
|
||||
test("moves to the closest row in view once the last one focused is hidden", () => {
|
||||
expect(tabbableSelection(["a", "child"], "child", "parent")).toEqual(["parent"]);
|
||||
});
|
||||
|
||||
test("selects the last row focused when the selection no longer holds it", () => {
|
||||
expect(tabbableSelection([], "b", "b")).toEqual(["b"]);
|
||||
expect(tabbableSelection(["a"], "b", "b")).toEqual(["b"]);
|
||||
});
|
||||
});
|
||||
@@ -85,6 +85,20 @@ export function isVisibleNode<T extends { id: string }>(
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The selection that keeps a row tabbable, from the last row focused and the closest of it still
|
||||
* in view, or null to leave the selection as it is: while that row is in view and selected, a
|
||||
* selection of several rows stands, rather than shrinking to it each time the tree renders.
|
||||
*/
|
||||
export function tabbableSelection(
|
||||
selected: readonly string[],
|
||||
lastId: string,
|
||||
closestId: string,
|
||||
): string[] | null {
|
||||
if (closestId === lastId && selected.includes(lastId)) return null;
|
||||
return [closestId];
|
||||
}
|
||||
|
||||
export function closestVisibleNode<T extends { id: string }>(
|
||||
store: JotaiStore,
|
||||
collapsedAtom: CollapsedAtom,
|
||||
|
||||
Reference in new issue
Block a user