@atlaskit/editor-plugin-block-controls 3.15.9 → 3.15.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 3.15.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#165562](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/165562)
8
+ [`59af663a32c9a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/59af663a32c9a) -
9
+ Reduce block control re-renders under experiment
10
+ - Updated dependencies
11
+
3
12
  ## 3.15.9
4
13
 
5
14
  ### Patch Changes
@@ -30,7 +30,11 @@ var findHandleDec = exports.findHandleDec = function findHandleDec(decorations,
30
30
  });
31
31
  };
32
32
  var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, nodeViewPortalProviderAPI, handleOptions, anchorRectCache) {
33
- (0, _decorationsCommon.unmountDecorations)(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
33
+ if (!(0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true, {
34
+ exposure: true
35
+ })) {
36
+ (0, _decorationsCommon.unmountDecorations)(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
37
+ }
34
38
  var unbind;
35
39
  var key = (0, _uuid.default)();
36
40
  return _view.Decoration.widget(pos, function (view, getPosUnsafe) {
@@ -126,8 +130,11 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
126
130
  side: -1,
127
131
  type: _decorationsCommon.TYPE_HANDLE_DEC,
128
132
  testid: "".concat(_decorationsCommon.TYPE_HANDLE_DEC, "-").concat((0, _uuid.default)()),
129
- destroy: function destroy(_) {
133
+ destroy: function destroy(node) {
130
134
  unbind && unbind();
135
+ if ((0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) && node instanceof HTMLElement) {
136
+ _reactDom.default.unmountComponentAtNode(node);
137
+ }
131
138
  }
132
139
  });
133
140
  };
@@ -20,8 +20,8 @@ var _styles = require("@atlaskit/editor-common/styles");
20
20
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
21
21
  var _state = require("@atlaskit/editor-prosemirror/state");
22
22
  var _utils = require("@atlaskit/editor-prosemirror/utils");
23
+ var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/core/drag-handle-vertical"));
23
24
  var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-handler"));
24
- var _dragHandleVertical = _interopRequireDefault(require("@atlaskit/icon/utility/drag-handle-vertical"));
25
25
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
26
26
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
27
27
  var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview");
@@ -272,29 +272,42 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
272
272
  _ref$isTopLevelNode = _ref.isTopLevelNode,
273
273
  isTopLevelNode = _ref$isTopLevelNode === void 0 ? true : _ref$isTopLevelNode,
274
274
  anchorRectCache = _ref.anchorRectCache;
275
- var start = getPos();
276
275
  var buttonRef = (0, _react.useRef)(null);
277
- var _useState = (0, _react.useState)(768),
276
+ var _useState = (0, _react.useState)(false),
278
277
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
279
- blockCardWidth = _useState2[0],
280
- setBlockCardWidth = _useState2[1];
278
+ dragHandleSelected = _useState2[0],
279
+ setDragHandleSelected = _useState2[1];
281
280
  var _useState3 = (0, _react.useState)(false),
282
281
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
283
- dragHandleSelected = _useState4[0],
284
- setDragHandleSelected = _useState4[1];
285
- var _useState5 = (0, _react.useState)(false),
282
+ dragHandleDisabled = _useState4[0],
283
+ setDragHandleDisabled = _useState4[1];
284
+ var _useState5 = (0, _react.useState)(768),
286
285
  _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
287
- dragHandleDisabled = _useState6[0],
288
- setDragHandleDisabled = _useState6[1];
286
+ blockCardWidth = _useState6[0],
287
+ setBlockCardWidth = _useState6[1];
288
+ var _useState7 = (0, _react.useState)(false),
289
+ _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
290
+ recalculatePosition = _useState8[0],
291
+ setRecalculatePosition = _useState8[1];
292
+ var _useState9 = (0, _react.useState)({
293
+ display: 'none'
294
+ }),
295
+ _useState0 = (0, _slicedToArray2.default)(_useState9, 2),
296
+ positionStylesOld = _useState0[0],
297
+ setPositionStylesOld = _useState0[1];
289
298
  var _useDragHandlePluginS = useDragHandlePluginState(api),
290
299
  macroInteractionUpdates = _useDragHandlePluginS.macroInteractionUpdates;
291
300
  var selection = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'selection.selection');
292
301
  var isShiftDown = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'blockControls.isShiftDown');
293
302
  var _hasHadInteraction = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'interaction.hasHadInteraction') !== false;
294
303
  var interactionState = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'interaction.interactionState');
304
+ var start = getPos();
295
305
  var isLayoutColumn = nodeType === 'layoutColumn';
296
306
  var isMultiSelect = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true);
297
307
  (0, _react.useEffect)(function () {
308
+ if ((0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
309
+ return;
310
+ }
298
311
  // blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
299
312
  if (nodeType === 'blockCard') {
300
313
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
@@ -581,7 +594,61 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
581
594
  }
582
595
  });
583
596
  }, [anchorName, api, getPos, isMultiSelect, nodeType, start, view]);
584
- var calculatePosition = (0, _react.useCallback)(function () {
597
+ var positionStyles = (0, _react.useMemo)(function () {
598
+ if (!(0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
599
+ return {};
600
+ }
601
+
602
+ // This is a no-op to allow recalculatePosition to be used as a dependency
603
+ if (recalculatePosition) {
604
+ setRecalculatePosition(recalculatePosition);
605
+ }
606
+ var pos = getPos();
607
+ var $pos = pos && view.state.doc.resolve(pos);
608
+ var parentPos = $pos && $pos.depth ? $pos.before() : undefined;
609
+ var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
610
+ var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
611
+ var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
612
+ var safeAnchorName = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_2') ? (0, _anchorName.refreshAnchorName)({
613
+ getPos: getPos,
614
+ view: view,
615
+ anchorName: anchorName
616
+ }) : anchorName;
617
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(safeAnchorName, "\"]"));
618
+ var hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
619
+ var isExtension = nodeType === 'extension' || nodeType === 'bodiedExtension' || nodeType === 'multiBodiedExtension' && (0, _platformFeatureFlags.fg)('platform_editor_multi_body_extension_extensibility');
620
+ var isBlockCard = nodeType === 'blockCard';
621
+ var isEmbedCard = nodeType === 'embedCard';
622
+ var isMacroInteractionUpdates = macroInteractionUpdates && isExtension;
623
+ var innerContainer = null;
624
+ if (dom) {
625
+ if (isEmbedCard) {
626
+ innerContainer = dom.querySelector('.rich-media-item');
627
+ } else if (hasResizer) {
628
+ innerContainer = dom.querySelector('.resizer-item');
629
+ } else if (isExtension) {
630
+ innerContainer = dom.querySelector('.extension-container[data-layout]');
631
+ } else if (isBlockCard) {
632
+ //specific to datasource blockCard
633
+ innerContainer = dom.querySelector('.datasourceView-content-inner-wrap');
634
+ }
635
+ }
636
+ var isEdgeCase = (hasResizer || isExtension || isEmbedCard || isBlockCard) && innerContainer;
637
+ var isSticky = (0, _dragHandlePositions.shouldBeSticky)(nodeType);
638
+ if (supportsAnchor) {
639
+ var bottom = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _dragHandlePositions.getControlBottomCSSValue)(safeAnchorName, isSticky, isTopLevelNode, isLayoutColumn) : {};
640
+ return _objectSpread({
641
+ left: isEdgeCase ? "calc(anchor(".concat(safeAnchorName, " start) + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType), ")") : (0, _experiments.editorExperiment)('advanced_layouts', true) && isLayoutColumn ? "calc((anchor(".concat(safeAnchorName, " right) + anchor(").concat(safeAnchorName, " left))/2 - ").concat(_consts.DRAG_HANDLE_HEIGHT / 2, "px)") : "calc(anchor(".concat(safeAnchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType, parentNodeType), "px)"),
642
+ top: (0, _experiments.editorExperiment)('advanced_layouts', true) && isLayoutColumn ? "calc(anchor(".concat(safeAnchorName, " top) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px)") : "calc(anchor(".concat(safeAnchorName, " start) + ").concat((0, _consts.topPositionAdjustment)(nodeType), "px)")
643
+ }, bottom);
644
+ }
645
+ var height = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _dragHandlePositions.getControlHeightCSSValue)((0, _dragHandlePositions.getNodeHeight)(dom, safeAnchorName, anchorRectCache) || 0, isSticky, isTopLevelNode, "".concat(_consts.DRAG_HANDLE_HEIGHT), isLayoutColumn) : {};
646
+ return _objectSpread({
647
+ left: isEdgeCase ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType), ")") : (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType),
648
+ top: (0, _dragHandlePositions.getTopPosition)(dom, nodeType)
649
+ }, height);
650
+ }, [anchorName, getPos, view, nodeType, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn, recalculatePosition]);
651
+ var calculatePositionOld = (0, _react.useCallback)(function () {
585
652
  var pos = getPos();
586
653
  var $pos = pos && view.state.doc.resolve(pos);
587
654
  var parentPos = $pos && $pos.depth ? $pos.before() : undefined;
@@ -627,13 +694,10 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
627
694
  top: (0, _dragHandlePositions.getTopPosition)(dom, nodeType)
628
695
  }, height);
629
696
  }, [anchorName, getPos, view, nodeType, blockCardWidth, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn]);
630
- var _useState7 = (0, _react.useState)({
631
- display: 'none'
632
- }),
633
- _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
634
- positionStyles = _useState8[0],
635
- setPositionStyles = _useState8[1];
636
697
  (0, _react.useEffect)(function () {
698
+ if ((0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
699
+ return;
700
+ }
637
701
  var cleanUpTransitionListener;
638
702
  if (nodeType === 'extension' || nodeType === 'embedCard') {
639
703
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
@@ -643,19 +707,41 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
643
707
  cleanUpTransitionListener = (0, _bindEventListener.bind)(dom, {
644
708
  type: 'transitionend',
645
709
  listener: function listener() {
646
- setPositionStyles(calculatePosition());
710
+ setPositionStylesOld(calculatePositionOld());
647
711
  }
648
712
  });
649
713
  }
650
714
  var calcPos = requestAnimationFrame(function () {
651
- setPositionStyles(calculatePosition());
715
+ setPositionStylesOld(calculatePositionOld());
652
716
  });
653
717
  return function () {
654
718
  var _cleanUpTransitionLis;
655
719
  cancelAnimationFrame(calcPos);
656
720
  (_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 || _cleanUpTransitionLis();
657
721
  };
658
- }, [calculatePosition, view.dom, anchorName, nodeType]);
722
+ }, [calculatePositionOld, view.dom, anchorName, nodeType]);
723
+ (0, _react.useEffect)(function () {
724
+ if (!(0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
725
+ return;
726
+ }
727
+ var cleanUpTransitionListener;
728
+ if (nodeType === 'extension' || nodeType === 'embedCard') {
729
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
730
+ if (!dom) {
731
+ return;
732
+ }
733
+ cleanUpTransitionListener = (0, _bindEventListener.bind)(dom, {
734
+ type: 'transitionend',
735
+ listener: function listener() {
736
+ setRecalculatePosition(!recalculatePosition);
737
+ }
738
+ });
739
+ }
740
+ return function () {
741
+ var _cleanUpTransitionLis2;
742
+ (_cleanUpTransitionLis2 = cleanUpTransitionListener) === null || _cleanUpTransitionLis2 === void 0 || _cleanUpTransitionLis2();
743
+ };
744
+ }, [view, anchorName, nodeType, recalculatePosition]);
659
745
  (0, _react.useEffect)(function () {
660
746
  if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
661
747
  var id = requestAnimationFrame(function () {
@@ -664,7 +750,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
664
750
  });
665
751
  return function () {
666
752
  cancelAnimationFrame(id);
667
- view.focus();
753
+ if (!(0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
754
+ view.focus();
755
+ }
668
756
  };
669
757
  }
670
758
  }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
@@ -673,7 +761,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
673
761
  return;
674
762
  }
675
763
  setDragHandleSelected((0, _getSelection.isHandleCorrelatedToSelection)(view.state, selection, start));
676
- }, [start, selection, view.state, isMultiSelect]);
764
+ }, [start, selection, view, isMultiSelect]);
677
765
  (0, _react.useEffect)(function () {
678
766
  var _api$blockControls$sh4;
679
767
  if (!isMultiSelect || isShiftDown === undefined || view.state.selection.empty || !(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_shift_click_select')) {
@@ -686,7 +774,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
686
774
  } else {
687
775
  setDragHandleDisabled(false);
688
776
  }
689
- }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view.state.doc, view.state.selection]);
777
+ }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view]);
690
778
  var helpDescriptors = isTopLevelNode ? [{
691
779
  description: formatMessage(_messages.blockControlsMessages.dragToMove)
692
780
  }, {
@@ -771,7 +859,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
771
859
  ref: buttonRef
772
860
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
773
861
  ,
774
- style: !(0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && positionStyles || {},
862
+ style: !(0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld : {},
775
863
  onClick: handleOnClick,
776
864
  onMouseDown: handleMouseDown,
777
865
  onKeyDown: handleKeyDown
@@ -790,7 +878,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
790
878
  spacing: "spacious",
791
879
  label: "",
792
880
  LEGACY_fallbackIcon: _dragHandler.default,
793
- LEGACY_size: "medium"
881
+ LEGACY_size: "medium",
882
+ size: "small"
794
883
  })))
795
884
  );
796
885
  };
@@ -798,7 +887,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
798
887
  return (0, _react2.jsx)(_primitives.Box
799
888
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
800
889
  , {
801
- style: positionStyles,
890
+ style: (0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
802
891
  xcss: [dragHandleContainerStyles],
803
892
  as: "span",
804
893
  testId: "block-ctrl-drag-handle-container"
@@ -824,7 +913,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
824
913
  return (0, _react2.jsx)(_primitives.Box
825
914
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
826
915
  , {
827
- style: positionStyles,
916
+ style: (0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
828
917
  xcss: [dragHandleContainerStyles],
829
918
  as: "span",
830
919
  testId: "block-ctrl-drag-handle-container"
@@ -860,6 +949,7 @@ var DragHandleWithVisibility = exports.DragHandleWithVisibility = function DragH
860
949
  getPos = _ref8.getPos,
861
950
  anchorName = _ref8.anchorName,
862
951
  nodeType = _ref8.nodeType,
952
+ handleOptions = _ref8.handleOptions,
863
953
  anchorRectCache = _ref8.anchorRectCache;
864
954
  return (0, _react2.jsx)(_visibilityContainer.VisibilityContainer, {
865
955
  api: api
@@ -870,6 +960,7 @@ var DragHandleWithVisibility = exports.DragHandleWithVisibility = function DragH
870
960
  getPos: getPos,
871
961
  anchorName: anchorName,
872
962
  nodeType: nodeType,
963
+ handleOptions: handleOptions,
873
964
  anchorRectCache: anchorRectCache
874
965
  }));
875
966
  };
@@ -21,7 +21,11 @@ export const findHandleDec = (decorations, from, to) => {
21
21
  return decorations.find(from, to, spec => spec.type === TYPE_HANDLE_DEC);
22
22
  };
23
23
  export const dragHandleDecoration = (api, formatMessage, pos, anchorName, nodeType, nodeViewPortalProviderAPI, handleOptions, anchorRectCache) => {
24
- unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
24
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true, {
25
+ exposure: true
26
+ })) {
27
+ unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
28
+ }
25
29
  let unbind;
26
30
  const key = uuid();
27
31
  return Decoration.widget(pos, (view, getPosUnsafe) => {
@@ -117,8 +121,11 @@ export const dragHandleDecoration = (api, formatMessage, pos, anchorName, nodeTy
117
121
  side: -1,
118
122
  type: TYPE_HANDLE_DEC,
119
123
  testid: `${TYPE_HANDLE_DEC}-${uuid()}`,
120
- destroy: _ => {
124
+ destroy: node => {
121
125
  unbind && unbind();
126
+ if (editorExperiment('platform_editor_block_control_optimise_render', true) && node instanceof HTMLElement) {
127
+ ReactDOM.unmountComponentAtNode(node);
128
+ }
122
129
  }
123
130
  });
124
131
  };
@@ -3,7 +3,7 @@
3
3
  * @jsx jsx
4
4
  */
5
5
 
6
- import { useCallback, useEffect, useRef, useState } from 'react';
6
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
7
7
 
8
8
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
9
9
  import { css, jsx } from '@emotion/react';
@@ -17,8 +17,8 @@ import { tableControlsSpacing } from '@atlaskit/editor-common/styles';
17
17
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
18
18
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
19
19
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
20
+ import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
20
21
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
21
- import DragHandleVerticalIcon from '@atlaskit/icon/utility/drag-handle-vertical';
22
22
  import { fg } from '@atlaskit/platform-feature-flags';
23
23
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
24
24
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
@@ -265,11 +265,14 @@ export const DragHandle = ({
265
265
  anchorRectCache
266
266
  }) => {
267
267
  var _api$core2, _api$blockControls3, _api$analytics2, _api$core4;
268
- const start = getPos();
269
268
  const buttonRef = useRef(null);
270
- const [blockCardWidth, setBlockCardWidth] = useState(768);
271
269
  const [dragHandleSelected, setDragHandleSelected] = useState(false);
272
270
  const [dragHandleDisabled, setDragHandleDisabled] = useState(false);
271
+ const [blockCardWidth, setBlockCardWidth] = useState(768);
272
+ const [recalculatePosition, setRecalculatePosition] = useState(false);
273
+ const [positionStylesOld, setPositionStylesOld] = useState({
274
+ display: 'none'
275
+ });
273
276
  const {
274
277
  macroInteractionUpdates
275
278
  } = useDragHandlePluginState(api);
@@ -277,9 +280,13 @@ export const DragHandle = ({
277
280
  const isShiftDown = useSharedPluginStateSelector(api, 'blockControls.isShiftDown');
278
281
  const _hasHadInteraction = useSharedPluginStateSelector(api, 'interaction.hasHadInteraction') !== false;
279
282
  const interactionState = useSharedPluginStateSelector(api, 'interaction.interactionState');
283
+ const start = getPos();
280
284
  const isLayoutColumn = nodeType === 'layoutColumn';
281
285
  const isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
282
286
  useEffect(() => {
287
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
288
+ return;
289
+ }
283
290
  // blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
284
291
  if (nodeType === 'blockCard') {
285
292
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
@@ -571,7 +578,63 @@ export const DragHandle = ({
571
578
  }
572
579
  });
573
580
  }, [anchorName, api, getPos, isMultiSelect, nodeType, start, view]);
574
- const calculatePosition = useCallback(() => {
581
+ const positionStyles = useMemo(() => {
582
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
583
+ return {};
584
+ }
585
+
586
+ // This is a no-op to allow recalculatePosition to be used as a dependency
587
+ if (recalculatePosition) {
588
+ setRecalculatePosition(recalculatePosition);
589
+ }
590
+ const pos = getPos();
591
+ const $pos = pos && view.state.doc.resolve(pos);
592
+ const parentPos = $pos && $pos.depth ? $pos.before() : undefined;
593
+ const node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
594
+ const parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
595
+ const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
596
+ const safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
597
+ getPos,
598
+ view,
599
+ anchorName
600
+ }) : anchorName;
601
+ const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${safeAnchorName}"]`);
602
+ const hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
603
+ const isExtension = nodeType === 'extension' || nodeType === 'bodiedExtension' || nodeType === 'multiBodiedExtension' && fg('platform_editor_multi_body_extension_extensibility');
604
+ const isBlockCard = nodeType === 'blockCard';
605
+ const isEmbedCard = nodeType === 'embedCard';
606
+ const isMacroInteractionUpdates = macroInteractionUpdates && isExtension;
607
+ let innerContainer = null;
608
+ if (dom) {
609
+ if (isEmbedCard) {
610
+ innerContainer = dom.querySelector('.rich-media-item');
611
+ } else if (hasResizer) {
612
+ innerContainer = dom.querySelector('.resizer-item');
613
+ } else if (isExtension) {
614
+ innerContainer = dom.querySelector('.extension-container[data-layout]');
615
+ } else if (isBlockCard) {
616
+ //specific to datasource blockCard
617
+ innerContainer = dom.querySelector('.datasourceView-content-inner-wrap');
618
+ }
619
+ }
620
+ const isEdgeCase = (hasResizer || isExtension || isEmbedCard || isBlockCard) && innerContainer;
621
+ const isSticky = shouldBeSticky(nodeType);
622
+ if (supportsAnchor) {
623
+ const bottom = editorExperiment('platform_editor_controls', 'variant1') ? getControlBottomCSSValue(safeAnchorName, isSticky, isTopLevelNode, isLayoutColumn) : {};
624
+ return {
625
+ left: isEdgeCase ? `calc(anchor(${safeAnchorName} start) + ${getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType)})` : editorExperiment('advanced_layouts', true) && isLayoutColumn ? `calc((anchor(${safeAnchorName} right) + anchor(${safeAnchorName} left))/2 - ${DRAG_HANDLE_HEIGHT / 2}px)` : `calc(anchor(${safeAnchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType, parentNodeType)}px)`,
626
+ top: editorExperiment('advanced_layouts', true) && isLayoutColumn ? `calc(anchor(${safeAnchorName} top) - ${DRAG_HANDLE_WIDTH}px)` : `calc(anchor(${safeAnchorName} start) + ${topPositionAdjustment(nodeType)}px)`,
627
+ ...bottom
628
+ };
629
+ }
630
+ const height = editorExperiment('platform_editor_controls', 'variant1') ? getControlHeightCSSValue(getNodeHeight(dom, safeAnchorName, anchorRectCache) || 0, isSticky, isTopLevelNode, `${DRAG_HANDLE_HEIGHT}`, isLayoutColumn) : {};
631
+ return {
632
+ left: isEdgeCase ? `calc(${(dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0}px + ${getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType)})` : getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType),
633
+ top: getTopPosition(dom, nodeType),
634
+ ...height
635
+ };
636
+ }, [anchorName, getPos, view, nodeType, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn, recalculatePosition]);
637
+ const calculatePositionOld = useCallback(() => {
575
638
  const pos = getPos();
576
639
  const $pos = pos && view.state.doc.resolve(pos);
577
640
  const parentPos = $pos && $pos.depth ? $pos.before() : undefined;
@@ -619,10 +682,10 @@ export const DragHandle = ({
619
682
  ...height
620
683
  };
621
684
  }, [anchorName, getPos, view, nodeType, blockCardWidth, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn]);
622
- const [positionStyles, setPositionStyles] = useState({
623
- display: 'none'
624
- });
625
685
  useEffect(() => {
686
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
687
+ return;
688
+ }
626
689
  let cleanUpTransitionListener;
627
690
  if (nodeType === 'extension' || nodeType === 'embedCard') {
628
691
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
@@ -632,19 +695,41 @@ export const DragHandle = ({
632
695
  cleanUpTransitionListener = bind(dom, {
633
696
  type: 'transitionend',
634
697
  listener: () => {
635
- setPositionStyles(calculatePosition());
698
+ setPositionStylesOld(calculatePositionOld());
636
699
  }
637
700
  });
638
701
  }
639
702
  const calcPos = requestAnimationFrame(() => {
640
- setPositionStyles(calculatePosition());
703
+ setPositionStylesOld(calculatePositionOld());
641
704
  });
642
705
  return () => {
643
706
  var _cleanUpTransitionLis;
644
707
  cancelAnimationFrame(calcPos);
645
708
  (_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 ? void 0 : _cleanUpTransitionLis();
646
709
  };
647
- }, [calculatePosition, view.dom, anchorName, nodeType]);
710
+ }, [calculatePositionOld, view.dom, anchorName, nodeType]);
711
+ useEffect(() => {
712
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
713
+ return;
714
+ }
715
+ let cleanUpTransitionListener;
716
+ if (nodeType === 'extension' || nodeType === 'embedCard') {
717
+ const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
718
+ if (!dom) {
719
+ return;
720
+ }
721
+ cleanUpTransitionListener = bind(dom, {
722
+ type: 'transitionend',
723
+ listener: () => {
724
+ setRecalculatePosition(!recalculatePosition);
725
+ }
726
+ });
727
+ }
728
+ return () => {
729
+ var _cleanUpTransitionLis2;
730
+ (_cleanUpTransitionLis2 = cleanUpTransitionListener) === null || _cleanUpTransitionLis2 === void 0 ? void 0 : _cleanUpTransitionLis2();
731
+ };
732
+ }, [view, anchorName, nodeType, recalculatePosition]);
648
733
  useEffect(() => {
649
734
  if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && fg('platform_editor_element_drag_and_drop_ed_23873')) {
650
735
  const id = requestAnimationFrame(() => {
@@ -653,7 +738,9 @@ export const DragHandle = ({
653
738
  });
654
739
  return () => {
655
740
  cancelAnimationFrame(id);
656
- view.focus();
741
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
742
+ view.focus();
743
+ }
657
744
  };
658
745
  }
659
746
  }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
@@ -662,7 +749,7 @@ export const DragHandle = ({
662
749
  return;
663
750
  }
664
751
  setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
665
- }, [start, selection, view.state, isMultiSelect]);
752
+ }, [start, selection, view, isMultiSelect]);
666
753
  useEffect(() => {
667
754
  var _api$blockControls$sh4;
668
755
  if (!isMultiSelect || isShiftDown === undefined || view.state.selection.empty || !fg('platform_editor_elements_dnd_shift_click_select')) {
@@ -675,7 +762,7 @@ export const DragHandle = ({
675
762
  } else {
676
763
  setDragHandleDisabled(false);
677
764
  }
678
- }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view.state.doc, view.state.selection]);
765
+ }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view]);
679
766
  let helpDescriptors = isTopLevelNode ? [{
680
767
  description: formatMessage(blockControlsMessages.dragToMove)
681
768
  }, {
@@ -759,7 +846,7 @@ export const DragHandle = ({
759
846
  ref: buttonRef
760
847
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
761
848
  ,
762
- style: !editorExperiment('platform_editor_controls', 'variant1') && positionStyles || {},
849
+ style: !editorExperiment('platform_editor_controls', 'variant1') ? editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld : {},
763
850
  onClick: handleOnClick,
764
851
  onMouseDown: handleMouseDown,
765
852
  onKeyDown: handleKeyDown
@@ -778,12 +865,13 @@ export const DragHandle = ({
778
865
  spacing: "spacious",
779
866
  label: "",
780
867
  LEGACY_fallbackIcon: DragHandlerIcon,
781
- LEGACY_size: "medium"
868
+ LEGACY_size: "medium",
869
+ size: "small"
782
870
  })));
783
871
  const stickyWithTooltip = () => jsx(Box
784
872
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
785
873
  , {
786
- style: positionStyles,
874
+ style: editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
787
875
  xcss: [dragHandleContainerStyles],
788
876
  as: "span",
789
877
  testId: "block-ctrl-drag-handle-container"
@@ -807,7 +895,7 @@ export const DragHandle = ({
807
895
  const stickyWithoutTooltip = () => jsx(Box
808
896
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
809
897
  , {
810
- style: positionStyles,
898
+ style: editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
811
899
  xcss: [dragHandleContainerStyles],
812
900
  as: "span",
813
901
  testId: "block-ctrl-drag-handle-container"
@@ -840,6 +928,7 @@ export const DragHandleWithVisibility = ({
840
928
  getPos,
841
929
  anchorName,
842
930
  nodeType,
931
+ handleOptions,
843
932
  anchorRectCache
844
933
  }) => {
845
934
  return jsx(VisibilityContainer, {
@@ -851,6 +940,7 @@ export const DragHandleWithVisibility = ({
851
940
  getPos: getPos,
852
941
  anchorName: anchorName,
853
942
  nodeType: nodeType,
943
+ handleOptions: handleOptions,
854
944
  anchorRectCache: anchorRectCache
855
945
  }));
856
946
  };
@@ -23,7 +23,11 @@ export var findHandleDec = function findHandleDec(decorations, from, to) {
23
23
  });
24
24
  };
25
25
  export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, nodeViewPortalProviderAPI, handleOptions, anchorRectCache) {
26
- unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
26
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true, {
27
+ exposure: true
28
+ })) {
29
+ unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
30
+ }
27
31
  var unbind;
28
32
  var key = uuid();
29
33
  return Decoration.widget(pos, function (view, getPosUnsafe) {
@@ -119,8 +123,11 @@ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessa
119
123
  side: -1,
120
124
  type: TYPE_HANDLE_DEC,
121
125
  testid: "".concat(TYPE_HANDLE_DEC, "-").concat(uuid()),
122
- destroy: function destroy(_) {
126
+ destroy: function destroy(node) {
123
127
  unbind && unbind();
128
+ if (editorExperiment('platform_editor_block_control_optimise_render', true) && node instanceof HTMLElement) {
129
+ ReactDOM.unmountComponentAtNode(node);
130
+ }
124
131
  }
125
132
  });
126
133
  };
@@ -8,7 +8,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
8
8
  * @jsx jsx
9
9
  */
10
10
 
11
- import { useCallback, useEffect, useRef, useState } from 'react';
11
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
12
 
13
13
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
14
14
  import { css, jsx } from '@emotion/react';
@@ -22,8 +22,8 @@ import { tableControlsSpacing } from '@atlaskit/editor-common/styles';
22
22
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
23
23
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
24
24
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
25
+ import DragHandleVerticalIcon from '@atlaskit/icon/core/drag-handle-vertical';
25
26
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
26
- import DragHandleVerticalIcon from '@atlaskit/icon/utility/drag-handle-vertical';
27
27
  import { fg } from '@atlaskit/platform-feature-flags';
28
28
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
29
29
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
@@ -269,29 +269,42 @@ export var DragHandle = function DragHandle(_ref) {
269
269
  _ref$isTopLevelNode = _ref.isTopLevelNode,
270
270
  isTopLevelNode = _ref$isTopLevelNode === void 0 ? true : _ref$isTopLevelNode,
271
271
  anchorRectCache = _ref.anchorRectCache;
272
- var start = getPos();
273
272
  var buttonRef = useRef(null);
274
- var _useState = useState(768),
273
+ var _useState = useState(false),
275
274
  _useState2 = _slicedToArray(_useState, 2),
276
- blockCardWidth = _useState2[0],
277
- setBlockCardWidth = _useState2[1];
275
+ dragHandleSelected = _useState2[0],
276
+ setDragHandleSelected = _useState2[1];
278
277
  var _useState3 = useState(false),
279
278
  _useState4 = _slicedToArray(_useState3, 2),
280
- dragHandleSelected = _useState4[0],
281
- setDragHandleSelected = _useState4[1];
282
- var _useState5 = useState(false),
279
+ dragHandleDisabled = _useState4[0],
280
+ setDragHandleDisabled = _useState4[1];
281
+ var _useState5 = useState(768),
283
282
  _useState6 = _slicedToArray(_useState5, 2),
284
- dragHandleDisabled = _useState6[0],
285
- setDragHandleDisabled = _useState6[1];
283
+ blockCardWidth = _useState6[0],
284
+ setBlockCardWidth = _useState6[1];
285
+ var _useState7 = useState(false),
286
+ _useState8 = _slicedToArray(_useState7, 2),
287
+ recalculatePosition = _useState8[0],
288
+ setRecalculatePosition = _useState8[1];
289
+ var _useState9 = useState({
290
+ display: 'none'
291
+ }),
292
+ _useState0 = _slicedToArray(_useState9, 2),
293
+ positionStylesOld = _useState0[0],
294
+ setPositionStylesOld = _useState0[1];
286
295
  var _useDragHandlePluginS = useDragHandlePluginState(api),
287
296
  macroInteractionUpdates = _useDragHandlePluginS.macroInteractionUpdates;
288
297
  var selection = useSharedPluginStateSelector(api, 'selection.selection');
289
298
  var isShiftDown = useSharedPluginStateSelector(api, 'blockControls.isShiftDown');
290
299
  var _hasHadInteraction = useSharedPluginStateSelector(api, 'interaction.hasHadInteraction') !== false;
291
300
  var interactionState = useSharedPluginStateSelector(api, 'interaction.interactionState');
301
+ var start = getPos();
292
302
  var isLayoutColumn = nodeType === 'layoutColumn';
293
303
  var isMultiSelect = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
294
304
  useEffect(function () {
305
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
306
+ return;
307
+ }
295
308
  // blockCard/datasource width is rendered correctly after this decoraton does. We need to observe for changes.
296
309
  if (nodeType === 'blockCard') {
297
310
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
@@ -578,7 +591,61 @@ export var DragHandle = function DragHandle(_ref) {
578
591
  }
579
592
  });
580
593
  }, [anchorName, api, getPos, isMultiSelect, nodeType, start, view]);
581
- var calculatePosition = useCallback(function () {
594
+ var positionStyles = useMemo(function () {
595
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
596
+ return {};
597
+ }
598
+
599
+ // This is a no-op to allow recalculatePosition to be used as a dependency
600
+ if (recalculatePosition) {
601
+ setRecalculatePosition(recalculatePosition);
602
+ }
603
+ var pos = getPos();
604
+ var $pos = pos && view.state.doc.resolve(pos);
605
+ var parentPos = $pos && $pos.depth ? $pos.before() : undefined;
606
+ var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
607
+ var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
608
+ var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
609
+ var safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
610
+ getPos: getPos,
611
+ view: view,
612
+ anchorName: anchorName
613
+ }) : anchorName;
614
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(safeAnchorName, "\"]"));
615
+ var hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
616
+ var isExtension = nodeType === 'extension' || nodeType === 'bodiedExtension' || nodeType === 'multiBodiedExtension' && fg('platform_editor_multi_body_extension_extensibility');
617
+ var isBlockCard = nodeType === 'blockCard';
618
+ var isEmbedCard = nodeType === 'embedCard';
619
+ var isMacroInteractionUpdates = macroInteractionUpdates && isExtension;
620
+ var innerContainer = null;
621
+ if (dom) {
622
+ if (isEmbedCard) {
623
+ innerContainer = dom.querySelector('.rich-media-item');
624
+ } else if (hasResizer) {
625
+ innerContainer = dom.querySelector('.resizer-item');
626
+ } else if (isExtension) {
627
+ innerContainer = dom.querySelector('.extension-container[data-layout]');
628
+ } else if (isBlockCard) {
629
+ //specific to datasource blockCard
630
+ innerContainer = dom.querySelector('.datasourceView-content-inner-wrap');
631
+ }
632
+ }
633
+ var isEdgeCase = (hasResizer || isExtension || isEmbedCard || isBlockCard) && innerContainer;
634
+ var isSticky = shouldBeSticky(nodeType);
635
+ if (supportsAnchor) {
636
+ var bottom = editorExperiment('platform_editor_controls', 'variant1') ? getControlBottomCSSValue(safeAnchorName, isSticky, isTopLevelNode, isLayoutColumn) : {};
637
+ return _objectSpread({
638
+ left: isEdgeCase ? "calc(anchor(".concat(safeAnchorName, " start) + ").concat(getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType), ")") : editorExperiment('advanced_layouts', true) && isLayoutColumn ? "calc((anchor(".concat(safeAnchorName, " right) + anchor(").concat(safeAnchorName, " left))/2 - ").concat(DRAG_HANDLE_HEIGHT / 2, "px)") : "calc(anchor(".concat(safeAnchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType, parentNodeType), "px)"),
639
+ top: editorExperiment('advanced_layouts', true) && isLayoutColumn ? "calc(anchor(".concat(safeAnchorName, " top) - ").concat(DRAG_HANDLE_WIDTH, "px)") : "calc(anchor(".concat(safeAnchorName, " start) + ").concat(topPositionAdjustment(nodeType), "px)")
640
+ }, bottom);
641
+ }
642
+ var height = editorExperiment('platform_editor_controls', 'variant1') ? getControlHeightCSSValue(getNodeHeight(dom, safeAnchorName, anchorRectCache) || 0, isSticky, isTopLevelNode, "".concat(DRAG_HANDLE_HEIGHT), isLayoutColumn) : {};
643
+ return _objectSpread({
644
+ left: isEdgeCase ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat(getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType), ")") : getLeftPosition(dom, nodeType, innerContainer, isMacroInteractionUpdates, parentNodeType),
645
+ top: getTopPosition(dom, nodeType)
646
+ }, height);
647
+ }, [anchorName, getPos, view, nodeType, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn, recalculatePosition]);
648
+ var calculatePositionOld = useCallback(function () {
582
649
  var pos = getPos();
583
650
  var $pos = pos && view.state.doc.resolve(pos);
584
651
  var parentPos = $pos && $pos.depth ? $pos.before() : undefined;
@@ -624,13 +691,10 @@ export var DragHandle = function DragHandle(_ref) {
624
691
  top: getTopPosition(dom, nodeType)
625
692
  }, height);
626
693
  }, [anchorName, getPos, view, nodeType, blockCardWidth, macroInteractionUpdates, anchorRectCache, isTopLevelNode, isLayoutColumn]);
