@atlaskit/editor-plugin-block-controls 3.9.1 → 3.10.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,26 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 3.10.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#139189](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/139189)
8
+ [`33e0a9b6291ae`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/33e0a9b6291ae) -
9
+ [ux] When table is selected via drag handle, we show Table floating controls toolbar. If the table
10
+ selected via other means, we show the Text Formatting toolbar.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 3.9.2
17
+
18
+ ### Patch Changes
19
+
20
+ - [#139175](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/139175)
21
+ [`6274734c42470`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6274734c42470) -
22
+ Allow drag handle to display for empty lines when platform_editor_controls is enabled
23
+
3
24
  ## 3.9.1
4
25
 
5
26
  ### Patch Changes
@@ -164,10 +164,19 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
164
164
  }));
165
165
  return tr;
166
166
  };
167
+ },
168
+ setSelectedViaDragHandle: function setSelectedViaDragHandle(isSelectedViaDragHandle) {
169
+ return function (_ref7) {
170
+ var tr = _ref7.tr;
171
+ var currMeta = tr.getMeta(_main.key);
172
+ return tr.setMeta(_main.key, _objectSpread(_objectSpread({}, currMeta), {}, {
173
+ isSelectedViaDragHandle: isSelectedViaDragHandle
174
+ }));
175
+ };
167
176
  }
168
177
  },
169
178
  getSharedState: function getSharedState(editorState) {
170
- var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP;
179
+ var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP, _key$getState$isSelec, _key$getState9;
171
180
  if (!editorState) {
172
181
  return undefined;
173
182
  }
@@ -180,14 +189,15 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
180
189
  multiSelectDnD: (_key$getState$multiSe = (_key$getState6 = _main.key.getState(editorState)) === null || _key$getState6 === void 0 ? void 0 : _key$getState6.multiSelectDnD) !== null && _key$getState$multiSe !== void 0 ? _key$getState$multiSe : undefined,
181
190
  isShiftDown: (_key$getState$isShift = (_key$getState7 = _main.key.getState(editorState)) === null || _key$getState7 === void 0 ? void 0 : _key$getState7.isShiftDown) !== null && _key$getState$isShift !== void 0 ? _key$getState$isShift : undefined,
182
191
  lastDragCancelled: (_key$getState$lastDra = (_key$getState8 = _main.key.getState(editorState)) === null || _key$getState8 === void 0 ? void 0 : _key$getState8.lastDragCancelled) !== null && _key$getState$lastDra !== void 0 ? _key$getState$lastDra : false,
183
- isEditing: (_interactionTrackingP = _pmPlugin.interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing
192
+ isEditing: (_interactionTrackingP = _pmPlugin.interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing,
193
+ isSelectedViaDragHandle: (_key$getState$isSelec = (_key$getState9 = _main.key.getState(editorState)) === null || _key$getState9 === void 0 ? void 0 : _key$getState9.isSelectedViaDragHandle) !== null && _key$getState$isSelec !== void 0 ? _key$getState$isSelec : false
184
194
  };
185
195
  },
186
- contentComponent: function contentComponent(_ref7) {
187
- var editorView = _ref7.editorView,
188
- popupsMountPoint = _ref7.popupsMountPoint,
189
- popupsBoundariesElement = _ref7.popupsBoundariesElement,
190
- popupsScrollableElement = _ref7.popupsScrollableElement;
196
+ contentComponent: function contentComponent(_ref8) {
197
+ var editorView = _ref8.editorView,
198
+ popupsMountPoint = _ref8.popupsMountPoint,
199
+ popupsBoundariesElement = _ref8.popupsBoundariesElement,
200
+ popupsScrollableElement = _ref8.popupsScrollableElement;
191
201
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? /*#__PURE__*/_react.default.createElement(_blockMenu.default, {
192
202
  editorView: editorView,
193
203
  mountPoint: popupsMountPoint,
@@ -4,12 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.handleMouseDown = void 0;
7
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
7
8
  var handleMouseDown = exports.handleMouseDown = function handleMouseDown(api) {
8
9
  return function (view, event) {
9
- if (view.editable) {
10
+ if (!(event.target instanceof HTMLElement)) {
10
11
  return false;
11
12
  }
12
- if (event.target instanceof HTMLElement) {
13
+ if (!view.editable) {
13
14
  var _rootNode$type$name, _rootNode$type$name2;
14
15
  var targetPos = view.posAtDOM(event.target, 0);
15
16
  // always fetch top level position for mouseDown to avoid drag handle positions being incorrect
@@ -19,6 +20,9 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(api) {
19
20
  return false;
20
21
  }
21
22
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
23
+ } else if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
24
+ var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
25
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
22
26
  }
23
27
  return false;
24
28
  };
@@ -166,7 +166,8 @@ var initialState = {
166
166
  isDocSizeLimitEnabled: null,
167
167
  isPMDragging: false,
168
168
  multiSelectDnD: undefined,
169
- lastDragCancelled: false
169
+ lastDragCancelled: false,
170
+ isSelectedViaDragHandle: false
170
171
  };
171
172
  var getDecorations = exports.getDecorations = function getDecorations(state) {
172
173
  var _key$getState;
@@ -199,7 +200,8 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
199
200
  menuTriggerBy = currentState.menuTriggerBy,
200
201
  isPMDragging = currentState.isPMDragging,
201
202
  isShiftDown = currentState.isShiftDown,
202
- lastDragCancelled = currentState.lastDragCancelled;
203
+ lastDragCancelled = currentState.lastDragCancelled,
204
+ isSelectedViaDragHandle = currentState.isSelectedViaDragHandle;
203
205
  var isActiveNodeDeleted = false;
204
206
  var _getTrMetadata = (0, _transactions.getTrMetadata)(tr),
205
207
  from = _getTrMetadata.from,
@@ -409,6 +411,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
409
411
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
410
412
  isMenuOpenNew = !isMenuOpen;
411
413
  }
414
+ var isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
412
415
  return {
413
416
  decorations: decorations,
414
417
  activeNode: newActiveNode,
@@ -423,7 +426,8 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
423
426
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
424
427
  multiSelectDnD: multiSelectDnD,
425
428
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
426
- lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled
429
+ lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
430
+ isSelectedViaDragHandle: isSelectedViaDragHandleNew
427
431
  };
428
432
  };
429
433
  var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI) {
@@ -580,6 +584,16 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
580
584
  return true;
581
585
  }
582
586
  }
587
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
588
+ var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
589
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
590
+ }
591
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
592
+ var _api$blockControls$sh;
593
+ if (api !== null && api !== void 0 && (_api$blockControls$sh = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh !== void 0 && _api$blockControls$sh.isSelectedViaDragHandle) {
594
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
595
+ }
596
+ }
583
597
  if (!event.repeat && event.shiftKey && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_shift_click_select')) {
584
598
  view.dispatch(view.state.tr.setMeta(key, _objectSpread(_objectSpread({}, view.state.tr.getMeta(key)), {}, {
585
599
  isShiftDown: true
@@ -607,8 +621,17 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
607
621
  return true;
608
622
  }
609
623
  }
624
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
625
+ var _isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
626
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(_isDragHandle));
627
+ }
628
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
629
+ var _api$blockControls$sh2;
630
+ if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
631
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
632
+ }
633
+ }
610
634
  }
611
- return false;
612
635
  },
