mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-24 12:24:01 +02:00
Collapse encoded media in editable fields too (#534)
This commit is contained in:
@@ -16,6 +16,8 @@ export interface ContextMenuInstance {
|
||||
triggerPosition: { x: number; y: number };
|
||||
/** The trigger's box, when it has one, so placement can align to its edges */
|
||||
triggerRect?: Pick<DOMRect, "top" | "bottom" | "left" | "right">;
|
||||
/** The element it belongs to, so clicking that doesn't read as a click outside */
|
||||
triggerEl?: HTMLElement | null;
|
||||
items: DropdownItem[];
|
||||
}
|
||||
|
||||
@@ -25,6 +27,20 @@ export function showContextMenu({ id, ...props }: ContextMenuInstance) {
|
||||
jotaiStore.set(contextMenusAtom, (m) => [...m.filter((c) => c.id !== id), { id, ...props }]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the menu, or closes it if this one is already open.
|
||||
*
|
||||
* What a trigger wants: pressing it a second time should put the menu away. Same shape as
|
||||
* {@link toggleDialog}.
|
||||
*/
|
||||
export function toggleContextMenu({ id, ...props }: ContextMenuInstance) {
|
||||
if (jotaiStore.get(contextMenusAtom).some((c) => c.id === id)) {
|
||||
hideContextMenu(id);
|
||||
} else {
|
||||
showContextMenu({ id, ...props });
|
||||
}
|
||||
}
|
||||
|
||||
export function hideContextMenu(id: string) {
|
||||
jotaiStore.set(contextMenusAtom, (m) => m.filter((c) => c.id !== id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user