@atlaskit/editor-plugin-block-controls 3.2.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#120928](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/120928)
8
+ [`01cb5ca9596cf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/01cb5ca9596cf) -
9
+ [ED-26316] Refactor checkTrActionType functions to be in it's own file to help with readability,
10
+ add check for safe insert count and update it in analytics event fired
11
+
12
+ ### Patch Changes
13
+
14
+ - [#121803](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/121803)
15
+ [`41a43b5d95052`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/41a43b5d95052) -
16
+ Fix logic for determining drag handle corresponding to selection, shortcuts
17
+ - Updated dependencies
18
+
3
19
  ## 3.2.1
4
20
 
5
21
  ### Patch Changes
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _selection = require("@atlaskit/editor-common/selection");
11
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
13
14
  var _moveNode = require("./editor-commands/move-node");
14
15
  var _moveToLayout = require("./editor-commands/move-to-layout");
@@ -89,6 +90,15 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
89
90
  nodeType: nodeType
90
91
  }
91
92
  }));
93
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
94
+ var _api$metrics;
95
+ api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.handleIntentToStartEdit({
96
+ shouldStartTimer: false,
97
+ shouldPersistActiveSession: true
98
+ })({
99
+ tr: tr
100
+ });
101
+ }
92
102
  return tr;
93
103
  };
94
104
  },
@@ -93,6 +93,7 @@ var getFocusedHandle = function getFocusedHandle(state) {
93
93
  };
94
94
  var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, formatMessage) {
95
95
  return function (state) {
96
+ var _hoistedPos;
96
97
  var isParentNodeOfTypeLayout;
97
98
  var shouldEnableNestedDndA11y = (0, _experiments.editorExperiment)('nested-dnd', true);
98
99
  var selection = state.selection;
@@ -103,19 +104,26 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
103
104
  var expandedSelection = (0, _selection.expandSelectionBounds)(selection.$anchor, selection.$head);
104
105
  var expandedAnchor = expandedSelection.$anchor.pos;
105
106
  var expandedHead = expandedSelection.$head.pos;
106
- var currentNodePos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.min(expandedAnchor, expandedHead) : getCurrentNodePos(state);
107
+ var hoistedPos;
108
+ var from = Math.min(expandedAnchor, expandedHead);
109
+ // Nodes like lists nest within themselves, we need to find the top most position
110
+ if (isParentNodeOfTypeLayout && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
111
+ var LAYOUT_COL_DEPTH = 3;
112
+ hoistedPos = state.doc.resolve(from).before(LAYOUT_COL_DEPTH);
113
+ }
114
+ var currentNodePos = isMultiSelectEnabled && !getFocusedHandle(state) && !selection.empty ? (_hoistedPos = hoistedPos) !== null && _hoistedPos !== void 0 ? _hoistedPos : from : getCurrentNodePos(state);
107
115
  if (currentNodePos > -1) {
108
116
  var _state$doc$nodeAt;
109
- var $pos = state.doc.resolve(currentNodePos);
110
- var nodeAfterPos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.max(expandedAnchor, expandedHead) : $pos.posAtIndex($pos.index() + 1);
111
- var isTopLevelNode = $pos.depth === 0;
117
+ var $currentNodePos = state.doc.resolve(currentNodePos);
118
+ var nodeAfterPos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.max(expandedAnchor, expandedHead) : $currentNodePos.posAtIndex($currentNodePos.index() + 1);
119
+ var isTopLevelNode = $currentNodePos.depth === 0;
112
120
  var moveToPos = -1;
113
- var nodeIndex = $pos.index();
121
+ var nodeIndex = $currentNodePos.index();
114
122
  var isLayoutColumnSelected = selection instanceof _state.NodeSelection && selection.node.type.name === 'layoutColumn';
115
123
  if (direction === _consts.DIRECTION.LEFT && shouldEnableNestedDndA11y) {
116
124
  if (isTopLevelNode && (0, _experiments.editorExperiment)('advanced_layouts', true) && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility')) {
117
125
  var _api$core, _api$core2;
118
- var nodeBefore = $pos.nodeBefore;
126
+ var nodeBefore = $currentNodePos.nodeBefore;
119
127
  if (nodeBefore) {
120
128
  moveToPos = currentNodePos - nodeBefore.nodeSize;
121
129
  }
@@ -139,28 +147,28 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
139
147
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.focus();
140
148
  return true;
141
149
  } else if (isLayoutColumnSelected && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility')) {
142
- var _$pos$nodeBefore, _api$core3, _api$blockControls2;
143
- moveToPos = selection.from - (((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.nodeSize) || 1);
150
+ var _$currentNodePos$node, _api$core3, _api$blockControls2;
151
+ moveToPos = selection.from - (((_$currentNodePos$node = $currentNodePos.nodeBefore) === null || _$currentNodePos$node === void 0 ? void 0 : _$currentNodePos$node.nodeSize) || 1);
144
152
  api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.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.moveToLayout(currentNodePos, moveToPos, {
145
153
  selectMovedNode: true
146
154
  }));
147
155
  return true;
148
156
  } else {
149
- if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
157
+ if ($currentNodePos.depth < 2 || !isParentNodeOfTypeLayout) {
150
158
  return false;
151
159
  }
152
160
 
153
161
  // get the previous layoutSection node
154
- var index = $pos.index($pos.depth - 1);
155
- var grandParent = $pos.node($pos.depth - 1);
162
+ var index = $currentNodePos.index($currentNodePos.depth - 1);
163
+ var grandParent = $currentNodePos.node($currentNodePos.depth - 1);
156
164
  var previousNode = grandParent ? grandParent.maybeChild(index - 1) : null;
157
- moveToPos = $pos.start() - ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.nodeSize) || 1);
165
+ moveToPos = $currentNodePos.start() - ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.nodeSize) || 1);
158
166
  }
159
167
  } else if (direction === _consts.DIRECTION.RIGHT && shouldEnableNestedDndA11y) {
160
168
  if (isTopLevelNode && (0, _experiments.editorExperiment)('advanced_layouts', true) && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility')) {
161
169
  var _api$core4, _api$core5;
162
- var endOfDoc = $pos.end();
163
- moveToPos = $pos.posAtIndex($pos.index() + 1);
170
+ var endOfDoc = $currentNodePos.end();
171
+ moveToPos = $currentNodePos.posAtIndex($currentNodePos.index() + 1);
164
172
  if (moveToPos >= endOfDoc) {
165
173
  return false;
166
174
  }
@@ -181,8 +189,8 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
181
189
  return true;
182
190
  } else if (isLayoutColumnSelected && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility')) {
183
191
  var _api$core6, _api$blockControls4;
184
- var _index = $pos.index($pos.depth);
185
- var parent = $pos.node($pos.depth);
192
+ var _index = $currentNodePos.index($currentNodePos.depth);
193
+ var parent = $currentNodePos.node($currentNodePos.depth);
186
194
  // get the next layoutColumn node
187
195
  var nextNode = parent ? parent.maybeChild(_index + 1) : null;
188
196
 
@@ -192,29 +200,29 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
192
200
  return true;
193
201
  }
194
202
  var moveToEnd = _index === parent.childCount - 2;
195
- moveToPos = moveToEnd ? $pos.before() : selection.to + ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.nodeSize) || 1);
203
+ moveToPos = moveToEnd ? $currentNodePos.before() : selection.to + ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.nodeSize) || 1);
196
204
  api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || (_api$blockControls4 = _api$blockControls4.commands) === null || _api$blockControls4 === void 0 ? void 0 : _api$blockControls4.moveToLayout(currentNodePos, moveToPos, {
197
205
  moveToEnd: moveToEnd,
198
206
  selectMovedNode: true
199
207
  }));
200
208
  return true;
201
209
  } else {
202
- if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
210
+ if ($currentNodePos.depth < 2 || !isParentNodeOfTypeLayout) {
203
211
  return false;
204
212
  }
205
- moveToPos = $pos.after($pos.depth) + 1;
213
+ moveToPos = $currentNodePos.after($currentNodePos.depth) + 1;
206
214
  }
207
215
  } else if (direction === _consts.DIRECTION.UP) {
208
216
  if (isLayoutColumnSelected && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility')) {
209
- moveToPos = $pos.start() - 1;
217
+ moveToPos = $currentNodePos.start() - 1;
210
218
  } else {
211
- var _nodeBefore = $pos.depth > 1 && nodeIndex === 0 && shouldEnableNestedDndA11y ? $pos.node($pos.depth) : $pos.nodeBefore;
219
+ var _nodeBefore = $currentNodePos.depth > 1 && nodeIndex === 0 && shouldEnableNestedDndA11y ? $currentNodePos.node($currentNodePos.depth) : $currentNodePos.nodeBefore;
212
220
  if (_nodeBefore) {
213
221
  moveToPos = currentNodePos - _nodeBefore.nodeSize;
214
222
  }
215
223
  }
216
224
  } else {
217
- var _endOfDoc = $pos.end();
225
+ var _endOfDoc = $currentNodePos.end();
218
226
  if (nodeAfterPos > _endOfDoc) {
219
227
  return false;
220
228
  }
@@ -231,14 +239,23 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
231
239
  var nodeType = (_state$doc$nodeAt = state.doc.nodeAt(currentNodePos)) === null || _state$doc$nodeAt === void 0 ? void 0 : _state$doc$nodeAt.type.name;
232
240
 
233
241
  // only move the node if the destination is at the same depth, not support moving a nested node to a parent node
234
- var shouldMoveNode = (shouldEnableNestedDndA11y ? moveToPos > -1 && $pos.depth === state.doc.resolve(moveToPos).depth || nodeType === 'layoutColumn' : moveToPos > -1) || nodeType === 'layoutColumn' && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility');
242
+ var shouldMoveNode = (shouldEnableNestedDndA11y ? moveToPos > -1 && $currentNodePos.depth === state.doc.resolve(moveToPos).depth || nodeType === 'layoutColumn' : moveToPos > -1) || nodeType === 'layoutColumn' && (0, _platformFeatureFlags.fg)('platform_editor_advanced_layouts_accessibility');
243
+ var _expandSelectionBound = (0, _selection.expandSelectionBounds)($currentNodePos, selection.$to),
244
+ $newAnchor = _expandSelectionBound.$anchor,
245
+ $newHead = _expandSelectionBound.$head;
235
246
  if (shouldMoveNode) {
236
247
  var _api$core7;
237
248
  api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref4) {
238
249
  var tr = _ref4.tr;
239
- api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
240
- tr: tr
241
- });
250
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
251
+ api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions($newAnchor.pos, $newHead.pos)({
252
+ tr: tr
253
+ });
254
+ } else {
255
+ api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
256
+ tr: tr
257
+ });
258
+ }
242
259
  moveNode(api)(currentNodePos, moveToPos, _analytics.INPUT_METHOD.SHORTCUT, formatMessage)({
243
260
  tr: tr
244
261
  });
@@ -260,9 +277,15 @@ var moveNodeViaShortcut = exports.moveNodeViaShortcut = function moveNodeViaShor
260
277
  var _api$core9;
261
278
  api === null || api === void 0 || (_api$core9 = api.core) === null || _api$core9 === void 0 || _api$core9.actions.execute(function (_ref6) {
262
279
  var tr = _ref6.tr;
263
- api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
264
- tr: tr
265
- });
280
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
281
+ api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions($newAnchor.pos, $newHead.pos)({
282
+ tr: tr
283
+ });
284
+ } else {
285
+ api === null || api === void 0 || api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
286
+ tr: tr
287
+ });
288
+ }
266
289
  tr.scrollIntoView();
267
290
  return tr;
268
291
  });
@@ -293,6 +316,12 @@ var moveNode = exports.moveNode = function moveNode(api) {
293
316
  var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true, {
294
317
  exposure: true
295
318
  });
319
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
320
+ var _api$metrics;
321
+ api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.setContentMoved()({
322
+ tr: tr
323
+ });
324
+ }
296
325
  var slicePosition = (0, _selection2.getSelectedSlicePosition)(start, tr, api);
297
326
  if (isMultiSelect) {
298
327
  sliceFrom = slicePosition.from;
@@ -319,6 +319,12 @@ var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
319
319
  if (!fromContentWithoutBreakout) {
320
320
  return tr;
321
321
  }
322
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
323
+ var _api$metrics;
324
+ api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.setContentMoved()({
325
+ tr: tr
326
+ });
327
+ }
322
328
  var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true);
323
329
  if (toNode.type === layoutSection) {
324
330
  var toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize - 1 : to + 1;
@@ -138,6 +138,12 @@ var destroyFn = function destroyFn(api, editorView) {
138
138
  })
139
139
  })(tr);
140
140
  }
141
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
142
+ var _api$metrics;
143
+ api === null || api === void 0 || (_api$metrics = api.metrics) === null || _api$metrics === void 0 || _api$metrics.commands.startActiveSessionTimer()({
144
+ tr: tr
145
+ });
146
+ }
141
147
  return tr.setMeta(key, _objectSpread(_objectSpread({}, tr.getMeta(key)), {}, {
142
148
  isDragging: false,
143
149
  isPMDragging: false,
@@ -591,7 +597,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
591
597
  },
592
598
  handleDOMEvents: {
593
599
  drop: function drop(view, event) {
594
- var _pluginState, _pluginState2, _pluginState3, _event$target;
600
+ var _pluginState, _pluginState2, _pluginState3, _event$target, _event$target$closest;
595
601
  // Prevent native DnD from triggering if we are in drag
596
602
  var dispatch = view.dispatch,
597
603
  dragging = view.dragging,
@@ -600,6 +606,12 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
600
606
  var pluginState = key.getState(state);
601
607
  var dndDragCancelled = (_pluginState = pluginState) === null || _pluginState === void 0 ? void 0 : _pluginState.lastDragCancelled;
602
608
  if ((_pluginState2 = pluginState) !== null && _pluginState2 !== void 0 && _pluginState2.isPMDragging || dndDragCancelled && isMultiSelectEnabled) {
609
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
610
+ var _api$metrics2;
611
+ api === null || api === void 0 || (_api$metrics2 = api.metrics) === null || _api$metrics2 === void 0 || _api$metrics2.commands.startActiveSessionTimer()({
612
+ tr: tr
613
+ });
614
+ }
603
615
  dispatch(tr.setMeta(key, _objectSpread(_objectSpread({}, tr.getMeta(key)), {}, {
604
616
  isPMDragging: false,
605
617
  lastDragCancelled: false
@@ -617,7 +629,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
617
629
  event.preventDefault();
618
630
  return false;
619
631
  }
620
- var nodeElement = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.closest('[data-drag-handler-anchor-name]');
632
+ var nodeElement = (_event$target = event.target) === null || _event$target === void 0 || (_event$target$closest = _event$target.closest) === null || _event$target$closest === void 0 ? void 0 : _event$target$closest.call(_event$target, '[data-drag-handler-anchor-name]');
621
633
  if (!nodeElement) {
622
634
  return false;
623
635
  }
@@ -663,9 +675,17 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
663
675
  var state = view.state,
664
676
  dispatch = view.dispatch;
665
677
  if ((_key$getState3 = key.getState(state)) !== null && _key$getState3 !== void 0 && _key$getState3.isPMDragging) {
666
- dispatch(state.tr.setMeta(key, _objectSpread(_objectSpread({}, state.tr.getMeta(key)), {}, {
678
+ var tr = state.tr;
679
+ tr.setMeta(key, _objectSpread(_objectSpread({}, state.tr.getMeta(key)), {}, {
667
680
  isPMDragging: false
668
- })));
681
+ }));
682
+ if ((0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
683
+ var _api$metrics3;
684
+ api === null || api === void 0 || (_api$metrics3 = api.metrics) === null || _api$metrics3 === void 0 || _api$metrics3.commands.startActiveSessionTimer()({
685
+ tr: tr
686
+ });
687
+ }
688
+ dispatch(tr);
669
689
  }
670
690
  },
671
691
  mouseover: function mouseover(view, event) {
@@ -8,6 +8,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");
10
10
  var _utils2 = require("@atlaskit/editor-tables/utils");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var getInlineNodePos = exports.getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
12
13
  var $startPos = tr.doc.resolve(start);
13
14
  // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
@@ -59,6 +60,8 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
59
60
  // we need a quick way to make all child media nodes appear as selected without the need for a custom selection
60
61
  nodeName === 'mediaGroup') {
61
62
  return new _state.NodeSelection($startPos);
63
+ } else if (nodeName === 'taskList' && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
64
+ return _state.TextSelection.create(tr.doc, start, start + nodeSize);
62
65
  } else {
63
66
  var _getInlineNodePos = getInlineNodePos(tr, start, nodeSize),
64
67
  inlineNodePos = _getInlineNodePos.inlineNodePos,
@@ -104,21 +107,42 @@ var isHandleCorrelatedToSelection = exports.isHandleCorrelatedToSelection = func
104
107
  if (selection.empty) {
105
108
  return false;
106
109
  }
110
+ var nodeStart;
107
111
  var $selectionFrom = selection.$from;
108
- var selectionFrom = $selectionFrom.pos;
109
- var nodeStart = $selectionFrom.depth ? $selectionFrom.before() : selectionFrom;
110
- var $resolvedNodePos = state.doc.resolve(nodeStart);
111
- if (['tableRow', 'tableCell', 'tableHeader'].includes($resolvedNodePos.node().type.name)) {
112
- var parentNodeFindRes = (0, _utils.findParentNodeOfType)(state.schema.nodes['table'])(selection);
113
- var tablePos = parentNodeFindRes === null || parentNodeFindRes === void 0 ? void 0 : parentNodeFindRes.pos;
114
- nodeStart = typeof tablePos === 'undefined' ? nodeStart : tablePos;
115
- } else if (['listItem'].includes($resolvedNodePos.node().type.name)) {
116
- nodeStart = $resolvedNodePos.before(rootListDepth($resolvedNodePos));
117
- } else if (['taskList'].includes($resolvedNodePos.node().type.name)) {
118
- var listdepth = rootTaskListDepth($resolvedNodePos);
119
- nodeStart = $resolvedNodePos.before(listdepth);
120
- } else if (['blockquote'].includes($resolvedNodePos.node().type.name)) {
121
- nodeStart = $resolvedNodePos.before();
112
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
113
+ nodeStart = $selectionFrom.before($selectionFrom.sharedDepth(selection.to) + 1);
114
+ if (nodeStart === $selectionFrom.pos) {
115
+ nodeStart = $selectionFrom.depth ? $selectionFrom.before() : $selectionFrom.pos;
116
+ }
117
+ var $resolvedNodePos = state.doc.resolve(nodeStart);
118
+ if (['tableRow', 'tableCell', 'tableHeader'].includes($resolvedNodePos.node().type.name)) {
119
+ var parentNodeFindRes = (0, _utils.findParentNodeOfType)(state.schema.nodes['table'])(selection);
120
+ var tablePos = parentNodeFindRes === null || parentNodeFindRes === void 0 ? void 0 : parentNodeFindRes.pos;
121
+ nodeStart = typeof tablePos === 'undefined' ? nodeStart : tablePos;
122
+ } else if (['listItem'].includes($resolvedNodePos.node().type.name)) {
123
+ nodeStart = $resolvedNodePos.before(rootListDepth($resolvedNodePos));
124
+ } else if (['taskList'].includes($resolvedNodePos.node().type.name)) {
125
+ var listdepth = rootTaskListDepth($resolvedNodePos);
126
+ nodeStart = $resolvedNodePos.before(listdepth);
127
+ } else if (['blockquote'].includes($resolvedNodePos.node().type.name)) {
128
+ nodeStart = $resolvedNodePos.before();
129
+ }
130
+ } else {
131
+ var selectionFrom = $selectionFrom.pos;
132
+ nodeStart = $selectionFrom.depth ? $selectionFrom.before() : selectionFrom;
133
+ var _$resolvedNodePos = state.doc.resolve(nodeStart);
134
+ if (['tableRow', 'tableCell', 'tableHeader'].includes(_$resolvedNodePos.node().type.name)) {
135
+ var _parentNodeFindRes = (0, _utils.findParentNodeOfType)(state.schema.nodes['table'])(selection);
136
+ var _tablePos = _parentNodeFindRes === null || _parentNodeFindRes === void 0 ? void 0 : _parentNodeFindRes.pos;
137
+ nodeStart = typeof _tablePos === 'undefined' ? nodeStart : _tablePos;
138
+ } else if (['listItem'].includes(_$resolvedNodePos.node().type.name)) {
139
+ nodeStart = _$resolvedNodePos.before(rootListDepth(_$resolvedNodePos));
140
+ } else if (['taskList'].includes(_$resolvedNodePos.node().type.name)) {
141
+ var _listdepth = rootTaskListDepth(_$resolvedNodePos);
142
+ nodeStart = _$resolvedNodePos.before(_listdepth);
143
+ } else if (['blockquote'].includes(_$resolvedNodePos.node().type.name)) {
144
+ nodeStart = _$resolvedNodePos.before();
145
+ }
122
146
  }
123
147
  return Boolean(handlePos < selection.$to.pos && handlePos >= nodeStart);
124
148
  };
@@ -308,7 +308,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
308
308
  return tr;
309
309
  }
310
310
  var oldHandlePosCheck = handlePos >= tr.selection.$from.start() - 1 && handlePos <= tr.selection.to;
311
- var newHandlePosCheck = handlePos >= (tr.selection.$from.depth ? tr.selection.$from.before() : tr.selection.from) && handlePos < tr.selection.to;
311
+ var newHandlePosCheck = (0, _getSelection.isHandleCorrelatedToSelection)(view.state, tr.selection, handlePos);
312
312
  if (!tr.selection.empty && ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1') ? newHandlePosCheck : oldHandlePosCheck)) {
313
313
  var _api$blockControls4;
314
314
  api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.commands.setMultiSelectPositions()({
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { expandSelectionBounds } from '@atlaskit/editor-common/selection';
3
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
6
  import { moveNode } from './editor-commands/move-node';
6
7
  import { moveToLayout } from './editor-commands/move-to-layout';
@@ -80,6 +81,15 @@ export const blockControlsPlugin = ({
80
81
  nodeType
81
82
  }
82
83
  });
84
+ if (fg('platform_editor_ease_of_use_metrics')) {
85
+ var _api$metrics;
86
+ api === null || api === void 0 ? void 0 : (_api$metrics = api.metrics) === null || _api$metrics === void 0 ? void 0 : _api$metrics.commands.handleIntentToStartEdit({
87
+ shouldStartTimer: false,
88
+ shouldPersistActiveSession: true
89
+ })({
90
+ tr
91
+ });
92
+ }
83
93
  return tr;
84
94
  },
85
95
  setMultiSelectPositions: (anchor, head) => ({
@@ -88,6 +88,7 @@ const getFocusedHandle = state => {
88
88
  };
89
89
  export const moveNodeViaShortcut = (api, direction, formatMessage) => {
90
90
  return state => {
91
+ var _hoistedPos;
91
92
  let isParentNodeOfTypeLayout;
92
93
  const shouldEnableNestedDndA11y = editorExperiment('nested-dnd', true);
93
94
  const {
@@ -100,19 +101,26 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
100
101
  const expandedSelection = expandSelectionBounds(selection.$anchor, selection.$head);
101
102
  const expandedAnchor = expandedSelection.$anchor.pos;
102
103
  const expandedHead = expandedSelection.$head.pos;
103
- const currentNodePos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.min(expandedAnchor, expandedHead) : getCurrentNodePos(state);
104
+ let hoistedPos;
105
+ const from = Math.min(expandedAnchor, expandedHead);
106
+ // Nodes like lists nest within themselves, we need to find the top most position
107
+ if (isParentNodeOfTypeLayout && fg('platform_editor_elements_dnd_multi_select_patch_1')) {
108
+ const LAYOUT_COL_DEPTH = 3;
109
+ hoistedPos = state.doc.resolve(from).before(LAYOUT_COL_DEPTH);
110
+ }
111
+ const currentNodePos = isMultiSelectEnabled && !getFocusedHandle(state) && !selection.empty ? (_hoistedPos = hoistedPos) !== null && _hoistedPos !== void 0 ? _hoistedPos : from : getCurrentNodePos(state);
104
112
  if (currentNodePos > -1) {
105
113
  var _state$doc$nodeAt;
106
- const $pos = state.doc.resolve(currentNodePos);
107
- const nodeAfterPos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.max(expandedAnchor, expandedHead) : $pos.posAtIndex($pos.index() + 1);
108
- const isTopLevelNode = $pos.depth === 0;
114
+ const $currentNodePos = state.doc.resolve(currentNodePos);
115
+ const nodeAfterPos = isMultiSelectEnabled && !getFocusedHandle(state) ? Math.max(expandedAnchor, expandedHead) : $currentNodePos.posAtIndex($currentNodePos.index() + 1);
116
+ const isTopLevelNode = $currentNodePos.depth === 0;
109
117
  let moveToPos = -1;
110
- const nodeIndex = $pos.index();
118
+ const nodeIndex = $currentNodePos.index();
111
119
  const isLayoutColumnSelected = selection instanceof NodeSelection && selection.node.type.name === 'layoutColumn';
112
120
  if (direction === DIRECTION.LEFT && shouldEnableNestedDndA11y) {
113
121
  if (isTopLevelNode && editorExperiment('advanced_layouts', true) && fg('platform_editor_advanced_layouts_accessibility')) {
114
122
  var _api$core, _api$core2;
115
- const nodeBefore = $pos.nodeBefore;
123
+ const nodeBefore = $currentNodePos.nodeBefore;
116
124
  if (nodeBefore) {
117
125
  moveToPos = currentNodePos - nodeBefore.nodeSize;
118
126
  }
@@ -137,28 +145,28 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
137
145
  api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.focus();
138
146
  return true;
139
147
  } else if (isLayoutColumnSelected && fg('platform_editor_advanced_layouts_accessibility')) {
140
- var _$pos$nodeBefore, _api$core3, _api$blockControls2, _api$blockControls2$c;
141
- moveToPos = selection.from - (((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.nodeSize) || 1);
148
+ var _$currentNodePos$node, _api$core3, _api$blockControls2, _api$blockControls2$c;
149
+ moveToPos = selection.from - (((_$currentNodePos$node = $currentNodePos.nodeBefore) === null || _$currentNodePos$node === void 0 ? void 0 : _$currentNodePos$node.nodeSize) || 1);
142
150
  api === null || api === void 0 ? void 0 : (_api$core3 = api.core) === null || _api$core3 === void 0 ? void 0 : _api$core3.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.moveToLayout(currentNodePos, moveToPos, {
143
151
  selectMovedNode: true
144
152
  }));
145
153
  return true;
146
154
  } else {
147
- if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
155
+ if ($currentNodePos.depth < 2 || !isParentNodeOfTypeLayout) {
148
156
  return false;
149
157
  }
150
158
 
151
159
  // get the previous layoutSection node
152
- const index = $pos.index($pos.depth - 1);
153
- const grandParent = $pos.node($pos.depth - 1);
160
+ const index = $currentNodePos.index($currentNodePos.depth - 1);
161
+ const grandParent = $currentNodePos.node($currentNodePos.depth - 1);
154
162
  const previousNode = grandParent ? grandParent.maybeChild(index - 1) : null;
155
- moveToPos = $pos.start() - ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.nodeSize) || 1);
163
+ moveToPos = $currentNodePos.start() - ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.nodeSize) || 1);
156
164
  }
157
165
  } else if (direction === DIRECTION.RIGHT && shouldEnableNestedDndA11y) {
158
166
  if (isTopLevelNode && editorExperiment('advanced_layouts', true) && fg('platform_editor_advanced_layouts_accessibility')) {
159
167
  var _api$core4, _api$core5;
160
- const endOfDoc = $pos.end();
161
- moveToPos = $pos.posAtIndex($pos.index() + 1);
168
+ const endOfDoc = $currentNodePos.end();
169
+ moveToPos = $currentNodePos.posAtIndex($currentNodePos.index() + 1);
162
170
  if (moveToPos >= endOfDoc) {
163
171
  return false;
164
172
  }
@@ -180,8 +188,8 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
180
188
  return true;
181
189
  } else if (isLayoutColumnSelected && fg('platform_editor_advanced_layouts_accessibility')) {
182
190
  var _api$core6, _api$blockControls4, _api$blockControls4$c;
183
- const index = $pos.index($pos.depth);
184
- const parent = $pos.node($pos.depth);
191
+ const index = $currentNodePos.index($currentNodePos.depth);
192
+ const parent = $currentNodePos.node($currentNodePos.depth);
185
193
  // get the next layoutColumn node
186
194
  const nextNode = parent ? parent.maybeChild(index + 1) : null;
187
195
 
@@ -191,29 +199,29 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
191
199
  return true;
192
200
  }
193
201
  const moveToEnd = index === parent.childCount - 2;
194
- moveToPos = moveToEnd ? $pos.before() : selection.to + ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.nodeSize) || 1);
202
+ moveToPos = moveToEnd ? $currentNodePos.before() : selection.to + ((nextNode === null || nextNode === void 0 ? void 0 : nextNode.nodeSize) || 1);
195
203
  api === null || api === void 0 ? void 0 : (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 ? void 0 : (_api$blockControls4$c = _api$blockControls4.commands) === null || _api$blockControls4$c === void 0 ? void 0 : _api$blockControls4$c.moveToLayout(currentNodePos, moveToPos, {
196
204
  moveToEnd,
197
205
  selectMovedNode: true
198
206
  }));
199
207
  return true;
200
208
  } else {
201
- if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
209
+ if ($currentNodePos.depth < 2 || !isParentNodeOfTypeLayout) {
202
210
  return false;
203
211
  }
204
- moveToPos = $pos.after($pos.depth) + 1;
212
+ moveToPos = $currentNodePos.after($currentNodePos.depth) + 1;
205
213
  }
206
214
  } else if (direction === DIRECTION.UP) {
207
215
  if (isLayoutColumnSelected && fg('platform_editor_advanced_layouts_accessibility')) {
208
- moveToPos = $pos.start() - 1;
216
+ moveToPos = $currentNodePos.start() - 1;
209
217
  } else {
210
- const nodeBefore = $pos.depth > 1 && nodeIndex === 0 && shouldEnableNestedDndA11y ? $pos.node($pos.depth) : $pos.nodeBefore;
218
+ const nodeBefore = $currentNodePos.depth > 1 && nodeIndex === 0 && shouldEnableNestedDndA11y ? $currentNodePos.node($currentNodePos.depth) : $currentNodePos.nodeBefore;
211
219
  if (nodeBefore) {
212
220
  moveToPos = currentNodePos - nodeBefore.nodeSize;
213
221
  }
214
222
  }
215
223
  } else {
216
- const endOfDoc = $pos.end();
224
+ const endOfDoc = $currentNodePos.end();
217
225
  if (nodeAfterPos > endOfDoc) {
218
226
  return false;
219
227
  }
@@ -230,15 +238,25 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
230
238
  const nodeType = (_state$doc$nodeAt = state.doc.nodeAt(currentNodePos)) === null || _state$doc$nodeAt === void 0 ? void 0 : _state$doc$nodeAt.type.name;
231
239
 
232
240
  // only move the node if the destination is at the same depth, not support moving a nested node to a parent node
233
- const shouldMoveNode = (shouldEnableNestedDndA11y ? moveToPos > -1 && $pos.depth === state.doc.resolve(moveToPos).depth || nodeType === 'layoutColumn' : moveToPos > -1) || nodeType === 'layoutColumn' && fg('platform_editor_advanced_layouts_accessibility');
241
+ const shouldMoveNode = (shouldEnableNestedDndA11y ? moveToPos > -1 && $currentNodePos.depth === state.doc.resolve(moveToPos).depth || nodeType === 'layoutColumn' : moveToPos > -1) || nodeType === 'layoutColumn' && fg('platform_editor_advanced_layouts_accessibility');
242
+ const {
243
+ $anchor: $newAnchor,
244
+ $head: $newHead
245
+ } = expandSelectionBounds($currentNodePos, selection.$to);
234
246
  if (shouldMoveNode) {
235
247
  var _api$core7;
236
248
  api === null || api === void 0 ? void 0 : (_api$core7 = api.core) === null || _api$core7 === void 0 ? void 0 : _api$core7.actions.execute(({
237
249
  tr
238
250
  }) => {
239
- api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
240
- tr
241
- });
251
+ if (fg('platform_editor_elements_dnd_multi_select_patch_1')) {
252
+ api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions($newAnchor.pos, $newHead.pos)({
253
+ tr
254
+ });
255
+ } else {
256
+ api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
257
+ tr
258
+ });
259
+ }
242
260
  moveNode(api)(currentNodePos, moveToPos, INPUT_METHOD.SHORTCUT, formatMessage)({
243
261
  tr
244
262
  });
@@ -262,9 +280,15 @@ export const moveNodeViaShortcut = (api, direction, formatMessage) => {
262
280
  api === null || api === void 0 ? void 0 : (_api$core9 = api.core) === null || _api$core9 === void 0 ? void 0 : _api$core9.actions.execute(({
263
281
  tr
264
282
  }) => {
265
- api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
266
- tr
267
- });
283
+ if (fg('platform_editor_elements_dnd_multi_select_patch_1')) {
284
+ api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions($newAnchor.pos, $newHead.pos)({
285
+ tr
286
+ });
287
+ } else {
288
+ api === null || api === void 0 ? void 0 : api.blockControls.commands.setMultiSelectPositions(expandedAnchor, expandedHead)({
289
+ tr
290
+ });
291
+ }
268
292
  tr.scrollIntoView();
269
293
  return tr;
270
294
  });
@@ -292,6 +316,12 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
292
316
  const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true, {
293
317
  exposure: true
294
318
  });
319
+ if (fg('platform_editor_ease_of_use_metrics')) {
320
+ var _api$metrics;
321
+ api === null || api === void 0 ? void 0 : (_api$metrics = api.metrics) === null || _api$metrics === void 0 ? void 0 : _api$metrics.commands.setContentMoved()({
322
+ tr
323
+ });
324
+ }
295
325
  const slicePosition = getSelectedSlicePosition(start, tr, api);
296
326
  if (isMultiSelect) {
297
327
  sliceFrom = slicePosition.from;
@@ -313,6 +313,12 @@ export const moveToLayout = api => (from, to, options) => ({
313
313
  if (!fromContentWithoutBreakout) {
314
314
  return tr;
315
315
  }
316
+ if (fg('platform_editor_ease_of_use_metrics')) {
317
+ var _api$metrics;
318
+ api === null || api === void 0 ? void 0 : (_api$metrics = api.metrics) === null || _api$metrics === void 0 ? void 0 : _api$metrics.commands.setContentMoved()({
319
+ tr
320
+ });
321
+ }
316
322
  const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
317
323
  if (toNode.type === layoutSection) {
318
324
  const toPos = options !== null && options !== void 0 && options.moveToEnd ? to + toNode.nodeSize - 1 : to + 1;