613
636
  keyup: function keyup(view, event) {
614
637
  if (!event.repeat && event.key === 'Shift') {
@@ -4,11 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.setCursorPositionAtMovedNode = exports.selectNode = exports.rootTaskListDepth = exports.rootListDepth = exports.isHandleCorrelatedToSelection = exports.getSelection = exports.getInlineNodePos = void 0;
7
- var _selection = require("@atlaskit/editor-common/selection");
7
+ var _selection2 = 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
11
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var getInlineNodePos = exports.getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
13
14
  var $startPos = tr.doc.resolve(start);
14
15
  // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
@@ -51,7 +52,7 @@ var isNodeWithMediaOrExtension = function isNodeWithMediaOrExtension(tr, start,
51
52
  });
52
53
  return hasMediaOrExtension;
53
54
  };
54
- var getSelection = exports.getSelection = function getSelection(tr, start) {
55
+ var oldGetSelection = function oldGetSelection(tr, start) {
55
56
  var node = tr.doc.nodeAt(start);
56
57
  var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
57
58
  var nodeSize = node ? node.nodeSize : 1;
@@ -81,12 +82,53 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
81
82
  return new _state.TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
82
83
  }
83
84
  };
85
+ var newGetSelection = function newGetSelection(tr, start) {
86
+ var node = tr.doc.nodeAt(start);
87
+ var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
88
+ var nodeSize = node ? node.nodeSize : 1;
89
+ var nodeName = node === null || node === void 0 ? void 0 : node.type.name;
90
+
91
+ // this is a fix for empty paragraph selection - put first to avoid any extra work
92
+ if (nodeName === 'paragraph' && tr.selection.empty && (node === null || node === void 0 ? void 0 : node.childCount) === 0) {
93
+ return false;
94
+ }
95
+ var isBlockQuoteWithMedia = nodeName === 'blockquote' && isNodeWithMedia(tr, start, nodeSize);
96
+ var isBlockQuoteWithMediaOrExtension = nodeName === 'blockquote' && isNodeWithMediaOrExtension(tr, start, nodeSize);
97
+ var isListWithMediaOrExtension = nodeName === 'bulletList' && isNodeWithMediaOrExtension(tr, start, nodeSize) || nodeName === 'orderedList' && isNodeWithMediaOrExtension(tr, start, nodeSize);
98
+ if (isNodeSelection && nodeName !== 'blockquote' || isListWithMediaOrExtension && (0, _platformFeatureFlags.fg)('platform_editor_non_macros_copy_and_paste_fix') || ((0, _platformFeatureFlags.fg)('platform_editor_non_macros_copy_and_paste_fix') ? isBlockQuoteWithMediaOrExtension : isBlockQuoteWithMedia) ||
99
+ // decisionList/layoutColumn node is not selectable, but we want to select the whole node not just text
100
+ ['decisionList', 'layoutColumn'].includes(nodeName || '') || nodeName === 'mediaGroup' && typeof (node === null || node === void 0 ? void 0 : node.childCount) === 'number' && (node === null || node === void 0 ? void 0 : node.childCount) > 1) {
101
+ return new _state.NodeSelection(tr.doc.resolve(start));
102
+ }
103
+
104
+ // if mediaGroup only has a single child, we want to select the child
105
+ if (nodeName === 'mediaGroup') {
106
+ var $mediaStartPos = tr.doc.resolve(start + 1);
107
+ return new _state.NodeSelection($mediaStartPos);
108
+ }
109
+ if (nodeName === 'taskList' && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_multi_select_patch_1')) {
110
+ return _state.TextSelection.create(tr.doc, start, start + nodeSize);
111
+ }
112
+ var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
113
+ inlineNodePos = _getInlineNodePos2.inlineNodePos,
114
+ inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
115
+ return new _state.TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
116
+ };
117
+ var getSelection = exports.getSelection = function getSelection(tr, start) {
118
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_widget_visibility')) {
119
+ return newGetSelection(tr, start);
120
+ }
121
+ return oldGetSelection(tr, start);
122
+ };
84
123
  var selectNode = exports.selectNode = function selectNode(tr, start, nodeType) {
85
124
  // For table, we need to do cell selection instead of node selection
86
125
  if (nodeType === 'table') {
87
126
  tr = (0, _utils2.selectTableClosestToPos)(tr, tr.doc.resolve(start + 1));
88
- } else {
89
- tr.setSelection(getSelection(tr, start));
127
+ return tr;
128
+ }
129
+ var selection = getSelection(tr, start);
130
+ if (selection) {
131
+ tr.setSelection(selection);
90
132
  }
91
133
  return tr;
92
134
  };
