@atlaskit/editor-plugin-block-controls 2.27.0 → 2.27.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,14 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.27.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#112996](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112996)
8
+ [`e76ab95452657`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e76ab95452657) -
9
+ ED-26395: Added tests for canMoveSliceToIndex, and fix drop target showing when first node is p,
10
+ second node table, drop into panel
11
+
3
12
  ## 2.27.0
4
13
 
5
14
  ### Minor Changes
@@ -8,6 +8,7 @@ exports.findDropTargetDecs = exports.dropTargetDecorations = exports.createLayou
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("react");
10
10
  var _uuid = _interopRequireDefault(require("uuid"));
11
+ var _selection = require("@atlaskit/editor-common/selection");
11
12
  var _utils = require("@atlaskit/editor-common/utils");
12
13
  var _view = require("@atlaskit/editor-prosemirror/view");
13
14
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
@@ -166,6 +167,15 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
166
167
  prevNodeStack.push(node);
167
168
  };
168
169
  var isAdvancedLayoutsPreRelease2 = (0, _experiments.editorExperiment)('advanced_layouts', true);
170
+
171
+ // For deciding to show drop targets or not when multiple nodes are selected
172
+ var selection = newState.selection;
173
+ var _expandSelectionBound = (0, _selection.expandSelectionBounds)(selection.$anchor, selection.$head),
174
+ expandedAnchor = _expandSelectionBound.$anchor,
175
+ expandedHead = _expandSelectionBound.$head;
176
+ var selectionFrom = Math.min(expandedAnchor.pos, expandedHead.pos);
177
+ var selectionTo = Math.max(expandedAnchor.pos, expandedHead.pos);
178
+ var handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom && activeNodePos <= selectionTo;
169
179
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
170
180
  var depth = 0;
171
181
  // drop target deco at the end position
@@ -200,10 +210,6 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
200
210
 
201
211
  // When multi select is on, validate all the nodes in the selection instead of just the handle node
