@atlaskit/editor-plugin-block-controls 30.0.1 → 30.1.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,17 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 30.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`0352c4e5b3ada`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0352c4e5b3ada) -
8
+ Add an optional onBlockHandleClick callback for drag-handle, including keyboard activation.
9
+ Confluence configures the callback behind the confluence_table_to_database experiment.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 30.0.1
4
16
 
5
17
  ### Patch Changes
@@ -77,6 +77,14 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
77
77
  return {
78
78
  name: 'blockControls',
79
79
  actions: {
80
+ notifyBlockHandleClick: function notifyBlockHandleClick(context) {
81
+ try {
82
+ var _config$onBlockHandle;
83
+ config === null || config === void 0 || (_config$onBlockHandle = config.onBlockHandleClick) === null || _config$onBlockHandle === void 0 || _config$onBlockHandle.call(config, context);
84
+ } catch (_unused) {
85
+ // A host callback must not prevent the block menu from opening.
86
+ }
87
+ },
80
88
  getTextInfo: function getTextInfo(editorView) {
81
89
  var _api$blockControls, _blockControlsState$m;
82
90
  var blockControlsState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
@@ -182,7 +182,7 @@ var BlockControlsSurfaceDragHandle = exports.BlockControlsSurfaceDragHandle = fu
182
182
  }
183
183
  var openedViaKeyboard = event.detail === 0;
184
184
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref4) {
185
- var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3, _activeNode$rootPos;
185
+ var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls3, _api$blockControls4, _activeNode$rootPos;
186
186
  var tr = _ref4.tr;
187
187
  var startPos = getPos();
188
188
  if (startPos === undefined) {
@@ -193,6 +193,12 @@ var BlockControlsSurfaceDragHandle = exports.BlockControlsSurfaceDragHandle = fu
193
193
  }
194
194
  var selection = (_selectionPreservatio = (_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) !== null && _selectionPreservatio !== void 0 ? _selectionPreservatio : tr.selection;
195
195
  var resolvedStartPos = tr.doc.resolve(startPos);
196
+ if (resolvedStartPos.nodeAfter) {
197
+ var _api$blockControls2;
198
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.actions.notifyBlockHandleClick({
199
+ node: resolvedStartPos.nodeAfter
200
+ });
201
+ }
196
202
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
197
203
  action: _enums.ACTION.CLICKED,
198
204
  actionSubject: _enums.ACTION_SUBJECT.BUTTON,
@@ -219,10 +225,10 @@ var BlockControlsSurfaceDragHandle = exports.BlockControlsSurfaceDragHandle = fu
219
225
  tr: tr
220
226
  });
221
227
  }
222
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
228
+ api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.startPreservingSelection()({
223
229
  tr: tr
224
230
  });
