Skip to content

Commit e3f3167

Browse files
iam-vipinzy1000
authored andcommitted
[WIKI-696] fix: peek view close on click block menu options (makeplane#7861)
* fix: block close * chore : add toggle option in block menu * fix: separate methods
1 parent 1a13489 commit e3f3167

2 files changed

Lines changed: 29 additions & 18 deletions

File tree

packages/editor/src/core/components/menus/block-menu.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ export const BlockMenu = (props: Props) => {
4343
const dismiss = useDismiss(context);
4444
const { getFloatingProps } = useInteractions([dismiss]);
4545

46+
const openBlockMenu = useCallback(() => {
47+
if (!isOpen) {
48+
setIsOpen(true);
49+
editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.SIDE_MENU);
50+
}
51+
}, [editor, isOpen]);
52+
53+
const closeBlockMenu = useCallback(() => {
54+
if (isOpen) {
55+
setIsOpen(false);
56+
editor.commands.removeActiveDropbarExtension(CORE_EXTENSIONS.SIDE_MENU);
57+
}
58+
}, [editor, isOpen]);
59+
4660
// Handle click on drag handle
4761
const handleClickDragHandle = useCallback(
4862
(event: MouseEvent) => {
@@ -70,27 +84,27 @@ export const BlockMenu = (props: Props) => {
7084
editor.chain().setNodeSelection(nodePos).run();
7185
}
7286
// Show the menu
73-
setIsOpen(true);
87+
openBlockMenu();
7488
return;
7589
}
7690

7791
// If clicking outside and not on a menu item, hide the menu
7892
if (menuRef.current && !menuRef.current.contains(target)) {
79-
setIsOpen(false);
93+
closeBlockMenu();
8094
}
8195
},
82-
[refs]
96+
[editor, refs, openBlockMenu, closeBlockMenu]
8397
);
8498

8599
useEffect(() => {
86100
const handleKeyDown = (event: KeyboardEvent) => {
87101
if (event.key === "Escape") {
88-
setIsOpen(false);
102+
closeBlockMenu();
89103
}
90104
};
91105

92106
const handleScroll = () => {
93-
setIsOpen(false);
107+
closeBlockMenu();
94108
};
95109
document.addEventListener("click", handleClickDragHandle);
96110
document.addEventListener("contextmenu", handleClickDragHandle);
@@ -103,7 +117,7 @@ export const BlockMenu = (props: Props) => {
103117
document.removeEventListener("keydown", handleKeyDown);
104118
document.removeEventListener("scroll", handleScroll, true);
105119
};
106-
}, [handleClickDragHandle]);
120+
}, [editor.commands, handleClickDragHandle, closeBlockMenu]);
107121

108122
// Animation effect
109123
useEffect(() => {
@@ -133,14 +147,9 @@ export const BlockMenu = (props: Props) => {
133147
icon: Trash2,
134148
key: "delete",
135149
label: "Delete",
136-
onClick: (e) => {
137-
e.preventDefault();
138-
e.stopPropagation();
139-
150+
onClick: (_e) => {
140151
// Execute the delete action
141152
editor.chain().deleteSelection().focus().run();
142-
143-
setIsOpen(false);
144153
},
145154
},
146155
{
@@ -150,10 +159,7 @@ export const BlockMenu = (props: Props) => {
150159
isDisabled:
151160
editor.state.selection.content().content.firstChild?.type.name === CORE_EXTENSIONS.IMAGE ||
152161
editor.isActive(CORE_EXTENSIONS.CUSTOM_IMAGE),
153-
onClick: (e) => {
154-
e.preventDefault();
155-
e.stopPropagation();
156-
162+
onClick: (_e) => {
157163
try {
158164
const { state } = editor;
159165
const { selection } = state;
@@ -187,7 +193,6 @@ export const BlockMenu = (props: Props) => {
187193
console.error(error.message);
188194
}
189195
}
190-
setIsOpen(false);
191196
},
192197
},
193198
];
@@ -225,7 +230,12 @@ export const BlockMenu = (props: Props) => {
225230
key={item.key}
226231
type="button"
227232
className="flex w-full items-center gap-1.5 truncate rounded px-1 py-1.5 text-xs text-custom-text-200 hover:bg-custom-background-90"
228-
onClick={item.onClick}
233+
onClick={(e) => {
234+
item.onClick(e);
235+
e.preventDefault();
236+
e.stopPropagation();
237+
closeBlockMenu();
238+
}}
229239
disabled={item.isDisabled}
230240
>
231241
<item.icon className="h-3 w-3" />

packages/editor/src/core/extensions/utility.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type TActiveDropbarExtensions =
1616
| CORE_EXTENSIONS.EMOJI
1717
| CORE_EXTENSIONS.SLASH_COMMANDS
1818
| CORE_EXTENSIONS.TABLE
19+
| CORE_EXTENSIONS.SIDE_MENU
1920
| TAdditionalActiveDropbarExtensions;
2021

2122
declare module "@tiptap/core" {

0 commit comments

Comments
 (0)