|
| 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> |
0 commit comments