@atlaskit/editor-plugin-block-controls 3.9.2 → 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,18 @@
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
+
3
16
  ## 3.9.2
4
17
 
5
18
  ### 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') {
@@ -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') {
@@ -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') {
@@ -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>;
@@ -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>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.9.2",
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.7.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
  }