Skip to content

Commit 3007991

Browse files
authored
Merge pull request #345 from qa-guru/QAGDEV-668
QAGDEV-688 – [FE] При редактировании ссылки в уроке не закрывается форма редактирования v2.0
2 parents a06a57c + 49e788d commit 3007991

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/shared/lib/mui-tiptap/controls/controlled-bubble-menu.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { ReactNode, useCallback } from "react";
22
import {
33
Fade,
44
Paper,
5-
Popover,
6-
useTheme,
75
type PaperProps,
6+
Popover,
87
type PopoverProps,
98
type PopoverVirtualElement,
9+
useTheme,
1010
} from "@mui/material";
11-
import { isNodeSelection, posToDOMRect, type Editor } from "@tiptap/core";
11+
import { type Editor, isNodeSelection, posToDOMRect } from "@tiptap/core";
1212
import { makeStyles } from "tss-react/mui";
1313

1414
import { Maybe } from "api/graphql/generated/graphql";
1515

16-
import { Z_INDEXES, getUtilityClasses } from "../styles";
16+
import { getUtilityClasses, Z_INDEXES } from "../styles";
1717

1818
export type ControlledBubbleMenuClasses = ReturnType<
1919
typeof useStyles

src/shared/lib/mui-tiptap/controls/link-bubble-menu/index.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/// <reference types="@tiptap/extension-link" />
21
import { makeStyles } from "tss-react/mui";
32
import type { Except } from "type-fest";
3+
import { useEffect } from "react";
44

55
import ControlledBubbleMenu, {
66
type ControlledBubbleMenuProps,
@@ -38,6 +38,12 @@ export default function LinkBubbleMenu({
3838
const { classes } = useStyles();
3939
const editor = useRichTextEditorContext();
4040

41+
useEffect(() => {
42+
if (editor?.isEditable && "linkBubbleMenuHandler" in editor.storage) {
43+
handleClose();
44+
}
45+
}, [location.pathname, editor]);
46+
4147
if (!editor?.isEditable) {
4248
return null;
4349
}
@@ -82,7 +88,6 @@ export default function LinkBubbleMenu({
8288
onSave={({ text, link }) => {
8389
editor
8490
.chain()
85-
8691
.extendMarkRange("link")
8792
.insertContent({
8893
type: "text",
@@ -96,11 +101,9 @@ export default function LinkBubbleMenu({
96101
],
97102
text,
98103
})
99-
100104
.setLink({
101105
href: link,
102106
})
103-
104107
.focus()
105108
.run();
106109

src/shared/lib/mui-tiptap/controls/menu-button-edit-link.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Link from "@mui/icons-material/Link";
22
import { useRef } from "react";
3+
import { type PopoverOrigin } from "@mui/material";
34

45
import { Maybe } from "api/graphql/generated/graphql";
56

@@ -11,6 +12,17 @@ export type MenuButtonEditLinkProps = Partial<MenuButtonProps>;
1112
export default function MenuButtonEditLink(props: MenuButtonEditLinkProps) {
1213
const editor = useRichTextEditorContext();
1314
const buttonRef = useRef<Maybe<HTMLButtonElement>>(null);
15+
16+
const anchorOrigin: PopoverOrigin = {
17+
vertical: "bottom",
18+
horizontal: "center",
19+
};
20+
21+
const transformOrigin: PopoverOrigin = {
22+
vertical: "top",
23+
horizontal: "center",
24+
};
25+
1426
return (
1527
<MenuButton
1628
buttonRef={buttonRef}
@@ -22,7 +34,10 @@ export default function MenuButtonEditLink(props: MenuButtonEditLinkProps) {
2234
onClick={() =>
2335
editor?.commands.openLinkBubbleMenu({
2436
anchorEl: buttonRef.current,
25-
placement: "bottom",
37+
placement: {
38+
anchorOrigin,
39+
transformOrigin,
40+
},
2641
})
2742
}
2843
{...props}

0 commit comments

Comments
 (0)