@@ -98,12 +140,20 @@ var setCursorPositionAtMovedNode = exports.setCursorPositionAtMovedNode = functi
98
140
  // decisionList node is not selectable, but we want to select the whole node not just text
99
141
  // blockQuote is selectable, but we want to set cursor at the inline end Pos instead of the gap cursor as this causes jittering post drop
100
142
  if (isNodeSelection && node.type.name !== 'blockquote' || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
101
- selection = new _selection.GapCursorSelection(tr.doc.resolve(start + node.nodeSize), _selection.Side.RIGHT);
102
- } else {
103
- var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
104
- inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
105
- selection = new _state.TextSelection(tr.doc.resolve(inlineNodeEndPos));
143
+ selection = new _selection2.GapCursorSelection(tr.doc.resolve(start + node.nodeSize), _selection2.Side.RIGHT);
144
+ tr.setSelection(selection);
145
+ return tr;
146
+ }
147
+
148
+ // this is a fix for empty paragraph selection - can safely use start position as the paragraph is empty
149
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'paragraph' && (node === null || node === void 0 ? void 0 : node.childCount) === 0 && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_widget_visibility')) {
150
+ var _selection = new _state.TextSelection(tr.doc.resolve(start));
151
+ tr.setSelection(_selection);
152
+ return tr;
106
153
  }
154
+ var _getInlineNodePos3 = getInlineNodePos(tr, start, nodeSize),
155
+ inlineNodeEndPos = _getInlineNodePos3.inlineNodeEndPos;
156
+ selection = new _state.TextSelection(tr.doc.resolve(inlineNodeEndPos));
107
157
  tr.setSelection(selection);
108
158
  return tr;
109
159
  };
