mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-12-04 13:56:23 +01:00
Apply Yaak Proxy's filter on Enter, with places, Back and Forward, and filter history
The search box now composes a filter and Enter applies it. The main window's view (filter, selected flow, card tabs) is a place: a session stack of them backs Back and Forward (⌘[ ⌘], mouse buttons, a Go menu), the current one survives a reload, and the last filter comes back at launch. Filters applied with Enter go into a new filter_history table, listed from the magnifier and recalled with Up in the empty box. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e870604607
commit
c2d4c39c62
31 files changed
+1981
-264
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 };
|
||||
|
||||
@@ -116,6 +116,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;
|
||||
}
|
||||
@@ -168,6 +170,7 @@ export function HttpRequestPaneView({
|
||||
urlLine,
|
||||
dimEmptyTabs = false,
|
||||
defaultTab,
|
||||
activeTab,
|
||||
onTabChange,
|
||||
}: HttpRequestPaneViewProps) {
|
||||
const { ErrorBoundary } = useEditorHost();
|
||||
@@ -291,6 +294,7 @@ export function HttpRequestPaneView({
|
||||
storageKey={tabsStorageKey}
|
||||
activeTabKey={request.id}
|
||||
defaultValue={defaultTab}
|
||||
value={activeTab}
|
||||
keyedDefault={defaultTab != null}
|
||||
onChangeValue={onTabChange}
|
||||
>
|
||||
|
||||
@@ -83,6 +83,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;
|
||||
}
|
||||
@@ -115,6 +117,7 @@ export function HttpResponsePaneView({
|
||||
bare = false,
|
||||
dimEmptyTabs = false,
|
||||
defaultTab,
|
||||
activeTab,
|
||||
onTabChange,
|
||||
}: HttpResponsePaneViewProps) {
|
||||
const { ErrorBoundary } = useEditorHost();
|
||||
@@ -269,6 +272,7 @@ export function HttpResponsePaneView({
|
||||
storageKey={tabsStorageKey}
|
||||
activeTabKey={activeTabKey}
|
||||
defaultValue={defaultTab}
|
||||
value={activeTab}
|
||||
keyedDefault={defaultTab != null}
|
||||
onChangeValue={onTabChange}
|
||||
>
|
||||
|
||||
@@ -79,6 +79,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[];
|
||||
@@ -103,6 +108,7 @@ export interface TabsProps {
|
||||
export const Tabs = forwardRef<TabsRef, TabsProps>(function Tabs(
|
||||
{
|
||||
defaultValue,
|
||||
value: controlledValue,
|
||||
onChangeValue: onChangeValueProp,
|
||||
label,
|
||||
children,
|
||||
@@ -146,7 +152,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(
|
||||
|
||||
Reference in new issue
Block a user