@atlaskit/editor-plugin-block-controls 1.0.0 → 1.2.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugin.js +30 -2
  3. package/dist/cjs/pm-plugins/decorations.js +50 -0
  4. package/dist/cjs/pm-plugins/main.js +66 -4
  5. package/dist/cjs/ui/consts.js +8 -0
  6. package/dist/cjs/ui/drag-handle-menu.js +15 -0
  7. package/dist/cjs/ui/drag-handle.js +99 -0
  8. package/dist/cjs/ui/drag-preview.js +35 -0
  9. package/dist/cjs/ui/drop-target.js +57 -0
  10. package/dist/cjs/ui/global-styles.js +19 -0
  11. package/dist/es2019/plugin.js +29 -3
  12. package/dist/es2019/pm-plugins/decorations.js +43 -0
  13. package/dist/es2019/pm-plugins/main.js +66 -5
  14. package/dist/es2019/ui/consts.js +2 -0
  15. package/dist/es2019/ui/drag-handle-menu.js +10 -0
  16. package/dist/es2019/ui/drag-handle.js +90 -0
  17. package/dist/es2019/ui/drag-preview.js +27 -0
  18. package/dist/es2019/ui/drop-target.js +39 -0
  19. package/dist/es2019/ui/global-styles.js +12 -0
  20. package/dist/esm/plugin.js +30 -3
  21. package/dist/esm/pm-plugins/decorations.js +43 -0
  22. package/dist/esm/pm-plugins/main.js +66 -4
  23. package/dist/esm/ui/consts.js +2 -0
  24. package/dist/esm/ui/drag-handle-menu.js +8 -0
  25. package/dist/esm/ui/drag-handle.js +92 -0
  26. package/dist/esm/ui/drag-preview.js +29 -0
  27. package/dist/esm/ui/drop-target.js +47 -0
  28. package/dist/esm/ui/global-styles.js +12 -0
  29. package/dist/types/pm-plugins/decorations.d.ts +6 -0
  30. package/dist/types/pm-plugins/main.d.ts +6 -3
  31. package/dist/types/types.d.ts +11 -2
  32. package/dist/types/ui/consts.d.ts +2 -0
  33. package/dist/types/ui/drag-handle-menu.d.ts +6 -0
  34. package/dist/types/ui/drag-handle.d.ts +9 -0
  35. package/dist/types/ui/drag-preview.d.ts +1 -0
  36. package/dist/types/ui/drop-target.d.ts +7 -0
  37. package/dist/types/ui/global-styles.d.ts +3 -0
  38. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +6 -0
  39. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -3
  40. package/dist/types-ts4.5/types.d.ts +11 -2
  41. package/dist/types-ts4.5/ui/consts.d.ts +2 -0
  42. package/dist/types-ts4.5/ui/drag-handle-menu.d.ts +6 -0
  43. package/dist/types-ts4.5/ui/drag-handle.d.ts +9 -0
  44. package/dist/types-ts4.5/ui/drag-preview.d.ts +1 -0
  45. package/dist/types-ts4.5/ui/drop-target.d.ts +7 -0
  46. package/dist/types-ts4.5/ui/global-styles.d.ts +3 -0
  47. package/package.json +8 -5
