@atlaskit/editor-plugin-block-controls 20.0.3 → 20.1.1

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 (107) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cjs/blockControlsPlugin.js +53 -17
  3. package/dist/cjs/editor-commands/show-drag-handle.js +17 -5
  4. package/dist/cjs/pm-plugins/decorations-anchor.js +2 -1
  5. package/dist/cjs/pm-plugins/decorations-drop-target-active.js +2 -1
  6. package/dist/cjs/pm-plugins/decorations-drop-target.js +2 -1
  7. package/dist/cjs/pm-plugins/decorations-surface-anchor.js +72 -0
  8. package/dist/cjs/pm-plugins/handle-mouse-down.js +2 -1
  9. package/dist/cjs/pm-plugins/handle-mouse-over.js +3 -2
  10. package/dist/cjs/pm-plugins/handle-sparse-mouse-over.js +125 -0
  11. package/dist/cjs/pm-plugins/main.js +66 -54
  12. package/dist/cjs/pm-plugins/sparse-surfaces.js +49 -0
  13. package/dist/cjs/pm-plugins/utils/sparse-surface-candidates.js +419 -0
  14. package/dist/cjs/pm-plugins/utils/sparse-surfaces-mapping.js +108 -0
  15. package/dist/cjs/pm-plugins/utils/sparse-surfaces-state.js +53 -0
  16. package/dist/cjs/pm-plugins/utils/sparse-surfaces-view.js +134 -0
  17. package/dist/cjs/pm-plugins/utils/surface-viewport.js +223 -0
  18. package/dist/cjs/pm-plugins/utils/transactions.js +5 -0
  19. package/dist/cjs/ui/block-controls-left-surfaces.js +31 -25
  20. package/dist/cjs/ui/block-controls-right-surfaces.js +31 -25
  21. package/dist/cjs/ui/block-controls-surface-context.js +1 -0
  22. package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +6 -7
  23. package/dist/cjs/ui/block-controls-surface-drag-handle.js +6 -2
  24. package/dist/cjs/ui/drag-handle.js +5 -3
  25. package/dist/cjs/ui/drop-target-layout.js +3 -2
  26. package/dist/cjs/ui/drop-target.js +3 -2
  27. package/dist/cjs/ui/global-styles.js +69 -27
  28. package/dist/cjs/ui/inline-drop-target.js +6 -5
  29. package/dist/cjs/ui/utils/anchor-name.js +2 -1
  30. package/dist/cjs/ui/utils/dom-attr-name.js +3 -2
  31. package/dist/cjs/ui/utils/get-surface-placement.js +2 -1
  32. package/dist/es2019/blockControlsPlugin.js +42 -8
  33. package/dist/es2019/editor-commands/show-drag-handle.js +14 -2
  34. package/dist/es2019/pm-plugins/decorations-anchor.js +2 -1
  35. package/dist/es2019/pm-plugins/decorations-drop-target-active.js +2 -1
  36. package/dist/es2019/pm-plugins/decorations-drop-target.js +2 -1
  37. package/dist/es2019/pm-plugins/decorations-surface-anchor.js +56 -0
  38. package/dist/es2019/pm-plugins/handle-mouse-down.js +2 -1
  39. package/dist/es2019/pm-plugins/handle-mouse-over.js +3 -2
  40. package/dist/es2019/pm-plugins/handle-sparse-mouse-over.js +116 -0
  41. package/dist/es2019/pm-plugins/main.js +70 -54
  42. package/dist/es2019/pm-plugins/sparse-surfaces.js +37 -0
  43. package/dist/es2019/pm-plugins/utils/sparse-surface-candidates.js +305 -0
  44. package/dist/es2019/pm-plugins/utils/sparse-surfaces-mapping.js +78 -0
  45. package/dist/es2019/pm-plugins/utils/sparse-surfaces-state.js +39 -0
  46. package/dist/es2019/pm-plugins/utils/sparse-surfaces-view.js +121 -0
  47. package/dist/es2019/pm-plugins/utils/surface-viewport.js +192 -0
  48. package/dist/es2019/pm-plugins/utils/transactions.js +5 -0
  49. package/dist/es2019/ui/block-controls-left-surfaces.js +21 -14
  50. package/dist/es2019/ui/block-controls-right-surfaces.js +21 -14
  51. package/dist/es2019/ui/block-controls-surface-context.js +1 -0
  52. package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +4 -5
  53. package/dist/es2019/ui/block-controls-surface-drag-handle.js +6 -2
  54. package/dist/es2019/ui/drag-handle.js +5 -3
  55. package/dist/es2019/ui/drop-target-layout.js +3 -2
  56. package/dist/es2019/ui/drop-target.js +3 -2
  57. package/dist/es2019/ui/global-styles.js +67 -28
  58. package/dist/es2019/ui/inline-drop-target.js +6 -5
  59. package/dist/es2019/ui/utils/anchor-name.js +2 -1
  60. package/dist/es2019/ui/utils/dom-attr-name.js +3 -2
  61. package/dist/es2019/ui/utils/get-surface-placement.js +2 -1
  62. package/dist/esm/blockControlsPlugin.js +53 -17
  63. package/dist/esm/editor-commands/show-drag-handle.js +17 -5
  64. package/dist/esm/pm-plugins/decorations-anchor.js +2 -1
  65. package/dist/esm/pm-plugins/decorations-drop-target-active.js +2 -1
  66. package/dist/esm/pm-plugins/decorations-drop-target.js +2 -1
  67. package/dist/esm/pm-plugins/decorations-surface-anchor.js +65 -0
  68. package/dist/esm/pm-plugins/handle-mouse-down.js +2 -1
  69. package/dist/esm/pm-plugins/handle-mouse-over.js +3 -2
  70. package/dist/esm/pm-plugins/handle-sparse-mouse-over.js +119 -0
  71. package/dist/esm/pm-plugins/main.js +66 -54
  72. package/dist/esm/pm-plugins/sparse-surfaces.js +43 -0
  73. package/dist/esm/pm-plugins/utils/sparse-surface-candidates.js +413 -0
  74. package/dist/esm/pm-plugins/utils/sparse-surfaces-mapping.js +101 -0
  75. package/dist/esm/pm-plugins/utils/sparse-surfaces-state.js +46 -0
  76. package/dist/esm/pm-plugins/utils/sparse-surfaces-view.js +127 -0
  77. package/dist/esm/pm-plugins/utils/surface-viewport.js +217 -0
  78. package/dist/esm/pm-plugins/utils/transactions.js +5 -0
  79. package/dist/esm/ui/block-controls-left-surfaces.js +33 -27
  80. package/dist/esm/ui/block-controls-right-surfaces.js +33 -27
  81. package/dist/esm/ui/block-controls-surface-context.js +1 -0
  82. package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +7 -8
  83. package/dist/esm/ui/block-controls-surface-drag-handle.js +6 -2
  84. package/dist/esm/ui/drag-handle.js +5 -3
  85. package/dist/esm/ui/drop-target-layout.js +3 -2
  86. package/dist/esm/ui/drop-target.js +3 -2
  87. package/dist/esm/ui/global-styles.js +70 -28
  88. package/dist/esm/ui/inline-drop-target.js +6 -5
  89. package/dist/esm/ui/utils/anchor-name.js +2 -1
  90. package/dist/esm/ui/utils/dom-attr-name.js +3 -2
  91. package/dist/esm/ui/utils/get-surface-placement.js +2 -1
  92. package/dist/types/blockControlsPluginType.d.ts +10 -3
  93. package/dist/types/pm-plugins/decorations-surface-anchor.d.ts +22 -0
  94. package/dist/types/pm-plugins/handle-sparse-mouse-over.d.ts +5 -0
  95. package/dist/types/pm-plugins/main.d.ts +2 -9
  96. package/dist/types/pm-plugins/sparse-surfaces.d.ts +8 -0
  97. package/dist/types/pm-plugins/utils/sparse-surface-candidates.d.ts +89 -0
  98. package/dist/types/pm-plugins/utils/sparse-surfaces-mapping.d.ts +20 -0
  99. package/dist/types/pm-plugins/utils/sparse-surfaces-state.d.ts +27 -0
  100. package/dist/types/pm-plugins/utils/sparse-surfaces-view.d.ts +15 -0
  101. package/dist/types/pm-plugins/utils/surface-viewport.d.ts +10 -0
  102. package/dist/types/ui/utils/get-surface-placement.d.ts +3 -2
  103. package/package.json +6 -6
  104. package/dist/cjs/pm-plugins/utils/surface-node-positions.js +0 -100
  105. package/dist/es2019/pm-plugins/utils/surface-node-positions.js +0 -78
  106. package/dist/esm/pm-plugins/utils/surface-node-positions.js +0 -93
  107. package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +0 -14
