mirror of
https://github.com/docmost/docmost.git
synced 2026-05-17 06:44:05 +08:00
657fdf8cb7
* Tiptap3 migration - WIP * fix collaboration * remove unused code * fix flicker * disable duplicate extensions * update tiptap version * Switch to useEditorState - Set shouldRerenderOnTransaction to false * fix editable state * add tippyoptions for reference * merge main * tiptap 3.6.1 * fix bubble menu * fix converter * fix menus * fix collaboration caret css * fix: Set `isInitialized` to force immediate react node view rendering * feat: Migrate tippy.js menus to Floating UI * feat: Update collaboration connection for HocusPocus v3 * fix: Connect/disconnect websocketProvider * cleanup * cleanup * feat: Improved placeholder and upload handling for images * feat: Improved placeholder and upload handling for videos * refactor: Image node and view clean-up * feat: Improved placeholder and upload handling for attachments * fix: Video view styles * fix: Transaction handling on asset upload * fix: Use imageDimensionsFromStream * feat: Multiple file upload, improved placeholders, local previews * fix: Drag & drop, paste upload * fix: Allow media as attachment * * add skeleton pulse animation * add translation strings * fix attachment view responsiveness * fix collab connection status display * Tiptap v3.17.0 * fix suggestion menu exit bug * fix search shortcut * fix history editor css * tiptap 3.17.1 --------- Co-authored-by: Arek Nawo <areknawo@areknawo.com>
82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { BubbleMenu as BaseBubbleMenu } from "@tiptap/react/menus";
|
|
import { posToDOMRect, findParentNode } from "@tiptap/react";
|
|
import { Node as PMNode } from "@tiptap/pm/model";
|
|
import React, { useCallback } from "react";
|
|
import { ActionIcon, Tooltip } from "@mantine/core";
|
|
import { IconTrash } from "@tabler/icons-react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { Editor } from "@tiptap/core";
|
|
|
|
interface SubpagesMenuProps {
|
|
editor: Editor;
|
|
}
|
|
|
|
interface ShouldShowProps {
|
|
state: any;
|
|
from?: number;
|
|
to?: number;
|
|
}
|
|
|
|
export const SubpagesMenu = React.memo(
|
|
({ editor }: SubpagesMenuProps): JSX.Element => {
|
|
const { t } = useTranslation();
|
|
|
|
const shouldShow = useCallback(
|
|
({ state }: ShouldShowProps) => {
|
|
if (!state) {
|
|
return false;
|
|
}
|
|
|
|
return editor.isActive("subpages");
|
|
},
|
|
[editor]
|
|
);
|
|
|
|
const getReferenceClientRect = useCallback(() => {
|
|
const { selection } = editor.state;
|
|
const predicate = (node: PMNode) => node.type.name === "subpages";
|
|
const parent = findParentNode(predicate)(selection);
|
|
|
|
if (parent) {
|
|
const dom = editor.view.nodeDOM(parent?.pos) as HTMLElement;
|
|
return dom.getBoundingClientRect();
|
|
}
|
|
|
|
return posToDOMRect(editor.view, selection.from, selection.to);
|
|
}, [editor]);
|
|
|
|
const deleteNode = useCallback(() => {
|
|
const { selection } = editor.state;
|
|
editor
|
|
.chain()
|
|
.focus()
|
|
.setNodeSelection(selection.from)
|
|
.deleteSelection()
|
|
.run();
|
|
}, [editor]);
|
|
|
|
return (
|
|
<BaseBubbleMenu
|
|
editor={editor}
|
|
pluginKey={`subpages-menu`}
|
|
updateDelay={0}
|
|
shouldShow={shouldShow}
|
|
>
|
|
<Tooltip position="top" label={t("Delete")}>
|
|
<ActionIcon
|
|
onClick={deleteNode}
|
|
variant="default"
|
|
size="lg"
|
|
color="red"
|
|
aria-label={t("Delete")}
|
|
>
|
|
<IconTrash size={18} />
|
|
</ActionIcon>
|
|
</Tooltip>
|
|
</BaseBubbleMenu>
|
|
);
|
|
}
|
|
);
|
|
|
|
export default SubpagesMenu;
|