627
- var _useState7 = useState({
628
- display: 'none'
629
- }),
630
- _useState8 = _slicedToArray(_useState7, 2),
631
- positionStyles = _useState8[0],
632
- setPositionStyles = _useState8[1];
633
694
  useEffect(function () {
695
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
696
+ return;
697
+ }
634
698
  var cleanUpTransitionListener;
635
699
  if (nodeType === 'extension' || nodeType === 'embedCard') {
636
700
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
@@ -640,19 +704,41 @@ export var DragHandle = function DragHandle(_ref) {
640
704
  cleanUpTransitionListener = bind(dom, {
641
705
  type: 'transitionend',
642
706
  listener: function listener() {
643
- setPositionStyles(calculatePosition());
707
+ setPositionStylesOld(calculatePositionOld());
644
708
  }
645
709
  });
646
710
  }
647
711
  var calcPos = requestAnimationFrame(function () {
648
- setPositionStyles(calculatePosition());
712
+ setPositionStylesOld(calculatePositionOld());
649
713
  });
650
714
  return function () {
651
715
  var _cleanUpTransitionLis;
652
716
  cancelAnimationFrame(calcPos);
653
717
  (_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 || _cleanUpTransitionLis();
654
718
  };
655
- }, [calculatePosition, view.dom, anchorName, nodeType]);
719
+ }, [calculatePositionOld, view.dom, anchorName, nodeType]);
720
+ useEffect(function () {
721
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
722
+ return;
723
+ }
724
+ var cleanUpTransitionListener;
725
+ if (nodeType === 'extension' || nodeType === 'embedCard') {
726
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
727
+ if (!dom) {
728
+ return;
729
+ }
730
+ cleanUpTransitionListener = bind(dom, {
731
+ type: 'transitionend',
732
+ listener: function listener() {
733
+ setRecalculatePosition(!recalculatePosition);
734
+ }
735
+ });
736
+ }
737
+ return function () {
738
+ var _cleanUpTransitionLis2;
739
+ (_cleanUpTransitionLis2 = cleanUpTransitionListener) === null || _cleanUpTransitionLis2 === void 0 || _cleanUpTransitionLis2();
740
+ };
741
+ }, [view, anchorName, nodeType, recalculatePosition]);
656
742
  useEffect(function () {
657
743
  if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && fg('platform_editor_element_drag_and_drop_ed_23873')) {
658
744
  var id = requestAnimationFrame(function () {
@@ -661,7 +747,9 @@ export var DragHandle = function DragHandle(_ref) {
661
747
  });
662
748
  return function () {
663
749
  cancelAnimationFrame(id);
664
- view.focus();
750
+ if (!editorExperiment('platform_editor_block_control_optimise_render', true)) {
751
+ view.focus();
752
+ }
665
753
  };
666
754
  }
667
755
  }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
@@ -670,7 +758,7 @@ export var DragHandle = function DragHandle(_ref) {
670
758
  return;
671
759
  }
672
760
  setDragHandleSelected(isHandleCorrelatedToSelection(view.state, selection, start));
673
- }, [start, selection, view.state, isMultiSelect]);
761
+ }, [start, selection, view, isMultiSelect]);
674
762
  useEffect(function () {
675
763
  var _api$blockControls$sh4;
676
764
  if (!isMultiSelect || isShiftDown === undefined || view.state.selection.empty || !fg('platform_editor_elements_dnd_shift_click_select')) {
@@ -683,7 +771,7 @@ export var DragHandle = function DragHandle(_ref) {
683
771
  } else {
684
772
  setDragHandleDisabled(false);
685
773
  }
686
- }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view.state.doc, view.state.selection]);
774
+ }, [api === null || api === void 0 ? void 0 : api.blockControls.sharedState, isMultiSelect, isShiftDown, isTopLevelNode, view]);
687
775
  var helpDescriptors = isTopLevelNode ? [{
688
776
  description: formatMessage(blockControlsMessages.dragToMove)
689
777
  }, {
@@ -768,7 +856,7 @@ export var DragHandle = function DragHandle(_ref) {
768
856
  ref: buttonRef
769
857
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
770
858
  ,
771
- style: !editorExperiment('platform_editor_controls', 'variant1') && positionStyles || {},
859
+ style: !editorExperiment('platform_editor_controls', 'variant1') ? editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld : {},
772
860
  onClick: handleOnClick,
773
861
  onMouseDown: handleMouseDown,
774
862
  onKeyDown: handleKeyDown
@@ -787,7 +875,8 @@ export var DragHandle = function DragHandle(_ref) {
787
875
  spacing: "spacious",
788
876
  label: "",
789
877
  LEGACY_fallbackIcon: DragHandlerIcon,
790
- LEGACY_size: "medium"
878
+ LEGACY_size: "medium",
879
+ size: "small"
791
880
  })))
