File tree Expand file tree Collapse file tree 3 files changed +27
-9
lines changed
src/shared/lib/mui-tiptap/controls Expand file tree Collapse file tree 3 files changed +27
-9
lines changed Original file line number Diff line number Diff line change @@ -2,18 +2,18 @@ import { ReactNode, useCallback } from "react";
22import {
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" ;
1212import { makeStyles } from "tss-react/mui" ;
1313
1414import { Maybe } from "api/graphql/generated/graphql" ;
1515
16- import { Z_INDEXES , getUtilityClasses } from "../styles" ;
16+ import { getUtilityClasses , Z_INDEXES } from "../styles" ;
1717
1818export type ControlledBubbleMenuClasses = ReturnType <
1919 typeof useStyles
Original file line number Diff line number Diff line change 1- /// <reference types="@tiptap/extension-link" />
21import { makeStyles } from "tss-react/mui" ;
32import type { Except } from "type-fest" ;
3+ import { useEffect } from "react" ;
44
55import 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
Original file line number Diff line number Diff line change 11import Link from "@mui/icons-material/Link" ;
22import { useRef } from "react" ;
3+ import { type PopoverOrigin } from "@mui/material" ;
34
45import { Maybe } from "api/graphql/generated/graphql" ;
56
@@ -11,6 +12,17 @@ export type MenuButtonEditLinkProps = Partial<MenuButtonProps>;
1112export 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 }
You can’t perform that action at this time.
0 commit comments