diff --git a/packages/client/src/tiptap/menubar.tsx b/packages/client/src/tiptap/menubar.tsx
index 32ae1f9..ef0300d 100644
--- a/packages/client/src/tiptap/menubar.tsx
+++ b/packages/client/src/tiptap/menubar.tsx
@@ -34,6 +34,7 @@ import { Search } from './menus/search';
import { Banner } from './menus/banner';
import { Countdonw } from './menus/countdown';
+import { DocumentReference } from './menus/document-reference';
import { Image } from './menus/image';
import { Iframe } from './menus/iframe';
import { Table } from './menus/table';
@@ -89,6 +90,7 @@ export const MenuBar: React.FC<{ editor: any }> = ({ editor }) => {
+
diff --git a/packages/client/src/tiptap/menus/document-reference/bubble.tsx b/packages/client/src/tiptap/menus/document-reference/bubble.tsx
new file mode 100644
index 0000000..4276cce
--- /dev/null
+++ b/packages/client/src/tiptap/menus/document-reference/bubble.tsx
@@ -0,0 +1,77 @@
+import { useCallback } from 'react';
+import { useRouter } from 'next/router';
+import { Space, Button, List, Popover } from '@douyinfe/semi-ui';
+import { IconEdit, IconDelete } from '@douyinfe/semi-icons';
+import { Tooltip } from 'components/tooltip';
+import { DataRender } from 'components/data-render';
+import { useWikiTocs } from 'data/wiki';
+import { BubbleMenu } from '../../views/bubble-menu';
+import { DocumentReference } from '../../extensions/document-reference';
+import { Divider } from '../../divider';
+
+export const DocumentReferenceBubbleMenu = ({ editor }) => {
+ const { pathname, query } = useRouter();
+ const wikiIdFromUrl = query?.wikiId;
+ const isShare = pathname.includes('share');
+ const { data: tocs, loading, error } = useWikiTocs(isShare ? null : wikiIdFromUrl);
+
+ const selectDoc = useCallback(
+ (item) => {
+ const { wikiId, title, id: documentId } = item;
+
+ editor
+ .chain()
+ .updateAttributes(DocumentReference.name, { wikiId, documentId, title })
+ .setNodeSelection(editor.state.selection.from)
+ .focus()
+ .run();
+ },
+ [editor]
+ );
+
+ const deleteNode = useCallback(() => editor.chain().deleteSelection().run(), [editor]);
+
+ return (
+ editor.isActive(DocumentReference.name)}
+ tippyOptions={{ maxWidth: 456 }}
+ >
+
+ (
+ (
+ selectDoc(item)}
+ style={{ cursor: 'pointer' }}
+ main={{item.title}}
+ />
+ )}
+ />
+ )}
+ />
+ }
+ trigger="click"
+ >
+ } />
+
+
+
+
+
+ } type="tertiary" theme="borderless" size="small" />
+
+
+
+ );
+};
diff --git a/packages/client/src/tiptap/menus/document-reference/index.tsx b/packages/client/src/tiptap/menus/document-reference/index.tsx
new file mode 100644
index 0000000..c52e446
--- /dev/null
+++ b/packages/client/src/tiptap/menus/document-reference/index.tsx
@@ -0,0 +1,15 @@
+import React from 'react';
+import { Editor } from '@tiptap/core';
+import { DocumentReferenceBubbleMenu } from './bubble';
+
+export const DocumentReference: React.FC<{ editor: Editor }> = ({ editor }) => {
+ if (!editor) {
+ return null;
+ }
+
+ return (
+ <>
+
+ >
+ );
+};
diff --git a/packages/client/src/tiptap/wrappers/document-reference/index.module.scss b/packages/client/src/tiptap/wrappers/document-reference/index.module.scss
index f2656cd..4ff8f5d 100644
--- a/packages/client/src/tiptap/wrappers/document-reference/index.module.scss
+++ b/packages/client/src/tiptap/wrappers/document-reference/index.module.scss
@@ -1,5 +1,5 @@
.wrap {
- margin-top: .75em;
+ margin-top: 0.75em;
border-radius: var(--border-radius);
.itemWrap {
@@ -7,7 +7,6 @@
padding: 8px;
color: var(--node-text-color);
text-decoration: none;
- border: 1px solid var(--node-border-color);
border-radius: var(--border-radius);
align-items: center;
@@ -27,21 +26,7 @@
color: var(--node-text-color);
text-decoration: none;
cursor: not-allowed;
- border: 1px solid var(--node-border-color);
border-radius: var(--border-radius);
align-items: center;
}
-
- &.isEditable {
- padding: 12px;
-
- .itemWrap {
- margin-top: 12px;
- pointer-events: none;
- }
-
- .empty {
- margin-top: 12px;
- }
- }
}
diff --git a/packages/client/src/tiptap/wrappers/document-reference/index.tsx b/packages/client/src/tiptap/wrappers/document-reference/index.tsx
index e404810..55f81ee 100644
--- a/packages/client/src/tiptap/wrappers/document-reference/index.tsx
+++ b/packages/client/src/tiptap/wrappers/document-reference/index.tsx
@@ -2,74 +2,53 @@ import { NodeViewWrapper } from '@tiptap/react';
import { useRouter } from 'next/router';
import Link from 'next/link';
import cls from 'classnames';
-import { Select } from '@douyinfe/semi-ui';
-import { useWikiTocs } from 'data/wiki';
-import { DataRender } from 'components/data-render';
import { IconDocument } from 'components/icons';
import styles from './index.module.scss';
+import { useMemo } from 'react';
export const DocumentReferenceWrapper = ({ editor, node, updateAttributes }) => {
- const { pathname, query } = useRouter();
- const wikiIdFromUrl = query?.wikiId;
+ const { pathname } = useRouter();
const isShare = pathname.includes('share');
const isEditable = editor.isEditable;
const { wikiId, documentId, title } = node.attrs;
- const { data: tocs, loading, error } = useWikiTocs(isShare ? null : wikiIdFromUrl);
- const selectDoc = (str) => {
- const [wikiId, title, documentId] = str.split('/');
- updateAttributes({ wikiId, documentId, title });
- };
+ const content = useMemo(() => {
+ if (!wikiId && !documentId) {
+ return (
+
+ {'用户未选择文档'}
+
+ );
+ }
+
+ if (isEditable) {
+ return (
+
+
+ {title}
+
+ );
+ }
+
+ return (
+
+
+
+ {title || '请选择文档'}
+
+
+ );
+ }, [wikiId, documentId]);
return (
-
-
- {isEditable && (
-
(
-
- )}
- />
- )}
- {wikiId && documentId ? (
-
-
-
- {title || '请选择文档'}
-
-
- ) : (
-
- {'用户未选择文档'}
-
- )}
-
+
+ {content}
);
};