@@ -0,0 +1,127 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ 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; }
4
+ 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) { _defineProperty(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; }
5
+ import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
6
+ import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor';
7
+ import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
8
+ import { createSurfaceAnchorDecorations } from '../decorations-surface-anchor';
9
+ import { key as blockControlsKey } from '../main';
10
+ import { reconcileSparseSurfaceCandidates } from './sparse-surface-candidates';
11
+ import { observeSurfaceViewport } from './surface-viewport';
12
+ var haveAnchorPositionsChanged = function haveAnchorPositionsChanged(positions, anchors) {
13
+ return positions.length !== anchors.size || positions.some(function (position) {
14
+ return !anchors.has(position);
15
+ });
16
+ };
17
+ export var createSparseSurfacesView = function createSparseSurfacesView(_ref) {
18
+ var _api$uiControlRegistr3, _api$editorDisabled, _api$editorViewMode, _api$limitedMode2, _api$showDiff, _api$userIntent;
19
+ var api = _ref.api,
20
+ pluginKey = _ref.pluginKey,
21
+ view = _ref.view;
22
+ var win = view.dom.ownerDocument.defaultView;
23
+ var frame;
24
+ var visiblePositions = [];
25
+ var registryChanged = true;
26
+ var reconcile = function reconcile() {
27
+ var _api$limitedMode;
28
+ frame = undefined;
29
+ var previous = pluginKey.getState(view.state);
30
+ if (!previous || api !== null && api !== void 0 && (_api$limitedMode = api.limitedMode) !== null && _api$limitedMode !== void 0 && (_api$limitedMode = _api$limitedMode.sharedState.currentState()) !== null && _api$limitedMode !== void 0 && _api$limitedMode.enabled) {
31
+ return;
32
+ }
33
+ var controls = blockControlsKey.getState(view.state);
34
+ var activeNode = controls === null || controls === void 0 ? void 0 : controls.activeNode;
35
+ var activeNodesByPosition = new Map();
36
+ var menu = controls !== null && controls !== void 0 && controls.isMenuOpen ? controls.menuTriggerByNode : undefined;
37
+ if (menu && controls !== null && controls !== void 0 && controls.menuTriggerBy && view.state.doc.nodeAt(menu.pos)) {
38
+ var _menu$rootPos;
39
+ var menuNode = _objectSpread(_objectSpread({}, menu), {}, {
40
+ anchorName: controls.menuTriggerBy
41
+ });
42
+ activeNodesByPosition.set(menu.pos, menuNode);
43
+ activeNodesByPosition.set((_menu$rootPos = menu.rootPos) !== null && _menu$rootPos !== void 0 ? _menu$rootPos : menu.pos, menuNode);
44
+ }
45
+ var resolvedSurfaces = [BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE].map(function (surface) {
46
+ var _api$uiControlRegistr, _api$uiControlRegistr2;
47
+ return resolveSurface((_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(surface)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], surface);
48
+ });
49
+ var candidates = reconcileSparseSurfaceCandidates({
50
+ activeNode: activeNode,
51
+ activeNodesByPosition: activeNodesByPosition,
52
+ newState: view.state,
53
+ state: previous.candidates,
54
+ visiblePositions: visiblePositions,
55
+ protectedPositions: _toConsumableArray(activeNodesByPosition.keys()),
56
+ resolvedSurfaces: resolvedSurfaces,
57
+ documentChanged: previous.documentChanged,
58
+ invalidation: _objectSpread(_objectSpread({}, previous.invalidation), {}, {
59
+ all: registryChanged
60
+ })
61
+ });
62
+ var visibilityChanged = registryChanged;
63
+ registryChanged = false;
64
+ var anchorPositions = candidates.positions;
65
+ if (!visibilityChanged && !haveAnchorPositionsChanged(anchorPositions, previous.anchors) && candidates === previous.candidates && !previous.documentChanged && !previous.invalidation) {
66
+ return;
67
+ }
68
+ var nodeIdProvider = getNodeIdProvider(view);
69
+ var _createSurfaceAnchorD = createSurfaceAnchorDecorations(view.state, anchorPositions, function (node, position, previousAnchorName) {
70
+ if (previousAnchorName) {
71
+ nodeIdProvider.setIdForNode(node, previousAnchorName);
72
+ return previousAnchorName;
73
+ }
74
+ return nodeIdProvider.getOrGenerateId(node, position);
75
+ }, previous.anchors),
76
+ anchors = _createSurfaceAnchorD.anchors,
77
+ decorations = _createSurfaceAnchorD.decorations;
78
+ view.dispatch(view.state.tr.setMeta(pluginKey, {
79
+ reconciliation: {
80
+ activeNodesByPosition: activeNodesByPosition,
81
+ anchors: anchors,
82
+ candidates: candidates,
83
+ decorations: decorations
84
+ },
85
+ type: 'commitReconciliation'
86
+ }));
87
+ };
88
+ var schedule = function schedule() {
89
+ if (frame === undefined && win) {
90
+ frame = win.requestAnimationFrame(reconcile);
91
+ }
92
+ };
93
+ var observer = observeSurfaceViewport(view, function (positions) {
94
+ visiblePositions = positions;
95
+ schedule();
96
+ });
97
+ var invalidate = function invalidate() {
98
+ registryChanged = true;
99
+ schedule();
100
+ };
101
+ var unsubscribe = api === null || api === void 0 || (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 ? void 0 : _api$uiControlRegistr3.actions.subscribe(invalidate);
102
+ var unsubscribers = [api === null || api === void 0 || (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.sharedState.onChange(invalidate), api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.onChange(invalidate), api === null || api === void 0 || (_api$limitedMode2 = api.limitedMode) === null || _api$limitedMode2 === void 0 ? void 0 : _api$limitedMode2.sharedState.onChange(invalidate), api === null || api === void 0 || (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.sharedState.onChange(invalidate), api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.sharedState.onChange(invalidate)];
103
+ return {
104
+ update: function update(currentView, previousState) {
105
+ observer.update();
106
+ var sparse = pluginKey.getState(currentView.state);
107
+ var controls = blockControlsKey.getState(currentView.state);
108
+ var previousControls = blockControlsKey.getState(previousState);
109
+ if ((controls === null || controls === void 0 ? void 0 : controls.isDragging) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isDragging) || (controls === null || controls === void 0 ? void 0 : controls.isResizerResizing) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isResizerResizing)) {
110
+ invalidate();
111
+ }
112
+ if (sparse !== null && sparse !== void 0 && sparse.documentChanged || sparse !== null && sparse !== void 0 && sparse.invalidation || (controls === null || controls === void 0 ? void 0 : controls.activeNode) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.activeNode) || (controls === null || controls === void 0 ? void 0 : controls.isMenuOpen) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isMenuOpen) || (controls === null || controls === void 0 ? void 0 : controls.menuTriggerByNode) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.menuTriggerByNode)) {
113
+ schedule();
114
+ }
115
+ },
116
+ destroy: function destroy() {
117
+ if (frame !== undefined) {
118
+ win === null || win === void 0 || win.cancelAnimationFrame(frame);
119
+ }
120
+ observer.destroy();
121
+ unsubscribe === null || unsubscribe === void 0 || unsubscribe();
122
+ unsubscribers.forEach(function (unsubscribe) {
123
+ return unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
124
+ });
125
+ }
126
+ };
127
+ };
@@ -0,0 +1,217 @@
1
+ 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
+ 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
+ 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
+ var NODE_NAME_ATTRIBUTE = 'data-prosemirror-node-name';
5
+ /**
6
+ * Tracks block DOM nodes that intersect the browser viewport. The browser owns clipping and
7
+ * visibility decisions; this helper only translates observer targets back to PM positions.
8
+ */
9
+ export var observeSurfaceViewport = function observeSurfaceViewport(view, onChange) {
10
+ var win = view.dom.ownerDocument.defaultView;
11
+ if (!win || typeof win.IntersectionObserver === 'undefined') {
12
+ return {
13
+ update: function update() {},
14
+ destroy: function destroy() {}
15
+ };
16
+ }
17
+ var targets = new Map();
18
+ var visibleTargets = new Set();
19
+ var previousPositions = [];
20
+ var previousDoc = view.state.doc;
21
+ var destroyed = false;
22
+ var resolvePosition = function resolvePosition(element) {
23
+ try {
24
+ var domPosition = view.posAtDOM(element, 0);
25
+ var nodeName = element.getAttribute(NODE_NAME_ATTRIBUTE);
26
+ var directNode = view.state.doc.nodeAt(domPosition);
27
+ if (directNode !== null && directNode !== void 0 && directNode.isBlock && directNode.type.name === nodeName && view.nodeDOM(domPosition) === element) {
28
+ return domPosition;
29
+ }
30
+ var $position = view.state.doc.resolve(domPosition);
31
+ for (var depth = $position.depth; depth > 0; depth--) {
32
+ var node = $position.node(depth);
33
+ if (!node.isBlock || node.type.name !== nodeName) {
34
+ continue;
35
+ }
36
+ var position = $position.before(depth);
37
+ var nodeDOM = view.nodeDOM(position);
38
+ if (nodeDOM === element || nodeDOM instanceof Node && (nodeDOM.contains(element) || element.contains(nodeDOM))) {
39
+ return position;
40
+ }
41
+ }
42
+ return undefined;
43
+ } catch (_unused) {
44
+ return undefined;
45
+ }
46
+ };
47
+ var getVisiblePositions = function getVisiblePositions() {
48
+ var positions = new Set();
49
+ visibleTargets.forEach(function (element) {
50
+ var _targets$get;
51
+ var position = (_targets$get = targets.get(element)) === null || _targets$get === void 0 ? void 0 : _targets$get.position;
52
+ if (position !== undefined) {
53
+ positions.add(position);
54
+ }
55
+ });
56
+ return Array.from(positions).sort(function (first, second) {
57
+ return first - second;
58
+ });
59
+ };
60
+ var emit = function emit() {
61
+ if (destroyed) {
62
+ return;
63
+ }
64
+ var positions = getVisiblePositions();
65
+ if (positions.length !== previousPositions.length || positions.some(function (position, index) {
66
+ return position !== previousPositions[index];
67
+ })) {
68
+ previousPositions = positions;
69
+ onChange(positions);
70
+ }
71
+ };
72
+ var intersectionObserver = new win.IntersectionObserver(function (entries) {
73
+ var changed = false;
74
+ var _iterator = _createForOfIteratorHelper(entries),
75
+ _step;
76
+ try {
77
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
78
+ var entry = _step.value;
79
+ var element = entry.target;
80
+ var target = targets.get(element);
81
+ if (!target || !view.dom.contains(element)) {
82
+ continue;
83
+ }
84
+ var isIntersecting = entry.isIntersecting;
85
+ if (target.isIntersecting !== isIntersecting) {
86
+ target.isIntersecting = isIntersecting;
87
+ if (isIntersecting) {
88
+ target.position = resolvePosition(element);
89
+ if (target.position !== undefined) {
90
+ visibleTargets.add(element);
91
+ } else {
92
+ target.isIntersecting = false;
93
+ }
94
+ } else {
95
+ visibleTargets.delete(element);
96
+ }
97
+ changed = true;
98
+ }
99
+ }
100
+ } catch (err) {
101
+ _iterator.e(err);
102
+ } finally {
103
+ _iterator.f();
104
+ }
105
+ if (changed) {
106
+ emit();
107
+ }
108
+ }, {
109
+ root: null,
110
+ threshold: 0
111
+ });
112
+ var removeTarget = function removeTarget(element) {
113
+ var target = targets.get(element);
114
+ if (!target) {
115
+ return;
116
+ }
117
+ targets.delete(element);
118
+ visibleTargets.delete(element);
119
+ intersectionObserver.unobserve(element);
120
+ };
121
+ var observeElement = function observeElement(element) {
122
+ var _view$state$schema$no;
123
+ var nodeName = element.getAttribute(NODE_NAME_ATTRIBUTE);
124
+ if (element === view.dom || !nodeName || !((_view$state$schema$no = view.state.schema.nodes[nodeName]) !== null && _view$state$schema$no !== void 0 && _view$state$schema$no.isBlock) || !view.dom.contains(element)) {
125
+ return;
126
+ }
127
+ if (targets.has(element)) {
128
+ return;
129
+ }
130
+ targets.set(element, {
131
+ isIntersecting: false
132
+ });
133
+ intersectionObserver.observe(element);
134
+ };
135
+ var observeSubtree = function observeSubtree(node) {
136
+ if (node.nodeType !== Node.ELEMENT_NODE) {
137
+ return;
138
+ }
139
+ var element = node;
140
+ observeElement(element);
141
+ var descendants = element.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
142
+ for (var index = 0; index < descendants.length; index++) {
143
+ observeElement(descendants[index]);
144
+ }
145
+ };
146
+ var unobserveSubtree = function unobserveSubtree(node) {
147
+ if (node.nodeType !== Node.ELEMENT_NODE) {
148
+ return;
149
+ }
150
+ var element = node;
151
+ removeTarget(element);
152
+ var descendants = element.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
153
+ for (var index = 0; index < descendants.length; index++) {
154
+ removeTarget(descendants[index]);
155
+ }
156
+ };
157
+ var mutationObserver = new win.MutationObserver(function (records) {
158
+ var removedVisibleTarget = false;
159
+ var _iterator2 = _createForOfIteratorHelper(records),
160
+ _step2;
161
+ try {
162
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
163
+ var record = _step2.value;
164
+ for (var index = 0; index < record.removedNodes.length; index++) {
165
+ var node = record.removedNodes[index];
166
+ if (node.nodeType === Node.ELEMENT_NODE) {
167
+ if (view.dom.contains(node)) {
168
+ continue;
169
+ }
170
+ var before = visibleTargets.size;
171
+ unobserveSubtree(node);
172
+ removedVisibleTarget || (removedVisibleTarget = before !== visibleTargets.size);
173
+ }
174
+ }
175
+ for (var _index = 0; _index < record.addedNodes.length; _index++) {
176
+ observeSubtree(record.addedNodes[_index]);
177
+ }
178
+ }
179
+ } catch (err) {
180
+ _iterator2.e(err);
181
+ } finally {
182
+ _iterator2.f();
183
+ }
184
+ if (removedVisibleTarget) {
185
+ emit();
186
+ }
187
+ });
188
+ var initialTargets = view.dom.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
189
+ for (var index = 0; index < initialTargets.length; index++) {
190
+ observeElement(initialTargets[index]);
191
+ }
192
+ mutationObserver.observe(view.dom, {
193
+ childList: true,
194
+ subtree: true
195
+ });
196
+ return {
197
+ update: function update() {
198
+ if (previousDoc !== view.state.doc) {
199
+ previousDoc = view.state.doc;
200
+ visibleTargets.forEach(function (element) {
201
+ var target = targets.get(element);
202
+ if (target) {
203
+ target.position = resolvePosition(element);
204
+ }
205
+ });
206
+ emit();
207
+ }
208
+ },
209
+ destroy: function destroy() {
210
+ destroyed = true;
211
+ mutationObserver.disconnect();
212
+ intersectionObserver.disconnect();
213
+ targets.clear();
214
+ visibleTargets.clear();
215
+ }
216
+ };
217
+ };
@@ -1,4 +1,5 @@
1
1
  import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