@@ -8,6 +8,7 @@ exports.GlobalStylesWrapper = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = require("@emotion/react");
10
10
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
11
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
12
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var _consts = require("./consts");
13
14
  /**
@@ -188,6 +189,6 @@ var blockCardWithoutLayout = (0, _react.css)({
188
189
  });
189
190
  var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
190
191
  return (0, _react.jsx)(_react.Global, {
191
- styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, (0, _experiments.editorExperiment)('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
192
+ styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_widget_visibility') ? undefined : withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, (0, _experiments.editorExperiment)('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
192
193
  });
193
194
  };
@@ -155,10 +155,19 @@ export const blockControlsPlugin = ({
155
155
  multiSelectDnD
156
156
  });
157
157
  return tr;
158
+ },
159
+ setSelectedViaDragHandle: isSelectedViaDragHandle => ({
160
+ tr
161
+ }) => {
162
+ const currMeta = tr.getMeta(key);
163
+ return tr.setMeta(key, {
164
+ ...currMeta,
165
+ isSelectedViaDragHandle
166
+ });
158
167
  }
159
168
  },
160
169
  getSharedState(editorState) {
161
- var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP;
170
+ var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP, _key$getState$isSelec, _key$getState9;
162
171
  if (!editorState) {
163
172
  return undefined;
164
173
  }
@@ -171,7 +180,8 @@ export const blockControlsPlugin = ({
171
180
  multiSelectDnD: (_key$getState$multiSe = (_key$getState6 = key.getState(editorState)) === null || _key$getState6 === void 0 ? void 0 : _key$getState6.multiSelectDnD) !== null && _key$getState$multiSe !== void 0 ? _key$getState$multiSe : undefined,
172
181
  isShiftDown: (_key$getState$isShift = (_key$getState7 = key.getState(editorState)) === null || _key$getState7 === void 0 ? void 0 : _key$getState7.isShiftDown) !== null && _key$getState$isShift !== void 0 ? _key$getState$isShift : undefined,
173
182
  lastDragCancelled: (_key$getState$lastDra = (_key$getState8 = key.getState(editorState)) === null || _key$getState8 === void 0 ? void 0 : _key$getState8.lastDragCancelled) !== null && _key$getState$lastDra !== void 0 ? _key$getState$lastDra : false,
174
- isEditing: (_interactionTrackingP = interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing
183
+ isEditing: (_interactionTrackingP = interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing,
184
+ isSelectedViaDragHandle: (_key$getState$isSelec = (_key$getState9 = key.getState(editorState)) === null || _key$getState9 === void 0 ? void 0 : _key$getState9.isSelectedViaDragHandle) !== null && _key$getState$isSelec !== void 0 ? _key$getState$isSelec : false
175
185
  };
176
186
  },
177
187
  contentComponent({
@@ -1,8 +1,9 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  export const handleMouseDown = api => (view, event) => {
2
- if (view.editable) {
3
+ if (!(event.target instanceof HTMLElement)) {
3
4
  return false;
4
5
  }
5
- if (event.target instanceof HTMLElement) {
6
+ if (!view.editable) {
6
7
  var _rootNode$type$name, _rootNode$type$name2;
7
8
  const targetPos = view.posAtDOM(event.target, 0);
8
9
  // always fetch top level position for mouseDown to avoid drag handle positions being incorrect
@@ -12,6 +13,9 @@ export const handleMouseDown = api => (view, event) => {
12
13
  return false;
13
14
  }
14
15
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
16
+ } else if (fg('platform_editor_controls_patch_5')) {
17
+ const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
18
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
15
19
  }
16
20
  return false;
17
21
  };
@@ -163,7 +163,8 @@ const initialState = {
163
163
  isDocSizeLimitEnabled: null,
164
164
  isPMDragging: false,
165
165
  multiSelectDnD: undefined,
166
- lastDragCancelled: false
166
+ lastDragCancelled: false,
167
+ isSelectedViaDragHandle: false
167
168
  };
168
169
  export const getDecorations = state => {
169
170
  var _key$getState;
@@ -197,7 +198,8 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
197
198
  menuTriggerBy,
198
199
  isPMDragging,
199
200
  isShiftDown,
200
- lastDragCancelled
201
+ lastDragCancelled,
202
+ isSelectedViaDragHandle
201
203
  } = currentState;
202
204
  let isActiveNodeDeleted = false;
203
205
  const {
@@ -407,6 +409,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
407
409
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
408
410
  isMenuOpenNew = !isMenuOpen;
409
411
  }
412
+ const isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
410
413
  return {
411
414
  decorations,
412
415
  activeNode: newActiveNode,
@@ -421,7 +424,8 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
421
424
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
422
425
  multiSelectDnD,
423
426
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
424
- lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled
427
+ lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
428
+ isSelectedViaDragHandle: isSelectedViaDragHandleNew
425
429
  };
426
430
  };
427
431
  export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
@@ -585,6 +589,16 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
585
589
  return true;
586
590
  }
587
591
  }
592
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
593
+ const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
594
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
595
+ }
596
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
597
+ var _api$blockControls$sh;
598
+ if (api !== null && api !== void 0 && (_api$blockControls$sh = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh !== void 0 && _api$blockControls$sh.isSelectedViaDragHandle) {
599
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
600
+ }
601
+ }
588
602
  if (!event.repeat && event.shiftKey && fg('platform_editor_elements_dnd_shift_click_select')) {
589
603
  view.dispatch(view.state.tr.setMeta(key, {
590
604
  ...view.state.tr.getMeta(key),
@@ -614,8 +628,17 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
614
628
  return true;
615
629
  }
616
630
  }
631
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
632
+ const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
633
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
634
+ }
635
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
636
+ var _api$blockControls$sh2;
637
+ if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
638
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
639
+ }
640
+ }
617
641
  }
618
- return false;
619
642
  },
620
643
  keyup(view, event) {
621
644
  if (!event.repeat && event.key === 'Shift') {
@@ -3,6 +3,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
3
3
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
4
  import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  export const getInlineNodePos = (tr, start, nodeSize) => {
7
8
  const $startPos = tr.doc.resolve(start);
8
9
  // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
@@ -45,7 +46,7 @@ const isNodeWithMediaOrExtension = (tr, start, nodeSize) => {
45
46
  });
46
47
  return hasMediaOrExtension;
47
48
  };
48
- export const getSelection = (tr, start) => {
49
+ const oldGetSelection = (tr, start) => {
49
50
  const node = tr.doc.nodeAt(start);
50
51
  const isNodeSelection = node && NodeSelection.isSelectable(node);
51
52
  const nodeSize = node ? node.nodeSize : 1;
@@ -76,12 +77,54 @@ export const getSelection = (tr, start) => {
76
77
  return new TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
77
78
  }
78
79
  };
80
+ const newGetSelection = (tr, start) => {
81
+ const node = tr.doc.nodeAt(start);
82
+ const isNodeSelection = node && NodeSelection.isSelectable(node);
83
+ const nodeSize = node ? node.nodeSize : 1;
84
+ const nodeName = node === null || node === void 0 ? void 0 : node.type.name;
85
+
86
+ // this is a fix for empty paragraph selection - put first to avoid any extra work
87
+ if (nodeName === 'paragraph' && tr.selection.empty && (node === null || node === void 0 ? void 0 : node.childCount) === 0) {
88
+ return false;
89
+ }
90
+ const isBlockQuoteWithMedia = nodeName === 'blockquote' && isNodeWithMedia(tr, start, nodeSize);
91
+ const isBlockQuoteWithMediaOrExtension = nodeName === 'blockquote' && isNodeWithMediaOrExtension(tr, start, nodeSize);
92
+ const isListWithMediaOrExtension = nodeName === 'bulletList' && isNodeWithMediaOrExtension(tr, start, nodeSize) || nodeName === 'orderedList' && isNodeWithMediaOrExtension(tr, start, nodeSize);
93
+ if (isNodeSelection && nodeName !== 'blockquote' || isListWithMediaOrExtension && fg('platform_editor_non_macros_copy_and_paste_fix') || (fg('platform_editor_non_macros_copy_and_paste_fix') ? isBlockQuoteWithMediaOrExtension : isBlockQuoteWithMedia) ||
94
+ // decisionList/layoutColumn node is not selectable, but we want to select the whole node not just text
95
+ ['decisionList', 'layoutColumn'].includes(nodeName || '') || nodeName === 'mediaGroup' && typeof (node === null || node === void 0 ? void 0 : node.childCount) === 'number' && (node === null || node === void 0 ? void 0 : node.childCount) > 1) {
96
+ return new NodeSelection(tr.doc.resolve(start));
97
+ }
98
+
99
+ // if mediaGroup only has a single child, we want to select the child
100
+ if (nodeName === 'mediaGroup') {
101
+ const $mediaStartPos = tr.doc.resolve(start + 1);
102
+ return new NodeSelection($mediaStartPos);
103
+ }
104
+ if (nodeName === 'taskList' && fg('platform_editor_elements_dnd_multi_select_patch_1')) {
105
+ return TextSelection.create(tr.doc, start, start + nodeSize);
106
+ }
107
+ const {
108
+ inlineNodePos,
109
+ inlineNodeEndPos
110
+ } = getInlineNodePos(tr, start, nodeSize);
111
+ return new TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
112
+ };
113
+ export const getSelection = (tr, start) => {
114
+ if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility')) {
115
+ return newGetSelection(tr, start);
116
+ }
117
+ return oldGetSelection(tr, start);
118
+ };
79
119
  export const selectNode = (tr, start, nodeType) => {
80
120
  // For table, we need to do cell selection instead of node selection
81
121
  if (nodeType === 'table') {
82
122
  tr = selectTableClosestToPos(tr, tr.doc.resolve(start + 1));
83
- } else {
84
- tr.setSelection(getSelection(tr, start));
123
+ return tr;
124
+ }
125
+ const selection = getSelection(tr, start);
126
+ if (selection) {
127
+ tr.setSelection(selection);
85
128
  }
86
129
  return tr;
87
130
  };
@@ -94,12 +137,20 @@ export const setCursorPositionAtMovedNode = (tr, start) => {
94
137
  // blockQuote is selectable, but we want to set cursor at the inline end Pos instead of the gap cursor as this causes jittering post drop
95
138
  if (isNodeSelection && node.type.name !== 'blockquote' || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
96
139
  selection = new GapCursorSelection(tr.doc.resolve(start + node.nodeSize), Side.RIGHT);
97
- } else {
98
- const {
99
- inlineNodeEndPos
100
- } = getInlineNodePos(tr, start, nodeSize);
101
- selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
140
+ tr.setSelection(selection);
141
+ return tr;
142
+ }
143
+
144
+ // this is a fix for empty paragraph selection - can safely use start position as the paragraph is empty
145
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'paragraph' && (node === null || node === void 0 ? void 0 : node.childCount) === 0 && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility')) {
146
+ const selection = new TextSelection(tr.doc.resolve(start));
147
+ tr.setSelection(selection);
148
+ return tr;
102
149
  }
150
+ const {
151
+ inlineNodeEndPos
152
+ } = getInlineNodePos(tr, start, nodeSize);
153
+ selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
103
154
  tr.setSelection(selection);
104
155
  return tr;
105
156
  };
@@ -5,6 +5,7 @@
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
6
  import { css, Global, jsx } from '@emotion/react';
7
7
  import { akEditorBreakoutPadding, akEditorCalculatedWideLayoutWidth, akEditorCalculatedWideLayoutWidthSmallViewport } from '@atlaskit/editor-shared-styles';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
10
  import { DRAG_HANDLE_MAX_WIDTH_PLUS_GAP, DRAG_HANDLE_WIDTH } from './consts';
10
11
 
@@ -218,6 +219,6 @@ const blockCardWithoutLayout = css({
218
219
  });
219
220
  export const GlobalStylesWrapper = () => {
220
221
  return jsx(Global, {
221
- styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, editorExperiment('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
222
+ styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility') ? undefined : withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, editorExperiment('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
222
223
  });
223
224
  };
@@ -157,10 +157,19 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
157
157
  }));
158
158
  return tr;
159
159
  };
160
+ },
161
+ setSelectedViaDragHandle: function setSelectedViaDragHandle(isSelectedViaDragHandle) {
162
+ return function (_ref7) {
163
+ var tr = _ref7.tr;
164
+ var currMeta = tr.getMeta(key);
165
+ return tr.setMeta(key, _objectSpread(_objectSpread({}, currMeta), {}, {
166
+ isSelectedViaDragHandle: isSelectedViaDragHandle
167
+ }));
168
+ };
160
169
  }
161
170
  },
162
171
  getSharedState: function getSharedState(editorState) {
163
- var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP;
172
+ var _key$getState$isMenuO, _key$getState, _key$getState$menuTri, _key$getState2, _key$getState$activeN, _key$getState3, _key$getState$isDragg, _key$getState4, _key$getState$isPMDra, _key$getState5, _key$getState$multiSe, _key$getState6, _key$getState$isShift, _key$getState7, _key$getState$lastDra, _key$getState8, _interactionTrackingP, _key$getState$isSelec, _key$getState9;
164
173
  if (!editorState) {
165
174
  return undefined;
166
175
  }
@@ -173,14 +182,15 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
173
182
  multiSelectDnD: (_key$getState$multiSe = (_key$getState6 = key.getState(editorState)) === null || _key$getState6 === void 0 ? void 0 : _key$getState6.multiSelectDnD) !== null && _key$getState$multiSe !== void 0 ? _key$getState$multiSe : undefined,
174
183
  isShiftDown: (_key$getState$isShift = (_key$getState7 = key.getState(editorState)) === null || _key$getState7 === void 0 ? void 0 : _key$getState7.isShiftDown) !== null && _key$getState$isShift !== void 0 ? _key$getState$isShift : undefined,
175
184
  lastDragCancelled: (_key$getState$lastDra = (_key$getState8 = key.getState(editorState)) === null || _key$getState8 === void 0 ? void 0 : _key$getState8.lastDragCancelled) !== null && _key$getState$lastDra !== void 0 ? _key$getState$lastDra : false,
176
- isEditing: (_interactionTrackingP = interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing
185
+ isEditing: (_interactionTrackingP = interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing,
186
+ isSelectedViaDragHandle: (_key$getState$isSelec = (_key$getState9 = key.getState(editorState)) === null || _key$getState9 === void 0 ? void 0 : _key$getState9.isSelectedViaDragHandle) !== null && _key$getState$isSelec !== void 0 ? _key$getState$isSelec : false
177
187
  };
178
188
  },
179
- contentComponent: function contentComponent(_ref7) {
180
- var editorView = _ref7.editorView,
181
- popupsMountPoint = _ref7.popupsMountPoint,
182
- popupsBoundariesElement = _ref7.popupsBoundariesElement,
183
- popupsScrollableElement = _ref7.popupsScrollableElement;
189
+ contentComponent: function contentComponent(_ref8) {
190
+ var editorView = _ref8.editorView,
191
+ popupsMountPoint = _ref8.popupsMountPoint,
192
+ popupsBoundariesElement = _ref8.popupsBoundariesElement,
193
+ popupsScrollableElement = _ref8.popupsScrollableElement;
184
194
  return /*#__PURE__*/React.createElement(React.Fragment, null, editorExperiment('platform_editor_controls', 'variant1') ? /*#__PURE__*/React.createElement(BlockMenu, {
185
195
  editorView: editorView,
186
196
  mountPoint: popupsMountPoint,
@@ -1,9 +1,10 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  export var handleMouseDown = function handleMouseDown(api) {
2
3
  return function (view, event) {
3
- if (view.editable) {
4
+ if (!(event.target instanceof HTMLElement)) {
4
5
  return false;
5
6
  }
6
- if (event.target instanceof HTMLElement) {
7
+ if (!view.editable) {
7
8
  var _rootNode$type$name, _rootNode$type$name2;
8
9
  var targetPos = view.posAtDOM(event.target, 0);
9
10
  // always fetch top level position for mouseDown to avoid drag handle positions being incorrect
@@ -13,6 +14,9 @@ export var handleMouseDown = function handleMouseDown(api) {
13
14
  return false;
14
15
  }
15
16
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
17
+ } else if (fg('platform_editor_controls_patch_5')) {
18
+ var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
19
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
16
20
  }
17
21
  return false;
18
22
  };
@@ -159,7 +159,8 @@ var initialState = {
159
159
  isDocSizeLimitEnabled: null,
160
160
  isPMDragging: false,
161
161
  multiSelectDnD: undefined,
162
- lastDragCancelled: false
162
+ lastDragCancelled: false,
163
+ isSelectedViaDragHandle: false
163
164
  };
164
165
  export var getDecorations = function getDecorations(state) {
165
166
  var _key$getState;
@@ -192,7 +193,8 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
192
193
  menuTriggerBy = currentState.menuTriggerBy,
193
194
  isPMDragging = currentState.isPMDragging,
194
195
  isShiftDown = currentState.isShiftDown,
195
- lastDragCancelled = currentState.lastDragCancelled;
196
+ lastDragCancelled = currentState.lastDragCancelled,
197
+ isSelectedViaDragHandle = currentState.isSelectedViaDragHandle;
196
198
  var isActiveNodeDeleted = false;
197
199
  var _getTrMetadata = getTrMetadata(tr),
198
200
  from = _getTrMetadata.from,
@@ -402,6 +404,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
402
404
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
403
405
  isMenuOpenNew = !isMenuOpen;
404
406
  }
407
+ var isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
405
408
  return {
406
409
  decorations: decorations,
407
410
  activeNode: newActiveNode,
@@ -416,7 +419,8 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
416
419
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
417
420
  multiSelectDnD: multiSelectDnD,
418
421
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
419
- lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled
422
+ lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
423
+ isSelectedViaDragHandle: isSelectedViaDragHandleNew
420
424
  };
421
425
  };
422
426
  export { _apply as apply };
@@ -574,6 +578,16 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
574
578
  return true;
575
579
  }
576
580
  }
581
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
582
+ var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
583
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
584
+ }
585
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
586
+ var _api$blockControls$sh;
587
+ if (api !== null && api !== void 0 && (_api$blockControls$sh = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh !== void 0 && _api$blockControls$sh.isSelectedViaDragHandle) {
588
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
589
+ }
590
+ }
577
591
  if (!event.repeat && event.shiftKey && fg('platform_editor_elements_dnd_shift_click_select')) {
578
592
  view.dispatch(view.state.tr.setMeta(key, _objectSpread(_objectSpread({}, view.state.tr.getMeta(key)), {}, {
579
593
  isShiftDown: true
@@ -601,8 +615,17 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
601
615
  return true;
602
616
  }
603
617
  }
618
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
619
+ var _isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
620
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(_isDragHandle));
621
+ }
622
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
623
+ var _api$blockControls$sh2;
624
+ if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
625
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
626
+ }
627
+ }
604
628
  }
