fix: Comment action not visible on mobile formatting toolbar
This commit is contained in:
@@ -223,6 +223,7 @@ const FloatingToolbar = React.forwardRef(function FloatingToolbar_(
|
|||||||
return (
|
return (
|
||||||
<ReactPortal>
|
<ReactPortal>
|
||||||
<MobileWrapper
|
<MobileWrapper
|
||||||
|
ref={menuRef}
|
||||||
style={{
|
style={{
|
||||||
bottom: `calc(100% - ${height - rect.y}px)`,
|
bottom: `calc(100% - ${height - rect.y}px)`,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -100,10 +100,10 @@ export default function SelectionToolbar(props: Props) {
|
|||||||
const { view, commands } = useEditor();
|
const { view, commands } = useEditor();
|
||||||
const dictionary = useDictionary();
|
const dictionary = useDictionary();
|
||||||
const menuRef = React.useRef<HTMLDivElement | null>(null);
|
const menuRef = React.useRef<HTMLDivElement | null>(null);
|
||||||
const isActive = useIsActive(view.state);
|
const isMobile = useMobile();
|
||||||
|
const isActive = useIsActive(view.state) || isMobile;
|
||||||
const isDragging = useIsDragging();
|
const isDragging = useIsDragging();
|
||||||
const previousIsActive = usePrevious(isActive);
|
const previousIsActive = usePrevious(isActive);
|
||||||
const isMobile = useMobile();
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// Trigger callbacks when the toolbar is opened or closed
|
// Trigger callbacks when the toolbar is opened or closed
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import * as React from "react";
|
|||||||
import { useMenuState } from "reakit";
|
import { useMenuState } from "reakit";
|
||||||
import { MenuButton } from "reakit/Menu";
|
import { MenuButton } from "reakit/Menu";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
import breakpoint from "styled-components-breakpoint";
|
||||||
import { MenuItem } from "@shared/editor/types";
|
import { MenuItem } from "@shared/editor/types";
|
||||||
import { s } from "@shared/styles";
|
import { s } from "@shared/styles";
|
||||||
import ContextMenu from "~/components/ContextMenu";
|
import ContextMenu from "~/components/ContextMenu";
|
||||||
@@ -123,6 +124,11 @@ const FlexibleWrapper = styled.div`
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
|
|
||||||
|
${breakpoint("mobile", "tablet")`
|
||||||
|
justify-content: space-evenly;
|
||||||
|
align-items: baseline;
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Label = styled.span`
|
const Label = styled.span`
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export default function formattingMenuItems(
|
|||||||
const isList = isInList(state);
|
const isList = isInList(state);
|
||||||
const isCode = isInCode(state);
|
const isCode = isInCode(state);
|
||||||
const isCodeBlock = isInCode(state, { onlyBlock: true });
|
const isCodeBlock = isInCode(state, { onlyBlock: true });
|
||||||
|
const isEmpty = state.selection.empty;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -44,50 +45,50 @@ export default function formattingMenuItems(
|
|||||||
tooltip: dictionary.placeholder,
|
tooltip: dictionary.placeholder,
|
||||||
icon: <InputIcon />,
|
icon: <InputIcon />,
|
||||||
active: isMarkActive(schema.marks.placeholder),
|
active: isMarkActive(schema.marks.placeholder),
|
||||||
visible: isTemplate,
|
visible: isTemplate && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "separator",
|
name: "separator",
|
||||||
visible: isTemplate,
|
visible: isTemplate && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "strong",
|
name: "strong",
|
||||||
tooltip: dictionary.strong,
|
tooltip: dictionary.strong,
|
||||||
icon: <BoldIcon />,
|
icon: <BoldIcon />,
|
||||||
active: isMarkActive(schema.marks.strong),
|
active: isMarkActive(schema.marks.strong),
|
||||||
visible: !isCode,
|
visible: !isCode && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "em",
|
name: "em",
|
||||||
tooltip: dictionary.em,
|
tooltip: dictionary.em,
|
||||||
icon: <ItalicIcon />,
|
icon: <ItalicIcon />,
|
||||||
active: isMarkActive(schema.marks.em),
|
active: isMarkActive(schema.marks.em),
|
||||||
visible: !isCode,
|
visible: !isCode && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "strikethrough",
|
name: "strikethrough",
|
||||||
tooltip: dictionary.strikethrough,
|
tooltip: dictionary.strikethrough,
|
||||||
icon: <StrikethroughIcon />,
|
icon: <StrikethroughIcon />,
|
||||||
active: isMarkActive(schema.marks.strikethrough),
|
active: isMarkActive(schema.marks.strikethrough),
|
||||||
visible: !isCode,
|
visible: !isCode && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "highlight",
|
name: "highlight",
|
||||||
tooltip: dictionary.mark,
|
tooltip: dictionary.mark,
|
||||||
icon: <HighlightIcon />,
|
icon: <HighlightIcon />,
|
||||||
active: isMarkActive(schema.marks.highlight),
|
active: isMarkActive(schema.marks.highlight),
|
||||||
visible: !isTemplate && !isCode,
|
visible: !isCode && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "code_inline",
|
name: "code_inline",
|
||||||
tooltip: dictionary.codeInline,
|
tooltip: dictionary.codeInline,
|
||||||
icon: <CodeIcon />,
|
icon: <CodeIcon />,
|
||||||
active: isMarkActive(schema.marks.code_inline),
|
active: isMarkActive(schema.marks.code_inline),
|
||||||
visible: !isCodeBlock,
|
visible: !isCodeBlock && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "separator",
|
name: "separator",
|
||||||
visible: !isCode,
|
visible: !isCodeBlock,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "heading",
|
name: "heading",
|
||||||
@@ -95,7 +96,7 @@ export default function formattingMenuItems(
|
|||||||
icon: <Heading1Icon />,
|
icon: <Heading1Icon />,
|
||||||
active: isNodeActive(schema.nodes.heading, { level: 1 }),
|
active: isNodeActive(schema.nodes.heading, { level: 1 }),
|
||||||
attrs: { level: 1 },
|
attrs: { level: 1 },
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "heading",
|
name: "heading",
|
||||||
@@ -103,7 +104,7 @@ export default function formattingMenuItems(
|
|||||||
icon: <Heading2Icon />,
|
icon: <Heading2Icon />,
|
||||||
active: isNodeActive(schema.nodes.heading, { level: 2 }),
|
active: isNodeActive(schema.nodes.heading, { level: 2 }),
|
||||||
attrs: { level: 2 },
|
attrs: { level: 2 },
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "heading",
|
name: "heading",
|
||||||
@@ -111,7 +112,7 @@ export default function formattingMenuItems(
|
|||||||
icon: <Heading3Icon />,
|
icon: <Heading3Icon />,
|
||||||
active: isNodeActive(schema.nodes.heading, { level: 3 }),
|
active: isNodeActive(schema.nodes.heading, { level: 3 }),
|
||||||
attrs: { level: 3 },
|
attrs: { level: 3 },
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "blockquote",
|
name: "blockquote",
|
||||||
@@ -119,11 +120,11 @@ export default function formattingMenuItems(
|
|||||||
icon: <BlockQuoteIcon />,
|
icon: <BlockQuoteIcon />,
|
||||||
active: isNodeActive(schema.nodes.blockquote),
|
active: isNodeActive(schema.nodes.blockquote),
|
||||||
attrs: { level: 2 },
|
attrs: { level: 2 },
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "separator",
|
name: "separator",
|
||||||
visible: !isCode,
|
visible: !isCodeBlock,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "checkbox_list",
|
name: "checkbox_list",
|
||||||
@@ -131,21 +132,21 @@ export default function formattingMenuItems(
|
|||||||
icon: <TodoListIcon />,
|
icon: <TodoListIcon />,
|
||||||
keywords: "checklist checkbox task",
|
keywords: "checklist checkbox task",
|
||||||
active: isNodeActive(schema.nodes.checkbox_list),
|
active: isNodeActive(schema.nodes.checkbox_list),
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bullet_list",
|
name: "bullet_list",
|
||||||
tooltip: dictionary.bulletList,
|
tooltip: dictionary.bulletList,
|
||||||
icon: <BulletedListIcon />,
|
icon: <BulletedListIcon />,
|
||||||
active: isNodeActive(schema.nodes.bullet_list),
|
active: isNodeActive(schema.nodes.bullet_list),
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ordered_list",
|
name: "ordered_list",
|
||||||
tooltip: dictionary.orderedList,
|
tooltip: dictionary.orderedList,
|
||||||
icon: <OrderedListIcon />,
|
icon: <OrderedListIcon />,
|
||||||
active: isNodeActive(schema.nodes.ordered_list),
|
active: isNodeActive(schema.nodes.ordered_list),
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "outdentList",
|
name: "outdentList",
|
||||||
@@ -161,7 +162,7 @@ export default function formattingMenuItems(
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "separator",
|
name: "separator",
|
||||||
visible: !isCode,
|
visible: !isCodeBlock,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "link",
|
name: "link",
|
||||||
@@ -169,7 +170,7 @@ export default function formattingMenuItems(
|
|||||||
icon: <LinkIcon />,
|
icon: <LinkIcon />,
|
||||||
active: isMarkActive(schema.marks.link),
|
active: isMarkActive(schema.marks.link),
|
||||||
attrs: { href: "" },
|
attrs: { href: "" },
|
||||||
visible: !isCode,
|
visible: !isCodeBlock && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "comment",
|
name: "comment",
|
||||||
@@ -177,16 +178,17 @@ export default function formattingMenuItems(
|
|||||||
icon: <CommentIcon />,
|
icon: <CommentIcon />,
|
||||||
label: isCodeBlock ? dictionary.comment : undefined,
|
label: isCodeBlock ? dictionary.comment : undefined,
|
||||||
active: isMarkActive(schema.marks.comment),
|
active: isMarkActive(schema.marks.comment),
|
||||||
|
visible: !isMobile || !isEmpty,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "separator",
|
name: "separator",
|
||||||
visible: isCode && !isCodeBlock,
|
visible: isCode && !isCodeBlock && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "copyToClipboard",
|
name: "copyToClipboard",
|
||||||
icon: <CopyIcon />,
|
icon: <CopyIcon />,
|
||||||
tooltip: dictionary.copy,
|
tooltip: dictionary.copy,
|
||||||
visible: isCode && !isCodeBlock,
|
visible: isCode && !isCodeBlock && (!isMobile || !isEmpty),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user