Skip to content

Commit 0571973

Browse files
authored
Merge pull request #361 from NiclasDev63/new-drag-handle
Updated Drag Handle
2 parents cb682b4 + 7a248c8 commit 0571973

File tree

6 files changed

+252
-328
lines changed

6 files changed

+252
-328
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: "Global Drag Handle (New)"
3+
description: "Drag and drop blocks across the editor"
4+
---
5+
6+
<Steps>
7+
8+
<Step title="Install the extension">
9+
Install the extension with a package manager of your choice.
10+
11+
```NPM
12+
$ npm i tiptap-extension-global-drag-handle
13+
```
14+
```Yarn
15+
$ yarn add tiptap-extension-global-drag-handle
16+
```
17+
18+
In order to enjoy all the advantages of a drag handle, it is recommended to install the auto joiner extension as well, which allows you to automatically join various nodes such as 2 lists that are next to each other.
19+
20+
```NPM
21+
$ npm i tiptap-extension-auto-joiner
22+
```
23+
```Yarn
24+
$ yarn add tiptap-extension-auto-joiner
25+
```
26+
27+
</Step>
28+
29+
<Step title="Add drag extension">
30+
```tsx
31+
// extensions.ts
32+
import GlobalDragHandle from 'tiptap-extension-global-drag-handle'
33+
import AutoJoiner from 'tiptap-extension-auto-joiner' // optional
34+
35+
export const defaultExtensions = [
36+
GlobalDragHandle,
37+
AutoJoiner, // optional
38+
// other extensions
39+
];
40+
41+
// editor.tsx
42+
const Editor = () => {
43+
return <EditorContent extensions={defaultExtensions} />
44+
}
45+
```
46+
</Step>
47+
48+
<Step title="Configure the extension">
49+
```tsx
50+
//extensions.ts
51+
import GlobalDragHandle from 'tiptap-extension-global-drag-handle'
52+
import AutoJoiner from 'tiptap-extension-auto-joiner' // optional
53+
54+
export const defaultExtensions = [
55+
GlobalDragHandle.configure({
56+
dragHandleWidth: 20, // default
57+
58+
// The scrollTreshold specifies how close the user must drag an element to the edge of the lower/upper screen for automatic
59+
// scrolling to take place. For example, scrollTreshold = 100 means that scrolling starts automatically when the user drags an
60+
// element to a position that is max. 99px away from the edge of the screen
61+
// You can set this to 0 to prevent auto scrolling caused by this extension
62+
scrollTreshold: 100 // default
63+
}),
64+
AutoJoiner.configure({
65+
elementsToJoin: ["bulletList", "orderedList"] // default
66+
}),
67+
// other extensions
68+
];
69+
70+
// editor.tsx
71+
const Editor = () => {
72+
return <EditorContent extensions={defaultExtensions} />
73+
}
74+
```
75+
</Step>
76+
77+
<Step title="Add styling">
78+
By default the drag handle is headless, which means it doesn't contain any css. If you want to apply styling to the drag handle, use the class "drag-handle" in your css file.
79+
80+
Take a look at [this](https://github.com/steven-tey/novel/blob/main/apps/web/styles/prosemirror.css#L131) to see an example of drag handle styling.
81+
</Step>
82+
83+
</Steps>

apps/docs/mint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
]
5252
},
5353
"guides/ai-command",
54-
"guides/image-upload"
54+
"guides/image-upload",
55+
"guides/global-drag-handle"
5556
]
5657
},
5758
{

packages/headless/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
"@tiptap/react": "^2.1.7",
5555
"@tiptap/starter-kit": "^2.1.7",
5656
"@tiptap/suggestion": "^2.1.7",
57+
"tiptap-extension-auto-joiner": "^0.1.1",
58+
"tiptap-extension-global-drag-handle": "^0.1.2",
5759
"@types/node": "18.15.3",
5860
"cmdk": "^0.2.1",
5961
"jotai": "^2.6.4",

packages/headless/src/extensions/drag-and-drop.tsx

Lines changed: 0 additions & 227 deletions
This file was deleted.

packages/headless/src/extensions/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import { Markdown } from "tiptap-markdown";
1313
import Highlight from "@tiptap/extension-highlight";
1414
import UpdatedImage from "./updated-image";
1515
import CustomKeymap from "./custom-keymap";
16-
import DragAndDrop from "./drag-and-drop";
1716
import { ImageResizer } from "./image-resizer";
17+
import GlobalDragHandle from "tiptap-extension-global-drag-handle";
18+
import AutoJoiner from "tiptap-extension-auto-joiner";
19+
1820
const PlaceholderExtension = Placeholder.configure({
1921
placeholder: ({ node }) => {
2022
if (node.type.name === "heading") {
@@ -38,7 +40,10 @@ const simpleExtensions = [
3840
transformCopiedText: true,
3941
}),
4042
CustomKeymap,
41-
DragAndDrop,
43+
GlobalDragHandle.configure({
44+
scrollTreshold: 0,
45+
}),
46+
AutoJoiner,
4247
] as const;
4348

4449
const Horizontal = HorizontalRule.extend({

0 commit comments

Comments
 (0)