605
- return false;
606
629
  },
607
630
  keyup: function keyup(view, event) {
608
631
  if (!event.repeat && event.key === 'Shift') {
@@ -3,6 +3,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
3
3
  import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
4
4
  import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
7
  export var getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
7
8
  var $startPos = tr.doc.resolve(start);
8
9
  // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
@@ -45,7 +46,7 @@ var isNodeWithMediaOrExtension = function isNodeWithMediaOrExtension(tr, start,
45
46
  });
46
47
  return hasMediaOrExtension;
47
48
  };
48
- export var getSelection = function getSelection(tr, start) {
49
+ var oldGetSelection = function oldGetSelection(tr, start) {
49
50
  var node = tr.doc.nodeAt(start);
50
51
  var isNodeSelection = node && NodeSelection.isSelectable(node);
51
52
  var nodeSize = node ? node.nodeSize : 1;
@@ -75,12 +76,53 @@ export var getSelection = function getSelection(tr, start) {
75
76
  return new TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
76
77
  }
77
78
  };
79
+ var newGetSelection = function newGetSelection(tr, start) {
80
+ var node = tr.doc.nodeAt(start);
81
+ var isNodeSelection = node && NodeSelection.isSelectable(node);
82
+ var nodeSize = node ? node.nodeSize : 1;
83
+ var nodeName = node === null || node === void 0 ? void 0 : node.type.name;
84
+
85
+ // this is a fix for empty paragraph selection - put first to avoid any extra work
86
+ if (nodeName === 'paragraph' && tr.selection.empty && (node === null || node === void 0 ? void 0 : node.childCount) === 0) {
87
+ return false;
88
+ }
89
+ var isBlockQuoteWithMedia = nodeName === 'blockquote' && isNodeWithMedia(tr, start, nodeSize);
90
+ var isBlockQuoteWithMediaOrExtension = nodeName === 'blockquote' && isNodeWithMediaOrExtension(tr, start, nodeSize);
91
+ var isListWithMediaOrExtension = nodeName === 'bulletList' && isNodeWithMediaOrExtension(tr, start, nodeSize) || nodeName === 'orderedList' && isNodeWithMediaOrExtension(tr, start, nodeSize);
92
+ if (isNodeSelection && nodeName !== 'blockquote' || isListWithMediaOrExtension && fg('platform_editor_non_macros_copy_and_paste_fix') || (fg('platform_editor_non_macros_copy_and_paste_fix') ? isBlockQuoteWithMediaOrExtension : isBlockQuoteWithMedia) ||
93
+ // decisionList/layoutColumn node is not selectable, but we want to select the whole node not just text
94
+ ['decisionList', 'layoutColumn'].includes(nodeName || '') || nodeName === 'mediaGroup' && typeof (node === null || node === void 0 ? void 0 : node.childCount) === 'number' && (node === null || node === void 0 ? void 0 : node.childCount) > 1) {
95
+ return new NodeSelection(tr.doc.resolve(start));
96
+ }
97
+
98
+ // if mediaGroup only has a single child, we want to select the child
99
+ if (nodeName === 'mediaGroup') {
100
+ var $mediaStartPos = tr.doc.resolve(start + 1);
101
+ return new NodeSelection($mediaStartPos);
102
+ }
103
+ if (nodeName === 'taskList' && fg('platform_editor_elements_dnd_multi_select_patch_1')) {
104
+ return TextSelection.create(tr.doc, start, start + nodeSize);
105
+ }
106
+ var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
107
+ inlineNodePos = _getInlineNodePos2.inlineNodePos,
108
+ inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
109
+ return new TextSelection(tr.doc.resolve(inlineNodePos), tr.doc.resolve(inlineNodeEndPos));
110
+ };
111
+ export var getSelection = function getSelection(tr, start) {
112
+ if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility')) {
113
+ return newGetSelection(tr, start);
114
+ }
115
+ return oldGetSelection(tr, start);
116
+ };
78
117
  export var selectNode = function selectNode(tr, start, nodeType) {
79
118
  // For table, we need to do cell selection instead of node selection
80
119
  if (nodeType === 'table') {
81
120
  tr = selectTableClosestToPos(tr, tr.doc.resolve(start + 1));
82
- } else {
83
- tr.setSelection(getSelection(tr, start));
121
+ return tr;
122
+ }
123
+ var selection = getSelection(tr, start);
124
+ if (selection) {
125
+ tr.setSelection(selection);
84
126
  }
85
127
  return tr;
86
128
  };