2
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
2
3
  /**
3
4
  * Checks if step adds inline char
4
5
  * @param s
@@ -28,6 +29,10 @@ export var isStepDelete = function isStepDelete(s) {
28
29
  var isStepContentReplacedWithAnotherOfSameSize = function isStepContentReplacedWithAnotherOfSameSize(s) {
29
30
  if (s instanceof ReplaceAroundStep) {
30
31
  var replacedContentSize = s.to - s.from;
32
+ if (isExperimentEnabled('platform_editor_block_control_migration')) {
33
+ var insertedContentSize = s.slice.size + (s.gapTo - s.gapFrom);
34
+ return insertedContentSize === replacedContentSize;
35
+ }
31
36
  return s.slice.content.size === replacedContentSize;
32
37
  }
33
38
  return false;
@@ -18,12 +18,13 @@ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-s
18
18
  import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
19
19
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
20
20
  import { BlockControlsLeftSurface } from './block-controls-left-surface';
21
- import { createBlockControlsSurfaceContext, createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
21
+ import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
22
22
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
23
- import { getNodeContentElement, hasInnerContentContainer } from './utils/get-node-content-element';
23
+ import { getNodeContentElement } from './utils/get-node-content-element';
24
24
  import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
25
25
  import { hasSurfaceControls } from './utils/has-surface-controls';
26
26
  var EMPTY_SURFACE_POSITIONS = [];
27
+ var EMPTY_SURFACE_ANCHORS = new Map();
27
28
  var EMPTY_SURFACE_COMPONENTS = [];
28
29
  var EMPTY_MEASURED_SURFACES = [];
29
30
  export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
@@ -31,22 +32,30 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
31
32
  var api = _ref.api,
32
33
  editorView = _ref.editorView;
33
34
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
34
- var _states$blockControls, _states$blockControls2, _states$blockControls3;
35
+ var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$blockControls4, _states$blockControls5, _states$blockControls6;
35
36
  return {
36
37
  activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
37
- 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
38
+ surfaceActiveNodes: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.surfaceActiveNodes,
39
+ surfaceAnchors: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.surfaceAnchors) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : EMPTY_SURFACE_ANCHORS,
40
+ surfaceNodePositions: (_states$blockControls5 = (_states$blockControls6 = states.blockControlsState) === null || _states$blockControls6 === void 0 ? void 0 : _states$blockControls6.surfaceNodePositions) !== null && _states$blockControls5 !== void 0 ? _states$blockControls5 : EMPTY_SURFACE_POSITIONS
38
41
  };
39
42
  }),
40
43
  activeNode = _useSharedPluginState.activeNode,
44
+ surfaceAnchors = _useSharedPluginState.surfaceAnchors,
45
+ surfaceActiveNodes = _useSharedPluginState.surfaceActiveNodes,
41
46
  surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
42
47
  var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
43
48
  var targets = useMemo(function () {
44
- return getBlockControlsSurfaceTargets(activeNode, surfaceNodePositions);
49
+ var candidates = new Set(surfaceNodePositions);
50
+ return getBlockControlsSurfaceTargets(activeNode, surfaceNodePositions).filter(function (_ref2) {
51
+ var position = _ref2.position;
52
+ return candidates.has(position);
53
+ });
45
54
  }, [activeNode, surfaceNodePositions]);
46
55
  var surfaces = useMemo(function () {
47
56
  return targets.flatMap(function (target) {
48
- var _api$core;
49
- var context = target.source === 'stored' ? createBlockControlsSurfaceContextForPosition(editorView.state, target.position, activeNode) : createBlockControlsSurfaceContext(editorView, activeNode, target.source);
57
+ var _surfaceActiveNodes$g;
58
+ var context = createBlockControlsSurfaceContextForPosition(editorView.state, target.position, (_surfaceActiveNodes$g = surfaceActiveNodes === null || surfaceActiveNodes === void 0 ? void 0 : surfaceActiveNodes.get(target.position)) !== null && _surfaceActiveNodes$g !== void 0 ? _surfaceActiveNodes$g : activeNode);
50
59
  if (!context) {
51
60
  return [];
52
61
  }
@@ -54,32 +63,29 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
54
63
  if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
55
64
  return [];
56
65
  }
57
- // Resolved here rather than in the measurement effect so an anchored surface is placed
58
- // in the same render that creates it — it never needs a second pass to find its node.
59
- //
60
- // At the moment, we only expect top-level nodes to have persistent controls.
61
- // See surfaceAnchorStyles in global-styles
62
- var anchorName = isCSSAnchorSupported() && context.targetNode.parentType === 'doc' && !hasInnerContentContainer(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
66
+ // The cache supplies the same anchor names used by ProseMirror decorations.
67
+ var anchorName = isCSSAnchorSupported() ? surfaceAnchors.get(target.position) : undefined;
63
68
  return [_objectSpread(_objectSpread({}, target), {}, {
64
69
  anchorName: anchorName,
65
70
  blockControlsContext: context,
66
71
  surfaceContext: surfaceContext
67
72
  })];
68
73
  });
69
- }, [activeNode, api, components, editorView, targets]);
74
+ }, [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
70
75
  /**
71
76
  * Placements that need no measuring, so they are derived rather than stored: every inset is an
72
77
  * `anchor()` the browser re-resolves on every layout change.
73
78
  */
