From 42822dc49ebf9359faa6462f333b1114e62c6872 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Sun, 3 Jul 2022 13:08:54 +0800 Subject: [PATCH] tiptap: dragable --- .../src/tiptap/core/extensions/code-block.ts | 1 + .../src/tiptap/core/extensions/countdown.ts | 1 + .../core/extensions/document-children.ts | 1 + .../core/extensions/document-reference.ts | 1 + .../client/src/tiptap/core/extensions/flow.ts | 1 + .../src/tiptap/core/extensions/iframe.ts | 1 + .../client/src/tiptap/core/extensions/mind.ts | 1 + .../src/tiptap/core/extensions/paragraph.ts | 6 +++- .../client/src/tiptap/core/styles/code.scss | 2 -- .../tiptap/core/wrappers/attachment/index.tsx | 4 +-- .../tiptap/core/wrappers/callout/index.tsx | 7 +++-- .../tiptap/core/wrappers/code-block/index.tsx | 7 +++-- .../tiptap/core/wrappers/countdown/index.tsx | 6 ++-- .../core/wrappers/document-children/index.tsx | 7 +++-- .../wrappers/document-reference/index.tsx | 6 ++-- .../core/wrappers/dragable/index.module.scss | 30 +++++++++++++++++++ .../tiptap/core/wrappers/dragable/index.tsx | 28 +++++++++++++++++ .../src/tiptap/core/wrappers/flow/index.tsx | 6 ++-- .../src/tiptap/core/wrappers/iframe/index.tsx | 6 ++-- .../src/tiptap/core/wrappers/image/index.tsx | 6 ++-- .../src/tiptap/core/wrappers/mind/index.tsx | 6 ++-- 21 files changed, 102 insertions(+), 32 deletions(-) create mode 100644 packages/client/src/tiptap/core/wrappers/dragable/index.module.scss create mode 100644 packages/client/src/tiptap/core/wrappers/dragable/index.tsx diff --git a/packages/client/src/tiptap/core/extensions/code-block.ts b/packages/client/src/tiptap/core/extensions/code-block.ts index 3c9fb68..91d8b27 100644 --- a/packages/client/src/tiptap/core/extensions/code-block.ts +++ b/packages/client/src/tiptap/core/extensions/code-block.ts @@ -47,6 +47,7 @@ export const tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/; export const BuiltInCodeBlock = Node.create({ name: 'codeBlock', + draggable: true, addOptions() { return { diff --git a/packages/client/src/tiptap/core/extensions/countdown.ts b/packages/client/src/tiptap/core/extensions/countdown.ts index 48f8e6f..d591cfb 100644 --- a/packages/client/src/tiptap/core/extensions/countdown.ts +++ b/packages/client/src/tiptap/core/extensions/countdown.ts @@ -18,6 +18,7 @@ export const Countdown = Node.create({ group: 'block', selectable: true, atom: true, + draggable: true, addOptions() { return { diff --git a/packages/client/src/tiptap/core/extensions/document-children.ts b/packages/client/src/tiptap/core/extensions/document-children.ts index f4aa420..e0423ef 100644 --- a/packages/client/src/tiptap/core/extensions/document-children.ts +++ b/packages/client/src/tiptap/core/extensions/document-children.ts @@ -15,6 +15,7 @@ export const DocumentChildren = Node.create({ name: 'documentChildren', group: 'block', atom: true, + draggable: true, addOptions() { return { diff --git a/packages/client/src/tiptap/core/extensions/document-reference.ts b/packages/client/src/tiptap/core/extensions/document-reference.ts index 23f0fe6..2f84914 100644 --- a/packages/client/src/tiptap/core/extensions/document-reference.ts +++ b/packages/client/src/tiptap/core/extensions/document-reference.ts @@ -21,6 +21,7 @@ export const DocumentReference = Node.create({ name: 'documentReference', group: 'block', atom: true, + draggable: true, addAttributes() { return { diff --git a/packages/client/src/tiptap/core/extensions/flow.ts b/packages/client/src/tiptap/core/extensions/flow.ts index ac64c0a..3f92923 100644 --- a/packages/client/src/tiptap/core/extensions/flow.ts +++ b/packages/client/src/tiptap/core/extensions/flow.ts @@ -25,6 +25,7 @@ export const Flow = Node.create({ group: 'block', selectable: true, atom: true, + draggable: true, addAttributes() { return { diff --git a/packages/client/src/tiptap/core/extensions/iframe.ts b/packages/client/src/tiptap/core/extensions/iframe.ts index fddfef4..657bbcc 100644 --- a/packages/client/src/tiptap/core/extensions/iframe.ts +++ b/packages/client/src/tiptap/core/extensions/iframe.ts @@ -27,6 +27,7 @@ export const Iframe = Node.create({ group: 'block', selectable: true, atom: true, + draggable: true, addOptions() { return { diff --git a/packages/client/src/tiptap/core/extensions/mind.ts b/packages/client/src/tiptap/core/extensions/mind.ts index 1607f99..f4ecc2a 100644 --- a/packages/client/src/tiptap/core/extensions/mind.ts +++ b/packages/client/src/tiptap/core/extensions/mind.ts @@ -35,6 +35,7 @@ export const Mind = Node.create({ group: 'block', selectable: true, atom: true, + draggable: true, inline: false, addAttributes() { diff --git a/packages/client/src/tiptap/core/extensions/paragraph.ts b/packages/client/src/tiptap/core/extensions/paragraph.ts index 8674999..28e8613 100644 --- a/packages/client/src/tiptap/core/extensions/paragraph.ts +++ b/packages/client/src/tiptap/core/extensions/paragraph.ts @@ -1 +1,5 @@ -export { Paragraph } from '@tiptap/extension-paragraph'; +import TitapParagraph from '@tiptap/extension-paragraph'; + +export const Paragraph = TitapParagraph.extend({ + draggable: true, +}); diff --git a/packages/client/src/tiptap/core/styles/code.scss b/packages/client/src/tiptap/core/styles/code.scss index 830ba53..fa61149 100644 --- a/packages/client/src/tiptap/core/styles/code.scss +++ b/packages/client/src/tiptap/core/styles/code.scss @@ -14,7 +14,6 @@ display: flex; min-width: 48px; margin: 0; - overflow-x: auto; line-height: 1.3; background-color: var(--semi-color-fill-0); counter-reset: line 0; @@ -24,7 +23,6 @@ max-height: 370px; padding: 0; margin: 8px; - overflow: auto; font-size: 0.875rem; line-height: 1.5rem; color: inherit; diff --git a/packages/client/src/tiptap/core/wrappers/attachment/index.tsx b/packages/client/src/tiptap/core/wrappers/attachment/index.tsx index 9346ef9..50687a5 100644 --- a/packages/client/src/tiptap/core/wrappers/attachment/index.tsx +++ b/packages/client/src/tiptap/core/wrappers/attachment/index.tsx @@ -1,12 +1,12 @@ import { IconClose, IconDownload, IconPlayCircle } from '@douyinfe/semi-icons'; import { Button, Collapsible, Progress, Space, Spin, Toast, Typography } from '@douyinfe/semi-ui'; import { FILE_CHUNK_SIZE } from '@think/domains'; -import { NodeViewWrapper } from '@tiptap/react'; import cls from 'classnames'; import { Tooltip } from 'components/tooltip'; import { useToggle } from 'hooks/use-toggle'; import { useCallback, useEffect, useRef, useState } from 'react'; import { uploadFile } from 'services/file'; +import { DragableWrapper } from 'tiptap/core/wrappers/dragable'; import { download, extractFileExtension, extractFilename, normalizeFileSize } from 'tiptap/prose-utils'; import { getFileTypeIcon } from './file-icon'; @@ -154,5 +154,5 @@ export const AttachmentWrapper = ({ editor, node, updateAttributes }) => { } })(); - return {content}; + return {content}; }; diff --git a/packages/client/src/tiptap/core/wrappers/callout/index.tsx b/packages/client/src/tiptap/core/wrappers/callout/index.tsx index 684fc36..f9d0371 100644 --- a/packages/client/src/tiptap/core/wrappers/callout/index.tsx +++ b/packages/client/src/tiptap/core/wrappers/callout/index.tsx @@ -1,9 +1,10 @@ -import { NodeViewContent, NodeViewWrapper } from '@tiptap/react'; +import { NodeViewContent } from '@tiptap/react'; import cls from 'classnames'; import { EmojiPicker } from 'components/emoji-picker'; import { convertColorToRGBA } from 'helpers/color'; import { Theme, ThemeEnum } from 'hooks/use-theme'; import { useCallback, useMemo } from 'react'; +import { DragableWrapper } from 'tiptap/core/wrappers/dragable'; import styles from './index.module.scss'; @@ -25,7 +26,7 @@ export const CalloutWrapper = ({ editor, node, updateAttributes }) => { ); return ( - +
{ }} />
-
+ ); }; diff --git a/packages/client/src/tiptap/core/wrappers/code-block/index.tsx b/packages/client/src/tiptap/core/wrappers/code-block/index.tsx index a840c90..a1794fe 100644 --- a/packages/client/src/tiptap/core/wrappers/code-block/index.tsx +++ b/packages/client/src/tiptap/core/wrappers/code-block/index.tsx @@ -1,9 +1,10 @@ import { IconCopy } from '@douyinfe/semi-icons'; import { Button, Select, Tooltip } from '@douyinfe/semi-ui'; -import { NodeViewContent, NodeViewWrapper } from '@tiptap/react'; +import { NodeViewContent } from '@tiptap/react'; import cls from 'classnames'; import { copy } from 'helpers/copy'; import React, { useRef } from 'react'; +import { DragableWrapper } from 'tiptap/core/wrappers/dragable'; import styles from './index.module.scss'; @@ -13,7 +14,7 @@ export const CodeBlockWrapper = ({ editor, node: { attrs }, updateAttributes, ex const $container = useRef(); return ( - +