@@ -0,0 +1,90 @@
1
+ /** @jsx jsx */
2
+ import { useEffect, useRef } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
5
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
7
+ import { key } from '../pm-plugins/main';
8
+ import { DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
9
+ import { dragPreview } from './drag-preview';
10
+ const styles = css({
11
+ position: 'absolute',
12
+ zIndex: 1,
13
+ height: DRAG_HANDLE_HEIGHT,
14
+ width: DRAG_HANDLE_WIDTH,
15
+ left: -DRAG_HANDLE_WIDTH
16
+ });
17
+ export const DragHandle = ({
18
+ dom,
19
+ api,
20
+ start,
21
+ end
22
+ }) => {
23
+ const buttonRef = useRef(null);
24
+ const domRef = useRef(dom);
25
+ useEffect(() => {
26
+ const element = buttonRef.current;
27
+ if (!element) {
28
+ return;
29
+ }
30
+ return combine(draggable({
31
+ element,
32
+ getInitialData: () => ({
33
+ start,
34
+ end
35
+ }),
36
+ onGenerateDragPreview: ({
37
+ nativeSetDragImage
38
+ }) => {
39
+ setCustomNativeDragPreview({
40
+ getOffset: () => {
41
+ const rect = domRef.current.getBoundingClientRect();
42
+ // Offset the drag preview to the center of the element
43
+ return {
44
+ x: 0,
45
+ y: rect.height / 2
46
+ };
47
+ },
48
+ render: ({
49
+ container
50
+ }) => {
51
+ return dragPreview(container, domRef);
52
+ },
53
+ nativeSetDragImage
54
+ });
55
+ },
56
+ onDragStart() {
57
+ var _api$core;
58
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
59
+ tr
60
+ }) => tr.setMeta(key, {
61
+ isDragging: true
62
+ }));
63
+ },
64
+ onDrop() {
65
+ var _api$core2;
66
+ api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
67
+ tr
68
+ }) => tr.setMeta(key, {
69
+ isDragging: false
70
+ }));
71
+ }
72
+ }));
73
+ }, [api, start, end]);
74
+ return jsx("button", {
75
+ css: styles,
76
+ style: {
77
+ bottom: dom.clientHeight / 2 - DRAG_HANDLE_HEIGHT / 2
78
+ },
79
+ ref: buttonRef,
80
+ type: "button",
81
+ onClick: () => {
82
+ var _api$core3;
83
+ api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
84
+ tr
85
+ }) => tr.setMeta(key, {
86
+ toggleMenu: true
87
+ }));
88
+ }
89
+ });
90
+ };
@@ -0,0 +1,27 @@
1
+ export const dragPreview = (container, domRef) => {
2
+ const rect = domRef.current.getBoundingClientRect();
3
+ container.style.width = `${rect.width}px`;
4
+ container.style.height = `${rect.height}px`;
5
+ container.style.pointerEvents = 'none';
6
+ const parent = document.createElement('div');
7
+ // ProseMirror class is required to make sure the cloned dom is styled correctly
8
+ parent.classList.add('ProseMirror');
9
+ const clonedDom = domRef.current.cloneNode(true);
10
+
11
+ // Remove any margin from the cloned element to ensure is doesn't position incorrectly
12
+ clonedDom.style.marginLeft = '0';
13
+ clonedDom.style.marginTop = '0';
14
+ clonedDom.style.marginRight = '0';
15
+ clonedDom.style.marginBottom = '0';
16
+ parent.appendChild(clonedDom);
17
+ container.appendChild(parent);
18
+ const scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
19
+ const scrollParentClassNames = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent.className;
20
+
21
+ // Add the scroll parent class to the container to ensure the cloned element is styled correctly
22
+ container.className = scrollParentClassNames || '';
23
+ container.classList.remove('fabric-editor-popup-scroll-parent');
24
+ // Prevents a scrollbar from showing
25
+ container.style.overflow = 'visible';
26
+ return () => container;
27
+ };
@@ -0,0 +1,39 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
3
+ export const DropTarget = ({
4
+ api,
5
+ pos
6
+ }) => {
7
+ const ref = useRef(null);
8
+ const [isDraggedOver, setIsDraggedOver] = useState(false);
9
+ useEffect(() => {
10
+ const element = ref.current;
11
+ if (!element) {
12
+ return;
13
+ }
14
+ return dropTargetForElements({
15
+ element,
16
+ getIsSticky: () => true,
17
+ onDragEnter: () => setIsDraggedOver(true),
18
+ onDragLeave: () => setIsDraggedOver(false),
19
+ onDrop: event => {
20
+ var _api$core, _api$blockControls, _api$blockControls$co;
21
+ const {
22
+ start,
23
+ end
24
+ } = event.source.data;
25
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : (_api$blockControls$co = _api$blockControls.commands) === null || _api$blockControls$co === void 0 ? void 0 : _api$blockControls$co.moveNode(start, end, pos));
26
+ }
27
+ });
28
+ }, [pos, api]);
29
+ return /*#__PURE__*/React.createElement("div", {
30
+ style: {
31
+ height: '20px',
32
+ marginTop: '-22px',
33
+ top: '10px',
34
+ position: 'relative',
35
+ borderBottom: `solid ${isDraggedOver ? 'blue' : 'transparent'} 2px`
36
+ },
37
+ ref: ref
38
+ });
39
+ };
@@ -0,0 +1,12 @@
1
+ /** @jsx jsx */
2
+ import { css, Global, jsx } from '@emotion/react';
3
+ const globalStyles = css({
4
+ '.ProseMirror-widget:first-child + *': {
5
+ 'margin-top': '0 !important'
6
+ }
7
+ });
8
+ export const GlobalStylesWrapper = () => {
9
+ return jsx(Global, {
10
+ styles: globalStyles
11
+ });
12
+ };
@@ -1,4 +1,7 @@
1
- import { createPlugin } from './pm-plugins/main';
1
+ import React from 'react';
2
+ import { createPlugin, key } from './pm-plugins/main';
3
+ import { DragHandleMenu } from './ui/drag-handle-menu';
4
+ import { GlobalStylesWrapper } from './ui/global-styles';
2
5
  export var blockControlsPlugin = function blockControlsPlugin(_ref) {
3
6
  var api = _ref.api;
4
7
  return {
@@ -11,8 +14,32 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
11
14
  }
12
15
  }];