@@ -93,11 +135,19 @@ export var setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(
93
135
  // blockQuote is selectable, but we want to set cursor at the inline end Pos instead of the gap cursor as this causes jittering post drop
94
136
  if (isNodeSelection && node.type.name !== 'blockquote' || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
95
137
  selection = new GapCursorSelection(tr.doc.resolve(start + node.nodeSize), Side.RIGHT);
96
- } else {
97
- var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
98
- inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
99
- selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
138
+ tr.setSelection(selection);
139
+ return tr;
140
+ }
141
+
142
+ // this is a fix for empty paragraph selection - can safely use start position as the paragraph is empty
143
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'paragraph' && (node === null || node === void 0 ? void 0 : node.childCount) === 0 && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility')) {
144
+ var _selection = new TextSelection(tr.doc.resolve(start));
145
+ tr.setSelection(_selection);
146
+ return tr;
100
147
  }
148
+ var _getInlineNodePos3 = getInlineNodePos(tr, start, nodeSize),
149
+ inlineNodeEndPos = _getInlineNodePos3.inlineNodeEndPos;
150
+ selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
101
151
  tr.setSelection(selection);
102
152
  return tr;
103
153
  };
@@ -6,6 +6,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
6
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
7
  import { css, Global, jsx } from '@emotion/react';
