Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/shared/lib/mui-tiptap/controls/controlled-bubble-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { ReactNode, useCallback } from "react";
import {
Fade,
Paper,
Popover,
useTheme,
type PaperProps,
Popover,
type PopoverProps,
type PopoverVirtualElement,
useTheme,
} from "@mui/material";
import { isNodeSelection, posToDOMRect, type Editor } from "@tiptap/core";
import { type Editor, isNodeSelection, posToDOMRect } from "@tiptap/core";
import { makeStyles } from "tss-react/mui";

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

import { Z_INDEXES, getUtilityClasses } from "../styles";
import { getUtilityClasses, Z_INDEXES } from "../styles";

export type ControlledBubbleMenuClasses = ReturnType<
typeof useStyles
Expand Down
11 changes: 7 additions & 4 deletions src/shared/lib/mui-tiptap/controls/link-bubble-menu/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="@tiptap/extension-link" />
import { makeStyles } from "tss-react/mui";
import type { Except } from "type-fest";
import { useEffect } from "react";

import ControlledBubbleMenu, {
type ControlledBubbleMenuProps,
Expand Down Expand Up @@ -38,6 +38,12 @@ export default function LinkBubbleMenu({
const { classes } = useStyles();
const editor = useRichTextEditorContext();

useEffect(() => {
if (editor?.isEditable && "linkBubbleMenuHandler" in editor.storage) {
handleClose();
}
}, [location.pathname, editor]);

if (!editor?.isEditable) {
return null;
}
Expand Down Expand Up @@ -82,7 +88,6 @@ export default function LinkBubbleMenu({
onSave={({ text, link }) => {
editor
.chain()

.extendMarkRange("link")
.insertContent({
type: "text",
Expand All @@ -96,11 +101,9 @@ export default function LinkBubbleMenu({
],
text,
})

.setLink({
href: link,
})

.focus()
.run();

Expand Down
17 changes: 16 additions & 1 deletion src/shared/lib/mui-tiptap/controls/menu-button-edit-link.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Link from "@mui/icons-material/Link";
import { useRef } from "react";
import { type PopoverOrigin } from "@mui/material";

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

Expand All @@ -11,6 +12,17 @@ export type MenuButtonEditLinkProps = Partial<MenuButtonProps>;
export default function MenuButtonEditLink(props: MenuButtonEditLinkProps) {
const editor = useRichTextEditorContext();
const buttonRef = useRef<Maybe<HTMLButtonElement>>(null);

const anchorOrigin: PopoverOrigin = {
vertical: "bottom",
horizontal: "center",
};

const transformOrigin: PopoverOrigin = {
vertical: "top",
horizontal: "center",
};

return (
<MenuButton
buttonRef={buttonRef}
Expand All @@ -22,7 +34,10 @@ export default function MenuButtonEditLink(props: MenuButtonEditLinkProps) {
onClick={() =>
editor?.commands.openLinkBubbleMenu({
anchorEl: buttonRef.current,
placement: "bottom",
placement: {
anchorOrigin,
transformOrigin,
},
})
}
{...props}
Expand Down