74
79
  var anchoredPlacements = useMemo(function () {
75
- return new Map(surfaces.flatMap(function (_ref2) {
76
- var anchorName = _ref2.anchorName,
77
- blockControlsContext = _ref2.blockControlsContext,
78
- position = _ref2.position;
80
+ return new Map(surfaces.flatMap(function (_ref3) {
81
+ var anchorName = _ref3.anchorName,
82
+ blockControlsContext = _ref3.blockControlsContext,
83
+ position = _ref3.position;
79
84
  return anchorName ? [[position, getAnchoredSurfacePlacement({
80
85
  anchorName: anchorName,
81
86
  nodeType: blockControlsContext.targetNode.type.name,
82
87
  nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
88
+ layout: blockControlsContext.targetNode.node.attrs.layout,
83
89
  parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
84
90
  side: 'left'
85
91
  })]] : [];
@@ -93,8 +99,8 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
93
99
  // changed dependency each time and re-run it for nothing, which is the cost the anchored path
94
100
  // exists to avoid.
95
101
  var measuredSurfaces = useMemo(function () {
96
- var measured = surfaces.filter(function (_ref3) {
97
- var anchorName = _ref3.anchorName;
102
+ var measured = surfaces.filter(function (_ref4) {
103
+ var anchorName = _ref4.anchorName;
98
104
  return !anchorName;
99
105
  });
100
106
  return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
@@ -114,9 +120,9 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
114
120
  });
115
121
  return;
116
122
  }
117
- var measurementTargets = measuredSurfaces.flatMap(function (_ref4) {
118
- var blockControlsContext = _ref4.blockControlsContext,
119
- position = _ref4.position;
123
+ var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
124
+ var blockControlsContext = _ref5.blockControlsContext,
125
+ position = _ref5.position;
120
126
  var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
121
127
  var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
122
128
  if (!targetElementRoot) {
@@ -241,11 +247,11 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
241
247
  unbindTransitionEnd();
242
248
  };
243
249
  }, [editorView, measuredSurfaces]);
244
- return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref5) {
250
+ return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref6) {
245
251
  var _activeNode$handleOpt, _anchoredPlacements$g;
246
- var position = _ref5.position,
247
- source = _ref5.source,
248
- surfaceContext = _ref5.surfaceContext;
252
+ var position = _ref6.position,
253
+ source = _ref6.source,
254
+ surfaceContext = _ref6.surfaceContext;
249
255
  return /*#__PURE__*/React.createElement(BlockControlsLeftSurface, {
250
256
  api: api,
251
257
  components: components,
@@ -18,12 +18,13 @@ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-s
18
18
  import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
19
19
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
20
20
  import { BlockControlsRightSurface } from './block-controls-right-surface';
21
- import { createBlockControlsSurfaceContext, createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
21
+ import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
22
22
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
23
- import { getNodeContentElement, hasInnerContentContainer } from './utils/get-node-content-element';
23
+ import { getNodeContentElement } from './utils/get-node-content-element';
24
24
  import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
25
25
  import { hasSurfaceControls } from './utils/has-surface-controls';
26
26
  var EMPTY_SURFACE_POSITIONS = [];
27
+ var EMPTY_SURFACE_ANCHORS = new Map();
27
28
  var EMPTY_SURFACE_COMPONENTS = [];
28
29
  var EMPTY_MEASURED_SURFACES = [];
29
30
  /**
@@ -40,22 +41,30 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
40
41
  var api = _ref.api,
41
42
  editorView = _ref.editorView;
42
43
  var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
43
- var _states$blockControls, _states$blockControls2, _states$blockControls3;
44
+ var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$blockControls4, _states$blockControls5, _states$blockControls6;
44
45
  return {
45
46
  activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
46
- 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
47
+ surfaceActiveNodes: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.surfaceActiveNodes,
48
+ surfaceAnchors: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.surfaceAnchors) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : EMPTY_SURFACE_ANCHORS,
49
+ surfaceNodePositions: (_states$blockControls5 = (_states$blockControls6 = states.blockControlsState) === null || _states$blockControls6 === void 0 ? void 0 : _states$blockControls6.surfaceNodePositions) !== null && _states$blockControls5 !== void 0 ? _states$blockControls5 : EMPTY_SURFACE_POSITIONS
47
50
  };
48
51
  }),
49
52
  activeNode = _useSharedPluginState.activeNode,
53
+ surfaceAnchors = _useSharedPluginState.surfaceAnchors,
54
+ surfaceActiveNodes = _useSharedPluginState.surfaceActiveNodes,
50
55
  surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
51
56
  var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
52
57
  var targets = useMemo(function () {
53
- return getBlockControlsSurfaceTargets(activeNode, surfaceNodePositions);
58
+ var candidates = new Set(surfaceNodePositions);
59
+ return getBlockControlsSurfaceTargets(activeNode, surfaceNodePositions).filter(function (_ref2) {
60
+ var position = _ref2.position;
61
+ return candidates.has(position);
62
+ });
54
63
  }, [activeNode, surfaceNodePositions]);
55
64
  var surfaces = useMemo(function () {
56
65
  return targets.flatMap(function (target) {
57
- var _api$core;
58
- var context = target.source === 'stored' ? createBlockControlsSurfaceContextForPosition(editorView.state, target.position, activeNode) : createBlockControlsSurfaceContext(editorView, activeNode, target.source);
66
+ var _surfaceActiveNodes$g;
67
+ var context = createBlockControlsSurfaceContextForPosition(editorView.state, target.position, (_surfaceActiveNodes$g = surfaceActiveNodes === null || surfaceActiveNodes === void 0 ? void 0 : surfaceActiveNodes.get(target.position)) !== null && _surfaceActiveNodes$g !== void 0 ? _surfaceActiveNodes$g : activeNode);
59
68
  if (!context) {
60
69
  return [];
61
70
  }
@@ -63,32 +72,29 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
63
72
  if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
64
73
  return [];
65
74
  }
66
- // Resolved here rather than in the measurement effect so an anchored surface is placed
67
- // in the same render that creates it — it never needs a second pass to find its node.
68
- //
69
- // At the moment, we only expect top-level nodes to have persistent controls.
70
- // See surfaceAnchorStyles in global-styles
71
- var anchorName = isCSSAnchorSupported() && context.targetNode.parentType === 'doc' && !hasInnerContentContainer(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
75
+ // The cache supplies the same anchor names used by ProseMirror decorations.
76
+ var anchorName = isCSSAnchorSupported() ? surfaceAnchors.get(target.position) : undefined;
72
77
  return [_objectSpread(_objectSpread({}, target), {}, {
73
78
  anchorName: anchorName,
74
79
  blockControlsContext: context,
75
80
  surfaceContext: surfaceContext
76
81
  })];
77
82
  });
78
- }, [activeNode, api, components, editorView, targets]);
83
+ }, [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
79
84
  /**
80
85
  * Placements that need no measuring, so they are derived rather than stored: every inset is an
81
86
  * `anchor()` the browser re-resolves on every layout change.
82
87
  */
83
88
  var anchoredPlacements = useMemo(function () {
84
- return new Map(surfaces.flatMap(function (_ref2) {
85
- var anchorName = _ref2.anchorName,
86
- blockControlsContext = _ref2.blockControlsContext,
87
- position = _ref2.position;
89
+ return new Map(surfaces.flatMap(function (_ref3) {
90
+ var anchorName = _ref3.anchorName,
91
+ blockControlsContext = _ref3.blockControlsContext,
92
+ position = _ref3.position;
88
93
  return anchorName ? [[position, getAnchoredSurfacePlacement({
89
94
  anchorName: anchorName,
90
95
  nodeType: blockControlsContext.targetNode.type.name,
91
96
  nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
97
+ layout: blockControlsContext.targetNode.node.attrs.layout,
92
98
  parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
93
99
  side: 'right'
94
100
  })]] : [];
@@ -102,8 +108,8 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
102
108
  // changed dependency each time and re-run it for nothing, which is the cost the anchored path
103
109
  // exists to avoid.
104
110
  var measuredSurfaces = useMemo(function () {
105
- var measured = surfaces.filter(function (_ref3) {
106
- var anchorName = _ref3.anchorName;
111
+ var measured = surfaces.filter(function (_ref4) {
112
+ var anchorName = _ref4.anchorName;
107
113
  return !anchorName;
108
114
  });
109
115
  return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
@@ -123,9 +129,9 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
123
129
  });
124
130
  return;
125
131
  }
126
- var measurementTargets = measuredSurfaces.flatMap(function (_ref4) {
127
- var blockControlsContext = _ref4.blockControlsContext,
128
- position = _ref4.position;
132
+ var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
133
+ var blockControlsContext = _ref5.blockControlsContext,
134
+ position = _ref5.position;
129
135
  var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
130
136
  var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
131
137
  if (!targetElementRoot) {
@@ -250,11 +256,11 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
250
256
  unbindTransitionEnd();
251
257
  };
252
258
  }, [editorView, measuredSurfaces]);
253
- return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref5) {
259
+ return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref6) {
254
260
  var _activeNode$handleOpt, _anchoredPlacements$g;
255
- var position = _ref5.position,
256
- source = _ref5.source,
257
- surfaceContext = _ref5.surfaceContext;
261
+ var position = _ref6.position,
262
+ source = _ref6.source,
263
+ surfaceContext = _ref6.surfaceContext;
258
264
  return /*#__PURE__*/React.createElement(BlockControlsRightSurface, {
259
265
  api: api,
260
266
  components: components,
@@ -42,6 +42,7 @@ export var createBlockControlsSurfaceContextForPosition = function createBlockCo
42
42
  var rootPos = activeNode ? (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos : targetPos;
43
43
  var rootNodeContext = (_getNodeContext = getNodeContext(state, rootPos)) !== null && _getNodeContext !== void 0 ? _getNodeContext : targetNodeContext;
44
44
  return {
45
+ activeControlKey: activeNode === null || activeNode === void 0 ? void 0 : activeNode.controlKey,
45
46
  activeNode: activeNode && activeNodeContext ? _objectSpread(_objectSpread({}, activeNodeContext), {}, {
46
47
  rootPos: rootPos,
47
48
  rootType: {