13
16
  },
14
- getSharedState: function getSharedState(_editorState) {
15
- return undefined;
17
+ commands: {
18
+ moveNode: function moveNode(start, end, to) {
19
+ return function (_ref2) {
20
+ var _api$core;
21
+ var tr = _ref2.tr;
22
+ var node = tr.doc.content.cut(start, end); // cut the content
23
+ tr.delete(start, end); // delete the content from the original position
24
+ tr.insert(tr.mapping.map(to), node); // insert the content at the new position
25
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.focus();
26
+ return tr;
27
+ };
28
+ }
29
+ },
30
+ getSharedState: function getSharedState(editorState) {
31
+ var _key$getState$isMenuO, _key$getState;
32
+ if (!editorState) {
33
+ return undefined;
34
+ }
35
+ return {
36
+ isMenuOpen: (_key$getState$isMenuO = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.isMenuOpen) !== null && _key$getState$isMenuO !== void 0 ? _key$getState$isMenuO : false
37
+ };
38
+ },
39
+ contentComponent: function contentComponent() {
40
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DragHandleMenu, {
41
+ api: api
42
+ }), /*#__PURE__*/React.createElement(GlobalStylesWrapper, null));
16
43
  }
17
44
  };
18
45
  };
@@ -0,0 +1,43 @@
1
+ import { createElement } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { DragHandle } from '../ui/drag-handle';
5
+ import { DropTarget } from '../ui/drop-target';
6
+ export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
7
+ var decorations = [];
8
+ oldState.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos) {
9
+ decorations.push(Decoration.widget(pos + node.nodeSize, function () {
10
+ var element = document.createElement('div');
11
+ ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
12
+ api: api,
13
+ pos: pos + node.nodeSize
14
+ }), element);
15
+ return element;
16
+ }));
17
+ return false;
18
+ });
19
+ decorations.push(Decoration.widget(0, function () {
20
+ var element = document.createElement('div');
21
+ ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
22
+ api: api,
23
+ pos: 0
24
+ }), element);
25
+ return element;
26
+ }));
27
+ return decorations;
28
+ };
29
+ export var dragHandleDecoration = function dragHandleDecoration(oldState,
30
+ // @ts-ignore
31
+ meta, api) {
32
+ return DecorationSet.create(oldState.doc, [Decoration.widget(meta.pos + meta.size, function (view, getPos) {
33
+ var element = document.createElement('div');
34
+ ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
35
+ dom: meta.dom,
36
+ api: api,
37
+ start: meta.pos,
38
+ end: meta.pos + meta.size
39
+ }), element);
40
+ element.style.position = 'absolute';
41
+ return element;
42
+ })]);
43
+ };
@@ -1,6 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { dragHandleDecoration, dropTargetDecorations } from './decorations';
4
5
  export var key = new PluginKey('blockControls');
