@tiptap/extension-drag-handle-react 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/DragHandle.d.ts +17 -0
- package/dist/DragHandle.d.ts.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +46 -0
- package/dist/index.umd.js.map +1 -0
- package/package.json +56 -0
- package/src/DragHandle.tsx +69 -0
- package/src/index.ts +5 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @tiptap/extension-drag-handle-react
|
|
2
|
+
[](https://www.npmjs.com/package/@tiptap/extension-drag-handle-react)
|
|
3
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
|
+
[](https://www.npmjs.com/package/@tiptap/extension-drag-handle-react)
|
|
5
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
|
9
|
+
|
|
10
|
+
## Official Documentation
|
|
11
|
+
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DragHandlePluginProps } from '@tiptap/extension-drag-handle';
|
|
2
|
+
import { Node } from '@tiptap/pm/model';
|
|
3
|
+
import { Editor } from '@tiptap/react';
|
|
4
|
+
import React, { ReactNode } from 'react';
|
|
5
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
6
|
+
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
7
|
+
className?: string;
|
|
8
|
+
onNodeChange?: (data: {
|
|
9
|
+
node: Node | null;
|
|
10
|
+
editor: Editor;
|
|
11
|
+
pos: number;
|
|
12
|
+
}) => void;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export declare const DragHandle: (props: DragHandleProps) => React.JSX.Element;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=DragHandle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DragHandle.d.ts","sourceRoot":"","sources":["../src/DragHandle.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,qBAAqB,EACtB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,KAAK,EAAE,EACZ,SAAS,EACV,MAAM,OAAO,CAAA;AAEd,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvE,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,qBAAqB,EAAE,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG;IAC5F,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAClF,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,UAAU,UAAW,eAAe,sBAgDhD,CAAA"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var extensionDragHandle = require('@tiptap/extension-drag-handle');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
11
|
+
|
|
12
|
+
const DragHandle = (props) => {
|
|
13
|
+
const { className = 'drag-handle', children, editor, pluginKey = extensionDragHandle.dragHandlePluginDefaultKey, onNodeChange, tippyOptions = {}, } = props;
|
|
14
|
+
const [element, setElement] = React.useState(null);
|
|
15
|
+
const plugin = React.useRef(null);
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (!element) {
|
|
18
|
+
return () => {
|
|
19
|
+
plugin.current = null;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (editor.isDestroyed) {
|
|
23
|
+
return () => {
|
|
24
|
+
plugin.current = null;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (!plugin.current) {
|
|
28
|
+
plugin.current = extensionDragHandle.DragHandlePlugin({
|
|
29
|
+
editor,
|
|
30
|
+
element,
|
|
31
|
+
pluginKey,
|
|
32
|
+
tippyOptions,
|
|
33
|
+
onNodeChange,
|
|
34
|
+
});
|
|
35
|
+
editor.registerPlugin(plugin.current);
|
|
36
|
+
}
|
|
37
|
+
return () => {
|
|
38
|
+
editor.unregisterPlugin(pluginKey);
|
|
39
|
+
plugin.current = null;
|
|
40
|
+
};
|
|
41
|
+
}, [element, editor, onNodeChange, pluginKey, tippyOptions]);
|
|
42
|
+
return (React__default.default.createElement("div", { className: className, ref: setElement }, children));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.DragHandle = DragHandle;
|
|
46
|
+
exports.default = DragHandle;
|
|
47
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/DragHandle.tsx"],"sourcesContent":["import {\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n DragHandlePluginProps,\n} from '@tiptap/extension-drag-handle'\nimport { Node } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Editor } from '@tiptap/react'\nimport React, {\n ReactNode, useEffect, useRef, useState,\n} from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {\n className?: string;\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void;\n children: ReactNode;\n};\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n tippyOptions = {},\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n useEffect(() => {\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n plugin.current = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n tippyOptions,\n onNodeChange,\n })\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n }\n }, [element, editor, onNodeChange, pluginKey, tippyOptions])\n\n return (\n <div className={className} ref={setElement}>\n {children}\n </div>\n )\n}\n"],"names":["dragHandlePluginDefaultKey","useState","useRef","useEffect","DragHandlePlugin","React"],"mappings":";;;;;;;;;;;AAoBa,MAAA,UAAU,GAAG,CAAC,KAAsB,KAAI;IACnD,MAAM,EACJ,SAAS,GAAG,aAAa,EACzB,QAAQ,EACR,MAAM,EACN,SAAS,GAAGA,8CAA0B,EACtC,YAAY,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,KAAK;IACT,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,cAAQ,CAAwB,IAAI,CAAC;AACnE,IAAA,MAAM,MAAM,GAAGC,YAAM,CAAgB,IAAI,CAAC;IAE1CC,eAAS,CAAC,MAAK;QACb,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,MAAK;AACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,aAAC;;AAGH,QAAA,IAAI,MAAM,CAAC,WAAW,EAAE;AACtB,YAAA,OAAO,MAAK;AACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,aAAC;;AAGH,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;AACnB,YAAA,MAAM,CAAC,OAAO,GAAGC,oCAAgB,CAAC;gBAChC,MAAM;gBACN,OAAO;gBACP,SAAS;gBACT,YAAY;gBACZ,YAAY;AACb,aAAA,CAAC;AAEF,YAAA,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;;AAGvC,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC;AAClC,YAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,SAAC;AACH,KAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAE5D,IAAA,QACEC,sBAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAA,EACvC,QAAQ,CACL;AAEV;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,cAAc,iBAAiB,CAAA;AAE/B,eAAe,UAAU,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DragHandlePlugin, dragHandlePluginDefaultKey } from '@tiptap/extension-drag-handle';
|
|
2
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
const DragHandle = (props) => {
|
|
5
|
+
const { className = 'drag-handle', children, editor, pluginKey = dragHandlePluginDefaultKey, onNodeChange, tippyOptions = {}, } = props;
|
|
6
|
+
const [element, setElement] = useState(null);
|
|
7
|
+
const plugin = useRef(null);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!element) {
|
|
10
|
+
return () => {
|
|
11
|
+
plugin.current = null;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (editor.isDestroyed) {
|
|
15
|
+
return () => {
|
|
16
|
+
plugin.current = null;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (!plugin.current) {
|
|
20
|
+
plugin.current = DragHandlePlugin({
|
|
21
|
+
editor,
|
|
22
|
+
element,
|
|
23
|
+
pluginKey,
|
|
24
|
+
tippyOptions,
|
|
25
|
+
onNodeChange,
|
|
26
|
+
});
|
|
27
|
+
editor.registerPlugin(plugin.current);
|
|
28
|
+
}
|
|
29
|
+
return () => {
|
|
30
|
+
editor.unregisterPlugin(pluginKey);
|
|
31
|
+
plugin.current = null;
|
|
32
|
+
};
|
|
33
|
+
}, [element, editor, onNodeChange, pluginKey, tippyOptions]);
|
|
34
|
+
return (React.createElement("div", { className: className, ref: setElement }, children));
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { DragHandle, DragHandle as default };
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/DragHandle.tsx"],"sourcesContent":["import {\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n DragHandlePluginProps,\n} from '@tiptap/extension-drag-handle'\nimport { Node } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Editor } from '@tiptap/react'\nimport React, {\n ReactNode, useEffect, useRef, useState,\n} from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {\n className?: string;\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void;\n children: ReactNode;\n};\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n tippyOptions = {},\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n useEffect(() => {\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n plugin.current = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n tippyOptions,\n onNodeChange,\n })\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n }\n }, [element, editor, onNodeChange, pluginKey, tippyOptions])\n\n return (\n <div className={className} ref={setElement}>\n {children}\n </div>\n )\n}\n"],"names":[],"mappings":";;;AAoBa,MAAA,UAAU,GAAG,CAAC,KAAsB,KAAI;IACnD,MAAM,EACJ,SAAS,GAAG,aAAa,EACzB,QAAQ,EACR,MAAM,EACN,SAAS,GAAG,0BAA0B,EACtC,YAAY,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,KAAK;IACT,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAwB,IAAI,CAAC;AACnE,IAAA,MAAM,MAAM,GAAG,MAAM,CAAgB,IAAI,CAAC;IAE1C,SAAS,CAAC,MAAK;QACb,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,MAAK;AACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,aAAC;;AAGH,QAAA,IAAI,MAAM,CAAC,WAAW,EAAE;AACtB,YAAA,OAAO,MAAK;AACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,aAAC;;AAGH,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;AACnB,YAAA,MAAM,CAAC,OAAO,GAAG,gBAAgB,CAAC;gBAChC,MAAM;gBACN,OAAO;gBACP,SAAS;gBACT,YAAY;gBACZ,YAAY;AACb,aAAA,CAAC;AAEF,YAAA,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;;AAGvC,QAAA,OAAO,MAAK;AACV,YAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC;AAClC,YAAA,MAAM,CAAC,OAAO,GAAG,IAAI;AACvB,SAAC;AACH,KAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAE5D,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAA,EACvC,QAAQ,CACL;AAEV;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/extension-drag-handle'), require('react')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/extension-drag-handle', 'react'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-drag-handle-react"] = {}, global.extensionDragHandle, global.React));
|
|
5
|
+
})(this, (function (exports, extensionDragHandle, React) { 'use strict';
|
|
6
|
+
|
|
7
|
+
const DragHandle = (props) => {
|
|
8
|
+
const { className = 'drag-handle', children, editor, pluginKey = extensionDragHandle.dragHandlePluginDefaultKey, onNodeChange, tippyOptions = {}, } = props;
|
|
9
|
+
const [element, setElement] = React.useState(null);
|
|
10
|
+
const plugin = React.useRef(null);
|
|
11
|
+
React.useEffect(() => {
|
|
12
|
+
if (!element) {
|
|
13
|
+
return () => {
|
|
14
|
+
plugin.current = null;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
if (editor.isDestroyed) {
|
|
18
|
+
return () => {
|
|
19
|
+
plugin.current = null;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (!plugin.current) {
|
|
23
|
+
plugin.current = extensionDragHandle.DragHandlePlugin({
|
|
24
|
+
editor,
|
|
25
|
+
element,
|
|
26
|
+
pluginKey,
|
|
27
|
+
tippyOptions,
|
|
28
|
+
onNodeChange,
|
|
29
|
+
});
|
|
30
|
+
editor.registerPlugin(plugin.current);
|
|
31
|
+
}
|
|
32
|
+
return () => {
|
|
33
|
+
editor.unregisterPlugin(pluginKey);
|
|
34
|
+
plugin.current = null;
|
|
35
|
+
};
|
|
36
|
+
}, [element, editor, onNodeChange, pluginKey, tippyOptions]);
|
|
37
|
+
return (React.createElement("div", { className: className, ref: setElement }, children));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.DragHandle = DragHandle;
|
|
41
|
+
exports.default = DragHandle;
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
44
|
+
|
|
45
|
+
}));
|
|
46
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/DragHandle.tsx"],"sourcesContent":["import {\n DragHandlePlugin,\n dragHandlePluginDefaultKey,\n DragHandlePluginProps,\n} from '@tiptap/extension-drag-handle'\nimport { Node } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Editor } from '@tiptap/react'\nimport React, {\n ReactNode, useEffect, useRef, useState,\n} from 'react'\n\ntype Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;\n\nexport type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {\n className?: string;\n onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void;\n children: ReactNode;\n};\n\nexport const DragHandle = (props: DragHandleProps) => {\n const {\n className = 'drag-handle',\n children,\n editor,\n pluginKey = dragHandlePluginDefaultKey,\n onNodeChange,\n tippyOptions = {},\n } = props\n const [element, setElement] = useState<HTMLDivElement | null>(null)\n const plugin = useRef<Plugin | null>(null)\n\n useEffect(() => {\n if (!element) {\n return () => {\n plugin.current = null\n }\n }\n\n if (editor.isDestroyed) {\n return () => {\n plugin.current = null\n }\n }\n\n if (!plugin.current) {\n plugin.current = DragHandlePlugin({\n editor,\n element,\n pluginKey,\n tippyOptions,\n onNodeChange,\n })\n\n editor.registerPlugin(plugin.current)\n }\n\n return () => {\n editor.unregisterPlugin(pluginKey)\n plugin.current = null\n }\n }, [element, editor, onNodeChange, pluginKey, tippyOptions])\n\n return (\n <div className={className} ref={setElement}>\n {children}\n </div>\n )\n}\n"],"names":["dragHandlePluginDefaultKey","useState","useRef","useEffect","DragHandlePlugin"],"mappings":";;;;;;AAoBa,QAAA,UAAU,GAAG,CAAC,KAAsB,KAAI;MACnD,MAAM,EACJ,SAAS,GAAG,aAAa,EACzB,QAAQ,EACR,MAAM,EACN,SAAS,GAAGA,8CAA0B,EACtC,YAAY,EACZ,YAAY,GAAG,EAAE,GAClB,GAAG,KAAK;MACT,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,cAAQ,CAAwB,IAAI,CAAC;EACnE,IAAA,MAAM,MAAM,GAAGC,YAAM,CAAgB,IAAI,CAAC;MAE1CC,eAAS,CAAC,MAAK;UACb,IAAI,CAAC,OAAO,EAAE;EACZ,YAAA,OAAO,MAAK;EACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;EACvB,aAAC;;EAGH,QAAA,IAAI,MAAM,CAAC,WAAW,EAAE;EACtB,YAAA,OAAO,MAAK;EACV,gBAAA,MAAM,CAAC,OAAO,GAAG,IAAI;EACvB,aAAC;;EAGH,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;EACnB,YAAA,MAAM,CAAC,OAAO,GAAGC,oCAAgB,CAAC;kBAChC,MAAM;kBACN,OAAO;kBACP,SAAS;kBACT,YAAY;kBACZ,YAAY;EACb,aAAA,CAAC;EAEF,YAAA,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,CAAC;;EAGvC,QAAA,OAAO,MAAK;EACV,YAAA,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC;EAClC,YAAA,MAAM,CAAC,OAAO,GAAG,IAAI;EACvB,SAAC;EACH,KAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;EAE5D,IAAA,QACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAA,EACvC,QAAQ,CACL;EAEV;;;;;;;;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiptap/extension-drag-handle-react",
|
|
3
|
+
"description": "drag handle extension for tiptap with react",
|
|
4
|
+
"version": "2.22.0",
|
|
5
|
+
"homepage": "https://tiptap.dev",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"tiptap",
|
|
8
|
+
"tiptap extension"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"funding": {
|
|
12
|
+
"type": "github",
|
|
13
|
+
"url": "https://github.com/sponsors/ueberdosis"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
18
|
+
"directory": "packages/extension-drag-handle-react"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.js",
|
|
30
|
+
"umd": "dist/index.umd.js",
|
|
31
|
+
"types": "dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"src",
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@tiptap/extension-drag-handle": "^2.14.0",
|
|
38
|
+
"@tiptap/pm": "^2.7.0",
|
|
39
|
+
"@tiptap/react": "^2.7.0",
|
|
40
|
+
"react": "^16.8 || ^17 || ^18 || ^19",
|
|
41
|
+
"react-dom": "^16.8 || ^17 || ^18 || ^19"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@tiptap/extension-drag-handle": "^2.22.0",
|
|
45
|
+
"@tiptap/pm": "^2.22.0",
|
|
46
|
+
"@tiptap/react": "^2.22.0",
|
|
47
|
+
"@types/react": "^18.0.0",
|
|
48
|
+
"@types/react-dom": "^18.0.0",
|
|
49
|
+
"react": "^18.0.0",
|
|
50
|
+
"react-dom": "^18.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"clean": "rm -rf dist",
|
|
54
|
+
"build": "npm run clean && rollup -c"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DragHandlePlugin,
|
|
3
|
+
dragHandlePluginDefaultKey,
|
|
4
|
+
DragHandlePluginProps,
|
|
5
|
+
} from '@tiptap/extension-drag-handle'
|
|
6
|
+
import { Node } from '@tiptap/pm/model'
|
|
7
|
+
import { Plugin } from '@tiptap/pm/state'
|
|
8
|
+
import { Editor } from '@tiptap/react'
|
|
9
|
+
import React, {
|
|
10
|
+
ReactNode, useEffect, useRef, useState,
|
|
11
|
+
} from 'react'
|
|
12
|
+
|
|
13
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
14
|
+
|
|
15
|
+
export type DragHandleProps = Omit<Optional<DragHandlePluginProps, 'pluginKey'>, 'element'> & {
|
|
16
|
+
className?: string;
|
|
17
|
+
onNodeChange?: (data: { node: Node | null; editor: Editor; pos: number }) => void;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const DragHandle = (props: DragHandleProps) => {
|
|
22
|
+
const {
|
|
23
|
+
className = 'drag-handle',
|
|
24
|
+
children,
|
|
25
|
+
editor,
|
|
26
|
+
pluginKey = dragHandlePluginDefaultKey,
|
|
27
|
+
onNodeChange,
|
|
28
|
+
tippyOptions = {},
|
|
29
|
+
} = props
|
|
30
|
+
const [element, setElement] = useState<HTMLDivElement | null>(null)
|
|
31
|
+
const plugin = useRef<Plugin | null>(null)
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!element) {
|
|
35
|
+
return () => {
|
|
36
|
+
plugin.current = null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (editor.isDestroyed) {
|
|
41
|
+
return () => {
|
|
42
|
+
plugin.current = null
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!plugin.current) {
|
|
47
|
+
plugin.current = DragHandlePlugin({
|
|
48
|
+
editor,
|
|
49
|
+
element,
|
|
50
|
+
pluginKey,
|
|
51
|
+
tippyOptions,
|
|
52
|
+
onNodeChange,
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
editor.registerPlugin(plugin.current)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
editor.unregisterPlugin(pluginKey)
|
|
60
|
+
plugin.current = null
|
|
61
|
+
}
|
|
62
|
+
}, [element, editor, onNodeChange, pluginKey, tippyOptions])
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className={className} ref={setElement}>
|
|
66
|
+
{children}
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|