Files
webstudio/apps/builder/app/canvas/instance-context-menu.ts
T
Oleg Isonen d91aa5821e feat: Context menus for navigator, canvas and tokens (#5511)
## Description

- [x] context menu for navigator
- [x] context menu for canvas instances
- [x] right click to open token menu
- [x] pages and folders context menu
- [x] duplicate pages

## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
0000)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env` file
2025-12-14 22:49:53 +01:00

26 lines
812 B
TypeScript

import { selectorIdAttribute } from "@webstudio-is/react-sdk";
import { $instanceContextMenu } from "~/shared/nano-states";
export const subscribeInstanceContextMenu = () => {
const handleContextMenu = (event: MouseEvent) => {
const target = event.target as HTMLElement;
const element = target.closest(`[${selectorIdAttribute}]`);
const selectorId = element?.getAttribute(selectorIdAttribute);
if (selectorId) {
event.preventDefault();
const instanceSelector = selectorId.split(",");
$instanceContextMenu.set({
position: { x: event.clientX, y: event.clientY },
instanceSelector,
});
}
};
document.addEventListener("contextmenu", handleContextMenu);
return () => {
document.removeEventListener("contextmenu", handleContextMenu);
};
};