8
8
  import { akEditorBreakoutPadding, akEditorCalculatedWideLayoutWidth, akEditorCalculatedWideLayoutWidthSmallViewport } from '@atlaskit/editor-shared-styles';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
11
  import { DRAG_HANDLE_MAX_WIDTH_PLUS_GAP, DRAG_HANDLE_WIDTH } from './consts';
11
12
 
@@ -181,6 +182,6 @@ var blockCardWithoutLayout = css({
181
182
  });
182
183
  export var GlobalStylesWrapper = function GlobalStylesWrapper() {
183
184
  return jsx(Global, {
184
- styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, editorExperiment('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
185
+ styles: [globalStyles(), globalDnDStyle, extendedHoverZone(), editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_widget_visibility') ? undefined : withInlineNodeStyle, withDeleteLinesStyleFix, withMediaSingleStyleFix, legacyBreakoutWideLayoutStyle, headingWithIndentationInLayoutStyleFix, editorExperiment('advanced_layouts', true) ? blockCardWithoutLayout : undefined, withDividerInPanelStyleFix, withFormatInLayoutStyleFix, withRelativePosStyle, topLevelNodeMarginStyles, withAnchorNameZindexStyle,,]
185
186
  });
186
187
  };
@@ -50,6 +50,7 @@ export interface PluginState {
50
50
  multiSelectDnD?: MultiSelectDnD;
51
51
  isShiftDown?: boolean;
52
52
  lastDragCancelled: boolean;
53
+ isSelectedViaDragHandle?: boolean;
53
54
  }
54
55
  export type ReleaseHiddenDecoration = () => boolean | undefined;
55
56
  export type BlockControlsSharedState = {
@@ -61,6 +62,7 @@ export type BlockControlsSharedState = {
61
62
  multiSelectDnD?: MultiSelectDnD;
62
63
  isShiftDown?: boolean;
63
64
  isEditing?: boolean;
65
+ isSelectedViaDragHandle?: boolean;
64
66
  } | undefined;
65
67
  export type HandleOptions = {
66
68
  isFocused: boolean;
@@ -101,6 +103,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
101
103
  }) => EditorCommand;
102
104
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
103
105
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
106
+ setSelectedViaDragHandle: (isSelectedViaDragHandle?: boolean) => EditorCommand;
104
107
  };
105
108
  }>;