792
881
  );
793
882
  };
@@ -795,7 +884,7 @@ export var DragHandle = function DragHandle(_ref) {
795
884
  return jsx(Box
796
885
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
797
886
  , {
798
- style: positionStyles,
887
+ style: editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
799
888
  xcss: [dragHandleContainerStyles],
800
889
  as: "span",
801
890
  testId: "block-ctrl-drag-handle-container"
@@ -821,7 +910,7 @@ export var DragHandle = function DragHandle(_ref) {
821
910
  return jsx(Box
822
911
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop
823
912
  , {
824
- style: positionStyles,
913
+ style: editorExperiment('platform_editor_block_control_optimise_render', true) ? positionStyles : positionStylesOld,
825
914
  xcss: [dragHandleContainerStyles],
826
915
  as: "span",
827
916
  testId: "block-ctrl-drag-handle-container"
@@ -857,6 +946,7 @@ export var DragHandleWithVisibility = function DragHandleWithVisibility(_ref8) {
857
946
  getPos = _ref8.getPos,
858
947
  anchorName = _ref8.anchorName,
859
948
  nodeType = _ref8.nodeType,
949
+ handleOptions = _ref8.handleOptions,
860
950
  anchorRectCache = _ref8.anchorRectCache;
861
951
  return jsx(VisibilityContainer, {
862
952
  api: api
@@ -867,6 +957,7 @@ export var DragHandleWithVisibility = function DragHandleWithVisibility(_ref8) {
867
957
  getPos: getPos,
868
958
  anchorName: anchorName,
869
959
  nodeType: nodeType,
960
+ handleOptions: handleOptions,
870
961
  anchorRectCache: anchorRectCache
871
962
  }));
872
963
  };
@@ -16,5 +16,5 @@ type DragHandleProps = {
16
16
  anchorRectCache?: AnchorRectCache;
17
17
  };
18
18
  export declare const DragHandle: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, isTopLevelNode, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
19
- export declare const DragHandleWithVisibility: ({ view, api, formatMessage, getPos, anchorName, nodeType, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
19
+ export declare const DragHandleWithVisibility: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
20
20
  export {};
@@ -16,5 +16,5 @@ type DragHandleProps = {
16
16
  anchorRectCache?: AnchorRectCache;
17
17
  };
18
18
  export declare const DragHandle: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, isTopLevelNode, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
19
- export declare const DragHandleWithVisibility: ({ view, api, formatMessage, getPos, anchorName, nodeType, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
19
+ export declare const DragHandleWithVisibility: ({ view, api, formatMessage, getPos, anchorName, nodeType, handleOptions, anchorRectCache, }: DragHandleProps) => jsx.JSX.Element;
20
20
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.15.9",
3
+ "version": "3.15.10",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -56,9 +56,9 @@
56
56
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
57
57
  "@atlaskit/primitives": "^14.8.0",
58
58
  "@atlaskit/theme": "^18.0.0",
59
- "@atlaskit/tmp-editor-statsig": "^5.8.0",
59
+ "@atlaskit/tmp-editor-statsig": "^5.11.0",
60
60
  "@atlaskit/tokens": "^5.0.0",
61
- "@atlaskit/tooltip": "^20.2.0",
61
+ "@atlaskit/tooltip": "^20.3.0",
62
62
  "@babel/runtime": "^7.0.0",
63
63
  "@emotion/react": "^11.7.1",
64
64
  "bind-event-listener": "^3.0.0",