@atlaskit/editor-plugin-block-controls 2.2.2 → 2.3.1

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,21 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149764](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/149764)
8
+ [`f6226757e21b9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f6226757e21b9) -
9
+ Change move left/right shortcut for nested nodes
10
+
11
+ ## 2.3.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#151121](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151121)
16
+ [`2909af0f0c958`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2909af0f0c958) -
17
+ ED-24591 implement drop target v2
18
+
3
19
  ## 2.2.2
4
20
 
5
21
  ### Patch Changes
@@ -105,7 +105,9 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
105
105
  moveToPos = $pos.after($pos.depth) + 1;
106
106
  } else if (direction === _consts.DIRECTION.UP) {
107
107
  var nodeBefore = $pos.depth > 1 && nodeIndex === 0 && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_a11y') ? $pos.node($pos.depth) : $pos.nodeBefore;
108
- moveToPos = $pos.depth > 1 && nodeIndex === 0 && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_a11y') ? $pos.before($pos.depth) - 1 : nodeBefore ? currentNodePos - nodeBefore.nodeSize : moveToPos;
108
+ if (nodeBefore) {
109
+ moveToPos = currentNodePos - nodeBefore.nodeSize;
110
+ }
109
111
  } else {
110
112
  var endOfDoc = $pos.end();
111
113
  var nodeAfterPos = $pos.posAtIndex($pos.index() + 1);
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.nodeDecorations = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
7
+ exports.nodeDecorations = exports.getNodeAnchor = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = exports.createDropTargetDecoration = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -17,10 +17,14 @@ var _utils = require("@atlaskit/editor-common/utils");
17
17
  var _view = require("@atlaskit/editor-prosemirror/view");
18
18
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
19
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
20
+ var _consts = require("../ui/consts");
20
21
  var _dragHandle = require("../ui/drag-handle");
21
22
  var _dropTarget = require("../ui/drop-target");
23
+ var _dropTargetV = require("../ui/drop-target-v2");
22
24
  var _dragTargetDebug = require("../utils/drag-target-debug");
23
25
  var _validation = require("../utils/validation");
26
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
24
28
  var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
25
29
  var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
26
30
  var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
@@ -28,24 +32,101 @@ var DISABLE_CHILD_DROP_TARGET = ['orderedList', 'bulletList'];
28
32
  var getNestedDepth = function getNestedDepth() {
29
33
  return (0, _experiments.editorExperiment)('nested-dnd', true) ? 100 : 0;
30
34
  };
31
- var createDropTargetDecoration = function createDropTargetDecoration(pos, dropTargetDec) {
35
+ var getNodeAnchor = exports.getNodeAnchor = function getNodeAnchor(node) {
36
+ var handleId = ObjHash.getForNode(node);
37
+ return "--node-anchor-".concat(node.type.name, "-").concat(handleId);
38
+ };
39
+ var getNodeMargins = function getNodeMargins(node) {
40
+ if (!node) {
41
+ return _consts.nodeMargins['default'];
42
+ }
43
+ var nodeTypeName = node.type.name;
44
+ if (nodeTypeName === 'heading') {
45
+ return _consts.nodeMargins["heading".concat(node.attrs.level)] || _consts.nodeMargins['default'];
46
+ }
47
+ return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
48
+ };
49
+ var getGapAndOffset = function getGapAndOffset(prevNode, nextNode, parentNode) {
50
+ if (!prevNode && nextNode) {
51
+ // first node
52
+ return {
53
+ gap: 0,
54
+ offset: 0
55
+ };
56
+ } else if (prevNode && !nextNode) {
57
+ return {
58
+ gap: 0,
59
+ offset: 0
60
+ };
61
+ }
62
+ var top = getNodeMargins(nextNode).top || 4;
63
+ var bottom = getNodeMargins(prevNode).bottom || 4;
64
+ var gap = Math.max(top, bottom);
65
+ var offset = top - gap / 2;
66
+ if ((prevNode === null || prevNode === void 0 ? void 0 : prevNode.type.name) === 'mediaSingle' && (nextNode === null || nextNode === void 0 ? void 0 : nextNode.type.name) === 'mediaSingle') {
67
+ offset = -offset;
68
+ } else if (prevNode !== null && prevNode !== void 0 && prevNode.type.name && ['tableCell', 'tableHeader'].includes(prevNode === null || prevNode === void 0 ? void 0 : prevNode.type.name)) {
69
+ offset = 0;
70
+ }
71
+ return {
72
+ gap: gap,
73
+ offset: offset
74
+ };
75
+ };
76
+ var shouldDescend = function shouldDescend(node) {
77
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
78
+ return !['mediaSingle', 'paragraph', 'heading'].includes(node.type.name);
79
+ }
80
+ return true;
81
+ };
82
+ var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorHeightsCache) {
32
83
  return _view.Decoration.widget(pos, function (_, getPos) {
33
84
  var element = document.createElement('div');
34
85
  element.setAttribute('data-blocks-drop-target-container', 'true');
35
86
  element.style.clear = 'unset';
36
- _reactDom.default.render(dropTargetDec(getPos), element);
87
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
88
+ var _getGapAndOffset = getGapAndOffset(props.prevNode, props.nextNode, props.parentNode),
89
+ gap = _getGapAndOffset.gap,
90
+ offset = _getGapAndOffset.offset;
91
+ element.style.setProperty(_dropTargetV.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, "".concat(offset, "px"));
92
+ element.style.setProperty(_dropTargetV.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, "".concat(gap, "px"));
93
+ }
94
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
95
+ _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTargetV.DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
96
+ getPos: getPos,
97
+ anchorHeightsCache: anchorHeightsCache
98
+ })), element);
99
+ } else {
100
+ _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, _objectSpread(_objectSpread({}, props), {}, {
101
+ getPos: getPos
102
+ })), element);
103
+ }
37
104
  return element;
38
105
  }, {
39
106
  type: 'drop-target-decoration',
40
- side: -1
107
+ side: side
41
108
  });
42
109
  };
43
- var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode) {
110
+ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorHeightsCache) {
44
111
  var decs = [];
45
112
  unmountDecorations('data-blocks-drop-target-container');
46
113
  var prevNode;
47
114
  var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
48
115
  var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
116
+ anchorHeightsCache === null || anchorHeightsCache === void 0 || anchorHeightsCache.clear();
117
+ var prevNodeStack = [];
118
+ var popNodeStack = function popNodeStack(depth) {
119
+ var result;
120
+ var toDepth = Math.max(depth, 0);
121
+ while (prevNodeStack.length > toDepth) {
122
+ result = prevNodeStack.pop();
123
+ }
124
+ return result;
125
+ };
126
+ var pushNodeStack = function pushNodeStack(node, depth) {
127
+ popNodeStack(depth);
128
+ prevNodeStack.push(node);
129
+ };
49
130
  newState.doc.descendants(function (node, pos, parent, index) {
50
131
  var depth = 0;
51
132
  // drop target deco at the end position
@@ -53,62 +134,65 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
53
134
  if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
54
135
  depth = newState.doc.resolve(pos).depth;
55
136
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
56
- prevNode = node;
137
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
138
+ pushNodeStack(node, depth);
139
+ } else {
140
+ prevNode = node;
141
+ }
57
142
  return false;
58
143
  }
59
144
  if (IGNORE_NODES.includes(node.type.name)) {
60
- prevNode = node;
61
- return true; //skip over, don't consider it a valid depth
145
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
146
+ pushNodeStack(node, depth);
147
+ } else {
148
+ prevNode = node;
149
+ }
150
+ return shouldDescend(node); //skip over, don't consider it a valid depth
62
151
  }
63
152
  var canDrop = activePMNode && (0, _validation.canMoveNodeToIndex)(parent, index, activePMNode);
64
153
 
65
154
  //NOTE: This will block drop targets showing for nodes that are valid after transformation (i.e. expand -> nestedExpand)
66
155
  if (!canDrop && !(0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
67
- prevNode = node;
156
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
157
+ pushNodeStack(node, depth);
158
+ } else {
159
+ prevNode = node;
160
+ }
68
161
  return false; //not valid pos, so nested not valid either
69
162
  }
70
163
  if (parent.lastChild === node && !(0, _utils.isEmptyParagraph)(node) && PARENT_WITH_END_DROP_TARGET.includes(parent.type.name)) {
71
164
  endPos = pos + node.nodeSize;
72
165
  }
73
166
  }
74
- var previousNode = prevNode; // created scoped variable
75
- decs.push(createDropTargetDecoration(pos, function (getPos) {
76
- return /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
167
+ var previousNode = (0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2') ? popNodeStack(depth) : prevNode; // created scoped variable
168
+ decs.push(createDropTargetDecoration(pos, {
169
+ api: api,
170
+ prevNode: previousNode,
171
+ nextNode: node,
172
+ parentNode: parent || undefined,
173
+ formatMessage: formatMessage
174
+ }, -1, anchorHeightsCache));
175
+ if (endPos !== undefined) {
176
+ decs.push(createDropTargetDecoration(endPos, {
77
177
  api: api,
78
- getPos: getPos,
79
- prevNode: previousNode,
80
- nextNode: node,
81
- parentNode: parent,
178
+ prevNode: (0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2') ? node : undefined,
179
+ parentNode: parent || undefined,
82
180
  formatMessage: formatMessage
83
- });
84
- }));
85
- if (endPos !== undefined) {
86
- decs.push(createDropTargetDecoration(endPos, function (getPos) {
87
- return /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
88
- api: api,
89
- getPos: getPos,
90
- parentNode: parent,
91
- formatMessage: formatMessage
92
- });
93
- }));
181
+ }, -1, anchorHeightsCache));
182
+ }
183
+ if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
184
+ pushNodeStack(node, depth);
185
+ } else {
186
+ prevNode = node;
94
187
  }
95
- prevNode = node;
96
- return depth < getNestedDepth();
188
+ return depth < getNestedDepth() && shouldDescend(node);
97
189
  });
98
-
99
- //TODO: Should this use createDropTargetDecoration?
100
- decs.push(_view.Decoration.widget(newState.doc.nodeSize - 2, function (_, getPos) {
101
- var element = document.createElement('div');
102
- element.setAttribute('data-blocks-drop-target-container', 'true');
103
- _reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
104
- api: api,
105
- getPos: getPos,
106
- formatMessage: formatMessage
107
- }), element);
108
- return element;
109
- }, {
110
- type: 'drop-target-decoration'
111
- }));
190
+ decs.push(createDropTargetDecoration(newState.doc.nodeSize - 2, {
191
+ api: api,
192
+ formatMessage: formatMessage,
193
+ prevNode: newState.doc.lastChild || undefined,
194
+ parentNode: newState.doc
195
+ }, undefined, anchorHeightsCache));
112
196
  return decs;
113
197
  };
114
198
  var emptyParagraphNodeDecorations = exports.emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
@@ -19,6 +19,7 @@ var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
19
19
  var _combine = require("@atlaskit/pragmatic-drag-and-drop/combine");
20
20
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
21
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
22
+ var _anchorUtils = require("../utils/anchor-utils");
22
23
  var _dragTargetDebug = require("../utils/drag-target-debug");
23
24
  var _decorations = require("./decorations");
24
25
  var _handleMouseOver = require("./handle-mouse-over");
@@ -102,6 +103,10 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
102
103
  if ((0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2')) {
103
104
  // TODO: Remove this once FG is used in code
104
105
  }
106
+ var anchorHeightsCache;
107
+ if (!(0, _anchorUtils.isAnchorSupported)() && (0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
108
+ anchorHeightsCache = new _anchorUtils.AnchorHeightsCache();
109
+ }
105
110
  return new _safePlugin.SafePlugin({
106
111
  key: key,
107
112
  state: {
@@ -270,7 +275,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
270
275
  // if the transaction is only for analytics and user is dragging, continue to draw drop targets
271
276
  if (shouldCreateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
272
277
  var _meta$activeNode6;
273
- var _decs2 = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
278
+ var _decs2 = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorHeightsCache);
274
279
  decorations = decorations.add(newState.doc, _decs2);
275
280
  }
276
281
  }
@@ -347,6 +352,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
347
352
  return false;
348
353
  },
349
354
  dragstart: function dragstart(view) {
355
+ var _anchorHeightsCache;
356
+ (_anchorHeightsCache = anchorHeightsCache) === null || _anchorHeightsCache === void 0 || _anchorHeightsCache.setEditorView(view);
350
357
  view.dispatch(view.state.tr.setMeta(key, {
351
358
  isPMDragging: true
352
359
  }));
@@ -107,7 +107,7 @@ var nodeMargins = exports.nodeMargins = {
107
107
  bottom: 0
108
108
  },
109
109
  codeBlock: {
110
- top: 0,
110
+ top: 12,
111
111
  bottom: 0
112
112
  },
113
113
  panel: {
@@ -115,8 +115,8 @@ var nodeMargins = exports.nodeMargins = {
115
115
  bottom: 0
116
116
  },
117
117
  rule: {
118
- top: 20,
119
- bottom: 20
118
+ top: 24,
119
+ bottom: 24
120
120
  },
121
121
  mediaSingle: {
122
122
  top: 24,
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = exports.DropTargetV2 = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = require("react");
11
+ var _react2 = require("@emotion/react");
12
+ var _hooks = require("@atlaskit/editor-common/hooks");
13
+ var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
14
+ var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
15
+ var _constants = require("@atlaskit/theme/constants");
16
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
17
+ var _decorations = require("../pm-plugins/decorations");
18
+ var _anchorUtils = require("../utils/anchor-utils");
19
+ var _dragTargetDebug = require("../utils/drag-target-debug");
20
+ var _consts = require("./consts");
21
+ /**
22
+ * @jsxRuntime classic
23
+ * @jsx jsx
24
+ */
25
+
26
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
27
+
28
+ var DEFAULT_DROP_INDICATOR_WIDTH = 760;
29
+ var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
30
+ var EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
31
+ var EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX = '--editor-block-controls-drop-target-zindex';
32
+ var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = '--editor-block-controls-drop-indicator-offset';
33
+ var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = '--editor-block-controls-drop-indicator-gap';
34
+ var styleDropTarget = (0, _react2.css)({
35
+ marginLeft: "calc(-1 * var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, ", 0))"),
36
+ paddingLeft: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, ", 0)"),
37
+ position: 'absolute',
38
+ left: '0',
39
+ display: 'block',
40
+ zIndex: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX, ", 110)"),
41
+ transform: "translateY(var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0))")
42
+ });
43
+ var styleDropIndicator = (0, _react2.css)({
44
+ height: '100%',
45
+ margin: '0 auto',
46
+ position: 'relative',
47
+ width: "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, ", 100%)")
48
+ });
49
+ var nestedDropIndicatorStyle = (0, _react2.css)({
50
+ position: 'relative'
51
+ });
52
+ var dropZoneStyles = (0, _react2.css)({
53
+ margin: 0,
54
+ position: 'absolute',
55
+ width: '100%',
56
+ zIndex: 110,
57
+ minHeight: '4px'
58
+ });
59
+ var nestedDropZoneStyle = (0, _react2.css)({
60
+ left: '4px',
61
+ right: '4px',
62
+ width: 'unset'
63
+ });
64
+ var enableDropZone = ['paragraph', 'mediaSingle', 'heading', 'codeBlock', 'decisionList', 'bulletList', 'orderedList', 'taskList', 'extension', 'blockCard'];
65
+ var HoverZone = function HoverZone(_ref) {
66
+ var onDragEnter = _ref.onDragEnter,
67
+ onDragLeave = _ref.onDragLeave,
68
+ onDrop = _ref.onDrop,
69
+ node = _ref.node,
70
+ editorWidth = _ref.editorWidth,
71
+ anchorHeightsCache = _ref.anchorHeightsCache,
72
+ position = _ref.position,
73
+ isNestedDropTarget = _ref.isNestedDropTarget;
74
+ var ref = (0, _react.useRef)(null);
75
+ (0, _react.useEffect)(function () {
76
+ if (ref.current) {
77
+ return (0, _adapter.dropTargetForElements)({
78
+ element: ref.current,
79
+ onDragEnter: onDragEnter,
80
+ onDragLeave: onDragLeave,
81
+ onDrop: onDrop
82
+ });
83
+ }
84
+ }, [onDragEnter, onDragLeave, onDrop]);
85
+ var hoverZoneUpperStyle = (0, _react.useMemo)(function () {
86
+ var anchorName = node ? (0, _decorations.getNodeAnchor)(node) : '';
87
+ var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
88
+ var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
89
+ var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? (0, _anchorUtils.isAnchorSupported)() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((anchorHeightsCache === null || anchorHeightsCache === void 0 ? void 0 : anchorHeightsCache.getHeight(anchorName)) || 0) / 2, "px + ").concat(heightStyleOffset, ")") : '4px';
90
+ var transform = position === 'upper' ? "translateY(calc(-100% + ".concat(transformOffset, "))") : "translateY(".concat(transformOffset, ")");
91
+ return (0, _react2.css)({
92
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
93
+ height: heightStyle,
94
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
95
+ transform: transform,
96
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
97
+ maxWidth: "".concat(editorWidth || 0, "px")
98
+ });
99
+ }, [anchorHeightsCache, editorWidth, node, position]);
100
+ return (0, _react2.jsx)("div", {
101
+ ref: ref
102
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
103
+ ,
104
+ className: "drop-target-hover-zone-".concat(position)
105
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
106
+ ,
107
+ css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle, hoverZoneUpperStyle]
108
+ });
109
+ };
110
+ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(_ref2) {
111
+ var _dynamicStyle;
112
+ var api = _ref2.api,
113
+ getPos = _ref2.getPos,
114
+ prevNode = _ref2.prevNode,
115
+ nextNode = _ref2.nextNode,
116
+ parentNode = _ref2.parentNode,
117
+ formatMessage = _ref2.formatMessage,
118
+ anchorHeightsCache = _ref2.anchorHeightsCache;
119
+ var _useState = (0, _react.useState)(false),
120
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
121
+ isDraggedOver = _useState2[0],
122
+ setIsDraggedOver = _useState2[1];
123
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['width']),
124
+ widthState = _useSharedPluginState.widthState;
125
+ var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
126
+ var onDrop = function onDrop() {
127
+ var _api$blockControls;
128
+ var _ref3 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
129
+ activeNode = _ref3.activeNode;
130
+ if (!activeNode) {
131
+ return;
132
+ }
133
+ var pos = getPos();
134
+ if (activeNode && pos !== undefined) {
135
+ var _api$core, _api$blockControls2;
136
+ var start = activeNode.pos;
137
+ api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos, undefined, formatMessage));
138
+ }
139
+ };
140
+ var dynamicStyle = (_dynamicStyle = {
141
+ width: isNestedDropTarget ? 'unset' : '100%'
142
+ }, (0, _defineProperty2.default)(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH, isNestedDropTarget ? '100%' : "".concat((widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH, "px")), (0, _defineProperty2.default)(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN, isNestedDropTarget ? (0, _consts.getNestedNodeLeftPaddingMargin)(parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) : '0'), (0, _defineProperty2.default)(_dynamicStyle, EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX, (0, _experiments.editorExperiment)('nested-dnd', true) ? _constants.layers.navigation() : _constants.layers.card()), _dynamicStyle);
143
+ return (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(HoverZone, {
144
+ onDragEnter: function onDragEnter() {
145
+ return setIsDraggedOver(true);
146
+ },
147
+ onDragLeave: function onDragLeave() {
148
+ return setIsDraggedOver(false);
149
+ },
150
+ onDrop: onDrop,
151
+ node: prevNode,
152
+ editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
153
+ anchorHeightsCache: anchorHeightsCache,
154
+ position: "upper",
155
+ isNestedDropTarget: isNestedDropTarget
156
+ }), (0, _react2.jsx)("div", {
157
+ // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
158
+ css: [styleDropTarget, isNestedDropTarget && nestedDropIndicatorStyle]
159
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
160
+ ,
161
+ style: dynamicStyle,
162
+ "data-testid": "block-ctrl-drop-target"
163
+ },
164
+ // 4px gap to clear expand node border
165
+ (isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)("div", {
166
+ css: styleDropIndicator,
167
+ "data-testid": "block-ctrl-drop-indicator"
168
+ }, (0, _react2.jsx)(_box.DropIndicator, {
169
+ edge: "bottom"
170
+ }))), (0, _react2.jsx)(HoverZone, {
171
+ onDragEnter: function onDragEnter() {
172
+ return setIsDraggedOver(true);
173
+ },
174
+ onDragLeave: function onDragLeave() {
175
+ return setIsDraggedOver(false);
176
+ },
177
+ onDrop: onDrop,
178
+ node: nextNode,
179
+ editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
180
+ anchorHeightsCache: anchorHeightsCache,
181
+ position: "lower",
182
+ isNestedDropTarget: isNestedDropTarget
183
+ }));
184
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.isAnchorSupported = exports.AnchorHeightsCache = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _memoizeOne = _interopRequireDefault(require("memoize-one"));
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ var isAnchorSupported = exports.isAnchorSupported = (0, _memoizeOne.default)(function () {
15
+ // directly use CSS would cause failed SSR tests.
16
+ if (window.CSS && window.CSS.supports) {
17
+ return window.CSS.supports('anchor-name: --a');
18
+ }
19
+ return false;
20
+ });
21
+ var AnchorHeightsCache = exports.AnchorHeightsCache = /*#__PURE__*/function () {
22
+ function AnchorHeightsCache() {
23
+ (0, _classCallCheck2.default)(this, AnchorHeightsCache);
24
+ (0, _defineProperty2.default)(this, "anchorHeightsMap", {});
25
+ (0, _defineProperty2.default)(this, "isAnchorSupported", isAnchorSupported());
26
+ (0, _defineProperty2.default)(this, "isDirty", true);
27
+ (0, _defineProperty2.default)(this, "view", null);
28
+ }
29
+ (0, _createClass2.default)(AnchorHeightsCache, [{
30
+ key: "clear",
31
+ value: function clear() {
32
+ this.isDirty = true;
33
+ this.anchorHeightsMap = {};
34
+ }
35
+ }, {
36
+ key: "getHeights",
37
+ value: function getHeights() {
38
+ if (this.isDirty) {
39
+ var _this$view;
40
+ var anchorElements = ((_this$view = this.view) === null || _this$view === void 0 ? void 0 : _this$view.dom.querySelectorAll('[data-drag-handler-anchor-name]')) || [];
41
+ this.anchorHeightsMap = Array.from(anchorElements).reduce(function (prev, curr) {
42
+ var anchorName = curr.getAttribute('data-drag-handler-anchor-name');
43
+ if (anchorName) {
44
+ return _objectSpread(_objectSpread({}, prev), {}, (0, _defineProperty2.default)({}, anchorName, curr.clientHeight));
45
+ }
46
+ return prev;
47
+ }, {});
48
+ this.isDirty = false;
49
+ }
50
+ return this.anchorHeightsMap;
51
+ }
52
+ }, {
53
+ key: "setEditorView",
54
+ value: function setEditorView(view) {
55
+ if (this.view !== view) {
56
+ this.view = view;
57
+ }
58
+ }
59
+ }, {
60
+ key: "getHeight",
61
+ value: function getHeight(anchorName) {
62
+ if (this.isAnchorSupported) {
63
+ return null;
64
+ }
65
+ var heights = this.getHeights();
66
+ return heights[anchorName];
67
+ }
68
+ }]);
69
+ return AnchorHeightsCache;
70
+ }();
@@ -15,10 +15,10 @@ var getNestedNodePosition = exports.getNestedNodePosition = function getNestedNo
15
15
  if ($pos.depth < 1) {
16
16
  return nestedNodePos;
17
17
  }
18
- var parentNodeOfSpecificTypes = (0, _utils.findParentNodeOfType)([state.schema.nodes.bulletList, state.schema.nodes.orderedList, state.schema.nodes.blockquote, state.schema.nodes.taskList])(state.selection);
18
+ var parentNodeOfSpecificTypes = (0, _utils.findParentNodeOfType)([state.schema.nodes.bulletList, state.schema.nodes.orderedList, state.schema.nodes.blockquote, state.schema.nodes.taskList, state.schema.nodes.decisionList])(state.selection);
19
19
  if (parentNodeOfSpecificTypes) {
20
20
  var parentNodeType = parentNodeOfSpecificTypes.node.type.name;
21
- nestedNodePos = ['bulletList', 'orderedList'].includes(parentNodeType) ? $pos.before($pos.depth - 1) : ['blockquote', 'taskList'].includes(parentNodeType) ? $pos.before() : nestedNodePos;
21
+ nestedNodePos = ['bulletList', 'orderedList'].includes(parentNodeType) ? $pos.before($pos.depth - 1) : ['blockquote', 'taskList', 'decisionList'].includes(parentNodeType) ? $pos.before() : nestedNodePos;
22
22
  }
23
23
  } else {
24
24
  nestedNodePos = selection.$from.pos;
@@ -100,7 +100,9 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
100
100
  moveToPos = $pos.after($pos.depth) + 1;
101
101
  } else if (direction === DIRECTION.UP) {
102
102
  const nodeBefore = $pos.depth > 1 && nodeIndex === 0 && fg('platform_editor_element_dnd_nested_a11y') ? $pos.node($pos.depth) : $pos.nodeBefore;
103
- moveToPos = $pos.depth > 1 && nodeIndex === 0 && fg('platform_editor_element_dnd_nested_a11y') ? $pos.before($pos.depth) - 1 : nodeBefore ? currentNodePos - nodeBefore.nodeSize : moveToPos;
103
+ if (nodeBefore) {
104
+ moveToPos = currentNodePos - nodeBefore.nodeSize;
105
+ }
104
106
  } else {
105
107
  const endOfDoc = $pos.end();
106
108
  const nodeAfterPos = $pos.posAtIndex($pos.index() + 1);