106
109
  export type BlockControlsMeta = {
@@ -27,5 +27,6 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
27
27
  multiSelectDnD: import("../blockControlsPluginType").MultiSelectDnD | undefined;
28
28
  isShiftDown: any;
29
29
  lastDragCancelled: any;
30
+ isSelectedViaDragHandle: boolean;
30
31
  };
31
32
  export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI) => SafePlugin<PluginState>;
@@ -4,7 +4,7 @@ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => false | NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
@@ -50,6 +50,7 @@ export interface PluginState {
50
50
  multiSelectDnD?: MultiSelectDnD;
51
51
  isShiftDown?: boolean;
52
52
  lastDragCancelled: boolean;
53
+ isSelectedViaDragHandle?: boolean;
53
54
  }
54
55
  export type ReleaseHiddenDecoration = () => boolean | undefined;
55
56
  export type BlockControlsSharedState = {
@@ -61,6 +62,7 @@ export type BlockControlsSharedState = {
61
62
  multiSelectDnD?: MultiSelectDnD;
62
63
  isShiftDown?: boolean;
63
64
  isEditing?: boolean;
65
+ isSelectedViaDragHandle?: boolean;
64
66
  } | undefined;
65
67
  export type HandleOptions = {
66
68
  isFocused: boolean;
@@ -101,6 +103,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
101
103
  }) => EditorCommand;
102
104
  setNodeDragged: (getPos: () => number | undefined, anchorName: string, nodeType: string) => EditorCommand;
103
105
  setMultiSelectPositions: (anchor?: number, head?: number) => EditorCommand;
106
+ setSelectedViaDragHandle: (isSelectedViaDragHandle?: boolean) => EditorCommand;
104
107
  };
105
108
  }>;
106
109
  export type BlockControlsMeta = {
@@ -27,5 +27,6 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
27
27
  multiSelectDnD: import("../blockControlsPluginType").MultiSelectDnD | undefined;
28
28
  isShiftDown: any;
29
29
  lastDragCancelled: any;
30
+ isSelectedViaDragHandle: boolean;
30
31
  };
31
32
  export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI) => SafePlugin<PluginState>;
@@ -4,7 +4,7 @@ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize
4
4
  inlineNodePos: number;
5
5
  inlineNodeEndPos: number;
6
6
  };
7
- export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
7
+ export declare const getSelection: (tr: Transaction, start: number) => false | NodeSelection | TextSelection;
8
8
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
9
9
  export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
10
10
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.9.1",
3
+ "version": "3.10.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^47.6.0",
36
- "@atlaskit/editor-common": "^103.6.0",
36
+ "@atlaskit/editor-common": "^103.7.0",
37
37
  "@atlaskit/editor-plugin-accessibility-utils": "^2.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
39
39
  "@atlaskit/editor-plugin-editor-disabled": "^2.0.0",
@@ -46,14 +46,14 @@
46
46
  "@atlaskit/editor-prosemirror": "7.0.0",
47
47
  "@atlaskit/editor-shared-styles": "^3.4.0",
48
48
  "@atlaskit/editor-tables": "^2.9.0",
49
- "@atlaskit/icon": "^25.5.0",
49
+ "@atlaskit/icon": "^25.6.0",
50
50
  "@atlaskit/platform-feature-flags": "^1.1.0",
51
51
  "@atlaskit/pragmatic-drag-and-drop": "^1.5.0",
52
52
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
53
53
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.1.0",
54
54
  "@atlaskit/primitives": "^14.4.0",
55
55
  "@atlaskit/theme": "^18.0.0",
56
- "@atlaskit/tmp-editor-statsig": "^4.6.0",
56
+ "@atlaskit/tmp-editor-statsig": "^4.8.0",
57
57
  "@atlaskit/tokens": "^4.7.0",
58
58
  "@atlaskit/tooltip": "^20.0.0",
59
59
  "@babel/runtime": "^7.0.0",
@@ -172,6 +172,9 @@
172
172
  },
173
173
  "platform_editor_controls_patch_4": {
174
174
  "type": "boolean"
175
+ },
176
+ "platform_editor_controls_patch_5": {
177
+ "type": "boolean"
175
178
  }
176
179
  }
177
180
  }