@atlaskit/editor-plugin-block-controls 17.2.5 → 17.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/blockControlsPlugin.js +22 -2
  3. package/dist/cjs/pm-plugins/main.js +9 -7
  4. package/dist/cjs/pm-plugins/utils/surface-node-positions.js +45 -19
  5. package/dist/cjs/ui/block-controls-left-surfaces.js +5 -4
  6. package/dist/cjs/ui/block-controls-right-surface.compiled.css +4 -0
  7. package/dist/cjs/ui/block-controls-right-surface.js +45 -0
  8. package/dist/cjs/ui/block-controls-right-surfaces.js +222 -0
  9. package/dist/{esm/ui/block-controls-left-surface-targets.js → cjs/ui/block-controls-surface-targets.js} +14 -2
  10. package/dist/cjs/ui/utils/get-surface-placement.js +20 -6
  11. package/dist/es2019/blockControlsPlugin.js +27 -3
  12. package/dist/es2019/pm-plugins/main.js +9 -9
  13. package/dist/es2019/pm-plugins/utils/surface-node-positions.js +34 -15
  14. package/dist/es2019/ui/block-controls-left-surfaces.js +5 -4
  15. package/dist/es2019/ui/block-controls-right-surface.compiled.css +4 -0
  16. package/dist/es2019/ui/block-controls-right-surface.js +39 -0
  17. package/dist/es2019/ui/block-controls-right-surfaces.js +187 -0
  18. package/dist/es2019/ui/{block-controls-left-surface-targets.js → block-controls-surface-targets.js} +8 -2
  19. package/dist/es2019/ui/utils/get-surface-placement.js +20 -6
  20. package/dist/esm/blockControlsPlugin.js +23 -3
  21. package/dist/esm/pm-plugins/main.js +10 -8
  22. package/dist/esm/pm-plugins/utils/surface-node-positions.js +45 -19
  23. package/dist/esm/ui/block-controls-left-surfaces.js +5 -4
  24. package/dist/esm/ui/block-controls-right-surface.compiled.css +4 -0
  25. package/dist/esm/ui/block-controls-right-surface.js +38 -0
  26. package/dist/esm/ui/block-controls-right-surfaces.js +213 -0
  27. package/dist/{cjs/ui/block-controls-left-surface-targets.js → esm/ui/block-controls-surface-targets.js} +8 -8
  28. package/dist/esm/ui/utils/get-surface-placement.js +20 -6
  29. package/dist/types/pm-plugins/main.d.ts +2 -2
  30. package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +3 -3
  31. package/dist/types/ui/block-controls-left-surface.d.ts +2 -2
  32. package/dist/types/ui/block-controls-right-surface.d.ts +23 -0
  33. package/dist/types/ui/block-controls-right-surfaces.d.ts +20 -0
  34. package/dist/types/ui/block-controls-surface-targets.d.ts +13 -0
  35. package/dist/types/ui/utils/get-surface-placement.d.ts +12 -4
  36. package/package.json +22 -22
  37. package/dist/types/ui/block-controls-left-surface-targets.d.ts +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 17.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`14f10ff093c15`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/14f10ff093c15) -
8
+ EDITOR-8770: Add the right control surface - currently only used in example page and behind
9
+ platform_editor_block_control_right_surface
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 17.2.5
4
16
 
5
17
  ### Patch Changes
@@ -32,6 +32,7 @@ var _pmPlugin2 = require("./pm-plugins/selection-preservation/pm-plugin");
32
32
  var _expandAndUpdateSelection2 = require("./pm-plugins/utils/expand-and-update-selection");
33
33
  var _getSelection = require("./pm-plugins/utils/getSelection");
34
34
  var _blockControlsLeftSurfaces = require("./ui/block-controls-left-surfaces");
35
+ var _blockControlsRightSurfaces = require("./ui/block-controls-right-surfaces");
35
36
  var _blockControlsSurfaceDragHandleRegistration = require("./ui/block-controls-surface-drag-handle-registration");
36
37
  var _globalStyles = require("./ui/global-styles");
37
38
  var _surfaceEditorViewContext = require("./ui/surface-editor-view-context");
@@ -47,6 +48,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
47
48
  var registryBlockControlsEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration');