5
6
  export var createPlugin = function createPlugin(api) {
6
7
  return new SafePlugin({
@@ -8,13 +9,40 @@ export var createPlugin = function createPlugin(api) {
8
9
  state: {
9
10
  init: function init() {
10
11
  return {
11
- decorations: DecorationSet.empty
12
+ decorations: DecorationSet.empty,
13
+ activeNode: null,
14
+ isDragging: false,
15
+ isMenuOpen: false
12
16
  };
13
17
  },
14
- apply: function apply(tr, currentState) {
15
- var decorations = currentState.decorations;
18
+ apply: function apply(tr, currentState, oldState, newState) {
19
+ var _meta$isDragging;
20
+ var activeNode = currentState.activeNode,
21
+ decorations = currentState.decorations,
22
+ isMenuOpen = currentState.isMenuOpen;
23
+ var meta = tr.getMeta(key);
24
+ // Drag handle decoration
25
+ if (meta && meta.pos !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && api) {
26
+ decorations = dragHandleDecoration(newState, meta, api);
27
+ }
28
+ // Drop target decorations
29
+ if (meta !== null && meta !== void 0 && meta.isDragging && api) {
30
+ decorations = DecorationSet.create(newState.doc, []);
31
+ var decs = dropTargetDecorations(oldState, newState, api);
32
+ decorations = decorations.add(newState.doc, decs);
33
+ }
34
+ // Remove target decorations when dragging is stopped
35
+ if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false) {
36
+ decorations = DecorationSet.create(newState.doc, []);
37
+ }
16
38
  return {
17
- decorations: decorations
39
+ decorations: decorations,
40
+ activeNode: {
41
+ pos: meta === null || meta === void 0 ? void 0 : meta.pos,
42
+ size: meta === null || meta === void 0 ? void 0 : meta.size
43
+ },
44
+ isDragging: (_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : false,
45
+ isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen
18
46
  };
19
47
  }
20
48
  },
@@ -22,6 +50,40 @@ export var createPlugin = function createPlugin(api) {
22
50
  decorations: function decorations(state) {
23
51
  var _key$getState;
24
52
  return (_key$getState = key.getState(state)) === null || _key$getState === void 0 ? void 0 : _key$getState.decorations;
53
+ },
54
+ handleDOMEvents: {
55
+ mousemove: function mousemove(view, event) {
56
+ var pos = view.posAtCoords({
57
+ left: event.clientX,
58
+ top: event.clientY
59
+ });
60
+ if (pos !== null && pos !== void 0 && pos.inside && pos.inside > 0) {
61
+ var _api$core;
62
+ var node = view.state.doc.nodeAt(pos.inside);
63
+ if (!node) {
64
+ return;
65
+ }
66
+ var resolvedPos = view.state.doc.resolve(pos.pos);
67
+ var topLevelPos = resolvedPos.before(1); // 1 here restricts the depth to the root level
68
+ var topLevelNode = view.state.doc.nodeAt(topLevelPos);
69
+ if (!topLevelNode) {
70
+ return;
71
+ }
72
+ var dom = view.nodeDOM(topLevelPos);
73
+ if (!dom) {
74
+ return;
75
+ }
76
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref) {
77
+ var tr = _ref.tr;
78
+ return tr.setMeta(key, {
79
+ pos: topLevelPos,
80
+ size: topLevelNode.nodeSize,
81
+ dom: dom,
82
+ type: topLevelNode.type.name
83
+ });
84
+ });
85
+ }
86
+ }
25
87
  }
26
88
  }
27
89
  });
@@ -0,0 +1,2 @@
1
+ export var DRAG_HANDLE_HEIGHT = 48;
2
+ export var DRAG_HANDLE_WIDTH = 24;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ export var DragHandleMenu = function DragHandleMenu(_ref) {
4
+ var api = _ref.api;
5
+ var _useSharedPluginState = useSharedPluginState(api, ['blockControls']),
6
+ blockControlsState = _useSharedPluginState.blockControlsState;
7
+ return blockControlsState !== null && blockControlsState !== void 0 && blockControlsState.isMenuOpen ? /*#__PURE__*/React.createElement("div", null, "menu") : null;
8
+ };
@@ -0,0 +1,92 @@
1
+ /** @jsx jsx */
2
+ import { useEffect, useRef } from 'react';
3
+ import { css, jsx } from '@emotion/react';
4
+ import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
5
+ import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
+ import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
7
+ import { key } from '../pm-plugins/main';
8
+ import { DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
9
+ import { dragPreview } from './drag-preview';
10
+ var styles = css({
11
+ position: 'absolute',
12
+ zIndex: 1,
13
+ height: DRAG_HANDLE_HEIGHT,
14
+ width: DRAG_HANDLE_WIDTH,
15
+ left: -DRAG_HANDLE_WIDTH
16
+ });
17
+ export var DragHandle = function DragHandle(_ref) {
18
+ var dom = _ref.dom,
19
+ api = _ref.api,
20
+ start = _ref.start,
21
+ end = _ref.end;
22
+ var buttonRef = useRef(null);
23
+ var domRef = useRef(dom);
24
+ useEffect(function () {
25
+ var element = buttonRef.current;
26
+ if (!element) {
27
+ return;
28
+ }
29
+ return combine(draggable({
30
+ element: element,
31
+ getInitialData: function getInitialData() {
32
+ return {
33
+ start: start,
34
+ end: end
35
+ };
36
+ },
37
+ onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
38
+ var nativeSetDragImage = _ref2.nativeSetDragImage;
39
+ setCustomNativeDragPreview({
40
+ getOffset: function getOffset() {
41
+ var rect = domRef.current.getBoundingClientRect();
42
+ // Offset the drag preview to the center of the element
43
+ return {
44
+ x: 0,
45
+ y: rect.height / 2
46
+ };
47
+ },
48
+ render: function render(_ref3) {
49
+ var container = _ref3.container;
50
+ return dragPreview(container, domRef);
51
+ },
52
+ nativeSetDragImage: nativeSetDragImage
53
+ });
54
+ },
55
+ onDragStart: function onDragStart() {
56
+ var _api$core;
57
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
58
+ var tr = _ref4.tr;
59
+ return tr.setMeta(key, {
60
+ isDragging: true
61
+ });
62
+ });
63
+ },
64
+ onDrop: function onDrop() {
65
+ var _api$core2;
66
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
67
+ var tr = _ref5.tr;
68
+ return tr.setMeta(key, {
69
+ isDragging: false
70
+ });
71
+ });
72
+ }
73
+ }));
74
+ }, [api, start, end]);
75
+ return jsx("button", {
76
+ css: styles,
77
+ style: {
78
+ bottom: dom.clientHeight / 2 - DRAG_HANDLE_HEIGHT / 2
79
+ },
80
+ ref: buttonRef,
81
+ type: "button",
82
+ onClick: function onClick() {
83
+ var _api$core3;
84
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref6) {
85
+ var tr = _ref6.tr;
86
+ return tr.setMeta(key, {
87
+ toggleMenu: true
88
+ });
89
+ });
90
+ }
91
+ });
92
+ };
@@ -0,0 +1,29 @@
1
+ export var dragPreview = function dragPreview(container, domRef) {
2
+ var rect = domRef.current.getBoundingClientRect();
3
+ container.style.width = "".concat(rect.width, "px");
4
+ container.style.height = "".concat(rect.height, "px");
5
+ container.style.pointerEvents = 'none';
6
+ var parent = document.createElement('div');
7
+ // ProseMirror class is required to make sure the cloned dom is styled correctly
8
+ parent.classList.add('ProseMirror');
9
+ var clonedDom = domRef.current.cloneNode(true);
10
+
11
+ // Remove any margin from the cloned element to ensure is doesn't position incorrectly
12
+ clonedDom.style.marginLeft = '0';
13
+ clonedDom.style.marginTop = '0';
14
+ clonedDom.style.marginRight = '0';
15
+ clonedDom.style.marginBottom = '0';
16
+ parent.appendChild(clonedDom);
17
+ container.appendChild(parent);
18
+ var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
19
+ var scrollParentClassNames = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent.className;
20
+
21
+ // Add the scroll parent class to the container to ensure the cloned element is styled correctly
22
+ container.className = scrollParentClassNames || '';
23
+ container.classList.remove('fabric-editor-popup-scroll-parent');
24
+ // Prevents a scrollbar from showing
25
+ container.style.overflow = 'visible';
26
+ return function () {
27
+ return container;
28
+ };
29
+ };
@@ -0,0 +1,47 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
4
+ export var DropTarget = function DropTarget(_ref) {
5
+ var api = _ref.api,
6
+ pos = _ref.pos;
7
+ var ref = useRef(null);
8
+ var _useState = useState(false),
9
+ _useState2 = _slicedToArray(_useState, 2),
10
+ isDraggedOver = _useState2[0],
11
+ setIsDraggedOver = _useState2[1];
12
+ useEffect(function () {
13
+ var element = ref.current;
14
+ if (!element) {
15
+ return;
16
+ }
17
+ return dropTargetForElements({
18
+ element: element,
19
+ getIsSticky: function getIsSticky() {
20
+ return true;
21
+ },
22
+ onDragEnter: function onDragEnter() {
23
+ return setIsDraggedOver(true);
24
+ },
25
+ onDragLeave: function onDragLeave() {
26
+ return setIsDraggedOver(false);
27
+ },
28
+ onDrop: function onDrop(event) {
29
+ var _api$core, _api$blockControls;
30
+ var _ref2 = event.source.data,
31
+ start = _ref2.start,
32
+ end = _ref2.end;
33
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || (_api$blockControls = _api$blockControls.commands) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.moveNode(start, end, pos));
34
+ }
35
+ });
36
+ }, [pos, api]);
37
+ return /*#__PURE__*/React.createElement("div", {
38
+ style: {
39
+ height: '20px',
40
+ marginTop: '-22px',
41
+ top: '10px',
42
+ position: 'relative',
43
+ borderBottom: "solid ".concat(isDraggedOver ? 'blue' : 'transparent', " 2px")
44
+ },
45
+ ref: ref
46
+ });
47
+ };
@@ -0,0 +1,12 @@
1
+ /** @jsx jsx */
2
+ import { css, Global, jsx } from '@emotion/react';
3
+ var globalStyles = css({
4
+ '.ProseMirror-widget:first-child + *': {
5
+ 'margin-top': '0 !important'
6
+ }
7
+ });
8
+ export var GlobalStylesWrapper = function GlobalStylesWrapper() {
9
+ return jsx(Global, {
10
+ styles: globalStyles
11
+ });
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import type { BlockControlsPlugin } from '../types';
5
+ export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
6
+ export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
@@ -7,7 +7,10 @@ export declare const key: PluginKey<PluginState>;
7
7
  export interface PluginState {
8
8
  decorations: DecorationSet;
9
9
  isDragging: boolean;
10
+ isMenuOpen?: boolean;
11
+ activeNode: {
12
+ pos: number;
13
+ size: number;
14
+ } | null;
10
15
  }
11
- export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<{
12
- decorations: DecorationSet;
13
- }>;
16
+ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<PluginState>;
@@ -1,7 +1,16 @@
1
- import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
1
+ import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
2
  export type ReleaseHiddenDecoration = () => boolean | undefined;
3
3
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
4
4
  dependencies: [];
5
- sharedState: undefined;
5
+ sharedState: {
6
+ isMenuOpen: boolean;
7
+ } | undefined;
6
8
  actions: {};
9
+ commands: {
10
+ moveNode: (start: number, end: number, to: number) => EditorCommand;
11
+ };
7
12
  }>;