202
212
  if (isMultiSelect) {
203
- var selection = newState.selection;
204
- var selectionFrom = selection.$from.pos;
205
- var selectionTo = selection.$to.pos;
206
- var handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom - 1 && activeNodePos <= selectionTo;
207
213
  var selectionSlice = newState.doc.slice(selectionFrom, selectionTo, false);
208
214
  var selectionSliceChildCount = selectionSlice.content.childCount;
209
215
  var canDropSingleNode = true;
@@ -211,7 +217,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
211
217
 
212
218
  // when there is only one node in the slice, use the same logic as when multi select is not on
213
219
  if (selectionSliceChildCount > 1 && handleInsideSelection) {
214
- canDropMultipleNodes = (0, _validation.canMoveSliceToIndex)(selectionSlice, selectionFrom, newState.doc, parent, index, $pos);
220
+ canDropMultipleNodes = (0, _validation.canMoveSliceToIndex)(selectionSlice, selectionFrom, parent, index, $pos);
215
221
  } else {
216
222
  canDropSingleNode = !!(activePMNode && (0, _validation.canMoveNodeToIndex)(parent, index, activePMNode, $pos, node));
217
223
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isHandleInSelection = exports.getSelection = exports.getInlineNodePos = void 0;
6
+ exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = void 0;
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
@@ -100,7 +100,7 @@ var setCursorPositionAtMovedNode = exports.setCursorPositionAtMovedNode = functi
100
100
  * @param handlePos
101
101
  * @returns
102
102
  */
103
- var isHandleInSelection = exports.isHandleInSelection = function isHandleInSelection(state, selection, handlePos) {
103
+ var isHandleCorrelatedToSelection = exports.isHandleCorrelatedToSelection = function isHandleCorrelatedToSelection(state, selection, handlePos) {
104
104
  if (selection.empty) {
105
105
  return false;
106
106
  }
@@ -121,8 +121,9 @@ function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNodePos,
121
121
  }
122
122
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
123
123
  }
124
- function canMoveSliceToIndex(slice, sliceFromPos, doc, destParent, indexIntoParent, $destNodePos, destNode) {
124
+ function canMoveSliceToIndex(slice, sliceFromPos, destParent, indexIntoParent, $destNodePos, destNode) {
125
125
  var canMoveNodes = true;
126
+ var doc = $destNodePos.doc;
126
127
  var nodesPos = [];
127
128
  for (var i = 0; i < slice.content.childCount; i++) {
128
129
  var node = slice.content.maybeChild(i);
@@ -401,7 +401,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
401
401
  if (!isMultiSelect || typeof start !== 'number' || !selection) {
402
402
  return;
403
403
  }
404
- setDragHandleSelected((0, _getSelection.isHandleInSelection)(view.state, selection, start));
404
+ setDragHandleSelected((0, _getSelection.isHandleCorrelatedToSelection)(view.state, selection, start));
405
405
  }, [start, selection, view.state]);
406
406
  var helpDescriptors = isTopLevelNode && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility') ? [{
407
407
  description: formatMessage(_messages.blockControlsMessages.dragToMove)
@@ -1,5 +1,6 @@
1
1
  import { createElement } from 'react';
2
2
  import uuid from 'uuid';
3
+ import { expandSelectionBounds } from '@atlaskit/editor-common/selection';
3
4
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
4
5
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
6
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -153,6 +154,16 @@ export const dropTargetDecorations = (newState, api, formatMessage, nodeViewPort
153
154
  prevNodeStack.push(node);
154
155
  };
155
156
  const isAdvancedLayoutsPreRelease2 = editorExperiment('advanced_layouts', true);
157
+
158
+ // For deciding to show drop targets or not when multiple nodes are selected
159
+ const selection = newState.selection;
160
+ const {
161
+ $anchor: expandedAnchor,
162
+ $head: expandedHead
163
+ } = expandSelectionBounds(selection.$anchor, selection.$head);
164
+ const selectionFrom = Math.min(expandedAnchor.pos, expandedHead.pos);
165
+ const selectionTo = Math.max(expandedAnchor.pos, expandedHead.pos);
166
+ const handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom && activeNodePos <= selectionTo;
156
167
  newState.doc.nodesBetween(docFrom, docTo, (node, pos, parent, index) => {
157
168
  let depth = 0;
158
169
  // drop target deco at the end position
@@ -187,10 +198,6 @@ export const dropTargetDecorations = (newState, api, formatMessage, nodeViewPort
187
198
 
188
199
  // When multi select is on, validate all the nodes in the selection instead of just the handle node
189
200
  if (isMultiSelect) {
190
- const selection = newState.selection;
191
- const selectionFrom = selection.$from.pos;
192
- const selectionTo = selection.$to.pos;
193
- const handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom - 1 && activeNodePos <= selectionTo;
194
201
  const selectionSlice = newState.doc.slice(selectionFrom, selectionTo, false);
195
202
  const selectionSliceChildCount = selectionSlice.content.childCount;
196
203
  let canDropSingleNode = true;
@@ -198,7 +205,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, nodeViewPort
198
205
 
199
206
  // when there is only one node in the slice, use the same logic as when multi select is not on
200
207
  if (selectionSliceChildCount > 1 && handleInsideSelection) {
201
- canDropMultipleNodes = canMoveSliceToIndex(selectionSlice, selectionFrom, newState.doc, parent, index, $pos);
208
+ canDropMultipleNodes = canMoveSliceToIndex(selectionSlice, selectionFrom, parent, index, $pos);
202
209
  } else {
203
210
  canDropSingleNode = !!(activePMNode && canMoveNodeToIndex(parent, index, activePMNode, $pos, node));
204
211
  }
@@ -96,7 +96,7 @@ export const setCursorPositionAtMovedNode = (tr, start) => {
96
96
  * @param handlePos
97
97
  * @returns
98
98
  */
99
- export const isHandleInSelection = (state, selection, handlePos) => {
99
+ export const isHandleCorrelatedToSelection = (state, selection, handlePos) => {
100
100
  if (selection.empty) {
101
101
  return false;
102
102
  }
@@ -114,8 +114,9 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNo
114
114
  }
115
115
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
116
116
  }
117
- export function canMoveSliceToIndex(slice, sliceFromPos, doc, destParent, indexIntoParent, $destNodePos, destNode) {
117
+ export function canMoveSliceToIndex(slice, sliceFromPos, destParent, indexIntoParent, $destNodePos, destNode) {
118
118
  let canMoveNodes = true;
119
+ const doc = $destNodePos.doc;
119
120
  const nodesPos = [];
120
121
  for (let i = 0; i < slice.content.childCount; i++) {
121
122
  const node = slice.content.maybeChild(i);
@@ -24,7 +24,7 @@ import { key } from '../pm-plugins/main';
24
24
  import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
25
25
  import { getLeftPosition, getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
26
26
  import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
27
- import { isHandleInSelection, selectNode } from '../pm-plugins/utils/getSelection';
27
+ import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
28
28
  import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, topPositionAdjustment } from './consts';
29
29
  import { dragPreview } from './drag-preview';
30
30
  const iconWrapperStyles = xcss({
@@ -383,7 +383,7 @@ export const DragHandle = ({
383
383
  if (!isMultiSelect || typeof start !== 'number' || !selection) {
384
384
  return;
385
385
  }
386
- setDragHandleSelected(isHandleInSelection(view.state, selection, start));
386
+ setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
387
387
  }, [start, selection, view.state]);
388
388
  let helpDescriptors = isTopLevelNode && fg('platform_editor_advanced_layouts_accessibility') ? [{
389
389
  description: formatMessage(blockControlsMessages.dragToMove)
@@ -3,6 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  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) { _defineProperty(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; }
4
4
  import { createElement } from 'react';
5
5
  import uuid from 'uuid';
6
+ import { expandSelectionBounds } from '@atlaskit/editor-common/selection';
6
7
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
7
8
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
@@ -159,6 +160,15 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
159
160
  prevNodeStack.push(node);
160
161
  };
161
162
  var isAdvancedLayoutsPreRelease2 = editorExperiment('advanced_layouts', true);
163
+
164
+ // For deciding to show drop targets or not when multiple nodes are selected
165
+ var selection = newState.selection;
166
+ var _expandSelectionBound = expandSelectionBounds(selection.$anchor, selection.$head),
167
+ expandedAnchor = _expandSelectionBound.$anchor,
168
+ expandedHead = _expandSelectionBound.$head;
169
+ var selectionFrom = Math.min(expandedAnchor.pos, expandedHead.pos);
170
+ var selectionTo = Math.max(expandedAnchor.pos, expandedHead.pos);
171
+ var handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom && activeNodePos <= selectionTo;
162
172
  newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
163
173
  var depth = 0;
164
174
  // drop target deco at the end position
@@ -193,10 +203,6 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
193
203
 
194
204
  // When multi select is on, validate all the nodes in the selection instead of just the handle node
195
205
  if (isMultiSelect) {
196
- var selection = newState.selection;
197
- var selectionFrom = selection.$from.pos;
198
- var selectionTo = selection.$to.pos;
199
- var handleInsideSelection = activeNodePos !== undefined && activeNodePos >= selectionFrom - 1 && activeNodePos <= selectionTo;
200
206
  var selectionSlice = newState.doc.slice(selectionFrom, selectionTo, false);
201
207
  var selectionSliceChildCount = selectionSlice.content.childCount;
202
208
  var canDropSingleNode = true;
@@ -204,7 +210,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
204
210
 
205
211
  // when there is only one node in the slice, use the same logic as when multi select is not on
206
212
  if (selectionSliceChildCount > 1 && handleInsideSelection) {
207
- canDropMultipleNodes = canMoveSliceToIndex(selectionSlice, selectionFrom, newState.doc, parent, index, $pos);
213
+ canDropMultipleNodes = canMoveSliceToIndex(selectionSlice, selectionFrom, parent, index, $pos);
208
214
  } else {
209
215
  canDropSingleNode = !!(activePMNode && canMoveNodeToIndex(parent, index, activePMNode, $pos, node));
210
216
  }
@@ -94,7 +94,7 @@ export var setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(
94
94
  * @param handlePos
95
95
  * @returns
96
96
  */
97
- export var isHandleInSelection = function isHandleInSelection(state, selection, handlePos) {
97
+ export var isHandleCorrelatedToSelection = function isHandleCorrelatedToSelection(state, selection, handlePos) {
98
98
  if (selection.empty) {
99
99
  return false;
100
100
  }
@@ -112,8 +112,9 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode, $destNo
112
112
  }
113
113
  return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
114
114
  }
115
- export function canMoveSliceToIndex(slice, sliceFromPos, doc, destParent, indexIntoParent, $destNodePos, destNode) {
115
+ export function canMoveSliceToIndex(slice, sliceFromPos, destParent, indexIntoParent, $destNodePos, destNode) {
116
116
  var canMoveNodes = true;
117
+ var doc = $destNodePos.doc;
117
118
  var nodesPos = [];
118
119
  for (var i = 0; i < slice.content.childCount; i++) {
119
120
  var node = slice.content.maybeChild(i);
@@ -29,7 +29,7 @@ import { key } from '../pm-plugins/main';
29
29
  import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
30
30
  import { getLeftPosition, getTopPosition } from '../pm-plugins/utils/drag-handle-positions';
31
31
  import { getNestedNodePosition } from '../pm-plugins/utils/getNestedNodePosition';
32
- import { isHandleInSelection, selectNode } from '../pm-plugins/utils/getSelection';
32
+ import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
33
33
  import { DRAG_HANDLE_BORDER_RADIUS, DRAG_HANDLE_HEIGHT, DRAG_HANDLE_WIDTH, DRAG_HANDLE_ZINDEX, dragHandleGap, topPositionAdjustment } from './consts';
34
34
  import { dragPreview } from './drag-preview';
35
35
  var iconWrapperStyles = xcss({
@@ -396,7 +396,7 @@ export var DragHandle = function DragHandle(_ref) {
396
396
  if (!isMultiSelect || typeof start !== 'number' || !selection) {
397
397
  return;
398
398
  }
399
- setDragHandleSelected(isHandleInSelection(view.state, selection, start));
399
+ setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
400
400
  }, [start, selection, view.state]);
401
401
  var helpDescriptors = isTopLevelNode && fg('platform_editor_advanced_layouts_accessibility') ? [{
402
402
  description: formatMessage(blockControlsMessages.dragToMove)
@@ -14,6 +14,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
14
14
  * @param handlePos
15
15
  * @returns
16
16
  */
17
- export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
17
+ export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
18
18
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
19
19
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
@@ -17,4 +17,4 @@ export declare const transformExpandToNestedExpand: (expandNode: PMNode) => PMNo
17
17
  export declare const transformSliceExpandToNestedExpand: (slice: Slice) => Slice | null;
18
18
  export declare const memoizedTransformExpandToNestedExpand: import("memoize-one").MemoizedFn<(node: PMNode) => PMNode | null>;
19
19
  export declare function canMoveNodeToIndex(destParent: PMNode, indexIntoParent: number, srcNode: PMNode, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
- export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, doc: PMNode, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
+ export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
@@ -14,6 +14,6 @@ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: numb
14
14
  * @param handlePos
15
15
  * @returns
16
16
  */
17
- export declare const isHandleInSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
17
+ export declare const isHandleCorrelatedToSelection: (state: EditorState, selection: Selection, handlePos: number) => boolean;
18
18
  export declare const rootListDepth: (itemPos: ResolvedPos) => number | undefined;
19
19
  export declare const rootTaskListDepth: (taskListPos: ResolvedPos) => number | undefined;
@@ -17,4 +17,4 @@ export declare const transformExpandToNestedExpand: (expandNode: PMNode) => PMNo
17
17
  export declare const transformSliceExpandToNestedExpand: (slice: Slice) => Slice | null;
18
18
  export declare const memoizedTransformExpandToNestedExpand: import("memoize-one").MemoizedFn<(node: PMNode) => PMNode | null>;
19
19
  export declare function canMoveNodeToIndex(destParent: PMNode, indexIntoParent: number, srcNode: PMNode, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
- export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, doc: PMNode, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
20
+ export declare function canMoveSliceToIndex(slice: Slice, sliceFromPos: number, destParent: PMNode, indexIntoParent: number, $destNodePos: ResolvedPos, destNode?: PMNode): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.27.0",
3
+ "version": "2.27.1",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",