48
49
  var surfaceNodePositionsEnabled = registryBlockControlsEnabled && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings');
49
50
  var legacyBlockControlsEnabled = !registryBlockControlsEnabled;
51
+ var rightSurfaceEnabled = registryBlockControlsEnabled && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_right_surface');
50
52
  if (registryBlockControlsEnabled) {
51
53
  var _api$uiControlRegistr;
52
54
  api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register([_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, _objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_LEFT_SECTION), {}, {
@@ -60,6 +62,21 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
60
62
  })].concat((0, _toConsumableArray2.default)((0, _blockControlsSurfaceDragHandleRegistration.getBlockControlsSurfaceDragHandleComponents)({
61
63
  api: api
62
64
  }))));
65
+ if (rightSurfaceEnabled) {
66
+ var _api$uiControlRegistr2;
67
+ // The right surface host stays generic: it only registers the toolbar/section/group
68
+ // hierarchy. Individual features contribute their own buttons into
69
+ // BLOCK_CONTROLS_RIGHT_GROUP from their own plugins, same as the left surface.
70
+ api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 || _api$uiControlRegistr2.actions.register([_surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, _objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SECTION), {}, {
71
+ parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE), {}, {
72
+ rank: 100
73
+ })]
74
+ }), _objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_RIGHT_GROUP), {}, {
75
+ parents: [_objectSpread(_objectSpread({}, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SECTION), {}, {
76
+ rank: 100
77
+ })]
78
+ })]);
79
+ }
63
80
  }
64
81
  return {
65
82
  name: 'blockControls',
@@ -129,7 +146,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
129
146
  plugin: function plugin(_ref2) {
130
147
  var getIntl = _ref2.getIntl,
131
148
  nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
132
- return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled && legacyBlockControlsEnabled, legacyBlockControlsEnabled, surfaceNodePositionsEnabled);
149
+ return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled && legacyBlockControlsEnabled, legacyBlockControlsEnabled, surfaceNodePositionsEnabled, rightSurfaceEnabled);
133
150
  }
134
151
  }];
135
152
  if ((0, _editorExperiment.editorExperiment)('platform_editor_controls', 'variant1')) {
@@ -457,7 +474,10 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
457
474
  }, /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurfaces.BlockControlsLeftSurfaces, {
458
475
  api: api,
459
476
  editorView: editorView
460
- })) : null);
477
+ }), rightSurfaceEnabled ? /*#__PURE__*/_react.default.createElement(_blockControlsRightSurfaces.BlockControlsRightSurfaces, {
478
+ api: api,
479
+ editorView: editorView
480
+ }) : null) : null);
461
481
  }
462
482
  };
463
483
  };
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.key = exports.getDecorations = exports.getBlockControlsMeta = exports.createPlugin = exports.apply = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
10
11
  var _browserApis = require("@atlaskit/browser-apis");
@@ -246,7 +247,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
246
247
  var anchorRectCache = arguments.length > 10 ? arguments[10] : undefined;
247
248
  var resizeObserverWidth = arguments.length > 11 ? arguments[11] : undefined;
248
249
  var pragmaticCleanup = arguments.length > 12 ? arguments[12] : undefined;
249
- var resolvedSurface = arguments.length > 13 ? arguments[13] : undefined;
250
+ var resolvedSurfaces = arguments.length > 13 && arguments[13] !== undefined ? arguments[13] : [];
250
251
  var activeNode = currentState.activeNode,
251
252
  decorations = currentState.decorations,
252
253
  isResizerResizing = currentState.isResizerResizing,
@@ -817,14 +818,14 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
817
818
  var _latestActiveNode13, _latestActiveNode14;
818
819
  newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && flags.legacyDragHandleEnabled && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
819
820
  }
820
- if (flags.surfaceNodePositionsEnabled && resolvedSurface) {
821
+ if (flags.surfaceNodePositionsEnabled && resolvedSurfaces.length > 0) {
821
822
  surfaceNodePositions = (0, _surfaceNodePositions.updateSurfaceNodePositions)({
822
823
  activeNode: newActiveNode,
823
824
  currentPositions: surfaceNodePositions,
824
825
  from: from,
825
826
  newState: newState,
826
827
  previousActiveNode: previousActiveNode,
827
- resolvedSurface: resolvedSurface,
828
+ resolvedSurfaces: resolvedSurfaces,
828
829
  to: to,
829
830
  tr: tr
830
831
  });
@@ -873,11 +874,12 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
873
874
  };
874
875
  };