13
+ export interface DraggableSourceData extends Record<string | symbol, unknown> {
14
+ start: number;
15
+ end: number;
16
+ }
@@ -0,0 +1,2 @@
1
+ export declare const DRAG_HANDLE_HEIGHT = 48;
2
+ export declare const DRAG_HANDLE_WIDTH = 24;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockControlsPlugin } from '../types';
4
+ export declare const DragHandleMenu: ({ api, }: {
5
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
6
+ }) => JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ import { jsx } from '@emotion/react';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockControlsPlugin } from '../types';
4
+ export declare const DragHandle: ({ dom, api, start, end, }: {
5
+ dom: HTMLElement;
6
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
7
+ start: number;
8
+ end: number;
9
+ }) => jsx.JSX.Element;
@@ -0,0 +1 @@
1
+ export declare const dragPreview: (container: HTMLElement, domRef: React.MutableRefObject<HTMLElement>) => () => HTMLElement;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { BlockControlsPlugin } from '../types';
4
+ export declare const DropTarget: ({ api, pos, }: {
5
+ api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
6
+ pos: number;
7
+ }) => JSX.Element;
@@ -0,0 +1,3 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/react';
3
+ export declare const GlobalStylesWrapper: () => jsx.JSX.Element;
@@ -0,0 +1,6 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import type { BlockControlsPlugin } from '../types';
5
+ export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
6
+ export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
@@ -7,7 +7,10 @@ export declare const key: PluginKey<PluginState>;
7
7
  export interface PluginState {
8
8
  decorations: DecorationSet;
9
9
  isDragging: boolean;
10
+ isMenuOpen?: boolean;
11
+ activeNode: {
12
+ pos: number;
13
+ size: number;
14
+ } | null;
10
15
  }
11
- export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<{
12
- decorations: DecorationSet;
13
- }>;
16
+ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<PluginState>;