@atlaskit/editor-plugin-block-controls 1.3.6 → 1.3.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.3.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#100787](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100787)
8
+ [`50f1093f6e70`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/50f1093f6e70) -
9
+ [ux] Fix node controls in incorrect pos when drag handle visible
10
+
11
+ ## 1.3.7
12
+
13
+ ### Patch Changes
14
+
15
+ - [#98222](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98222)
16
+ [`d94cd00110eb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d94cd00110eb) -
17
+ [ux] ED-23206 Set node selection when drag handle is clicked, dragged and content is dropped
18
+ - [#100193](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100193)
19
+ [`e9a08f4f88aa`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e9a08f4f88aa) -
20
+ [ux] Update drag handle position
21
+ - Updated dependencies
22
+
3
23
  ## 1.3.6
4
24
 
5
25
  ### Patch Changes
@@ -9,6 +9,7 @@ var _react = _interopRequireDefault(require("react"));
9
9
  var _main = require("./pm-plugins/main");
10
10
  var _dragHandleMenu = require("./ui/drag-handle-menu");
11
11
  var _globalStyles = require("./ui/global-styles");
12
+ var _getSelection = require("./utils/getSelection");
12
13
  var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPlugin(_ref) {
13
14
  var api = _ref.api;
14
15
  return {
@@ -24,7 +25,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
24
25
  commands: {
25
26
  moveNode: function moveNode(start, to) {
26
27
  return function (_ref2) {
27
- var _node$nodeSize, _api$core;
28
+ var _node$nodeSize;
28
29
  var tr = _ref2.tr;
29
30
  var node = tr.doc.nodeAt(start);
30
31
  var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
@@ -33,7 +34,8 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
33
34
  tr.delete(start, end); // delete the content from the original position
34
35
  var mappedTo = tr.mapping.map(to);
35
36
  tr.insert(mappedTo, nodeCopy); // insert the content at the new position
36
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.focus();
37
+ tr.setSelection((0, _getSelection.getSelection)(tr, mappedTo));
38
+ api === null || api === void 0 || api.core.actions.focus();
37
39
  return tr;
38
40
  };
39
41
  }
@@ -8,6 +8,7 @@ exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
8
8
  var _react = require("react");
9
9
  var _reactDom = _interopRequireDefault(require("react-dom"));
10
10
  var _view = require("@atlaskit/editor-prosemirror/view");
11
+ var _consts = require("../ui/consts");
11
12
  var _dragHandle = require("../ui/drag-handle");
12
13
  var _dropTarget = require("../ui/drop-target");
13
14
  var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
@@ -55,9 +56,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
55
56
  decorationState: decorationState
56
57
  };
57
58
  };
58
- var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(oldState,
59
- // @ts-ignore
60
- meta, api) {
59
+ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(oldState, meta, api) {
61
60
  return _view.DecorationSet.create(oldState.doc, [_view.Decoration.widget(meta.pos, function (view, getPos) {
62
61
  var element = document.createElement('div');
63
62
  _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
@@ -66,6 +65,21 @@ meta, api) {
66
65
  start: meta.pos
67
66
  }), element);
68
67
  element.style.position = 'absolute';
68
+ element.style.zIndex = '1';
69
+ var resizer = meta.dom.querySelector('.resizer-item');
70
+ if (resizer) {
71
+ element.style.left = "".concat(resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
72
+ } else {
73
+ element.style.left = "".concat(meta.dom.offsetLeft - _consts.DRAG_HANDLE_NODE_GAP - _consts.DRAG_HANDLE_WIDTH, "px");
74
+ }
75
+ if (meta.type === 'table') {
76
+ var table = meta.dom.querySelector('table');
77
+ element.style.top = "".concat(meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
78
+ } else {
79
+ element.style.top = "".concat(meta.dom.offsetTop, "px");
80
+ }
69
81
  return element;
82
+ }, {
83
+ side: -1
70
84
  })]);
71
85
  };
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DROP_TARGET_LINE_WIDTH = exports.DROP_TARGET_CIRCLE_DIAMETER = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
6
+ exports.DROP_TARGET_LINE_WIDTH = exports.DROP_TARGET_CIRCLE_DIAMETER = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_NODE_GAP = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
7
7
  var DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_HEIGHT = 24;
8
8
  var DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_WIDTH = 12;
9
9
  var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
10
10
  var DROP_TARGET_LINE_WIDTH = exports.DROP_TARGET_LINE_WIDTH = 2;
11
- var DROP_TARGET_CIRCLE_DIAMETER = exports.DROP_TARGET_CIRCLE_DIAMETER = 4;
11
+ var DROP_TARGET_CIRCLE_DIAMETER = exports.DROP_TARGET_CIRCLE_DIAMETER = 4;
12
+ var DRAG_HANDLE_NODE_GAP = exports.DRAG_HANDLE_NODE_GAP = 12;
@@ -12,16 +12,12 @@ var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-han
12
12
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
13
13
  var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview");
14
14
  var _main = require("../pm-plugins/main");
15
+ var _getSelection = require("../utils/getSelection");
15
16
  var _consts = require("./consts");
16
17
  var _dragPreview = require("./drag-preview");
17
18
  /** @jsx jsx */
18
19
 
19
20
  var dragHandleButtonStyles = (0, _react2.css)({
20
- position: 'relative',
21
- // TODO - we have ticket ED-23209 to correctly position the drag handle for each node
22
- //https://product-fabric.atlassian.net/browse/ED-23209
23
- top: 12,
24
- left: -18,
25
21
  padding: "var(--ds-space-025, 2px)".concat(" 0"),
26
22
  boxSizing: 'border-box',
27
23
  display: 'flex',
@@ -56,6 +52,22 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
56
52
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
57
53
  dragHandleSelected = _useState2[0],
58
54
  setDragHandleSelected = _useState2[1];
55
+ var handleClick = (0, _react.useCallback)(function () {
56
+ var _api$core, _api$core2;
57
+ setDragHandleSelected(!dragHandleSelected);
58
+ // TODO - add drag menu
59
+ // api?.core?.actions.execute(({ tr }) =>
60
+ // tr.setMeta(key, {
61
+ // toggleMenu: true,
62
+ // }),
63
+ // );
64
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
65
+ var tr = _ref2.tr;
66
+ tr.setSelection((0, _getSelection.getSelection)(tr, start));
67
+ return tr;
68
+ });
69
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
70
+ }, [start, api, dragHandleSelected, setDragHandleSelected]);
59
71
  (0, _react.useEffect)(function () {
60
72
  var element = buttonRef.current;
61
73
  if (!element) {
@@ -63,8 +75,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
63
75
  }
64
76
  return (0, _adapter.draggable)({
65
77
  element: element,
66
- onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
67
- var nativeSetDragImage = _ref2.nativeSetDragImage;
78
+ onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
79
+ var nativeSetDragImage = _ref3.nativeSetDragImage;
68
80
  (0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
69
81
  getOffset: function getOffset() {
70
82
  var rect = domRef.current.getBoundingClientRect();
@@ -74,27 +86,31 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
74
86
  y: rect.height / 2
75
87
  };
76
88
  },
77
- render: function render(_ref3) {
78
- var container = _ref3.container;
89
+ render: function render(_ref4) {
90
+ var container = _ref4.container;
79
91
  return (0, _dragPreview.dragPreview)(container, domRef);
80
92
  },
81
93
  nativeSetDragImage: nativeSetDragImage
82
94
  });
83
95
  },
84
96
  onDragStart: function onDragStart() {
85
- var _api$core;
86
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
87
- var tr = _ref4.tr;
88
- return tr.setMeta(_main.key, {
97
+ var _api$core3, _api$core4;
98
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref5) {
99
+ var tr = _ref5.tr;
100
+ var newTr = tr;
101
+ newTr.setSelection((0, _getSelection.getSelection)(newTr, start));
102
+ newTr.setMeta(_main.key, {
89
103
  isDragging: true,
90
104
  start: start
91
105
  });
106
+ return newTr;
92
107
  });
108
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
93
109
  },
94
110
  onDrop: function onDrop() {
95
- var _api$core2;
96
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
97
- var tr = _ref5.tr;
111
+ var _api$core5;
112
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
113
+ var tr = _ref6.tr;
98
114
  return tr.setMeta(_main.key, {
99
115
  isDragging: false
100
116
  });
@@ -106,16 +122,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
106
122
  type: "button",
107
123
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
108
124
  ref: buttonRef,
109
- onClick: function onClick() {
110
- setDragHandleSelected(!dragHandleSelected);
111
-
112
- // TODO - add drag menu
113
- // api?.core?.actions.execute(({ tr }) =>
114
- // tr.setMeta(key, {
115
- // toggleMenu: true,
116
- // }),
117
- // );
118
- }
125
+ onClick: handleClick
119
126
  }, (0, _react2.jsx)(_dragHandler.default, {
120
127
  label: "",
121
128
  size: "medium"
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSelection = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var getSelection = exports.getSelection = function getSelection(tr, start) {
9
+ var node = tr.doc.nodeAt(start);
10
+ var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
11
+ var nodeSize = node ? node.nodeSize : 1;
12
+ var depth = tr.doc.resolve(start).depth;
13
+ var selection = isNodeSelection ? new _state.NodeSelection(tr.doc.resolve(start)) : new _state.TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
14
+ return selection;
15
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { createPlugin, key } from './pm-plugins/main';
3
3
  import { DragHandleMenu } from './ui/drag-handle-menu';
4
4
  import { GlobalStylesWrapper } from './ui/global-styles';
5
+ import { getSelection } from './utils/getSelection';
5
6
  export const blockControlsPlugin = ({
6
7
  api
7
8
  }) => ({
@@ -16,7 +17,7 @@ export const blockControlsPlugin = ({
16
17
  moveNode: (start, to) => ({
17
18
  tr
18
19
  }) => {
19
- var _node$nodeSize, _api$core;
20
+ var _node$nodeSize;
20
21
  const node = tr.doc.nodeAt(start);
21
22
  const size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
22
23
  const end = start + size;
@@ -24,7 +25,8 @@ export const blockControlsPlugin = ({
24
25
  tr.delete(start, end); // delete the content from the original position
25
26
  const mappedTo = tr.mapping.map(to);
26
27
  tr.insert(mappedTo, nodeCopy); // insert the content at the new position
27
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.focus();
28
+ tr.setSelection(getSelection(tr, mappedTo));
29
+ api === null || api === void 0 ? void 0 : api.core.actions.focus();
28
30
  return tr;
29
31
  }
30
32
  },
@@ -1,6 +1,7 @@
1
1
  import { createElement } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { DRAG_HANDLE_NODE_GAP, DRAG_HANDLE_WIDTH } from '../ui/consts';
4
5
  import { DragHandle } from '../ui/drag-handle';
5
6
  import { DropTarget } from '../ui/drop-target';
6
7
  export const dropTargetDecorations = (oldState, newState, api) => {
@@ -48,9 +49,7 @@ export const dropTargetDecorations = (oldState, newState, api) => {
48
49
  decorationState
49
50
  };
50
51
  };
51
- export const dragHandleDecoration = (oldState,
52
- // @ts-ignore
53
- meta, api) => {
52
+ export const dragHandleDecoration = (oldState, meta, api) => {
54
53
  return DecorationSet.create(oldState.doc, [Decoration.widget(meta.pos, (view, getPos) => {
55
54
  const element = document.createElement('div');
56
55
  ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
@@ -59,6 +58,21 @@ meta, api) => {
59
58
  start: meta.pos
60
59
  }), element);
61
60
  element.style.position = 'absolute';
61
+ element.style.zIndex = '1';
62
+ const resizer = meta.dom.querySelector('.resizer-item');
63
+ if (resizer) {
64
+ element.style.left = `${resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH}px`;
65
+ } else {
66
+ element.style.left = `${meta.dom.offsetLeft - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH}px`;
67
+ }
68
+ if (meta.type === 'table') {
69
+ const table = meta.dom.querySelector('table');
70
+ element.style.top = `${meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0)}px`;
71
+ } else {
72
+ element.style.top = `${meta.dom.offsetTop}px`;
73
+ }
62
74
  return element;
75
+ }, {
76
+ side: -1
63
77
  })]);
64
78
  };
@@ -2,4 +2,5 @@ export const DRAG_HANDLE_HEIGHT = 24;
2
2
  export const DRAG_HANDLE_WIDTH = 12;
3
3
  export const DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export const DROP_TARGET_LINE_WIDTH = 2;
5
- export const DROP_TARGET_CIRCLE_DIAMETER = 4;
5
+ export const DROP_TARGET_CIRCLE_DIAMETER = 4;
6
+ export const DRAG_HANDLE_NODE_GAP = 12;
@@ -1,18 +1,14 @@
1
1
  /** @jsx jsx */
2
- import { useEffect, useRef, useState } from 'react';
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
4
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
5
5
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
6
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
7
7
  import { key } from '../pm-plugins/main';
8
+ import { getSelection } from '../utils/getSelection';
8
9
  import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
9
10
  import { dragPreview } from './drag-preview';
10
11
  const dragHandleButtonStyles = css({
11
- position: 'relative',
12
- // TODO - we have ticket ED-23209 to correctly position the drag handle for each node
13
- //https://product-fabric.atlassian.net/browse/ED-23209
14
- top: 12,
15
- left: -18,
16
12
  padding: `${"var(--ds-space-025, 2px)"} 0`,
17
13
  boxSizing: 'border-box',
18
14
  display: 'flex',
@@ -45,6 +41,23 @@ export const DragHandle = ({
45
41
  const buttonRef = useRef(null);
46
42
  const domRef = useRef(dom);
47
43
  const [dragHandleSelected, setDragHandleSelected] = useState(false);
44
+ const handleClick = useCallback(() => {
45
+ var _api$core, _api$core2;
46
+ setDragHandleSelected(!dragHandleSelected);
47
+ // TODO - add drag menu
48
+ // api?.core?.actions.execute(({ tr }) =>
49
+ // tr.setMeta(key, {
50
+ // toggleMenu: true,
51
+ // }),
52
+ // );
53
+ api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
54
+ tr
55
+ }) => {
56
+ tr.setSelection(getSelection(tr, start));
57
+ return tr;
58
+ });
59
+ api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
60
+ }, [start, api, dragHandleSelected, setDragHandleSelected]);
48
61
  useEffect(() => {
49
62
  const element = buttonRef.current;
50
63
  if (!element) {
@@ -73,17 +86,23 @@ export const DragHandle = ({
73
86
  });
74
87
  },
75
88
  onDragStart() {
76
- var _api$core;
77
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
89
+ var _api$core3, _api$core4;
90
+ api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(({
78
91
  tr
79
- }) => tr.setMeta(key, {
80
- isDragging: true,
81
- start
82
- }));
92
+ }) => {
93
+ const newTr = tr;
94
+ newTr.setSelection(getSelection(newTr, start));
95
+ newTr.setMeta(key, {
96
+ isDragging: true,
97
+ start
98
+ });
99
+ return newTr;
100
+ });
101
+ api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.focus();
83
102
  },
84
103
  onDrop() {
85
- var _api$core2;
86
- api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
104
+ var _api$core5;
105
+ api === null || api === void 0 ? void 0 : (_api$core5 = api.core) === null || _api$core5 === void 0 ? void 0 : _api$core5.actions.execute(({
87
106
  tr
88
107
  }) => tr.setMeta(key, {
89
108
  isDragging: false
@@ -95,16 +114,7 @@ export const DragHandle = ({
95
114
  type: "button",
96
115
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
97
116
  ref: buttonRef,
98
- onClick: () => {
99
- setDragHandleSelected(!dragHandleSelected);
100
-
101
- // TODO - add drag menu
102
- // api?.core?.actions.execute(({ tr }) =>
103
- // tr.setMeta(key, {
104
- // toggleMenu: true,
105
- // }),
106
- // );
107
- }
117
+ onClick: handleClick
108
118
  }, jsx(DragHandlerIcon, {
109
119
  label: "",
110
120
  size: "medium"
@@ -0,0 +1,9 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ export const getSelection = (tr, start) => {
3
+ const node = tr.doc.nodeAt(start);
4
+ const isNodeSelection = node && NodeSelection.isSelectable(node);
5
+ const nodeSize = node ? node.nodeSize : 1;
6
+ const depth = tr.doc.resolve(start).depth;
7
+ const selection = isNodeSelection ? new NodeSelection(tr.doc.resolve(start)) : new TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
8
+ return selection;
9
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { createPlugin, key } from './pm-plugins/main';
3
3
  import { DragHandleMenu } from './ui/drag-handle-menu';
4
4
  import { GlobalStylesWrapper } from './ui/global-styles';
5
+ import { getSelection } from './utils/getSelection';
5
6
  export var blockControlsPlugin = function blockControlsPlugin(_ref) {
6
7
  var api = _ref.api;
7
8
  return {
@@ -17,7 +18,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
17
18
  commands: {
18
19
  moveNode: function moveNode(start, to) {
19
20
  return function (_ref2) {
20
- var _node$nodeSize, _api$core;
21
+ var _node$nodeSize;
21
22
  var tr = _ref2.tr;
22
23
  var node = tr.doc.nodeAt(start);
23
24
  var size = (_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 1;
@@ -26,7 +27,8 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
26
27
  tr.delete(start, end); // delete the content from the original position
27
28
  var mappedTo = tr.mapping.map(to);
28
29
  tr.insert(mappedTo, nodeCopy); // insert the content at the new position
29
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.focus();
30
+ tr.setSelection(getSelection(tr, mappedTo));
31
+ api === null || api === void 0 || api.core.actions.focus();
30
32
  return tr;
31
33
  };
32
34
  }
@@ -1,6 +1,7 @@
1
1
  import { createElement } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { DRAG_HANDLE_NODE_GAP, DRAG_HANDLE_WIDTH } from '../ui/consts';
4
5
  import { DragHandle } from '../ui/drag-handle';
5
6
  import { DropTarget } from '../ui/drop-target';
6
7
  export var dropTargetDecorations = function dropTargetDecorations(oldState, newState, api) {
@@ -48,9 +49,7 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
48
49
  decorationState: decorationState
49
50
  };
50
51
  };
51
- export var dragHandleDecoration = function dragHandleDecoration(oldState,
52
- // @ts-ignore
53
- meta, api) {
52
+ export var dragHandleDecoration = function dragHandleDecoration(oldState, meta, api) {
54
53
  return DecorationSet.create(oldState.doc, [Decoration.widget(meta.pos, function (view, getPos) {
55
54
  var element = document.createElement('div');
56
55
  ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
@@ -59,6 +58,21 @@ meta, api) {
59
58
  start: meta.pos
60
59
  }), element);
61
60
  element.style.position = 'absolute';
61
+ element.style.zIndex = '1';
62
+ var resizer = meta.dom.querySelector('.resizer-item');
63
+ if (resizer) {
64
+ element.style.left = "".concat(resizer.offsetLeft - parseInt(getComputedStyle(resizer).marginLeft) - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH, "px");
65
+ } else {
66
+ element.style.left = "".concat(meta.dom.offsetLeft - DRAG_HANDLE_NODE_GAP - DRAG_HANDLE_WIDTH, "px");
67
+ }
68
+ if (meta.type === 'table') {
69
+ var table = meta.dom.querySelector('table');
70
+ element.style.top = "".concat(meta.dom.offsetTop + ((table === null || table === void 0 ? void 0 : table.offsetTop) || 0), "px");
71
+ } else {
72
+ element.style.top = "".concat(meta.dom.offsetTop, "px");
73
+ }
62
74
  return element;
75
+ }, {
76
+ side: -1
63
77
  })]);
64
78
  };
@@ -2,4 +2,5 @@ export var DRAG_HANDLE_HEIGHT = 24;
2
2
  export var DRAG_HANDLE_WIDTH = 12;
3
3
  export var DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export var DROP_TARGET_LINE_WIDTH = 2;
5
- export var DROP_TARGET_CIRCLE_DIAMETER = 4;
5
+ export var DROP_TARGET_CIRCLE_DIAMETER = 4;
6
+ export var DRAG_HANDLE_NODE_GAP = 12;
@@ -1,19 +1,15 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
- import { useEffect, useRef, useState } from 'react';
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
5
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
6
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
7
7
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
8
8
  import { key } from '../pm-plugins/main';
9
+ import { getSelection } from '../utils/getSelection';
9
10
  import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH } from './consts';
10
11
  import { dragPreview } from './drag-preview';
11
12
  var dragHandleButtonStyles = css({
12
- position: 'relative',
13
- // TODO - we have ticket ED-23209 to correctly position the drag handle for each node
14
- //https://product-fabric.atlassian.net/browse/ED-23209
15
- top: 12,
16
- left: -18,
17
13
  padding: "var(--ds-space-025, 2px)".concat(" 0"),
18
14
  boxSizing: 'border-box',
19
15
  display: 'flex',
@@ -48,6 +44,22 @@ export var DragHandle = function DragHandle(_ref) {
48
44
  _useState2 = _slicedToArray(_useState, 2),
49
45
  dragHandleSelected = _useState2[0],
50
46
  setDragHandleSelected = _useState2[1];
47
+ var handleClick = useCallback(function () {
48
+ var _api$core, _api$core2;
49
+ setDragHandleSelected(!dragHandleSelected);
50
+ // TODO - add drag menu
51
+ // api?.core?.actions.execute(({ tr }) =>
52
+ // tr.setMeta(key, {
53
+ // toggleMenu: true,
54
+ // }),
55
+ // );
56
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
57
+ var tr = _ref2.tr;
58
+ tr.setSelection(getSelection(tr, start));
59
+ return tr;
60
+ });
61
+ api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
62
+ }, [start, api, dragHandleSelected, setDragHandleSelected]);
51
63
  useEffect(function () {
52
64
  var element = buttonRef.current;
53
65
  if (!element) {
@@ -55,8 +67,8 @@ export var DragHandle = function DragHandle(_ref) {
55
67
  }
56
68
  return draggable({
57
69
  element: element,
58
- onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
59
- var nativeSetDragImage = _ref2.nativeSetDragImage;
70
+ onGenerateDragPreview: function onGenerateDragPreview(_ref3) {
71
+ var nativeSetDragImage = _ref3.nativeSetDragImage;
60
72
  setCustomNativeDragPreview({
61
73
  getOffset: function getOffset() {
62
74
  var rect = domRef.current.getBoundingClientRect();
@@ -66,27 +78,31 @@ export var DragHandle = function DragHandle(_ref) {
66
78
  y: rect.height / 2
67
79
  };
68
80
  },
69
- render: function render(_ref3) {
70
- var container = _ref3.container;
81
+ render: function render(_ref4) {
82
+ var container = _ref4.container;
71
83
  return dragPreview(container, domRef);
72
84
  },
73
85
  nativeSetDragImage: nativeSetDragImage
74
86
  });
75
87
  },
76
88
  onDragStart: function onDragStart() {
77
- var _api$core;
78
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref4) {
79
- var tr = _ref4.tr;
80
- return tr.setMeta(key, {
89
+ var _api$core3, _api$core4;
90
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref5) {
91
+ var tr = _ref5.tr;
92
+ var newTr = tr;
93
+ newTr.setSelection(getSelection(newTr, start));
94
+ newTr.setMeta(key, {
81
95
  isDragging: true,
82
96
  start: start
83
97
  });
98
+ return newTr;
84
99
  });
100
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.focus();
85
101
  },
86
102
  onDrop: function onDrop() {
87
- var _api$core2;
88
- api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
89
- var tr = _ref5.tr;
103
+ var _api$core5;
104
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref6) {
105
+ var tr = _ref6.tr;
90
106
  return tr.setMeta(key, {
91
107
  isDragging: false
92
108
  });
@@ -98,16 +114,7 @@ export var DragHandle = function DragHandle(_ref) {
98
114
  type: "button",
99
115
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
100
116
  ref: buttonRef,
101
- onClick: function onClick() {
102
- setDragHandleSelected(!dragHandleSelected);
103
-
104
- // TODO - add drag menu
105
- // api?.core?.actions.execute(({ tr }) =>
106
- // tr.setMeta(key, {
107
- // toggleMenu: true,
108
- // }),
109
- // );
110
- }
117
+ onClick: handleClick
111
118
  }, jsx(DragHandlerIcon, {
112
119
  label: "",
113
120
  size: "medium"
@@ -0,0 +1,9 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ export var getSelection = function getSelection(tr, start) {
3
+ var node = tr.doc.nodeAt(start);
4
+ var isNodeSelection = node && NodeSelection.isSelectable(node);
5
+ var nodeSize = node ? node.nodeSize : 1;
6
+ var depth = tr.doc.resolve(start).depth;
7
+ var selection = isNodeSelection ? new NodeSelection(tr.doc.resolve(start)) : new TextSelection(tr.doc.resolve(start), tr.doc.resolve(start + nodeSize - depth));
8
+ return selection;
9
+ };
@@ -1,7 +1,7 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import type { BlockControlsPlugin } from '../types';
4
+ import type { BlockControlsMeta, BlockControlsPlugin } from '../types';
5
5
  export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
6
6
  decs: Decoration[];
7
7
  decorationState: {
@@ -9,4 +9,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
9
9
  pos: number;
10
10
  }[];
11
11
  };
12
- export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
12
+ export declare const dragHandleDecoration: (oldState: EditorState, meta: BlockControlsMeta, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
@@ -28,3 +28,8 @@ export type DecorationState = {
28
28
  index: number;
29
29
  pos: number;
30
30
  }[];
31
+ export type BlockControlsMeta = {
32
+ pos: number;
33
+ type: string;
34
+ dom: HTMLElement;
35
+ };
@@ -3,3 +3,4 @@ export declare const DRAG_HANDLE_WIDTH = 12;
3
3
  export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export declare const DROP_TARGET_LINE_WIDTH = 2;
5
5
  export declare const DROP_TARGET_CIRCLE_DIAMETER = 4;
6
+ export declare const DRAG_HANDLE_NODE_GAP = 12;
@@ -0,0 +1,2 @@
1
+ import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
@@ -1,7 +1,7 @@
1
1
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import type { BlockControlsPlugin } from '../types';
4
+ import type { BlockControlsMeta, BlockControlsPlugin } from '../types';
5
5
  export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
6
6
  decs: Decoration[];
7
7
  decorationState: {
@@ -9,4 +9,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
9
9
  pos: number;
10
10
  }[];
11
11
  };
12
- export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
12
+ export declare const dragHandleDecoration: (oldState: EditorState, meta: BlockControlsMeta, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
@@ -29,3 +29,8 @@ export type DecorationState = {
29
29
  index: number;
30
30
  pos: number;
31
31
  }[];
32
+ export type BlockControlsMeta = {
33
+ pos: number;
34
+ type: string;
35
+ dom: HTMLElement;
36
+ };
@@ -3,3 +3,4 @@ export declare const DRAG_HANDLE_WIDTH = 12;
3
3
  export declare const DRAG_HANDLE_BORDER_RADIUS = 4;
4
4
  export declare const DROP_TARGET_LINE_WIDTH = 2;
5
5
  export declare const DROP_TARGET_CIRCLE_DIAMETER = 4;
6
+ export declare const DRAG_HANDLE_NODE_GAP = 12;
@@ -0,0 +1,2 @@
1
+ import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^80.0.0",
34
+ "@atlaskit/editor-common": "^80.3.0",
35
35
  "@atlaskit/editor-prosemirror": "4.0.1",
36
36
  "@atlaskit/icon": "^22.2.0",
37
37
  "@atlaskit/pragmatic-drag-and-drop": "^1.1.0",