225
- api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.toggleBlockMenu({
231
+ api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.commands.toggleBlockMenu({
226
232
  anchorName: getAnchorName(),
227
233
  openedViaKeyboard: openedViaKeyboard,
228
234
  triggerByNode: {
@@ -459,7 +459,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
459
459
  var handleOnClickNew = (0, _react.useCallback)(function (e) {
460
460
  var _api$core;
461
461
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
462
- var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
462
+ var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3;
463
463
  var tr = _ref3.tr;
464
464
  var startPos = getPos();
465
465
  if (startPos === undefined) {
@@ -469,6 +469,12 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
469
469
  tr.setMeta('toggleLayoutColumnMenu', buildToggleLayoutColumnMenuMeta(startPos, false));
470
470
  }
471
471
  var resolvedStartPos = tr.doc.resolve(startPos);
472
+ if (resolvedStartPos.nodeAfter) {
473
+ var _api$blockControls;
474
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.actions.notifyBlockHandleClick({
475
+ node: resolvedStartPos.nodeAfter
476
+ });
477
+ }
472
478
  var selection = ((_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
473
479
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
474
480
  eventType: _enums.EVENT_TYPE.UI,
@@ -488,10 +494,10 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
488
494
  nodeType: nodeType,
489
495
  api: api
490
496
  });
491
- api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.startPreservingSelection()({
497
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
492
498
  tr: tr
493
499
  });
494
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.toggleBlockMenu({
500
+ api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.toggleBlockMenu({
495
501
  anchorName: anchorName,
496
502
  openedViaKeyboard: false,
497
503
  triggerByNode: {
@@ -518,11 +524,18 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
518
524
  e.stopPropagation();
519
525
  var startPos = getPos();
520
526
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref4) {
521
- var _selectionPreservatio2, _api$blockControls3, _api$blockControls4, _api$userIntent;
527
+ var _selectionPreservatio2, _api$blockControls5, _api$blockControls6, _api$userIntent;
522
528
  var tr = _ref4.tr;
523
529
  if (startPos === undefined) {
524
530
  return tr;
525
531
  }
532
+ var node = tr.doc.resolve(startPos).nodeAfter;
533
+ if (node) {
534
+ var _api$blockControls4;
535
+ api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.actions.notifyBlockHandleClick({
536
+ node: node
537
+ });
538
+ }
526
539
  var selection = ((_selectionPreservatio2 = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) || tr.selection;
527
540
  (0, _expandAndUpdateSelection.expandAndUpdateSelection)({
528
541
  tr: tr,
@@ -532,7 +545,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
532
545
  nodeType: nodeType,
533
546
  api: api
534
547
  });
535
- api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.startPreservingSelection()({
548
+ api === null || api === void 0 || (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 || _api$blockControls5.commands.startPreservingSelection()({
536
549
  tr: tr
537
550
  });
538
551
  if (nodeType === 'layoutColumn') {
@@ -543,7 +556,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
543
556
  pos: startPos,
544
557
  rootPos: tr.doc.resolve(startPos).before(1)
545
558
  };
546
- api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.commands.toggleBlockMenu({
559
+ api === null || api === void 0 || (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 || _api$blockControls6.commands.toggleBlockMenu({
547
560
  anchorName: anchorName,
548
561
  triggerByNode: triggerByNode,
549
562
  openedViaKeyboard: true
@@ -588,8 +601,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
588
601
  }
589
602
  var newHandlePosCheck = (0, _getSelection.isHandleCorrelatedToSelection)(view.state, tr.selection, handlePos);
590
603
  if (!tr.selection.empty && newHandlePosCheck) {
591
- var _api$blockControls5;
592
- api === null || api === void 0 || (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 || _api$blockControls5.commands.setMultiSelectPositions()({
604
+ var _api$blockControls7;
605
+ api === null || api === void 0 || (_api$blockControls7 = api.blockControls) === null || _api$blockControls7 === void 0 || _api$blockControls7.commands.setMultiSelectPositions()({
593
606
  tr: tr
594
607
  });
595
608
  } else {
@@ -696,7 +709,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
696
709
  return;
697
710
  }
698
711
  api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref8) {
699
- var _api$blockControls$sh2, _api$blockControls6, _api$analytics2;
712
+ var _api$blockControls$sh2, _api$blockControls8, _api$analytics2;
700
713
  var tr = _ref8.tr;
701
714
  var nodeTypes, hasSelectedMultipleNodes;
702
715
  var resolvedMovingNode = tr.doc.resolve(start);
@@ -710,7 +723,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref2) {
710
723
  nodeTypes = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name;
711
724
  hasSelectedMultipleNodes = false;
712
725
  }
713
- api === null || api === void 0 || (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 || _api$blockControls6.commands.setNodeDragged(getPos, anchorName, nodeType)({
726
+ api === null || api === void 0 || (_api$blockControls8 = api.blockControls) === null || _api$blockControls8 === void 0 || _api$blockControls8.commands.setNodeDragged(getPos, anchorName, nodeType)({
714
727
  tr: tr
715
728
  });
716
729
  tr.setMeta('scrollIntoView', false);
@@ -75,6 +75,14 @@ export const blockControlsPlugin = ({
75
75
  return {
76
76
  name: 'blockControls',
77
77
  actions: {
78
+ notifyBlockHandleClick: context => {
79
+ try {
80
+ var _config$onBlockHandle;
81
+ config === null || config === void 0 ? void 0 : (_config$onBlockHandle = config.onBlockHandleClick) === null || _config$onBlockHandle === void 0 ? void 0 : _config$onBlockHandle.call(config, context);
82
+ } catch {
83
+ // A host callback must not prevent the block menu from opening.
84
+ }
85
+ },
78
86
  getTextInfo: editorView => {
79
87
  var _api$blockControls, _blockControlsState$m;
80
88
  const blockControlsState = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
@@ -173,7 +173,7 @@ export const BlockControlsSurfaceDragHandle = ({
173
173
  api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
174
174
  tr
175
175
  }) => {
176
- var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3, _activeNode$rootPos;
176
+ var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls3, _api$blockControls4, _activeNode$rootPos;
177
177
  const startPos = getPos();
178
178
  if (startPos === undefined) {
179
179
  return tr;
@@ -183,6 +183,12 @@ export const BlockControlsSurfaceDragHandle = ({
183
183
  }
184
184
  const selection = (_selectionPreservatio = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) !== null && _selectionPreservatio !== void 0 ? _selectionPreservatio : tr.selection;
185
185
  const resolvedStartPos = tr.doc.resolve(startPos);
186
+ if (resolvedStartPos.nodeAfter) {
187
+ var _api$blockControls2;
188
+ api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.actions.notifyBlockHandleClick({
189
+ node: resolvedStartPos.nodeAfter
190
+ });
191
+ }
186
192
  api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
187
193
  action: ACTION.CLICKED,
188
194
  actionSubject: ACTION_SUBJECT.BUTTON,
@@ -209,10 +215,10 @@ export const BlockControlsSurfaceDragHandle = ({
209
215
  tr
210
216
  });
211
217
  }
212
- api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.startPreservingSelection()({
218
+ api === null || api === void 0 ? void 0 : (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.commands.startPreservingSelection()({
213
219
  tr
214
220
  });
215
- api === null || api === void 0 ? void 0 : (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.commands.toggleBlockMenu({
221
+ api === null || api === void 0 ? void 0 : (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 ? void 0 : _api$blockControls4.commands.toggleBlockMenu({
216
222
  anchorName: getAnchorName(),
217
223
  openedViaKeyboard,
218
224
  triggerByNode: {
@@ -438,7 +438,7 @@ export const DragHandle = ({
438
438
  api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
439
439
  tr
440
440
  }) => {
441
- var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
441
+ var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3;
442
442
  const startPos = getPos();
443
443
  if (startPos === undefined) {
444
444
  return tr;
@@ -447,6 +447,12 @@ export const DragHandle = ({
447
447
  tr.setMeta('toggleLayoutColumnMenu', buildToggleLayoutColumnMenuMeta(startPos, false));
448
448
  }
449
449
  const resolvedStartPos = tr.doc.resolve(startPos);
450
+ if (resolvedStartPos.nodeAfter) {
451
+ var _api$blockControls;
452
+ api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.actions.notifyBlockHandleClick({
453
+ node: resolvedStartPos.nodeAfter
454
+ });
455
+ }
450
456
  const selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
451
457
  api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
452
458
  eventType: EVENT_TYPE.UI,
@@ -466,10 +472,10 @@ export const DragHandle = ({
466
472
  nodeType,
467
473
  api
468
474
  });
469
- api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.commands.startPreservingSelection()({
475
+ api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.startPreservingSelection()({
470
476
  tr
471
477
  });
472
- api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.toggleBlockMenu({
478
+ api === null || api === void 0 ? void 0 : (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.commands.toggleBlockMenu({
473
479
  anchorName,
474
480
  openedViaKeyboard: false,
475
481
  triggerByNode: {
@@ -498,10 +504,17 @@ export const DragHandle = ({
498
504
  api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
499
505
  tr
500
506
  }) => {
501
- var _selectionPreservatio2, _api$blockControls3, _api$blockControls4, _api$userIntent;
507
+ var _selectionPreservatio2, _api$blockControls5, _api$blockControls6, _api$userIntent;
502
508
  if (startPos === undefined) {
503
509
  return tr;
504
510
  }
511
+ const node = tr.doc.resolve(startPos).nodeAfter;
512
+ if (node) {
513
+ var _api$blockControls4;
514
+ api === null || api === void 0 ? void 0 : (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 ? void 0 : _api$blockControls4.actions.notifyBlockHandleClick({
515
+ node
516
+ });
517
+ }
505
518
  const selection = ((_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) || tr.selection;
506
519
  expandAndUpdateSelection({
507
520
  tr,
@@ -511,7 +524,7 @@ export const DragHandle = ({
511
524
  nodeType,
512
525
  api
513
526
  });
514
- api === null || api === void 0 ? void 0 : (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 ? void 0 : _api$blockControls3.commands.startPreservingSelection()({
527
+ api === null || api === void 0 ? void 0 : (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 ? void 0 : _api$blockControls5.commands.startPreservingSelection()({
515
528
  tr
516
529
  });
517
530
  if (nodeType === 'layoutColumn') {
@@ -522,7 +535,7 @@ export const DragHandle = ({
522
535
  pos: startPos,
523
536
  rootPos: tr.doc.resolve(startPos).before(1)
524
537
  };
525
- api === null || api === void 0 ? void 0 : (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 ? void 0 : _api$blockControls4.commands.toggleBlockMenu({
538
+ api === null || api === void 0 ? void 0 : (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 ? void 0 : _api$blockControls6.commands.toggleBlockMenu({
526
539
  anchorName,
527
540
  triggerByNode,
528
541
  openedViaKeyboard: true
@@ -565,8 +578,8 @@ export const DragHandle = ({
565
578
  }
566
579
  const newHandlePosCheck = isHandleCorrelatedToSelection(view.state, tr.selection, handlePos);
567
580
  if (!tr.selection.empty && newHandlePosCheck) {
568
- var _api$blockControls5;
569
- api === null || api === void 0 ? void 0 : (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 ? void 0 : _api$blockControls5.commands.setMultiSelectPositions()({
581
+ var _api$blockControls7;
582
+ api === null || api === void 0 ? void 0 : (_api$blockControls7 = api.blockControls) === null || _api$blockControls7 === void 0 ? void 0 : _api$blockControls7.commands.setMultiSelectPositions()({
570
583
  tr
571
584
  });
572
585
  } else {
@@ -680,7 +693,7 @@ export const DragHandle = ({
680
693
  api === null || api === void 0 ? void 0 : (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions.execute(({
681
694
  tr
682
695
  }) => {
683
- var _api$blockControls$sh2, _api$blockControls6, _api$analytics2;
696
+ var _api$blockControls$sh2, _api$blockControls8, _api$analytics2;
684
697
  let nodeTypes, hasSelectedMultipleNodes;
685
698
  const resolvedMovingNode = tr.doc.resolve(start);
686
699
  const maybeNode = resolvedMovingNode.nodeAfter;
@@ -693,7 +706,7 @@ export const DragHandle = ({
693
706
  nodeTypes = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name;
694
707
  hasSelectedMultipleNodes = false;
695
708
  }
696
- api === null || api === void 0 ? void 0 : (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 ? void 0 : _api$blockControls6.commands.setNodeDragged(getPos, anchorName, nodeType)({
709
+ api === null || api === void 0 ? void 0 : (_api$blockControls8 = api.blockControls) === null || _api$blockControls8 === void 0 ? void 0 : _api$blockControls8.commands.setNodeDragged(getPos, anchorName, nodeType)({
697
710
  tr
698
711
  });
699
712
  tr.setMeta('scrollIntoView', false);
@@ -70,6 +70,14 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
70
70
  return {
71
71
  name: 'blockControls',
72
72
  actions: {
73
+ notifyBlockHandleClick: function notifyBlockHandleClick(context) {
74
+ try {
75
+ var _config$onBlockHandle;
76
+ config === null || config === void 0 || (_config$onBlockHandle = config.onBlockHandleClick) === null || _config$onBlockHandle === void 0 || _config$onBlockHandle.call(config, context);
77
+ } catch (_unused) {
78
+ // A host callback must not prevent the block menu from opening.
79
+ }
80
+ },
73
81
  getTextInfo: function getTextInfo(editorView) {
74
82
  var _api$blockControls, _blockControlsState$m;
75
83
  var blockControlsState = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState();
@@ -176,7 +176,7 @@ export var BlockControlsSurfaceDragHandle = function BlockControlsSurfaceDragHan
176
176
  }
177
177
  var openedViaKeyboard = event.detail === 0;
178
178
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref4) {
179
- var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3, _activeNode$rootPos;
179
+ var _selectionPreservatio, _selectionPreservatio2, _api$analytics, _resolvedStartPos$nod, _api$blockControls3, _api$blockControls4, _activeNode$rootPos;
180
180
  var tr = _ref4.tr;
181
181
  var startPos = getPos();
182
182
  if (startPos === undefined) {
@@ -187,6 +187,12 @@ export var BlockControlsSurfaceDragHandle = function BlockControlsSurfaceDragHan
187
187
  }
188
188
  var selection = (_selectionPreservatio = (_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) !== null && _selectionPreservatio !== void 0 ? _selectionPreservatio : tr.selection;
189
189
  var resolvedStartPos = tr.doc.resolve(startPos);
190
+ if (resolvedStartPos.nodeAfter) {
191
+ var _api$blockControls2;
192
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.actions.notifyBlockHandleClick({
193
+ node: resolvedStartPos.nodeAfter
194
+ });
195
+ }
190
196
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
191
197
  action: ACTION.CLICKED,
192
198
  actionSubject: ACTION_SUBJECT.BUTTON,
@@ -213,10 +219,10 @@ export var BlockControlsSurfaceDragHandle = function BlockControlsSurfaceDragHan
213
219
  tr: tr
214
220
  });
215
221
  }
216
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
222
+ api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.startPreservingSelection()({
217
223
  tr: tr
218
224
  });
219
- api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.toggleBlockMenu({
225
+ api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.commands.toggleBlockMenu({
220
226
  anchorName: getAnchorName(),
221
227
  openedViaKeyboard: openedViaKeyboard,
222
228
  triggerByNode: {
@@ -455,7 +455,7 @@ export var DragHandle = function DragHandle(_ref2) {
455
455
  var handleOnClickNew = useCallback(function (e) {
456
456
  var _api$core;
457
457
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
458
- var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls, _api$blockControls2;
458
+ var _selectionPreservatio, _api$analytics, _resolvedStartPos$nod, _api$blockControls2, _api$blockControls3;
459
459
  var tr = _ref3.tr;
460
460
  var startPos = getPos();
461
461
  if (startPos === undefined) {
@@ -465,6 +465,12 @@ export var DragHandle = function DragHandle(_ref2) {
465
465
  tr.setMeta('toggleLayoutColumnMenu', buildToggleLayoutColumnMenuMeta(startPos, false));
466
466
  }
467
467
  var resolvedStartPos = tr.doc.resolve(startPos);
468
+ if (resolvedStartPos.nodeAfter) {
469
+ var _api$blockControls;
470
+ api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.actions.notifyBlockHandleClick({
471
+ node: resolvedStartPos.nodeAfter
472
+ });
473
+ }
468
474
  var selection = ((_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection) || tr.selection;
469
475
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
470
476
  eventType: EVENT_TYPE.UI,
@@ -484,10 +490,10 @@ export var DragHandle = function DragHandle(_ref2) {
484
490
  nodeType: nodeType,
485
491
  api: api
486
492
  });
487
- api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.startPreservingSelection()({
493
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.startPreservingSelection()({
488
494
  tr: tr
489
495
  });
490
- api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.toggleBlockMenu({
496
+ api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.toggleBlockMenu({
491
497
  anchorName: anchorName,
492
498
  openedViaKeyboard: false,
493
499
  triggerByNode: {
@@ -514,11 +520,18 @@ export var DragHandle = function DragHandle(_ref2) {
514
520
  e.stopPropagation();
515
521
  var startPos = getPos();
516
522
  api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref4) {
517
- var _selectionPreservatio2, _api$blockControls3, _api$blockControls4, _api$userIntent;
523
+ var _selectionPreservatio2, _api$blockControls5, _api$blockControls6, _api$userIntent;
518
524
  var tr = _ref4.tr;
519
525
  if (startPos === undefined) {
520
526
  return tr;
521
527
  }
528
+ var node = tr.doc.resolve(startPos).nodeAfter;
529
+ if (node) {
530
+ var _api$blockControls4;
531
+ api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.actions.notifyBlockHandleClick({
532
+ node: node
533
+ });
534
+ }
522
535
  var selection = ((_selectionPreservatio2 = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio2 === void 0 ? void 0 : _selectionPreservatio2.preservedSelection) || tr.selection;
523
536
  expandAndUpdateSelection({
524
537
  tr: tr,
@@ -528,7 +541,7 @@ export var DragHandle = function DragHandle(_ref2) {
528
541
  nodeType: nodeType,
529
542
  api: api
530
543
  });
531
- api === null || api === void 0 || (_api$blockControls3 = api.blockControls) === null || _api$blockControls3 === void 0 || _api$blockControls3.commands.startPreservingSelection()({
544
+ api === null || api === void 0 || (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 || _api$blockControls5.commands.startPreservingSelection()({
532
545
  tr: tr
533
546
  });
534
547
  if (nodeType === 'layoutColumn') {
@@ -539,7 +552,7 @@ export var DragHandle = function DragHandle(_ref2) {
539
552
  pos: startPos,
540
553
  rootPos: tr.doc.resolve(startPos).before(1)
541
554
  };
542
- api === null || api === void 0 || (_api$blockControls4 = api.blockControls) === null || _api$blockControls4 === void 0 || _api$blockControls4.commands.toggleBlockMenu({
555
+ api === null || api === void 0 || (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 || _api$blockControls6.commands.toggleBlockMenu({
543
556
  anchorName: anchorName,
544
557
  triggerByNode: triggerByNode,
545
558
  openedViaKeyboard: true
@@ -584,8 +597,8 @@ export var DragHandle = function DragHandle(_ref2) {
584
597
  }
585
598
  var newHandlePosCheck = isHandleCorrelatedToSelection(view.state, tr.selection, handlePos);
586
599
  if (!tr.selection.empty && newHandlePosCheck) {
587
- var _api$blockControls5;
588
- api === null || api === void 0 || (_api$blockControls5 = api.blockControls) === null || _api$blockControls5 === void 0 || _api$blockControls5.commands.setMultiSelectPositions()({
600
+ var _api$blockControls7;
601
+ api === null || api === void 0 || (_api$blockControls7 = api.blockControls) === null || _api$blockControls7 === void 0 || _api$blockControls7.commands.setMultiSelectPositions()({
589
602
  tr: tr
590
603
  });
591
604
  } else {
@@ -692,7 +705,7 @@ export var DragHandle = function DragHandle(_ref2) {
692
705
  return;
693
706
  }
694
707
  api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref8) {
695
- var _api$blockControls$sh2, _api$blockControls6, _api$analytics2;
708
+ var _api$blockControls$sh2, _api$blockControls8, _api$analytics2;
696
709
  var tr = _ref8.tr;
697
710
  var nodeTypes, hasSelectedMultipleNodes;
698
711
  var resolvedMovingNode = tr.doc.resolve(start);
@@ -706,7 +719,7 @@ export var DragHandle = function DragHandle(_ref2) {
706
719
  nodeTypes = maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.type.name;
707
720
  hasSelectedMultipleNodes = false;
708
721
  }
709
- api === null || api === void 0 || (_api$blockControls6 = api.blockControls) === null || _api$blockControls6 === void 0 || _api$blockControls6.commands.setNodeDragged(getPos, anchorName, nodeType)({
722
+ api === null || api === void 0 || (_api$blockControls8 = api.blockControls) === null || _api$blockControls8 === void 0 || _api$blockControls8.commands.setNodeDragged(getPos, anchorName, nodeType)({
710
723
  tr: tr
711
724
  });
712
725
  tr.setMeta('scrollIntoView', false);
@@ -21,6 +21,7 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead/type-ah
21
21
  import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry/ui-control-registry-plugin-type';
22
22
  import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent/user-intent-plugin-type';
23
23
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width/width-plugin-type';
24
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
24
25
  import type { EditorState, Selection } from '@atlaskit/editor-prosemirror/state';
25
26
  import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
26
27
  import type { Decoration, DecorationSet, EditorView } from '@atlaskit/editor-prosemirror/view';
@@ -85,6 +86,10 @@ export interface PluginState {
85
86
  }
86
87
  export type ReleaseHiddenDecoration = () => boolean | undefined;
87
88
  export type BlockControlsPluginConfig = {
89
+ /** Called with the clicked block from either drag-handle implementation. */
90
+ onBlockHandleClick?: (context: {
91
+ node: Node;
92
+ }) => void;
88
93
  /**
89
94
  * Enable the quick insert plus button icon on the left of the drag handle.
90
95
  *
@@ -192,6 +197,10 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
192
197
  textContent: string;
193
198
  textLength: number;
194
199
  } | null;
200
+ /** Notifies the host about a drag-handle click. */
201
+ notifyBlockHandleClick: (context: {
202
+ node: Node;
203
+ }) => void;
195
204
  registerNodeDecoration: (factory: NodeDecorationFactory) => void;
196
205
  unregisterNodeDecoration: (type: string) => void;
197
206
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "30.0.1",
3
+ "version": "30.1.0",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -61,7 +61,7 @@
61
61
  "@atlaskit/primitives": "^22.6.0",
62
62
  "@atlaskit/section-message": "^10.2.0",
63
63
  "@atlaskit/theme": "^28.2.0",
64
- "@atlaskit/tmp-editor-statsig": "^243.0.0",
64
+ "@atlaskit/tmp-editor-statsig": "^244.0.0",
65
65
  "@atlaskit/tokens": "^20.6.0",
66
66
  "@atlaskit/tooltip": "^24.4.0",
67
67
  "@babel/runtime": "^7.0.0",