875
876
  var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
876
- var _api$uiControlRegistr, _api$uiControlRegistr2;
877
+ var _api$uiControlRegistr, _api$uiControlRegistr2, _api$uiControlRegistr3, _api$uiControlRegistr4;
877
878
  var rightSideControlsEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
878
879
  var quickInsertButtonEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
879
880
  var legacyDragHandleEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
880
881
  var surfaceNodePositionsEnabled = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
882
+ var rightSurfaceEnabled = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
881
883
  var _getIntl = getIntl(),
882
884
  formatMessage = _getIntl.formatMessage;
883
885
  var isAdvancedLayoutEnabled = (0, _editorExperiment.editorExperiment)('advanced_layouts', true, {
@@ -889,7 +891,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
889
891
  surfaceNodePositionsEnabled: surfaceNodePositionsEnabled,
890
892
  toolbarFlagsEnabled: toolbarFlagsEnabled
891
893
  };
892
- var resolvedSurface = surfaceNodePositionsEnabled ? (0, _surfaceRenderer.resolveSurface)((_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE) : undefined;
894
+ var resolvedSurfaces = surfaceNodePositionsEnabled ? [(0, _surfaceRenderer.resolveSurface)((_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)].concat((0, _toConsumableArray2.default)(rightSurfaceEnabled ? [(0, _surfaceRenderer.resolveSurface)((_api$uiControlRegistr3 = api === null || api === void 0 || (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : [], _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)] : [])) : [];
893
895
  var anchorRectCache;
894
896
  if (!(0, _anchorUtils.isAnchorSupported)()) {
895
897
  anchorRectCache = new _anchorUtils.AnchorRectCache();
@@ -901,11 +903,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
901
903
  state: {
902
904
  init: function init(_config, editorState) {
903
905
  return _objectSpread(_objectSpread({}, initialState), {}, {
904
- surfaceNodePositions: resolvedSurface ? (0, _surfaceNodePositions.getSurfaceNodePositions)(editorState, resolvedSurface) : []
906
+ surfaceNodePositions: resolvedSurfaces.length > 0 ? (0, _surfaceNodePositions.getSurfaceNodePositions)(editorState, resolvedSurfaces) : []
905
907
  });
906
908
  },
907
909
  apply: function apply(tr, currentState, _, newState) {
908
- return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurface);
910
+ return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurfaces);
909
911
  }
910
912
  },
911
913
  props: {
@@ -14,19 +14,39 @@ var createSurfaceContextAtPosition = function createSurfaceContextAtPosition(sta
14
14
  var blockControlsContext = (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(state, position, activeNode);
15
15
  return blockControlsContext ? (0, _types.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
16
16
  };
17
- var getSurfaceNodePositions = exports.getSurfaceNodePositions = function getSurfaceNodePositions(state, resolvedSurface, activeNode) {
17
+
18
+ /**
19
+ * A position qualifies as soon as ANY of the given surfaces would render something for it.
20
+ * The surface context depends only on state/position/activeNode, not on which surface is being
21
+ * checked, so it's built once here rather than once per surface inside the `.some()`.
22
+ */
23
+ var willAnySurfaceRenderAt = function willAnySurfaceRenderAt(surfaces, state, position, activeNode) {
24
+ var surfaceContext = createSurfaceContextAtPosition(state, position, activeNode);
25
+ return surfaces.some(function (_ref) {
26
+ var childrenMap = _ref.childrenMap,
27
+ root = _ref.root;
28
+ return (0, _surfaceRenderer.willComponentRender)(root, childrenMap, surfaceContext);
29
+ });
30
+ };
31
+ var getSurfaceNodePositions = exports.getSurfaceNodePositions = function getSurfaceNodePositions(state, resolvedSurfaces, activeNode) {
18
32
  var from = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
19
33
  var to = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : state.doc.content.size;
20
- var root = resolvedSurface.root,
21
- childrenMap = resolvedSurface.childrenMap;
22
- if (!root) {
34
+ var surfaces = resolvedSurfaces.flatMap(function (_ref2) {
35
+ var childrenMap = _ref2.childrenMap,
36
+ root = _ref2.root;
37
+ return root ? [{
38
+ childrenMap: childrenMap,
39
+ root: root
40
+ }] : [];
41
+ });
42
+ if (surfaces.length === 0) {
23
43
  return [];
24
44
  }
25
45
  var positions = [];
26
46
  var start = Math.max(0, from);
27
47
  var end = Math.min(state.doc.content.size, Math.max(start, to));
28
48
  state.doc.nodesBetween(start, end, function (node, position) {
29
- if (node.isBlock && (0, _surfaceRenderer.willComponentRender)(root, childrenMap, createSurfaceContextAtPosition(state, position, activeNode))) {
49
+ if (node.isBlock && willAnySurfaceRenderAt(surfaces, state, position, activeNode)) {
30
50
  positions.push(position);
31
51
  }
32
52
  });
@@ -35,25 +55,31 @@ var getSurfaceNodePositions = exports.getSurfaceNodePositions = function getSurf
35
55
  var hasActiveNodeChanged = function hasActiveNodeChanged(previousActiveNode, activeNode) {
36
56
  return (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) || (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) || (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.rootPos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.rootPos);
37
57
  };
38
- var updateSurfaceNodePositions = exports.updateSurfaceNodePositions = function updateSurfaceNodePositions(_ref) {
39
- var activeNode = _ref.activeNode,
40
- currentPositions = _ref.currentPositions,
41
- from = _ref.from,
42
- newState = _ref.newState,
43
- previousActiveNode = _ref.previousActiveNode,
44
- resolvedSurface = _ref.resolvedSurface,
45
- to = _ref.to,
46
- tr = _ref.tr;
58
+ var updateSurfaceNodePositions = exports.updateSurfaceNodePositions = function updateSurfaceNodePositions(_ref3) {
59
+ var activeNode = _ref3.activeNode,
60
+ currentPositions = _ref3.currentPositions,
61
+ from = _ref3.from,
62
+ newState = _ref3.newState,
63
+ previousActiveNode = _ref3.previousActiveNode,
64
+ resolvedSurfaces = _ref3.resolvedSurfaces,
65
+ to = _ref3.to,
66
+ tr = _ref3.tr;
47
67
  var activeNodeChanged = hasActiveNodeChanged(previousActiveNode, activeNode);
48
68
  if (!tr.docChanged && !activeNodeChanged) {
49
69
  return currentPositions;
50
70
  }
51
71
  var nextActiveNode = activeNode !== null && activeNode !== void 0 ? activeNode : undefined;
52
72
  if (activeNodeChanged) {
53
- return getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode);
73
+ return getSurfaceNodePositions(newState, resolvedSurfaces, nextActiveNode);
54
74
  }
55
- var root = resolvedSurface.root,
56
- childrenMap = resolvedSurface.childrenMap;
75
+ var surfaces = resolvedSurfaces.flatMap(function (_ref4) {
76
+ var childrenMap = _ref4.childrenMap,
77
+ root = _ref4.root;
78
+ return root ? [{
79
+ childrenMap: childrenMap,
80
+ root: root
81
+ }] : [];
82
+ });
57
83
  var mappedPositions = currentPositions.map(function (position) {
58
84
  return tr.mapping.mapResult(position, -1);
59
85
  }).filter(function (result) {
@@ -62,9 +88,9 @@ var updateSurfaceNodePositions = exports.updateSurfaceNodePositions = function u
62
88
  return result.pos;
63
89
  }).filter(function (position) {
64
90
  var node = newState.doc.nodeAt(position);
65
- return Boolean((node === null || node === void 0 ? void 0 : node.isBlock) && root && (0, _surfaceRenderer.willComponentRender)(root, childrenMap, createSurfaceContextAtPosition(newState, position, nextActiveNode)));
91
+ return Boolean((node === null || node === void 0 ? void 0 : node.isBlock) && willAnySurfaceRenderAt(surfaces, newState, position, nextActiveNode));
66
92
  });
67
- var changedPositions = getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode, from - 1, to + 1);
93
+ var changedPositions = getSurfaceNodePositions(newState, resolvedSurfaces, nextActiveNode, from - 1, to + 1);
68
94
  return Array.from(new Set([].concat((0, _toConsumableArray2.default)(mappedPositions), (0, _toConsumableArray2.default)(changedPositions)))).sort(function (first, second) {
69
95
  return first - second;
70
96
  });
@@ -18,9 +18,9 @@ var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys"
18
18
  var _hooks = require("@atlaskit/editor-common/hooks");
19
19
  var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
20
20
  var _decorationsCommon = require("../pm-plugins/decorations-common");
21
- var _blockControlsSurfaceContext = require("./block-controls-surface-context");
22
21
  var _blockControlsLeftSurface = require("./block-controls-left-surface");
23
- var _blockControlsLeftSurfaceTargets = require("./block-controls-left-surface-targets");
22
+ var _blockControlsSurfaceContext = require("./block-controls-surface-context");
23
+ var _blockControlsSurfaceTargets = require("./block-controls-surface-targets");
24
24
  var _getNodeContentElement = require("./utils/get-node-content-element");
25
25
  var _getSurfacePlacement = require("./utils/get-surface-placement");
26
26
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
@@ -46,7 +46,7 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
46
46
  surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
47
47
  var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
48
48
  var targets = (0, _react.useMemo)(function () {
49
- return (0, _blockControlsLeftSurfaceTargets.getBlockControlsLeftSurfaceTargets)(activeNode, surfaceNodePositions);
49
+ return (0, _blockControlsSurfaceTargets.getBlockControlsSurfaceTargets)(activeNode, surfaceNodePositions);
50
50
  }, [activeNode, surfaceNodePositions]);
51
51
  var surfaces = (0, _react.useMemo)(function () {
52
52
  return targets.flatMap(function (target) {
@@ -115,7 +115,8 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
115
115
  nodeRect: targetElement.getBoundingClientRect(),
116
116
  nodeType: blockControlsContext.targetNode.type.name,
117
117
  nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
118
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
118
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
119
+ side: 'left'
119
120
  });
120
121
  nextPlacements.set(position, (0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
121
122
  offsetParentRect: offsetParentRect,
@@ -0,0 +1,4 @@
1
+ ._zulpv77o{gap:var(--ds-space-025,2px)}._1e0c1txw{display:flex}
2
+ ._1pbyb4wl{z-index:100}
3
+ ._4cvr1h6o{align-items:center}
4
+ ._kqswstnw{position:absolute}
@@ -0,0 +1,45 @@
1
+ /* block-controls-right-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.BlockControlsRightSurface = void 0;
9
+ require("./block-controls-right-surface.compiled.css");
10
+ var _runtime = require("@compiled/react/runtime");
11
+ var _react = _interopRequireDefault(require("react"));
12
+ var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
13
+ var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
14
+ var _visibilityContainer = require("./visibility-container");
15
+ var rightSurfaceStyles = null;
16
+ /** Renders one right block-controls surface at a document position. */
17
+ var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref) {
18
+ var api = _ref.api,
19
+ components = _ref.components,
20
+ forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
21
+ placement = _ref.placement,
22
+ source = _ref.source,
23
+ surfaceContext = _ref.surfaceContext;
24
+ if (!placement || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
25
+ return null;
26
+ }
27
+ var surface = /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
28
+ components: components,
29
+ surface: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE,
30
+ surfaceContext: surfaceContext
31
+ });
32
+ return /*#__PURE__*/_react.default.createElement("div", {
33
+ "data-editor-block-controls-surface": true,
34
+ "data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
35
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the target node's runtime DOM geometry.
36
+ ,
37
+ style: placement,
38
+ className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
39
+ }, /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
40
+ api: api,
41
+ controlSide: "right",
42
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
43
+ shouldUseDisplayContents: true
44
+ }, surface));
45
+ };
@@ -0,0 +1,222 @@
1
+ /* block-controls-right-surfaces.tsx generated by @compiled/babel-plugin v2.0.0 */
2
+ "use strict";
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.BlockControlsRightSurfaces = void 0;
10
+ var _runtime = require("@compiled/react/runtime");
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _react = _interopRequireWildcard(require("react"));
14
+ var _bindEventListener = require("bind-event-listener");
15
+ var _browserApis = require("@atlaskit/browser-apis");
16
+ var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
17
+ var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
18
+ var _hooks = require("@atlaskit/editor-common/hooks");
19
+ var _types = require("@atlaskit/editor-ui-control-model/types");
20
+ var _decorationsCommon = require("../pm-plugins/decorations-common");
21
+ var _blockControlsRightSurface = require("./block-controls-right-surface");
22
+ var _blockControlsSurfaceContext = require("./block-controls-surface-context");
23
+ var _blockControlsSurfaceTargets = require("./block-controls-surface-targets");
24
+ var _getNodeContentElement = require("./utils/get-node-content-element");
25
+ var _getSurfacePlacement = require("./utils/get-surface-placement");
26
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
27
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
28
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
29
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
30
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
31
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
32
+ var EMPTY_SURFACE_POSITIONS = [];
33
+ var EMPTY_SURFACE_COMPONENTS = [];
34
+ /**
35
+ * Registry-backed right surface tree. Mirrors the left surface's single-tree, measured-placement
36
+ * approach, but keeps its own components lookup, targets, placements and measurement lifecycle so
37
+ * the right surface never depends on the left surface's render pass.
38
+ */
39
+ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref) {
40
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
41
+ var api = _ref.api,
42
+ editorView = _ref.editorView;
43
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
44
+ var _states$blockControls, _states$blockControls2, _states$blockControls3;
45
+ return {
46
+ activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
47
+ surfaceNodePositions: (_states$blockControls2 = (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 ? void 0 : _states$blockControls3.surfaceNodePositions) !== null && _states$blockControls2 !== void 0 ? _states$blockControls2 : EMPTY_SURFACE_POSITIONS
48
+ };
49
+ }),
50
+ activeNode = _useSharedPluginState.activeNode,
51
+ surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
52
+ var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
53
+ var targets = (0, _react.useMemo)(function () {
54
+ return (0, _blockControlsSurfaceTargets.getBlockControlsSurfaceTargets)(activeNode, surfaceNodePositions);
55
+ }, [activeNode, surfaceNodePositions]);
56
+ var surfaces = (0, _react.useMemo)(function () {
57
+ return targets.flatMap(function (target) {
58
+ var context = target.source === 'stored' ? (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(editorView.state, target.position, activeNode) : (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContext)(editorView, activeNode, target.source);
59
+ if (!context) {
60
+ return [];
61
+ }
62
+ var surfaceContext = (0, _types.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, context);
63
+ return [_objectSpread(_objectSpread({}, target), {}, {
64
+ blockControlsContext: context,
65
+ surfaceContext: surfaceContext
66
+ })];
67
+ });
68
+ }, [activeNode, editorView, targets]);
69
+ var _useState = (0, _react.useState)(new Map()),
70
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
71
+ placements = _useState2[0],
72
+ setPlacements = _useState2[1];
73
+ var animationFrameRef = (0, _react.useRef)(undefined);
74
+ (0, _react.useLayoutEffect)(function () {
75
+ var _getDocument;
76
+ if (surfaces.length === 0) {
77
+ setPlacements(new Map());
78
+ return;
79
+ }
80
+ var measurementTargets = surfaces.flatMap(function (_ref2) {
81
+ var blockControlsContext = _ref2.blockControlsContext,
82
+ position = _ref2.position;
83
+ var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
84
+ var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
85
+ if (!targetElementRoot) {
86
+ return [];
87
+ }
88
+ return [{
89
+ blockControlsContext: blockControlsContext,
90
+ position: position,
91
+ targetElement: (0, _getNodeContentElement.getNodeContentElement)(targetElementRoot, blockControlsContext.targetNode.type.name),
92
+ targetElementRoot: targetElementRoot
93
+ }];
94
+ });
95
+ var offsetParent = editorView.dom.offsetParent;
96
+ var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
97
+ var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
98
+ var updatePositions = function updatePositions() {
99
+ var _scrollingOffsetParen, _scrollingOffsetParen2;
100
+ animationFrameRef.current = undefined;
101
+ var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
102
+ var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
103
+ var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
104
+ var nextPlacements = new Map();
105
+ var _iterator = _createForOfIteratorHelper(measurementTargets),
106
+ _step;
107
+ try {
108
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
109
+ var _targetElementRoot$ge;
110
+ var _step$value = _step.value,
111
+ blockControlsContext = _step$value.blockControlsContext,
112
+ position = _step$value.position,
113
+ targetElement = _step$value.targetElement,
114
+ targetElementRoot = _step$value.targetElementRoot;
115
+ if (!targetElementRoot.isConnected || !targetElement.isConnected) {
116
+ continue;
117
+ }
118
+ var placement = (0, _getSurfacePlacement.getSurfacePlacement)({
119
+ layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
120
+ nodeRect: targetElement.getBoundingClientRect(),
121
+ nodeType: blockControlsContext.targetNode.type.name,
122
+ nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
123
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
124
+ side: 'right'
125
+ });
126
+ nextPlacements.set(position, (0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
127
+ offsetParentRect: offsetParentRect,
128
+ offsetParentScrollLeft: offsetParentScrollLeft,
129
+ offsetParentScrollTop: offsetParentScrollTop,
130
+ placement: placement
131
+ }));
132
+ }
133
+ } catch (err) {
134
+ _iterator.e(err);
135
+ } finally {
136
+ _iterator.f();
137
+ }
138
+ setPlacements(nextPlacements);
139
+ };
140
+ var schedulePositionUpdate = function schedulePositionUpdate() {
141
+ if (animationFrameRef.current === undefined) {
142
+ animationFrameRef.current = requestAnimationFrame(updatePositions);
143
+ }
144
+ };
145
+ updatePositions();
146
+ var resizeObserver = new ResizeObserver(schedulePositionUpdate);
147
+ var observedElements = new Set([editorView.dom]);
148
+ var _iterator2 = _createForOfIteratorHelper(measurementTargets),
149
+ _step2;
150
+ try {
151
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
152
+ var targetElement = _step2.value.targetElement;
153
+ observedElements.add(targetElement);
154
+ }
155
+ } catch (err) {
156
+ _iterator2.e(err);
157
+ } finally {
158
+ _iterator2.f();
159
+ }
160
+ if (offsetParent instanceof HTMLElement) {
161
+ observedElements.add(offsetParent);
162
+ }
163
+ observedElements.forEach(function (element) {
164
+ return resizeObserver.observe(element);
165
+ });
166
+ var unbindWindowResize = (0, _bindEventListener.bind)(window, {
167
+ type: 'resize',
168
+ listener: schedulePositionUpdate
169
+ });
170
+ var unbindWindowScroll = (0, _bindEventListener.bind)(window, {
171
+ type: 'scroll',
172
+ listener: schedulePositionUpdate,
173
+ options: {
174
+ capture: true,
175
+ passive: true
176
+ }
177
+ });
178
+ var visualViewport = window.visualViewport;
179
+ var unbindVisualViewportResize = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
180
+ type: 'resize',
181
+ listener: schedulePositionUpdate
182
+ }) : undefined;
183
+ var unbindVisualViewportScroll = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
184
+ type: 'scroll',
185
+ listener: schedulePositionUpdate
186
+ }) : undefined;
187
+ var unbindTransitionEnd = (0, _bindEventListener.bind)(editorView.dom, {
188
+ type: 'transitionend',
189
+ listener: schedulePositionUpdate,
190
+ options: {
191
+ capture: true
192
+ }
193
+ });
194
+ return function () {
195
+ if (animationFrameRef.current !== undefined) {
196
+ cancelAnimationFrame(animationFrameRef.current);
197
+ animationFrameRef.current = undefined;
198
+ }
199
+ resizeObserver.disconnect();
200
+ unbindWindowResize();
201
+ unbindWindowScroll();
202
+ unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
203
+ unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
204
+ unbindTransitionEnd();
205
+ };
206
+ }, [editorView, surfaces]);
207
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref3) {
208
+ var _activeNode$handleOpt;
209
+ var position = _ref3.position,
210
+ source = _ref3.source,
211
+ surfaceContext = _ref3.surfaceContext;
212
+ return /*#__PURE__*/_react.default.createElement(_blockControlsRightSurface.BlockControlsRightSurface, {
213
+ api: api,
214
+ components: components,
215
+ forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
216
+ key: position,
217
+ placement: placements.get(position),
218
+ source: source,
219
+ surfaceContext: surfaceContext
220
+ });
221
+ }));
222
+ };
@@ -1,8 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getBlockControlsSurfaceTargets = void 0;
1
7
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2
8
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
9
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
- /** Combines hover-driven and stored surface positions into one deduplicated list. */
5
- export var getBlockControlsLeftSurfaceTargets = function getBlockControlsLeftSurfaceTargets(activeNode, storedPositions) {
10
+ /**
11
+ * Combines hover-driven and stored surface positions into one deduplicated list.
12
+ * Shared by both the left and right surfaces: this is pure position bookkeeping with no
13
+ * surface-specific behavior, so there's nothing to keep independent between them. What *is*
14
+ * kept independent is each surface's own React tree (component lookup, measurement effects,
15
+ * observers) — see block-controls-left-surfaces.tsx / block-controls-right-surfaces.tsx.
16
+ */
17
+ var getBlockControlsSurfaceTargets = exports.getBlockControlsSurfaceTargets = function getBlockControlsSurfaceTargets(activeNode, storedPositions) {
6
18
  var targetsByPosition = new Map();
7
19
  var _iterator = _createForOfIteratorHelper(storedPositions),
8
20
  _step;
@@ -22,25 +22,39 @@ var getAbsoluteSurfacePlacement = exports.getAbsoluteSurfacePlacement = function
22
22
  };
23
23
 
24
24
  /**
25
- * Positions the Task 1 left surface beside the legacy drag-handle slot.
26
- * The surface's own width is handled by the transform, so later controls do not require measuring it.
25
+ * Positions the surface beside the legacy drag-handle slot, on either the left or right edge
26
+ * of the target node. Node-type-specific gap/top-adjustment maths (layouts, tables, media, cards,
27
+ * extensions, etc.) live in one place so left/right edge cases can't drift out of sync.
28
+ *
29
+ * The left side grows away from the node without knowing its own width, so it needs
30
+ * `translateX(-100%)` to anchor its right edge at `nodeRect.left` and extend backward. The right
31
+ * side grows in the normal box-flow direction (away from the node, into the margin), so the gap
32
+ * can be folded straight into `left` with no transform needed.
27
33
  */
28
34
  var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlacement(_ref2) {
29
35
  var layout = _ref2.layout,
30
36
  nodeRect = _ref2.nodeRect,
31
37
  nodeType = _ref2.nodeType,
32
38
  nodeTypeWithLevel = _ref2.nodeTypeWithLevel,
33
- parentNodeType = _ref2.parentNodeType;
39
+ parentNodeType = _ref2.parentNodeType,
40
+ side = _ref2.side;
34
41
  if (nodeType === 'layoutColumn') {
42
+ // nodeRect.left + width/2 === nodeRect.right - width/2 — side-independent.
35
43
  return {
36
44
  left: nodeRect.left + nodeRect.width / 2,
37
45
  top: nodeRect.top,
38
46
  transform: 'translate(-50%, -50%)'
39
47
  };
40
48
  }
41
- return {
49
+ var gap = (0, _consts.dragHandleGap)(nodeType, parentNodeType);
50
+ var top = nodeRect.top + (0, _consts.topPositionAdjustment)(nodeTypeWithLevel, layout);
51
+ return side === 'right' ? {
52
+ left: nodeRect.right + gap,
53
+ top: top,
54
+ transform: ''
55
+ } : {
42
56
  left: nodeRect.left,
43
- top: nodeRect.top + (0, _consts.topPositionAdjustment)(nodeTypeWithLevel, layout),
44
- transform: "translateX(calc(-100% - ".concat((0, _consts.dragHandleGap)(nodeType, parentNodeType), "px))")
57
+ top: top,
58
+ transform: "translateX(calc(-100% - ".concat(gap, "px))")
45
59
  };
46
60
  };