Open create submenu beside context menu and distinguish rename icons
This commit is contained in:
1 parent
c05293a948
commit
1afa755d4f
9 files changed
+193
-26
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { submenuPosition } from "../context-menu";
|
||||
import { iconPath } from "../icons";
|
||||
it("opens beside the parent and flips left at the screen edge", () => {
|
||||
const viewport = { width: 1000, height: 700 };
|
||||
expect(
|
||||
submenuPosition({ left: 100, right: 340, top: 80 }, 260, 400, viewport)
|
||||
).toEqual({ left: 344, top: 80 });
|
||||
expect(
|
||||
submenuPosition({ left: 700, right: 940, top: 80 }, 260, 400, viewport)
|
||||
).toEqual({ left: 436, top: 80 });
|
||||
});
|
||||
it("keeps the panel in the viewport near the bottom and on narrow screens", () => {
|
||||
expect(
|
||||
submenuPosition({ left: 100, right: 340, top: 600 }, 260, 400, {
|
||||
width: 1000,
|
||||
height: 700,
|
||||
})
|
||||
).toEqual({ left: 344, top: 292 });
|
||||
const position = submenuPosition(
|
||||
{ left: 8, right: 260, top: -10 },
|
||||
260,
|
||||
400,
|
||||
{ width: 320, height: 600 }
|
||||
);
|
||||
expect(position).toEqual({ left: 8, top: 8 });
|
||||
});
|
||||
it("distinguishes rename from editing file contents", () => {
|
||||
expect(iconPath("mode_edit")).not.toEqual(iconPath("edit_note"));
|
||||
expect(iconPath("edit_note")).not.toEqual(iconPath("file"));
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { InjectionKey } from "vue";
|
||||
export const contextMenuKey: InjectionKey<{ id: string; close: () => void }> =
|
||||
Symbol("context-menu");
|
||||
|
||||
export function submenuPosition(
|
||||
parent: { left: number; right: number; top: number },
|
||||
width: number,
|
||||
height: number,
|
||||
viewport: { width: number; height: number }
|
||||
) {
|
||||
const gap = 4,
|
||||
margin = 8;
|
||||
const preferred =
|
||||
parent.right + gap + width <= viewport.width - margin
|
||||
? parent.right + gap
|
||||
: parent.left - gap - width;
|
||||
return {
|
||||
left: Math.max(
|
||||
margin,
|
||||
Math.min(preferred, viewport.width - width - margin)
|
||||
),
|
||||
top: Math.max(
|
||||
margin,
|
||||
Math.min(parent.top, viewport.height - height - margin)
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -16,6 +16,9 @@ const paths: Record<string, string> = {
|
||||
upload: "M12 16V4 m-5 5 5-5 5 5 M4 16v5h16v-5",
|
||||
trash: "M3 6h18 M9 6V3h6v3 M5 6l1 15h12l1-15 M10 10v7 M14 10v7",
|
||||
edit: "m15 4 5 5 M4 20l5-1L21 7l-5-5L4 14z",
|
||||
rename: "M3 7h7 M3 12h5 M3 17h7 M13 3h7 M16.5 3v18 M13 21h7",
|
||||
editDocument:
|
||||
"M5 3h9l5 5v3 M14 3v5h5 M5 3v18h6 M8 11h4 M8 15h2 m3 6 1-4 6-6 3 3-6 6z",
|
||||
copy: "M8 8h12v13H8z M4 16H2V2h13v2",
|
||||
paste: "M9 4H5v17h14V4h-4 M9 2h6v5H9z M8 11h8 M8 15h8",
|
||||
cut: "M9 8 20 20 M9 16 20 4 M9 7a3 3 0 1 1-6 0 3 3 0 0 1 6 0 M9 17a3 3 0 1 1-6 0 3 3 0 0 1 6 0",
|
||||
@@ -68,7 +71,7 @@ const paths: Record<string, string> = {
|
||||
const aliases: Record<string, string> = {
|
||||
cloud_off: "warning",
|
||||
gps_off: "search",
|
||||
edit_note: "edit",
|
||||
edit_note: "editDocument",
|
||||
view_module: "table",
|
||||
grid_view: "table",
|
||||
view_list: "menu",
|
||||
@@ -94,7 +97,7 @@ const aliases: Record<string, string> = {
|
||||
cancel: "close",
|
||||
delete: "trash",
|
||||
delete_outline: "trash",
|
||||
mode_edit: "edit",
|
||||
mode_edit: "rename",
|
||||
content_copy: "copy",
|
||||
content_paste: "paste",
|
||||
content_cut: "cut",
|
||||
|
||||
Reference in new issue
Block a user