@atlaskit/editor-plugin-block-controls 31.0.4 → 31.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/blockControlsPlugin.js +6 -2
  3. package/dist/cjs/pm-plugins/sparse-gutter-hover.js +23 -2
  4. package/dist/cjs/pm-plugins/sparse-surfaces-view.js +10 -1
  5. package/dist/cjs/surface-lifecycle/are-block-controls-surface-contexts-equal.js +39 -0
  6. package/dist/cjs/surface-lifecycle/block-controls-surface-descriptors.js +83 -0
  7. package/dist/cjs/surface-lifecycle/block-controls-surface-with-cls-fix.js +46 -0
  8. package/dist/cjs/surface-lifecycle/block-controls-surfaces.js +80 -0
  9. package/dist/cjs/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +287 -0
  10. package/dist/cjs/surface-lifecycle/surface-lifecycle.js +206 -0
  11. package/dist/cjs/surface-lifecycle/use-measured-surface-placements.js +199 -0
  12. package/dist/cjs/ui/block-controls-left-surface.compiled.css +1 -0
  13. package/dist/cjs/ui/block-controls-left-surface.js +61 -16
  14. package/dist/cjs/ui/block-controls-right-surface.compiled.css +1 -0
  15. package/dist/cjs/ui/block-controls-right-surface.js +48 -14
  16. package/dist/es2019/blockControlsPlugin.js +6 -2
  17. package/dist/es2019/pm-plugins/sparse-gutter-hover.js +23 -2
  18. package/dist/es2019/pm-plugins/sparse-surfaces-view.js +10 -1
  19. package/dist/es2019/surface-lifecycle/are-block-controls-surface-contexts-equal.js +31 -0
  20. package/dist/es2019/surface-lifecycle/block-controls-surface-descriptors.js +67 -0
  21. package/dist/es2019/surface-lifecycle/block-controls-surface-with-cls-fix.js +41 -0
  22. package/dist/es2019/surface-lifecycle/block-controls-surfaces.js +69 -0
  23. package/dist/es2019/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +256 -0
  24. package/dist/es2019/surface-lifecycle/surface-lifecycle.js +125 -0
  25. package/dist/es2019/surface-lifecycle/use-measured-surface-placements.js +163 -0
  26. package/dist/es2019/ui/block-controls-left-surface.compiled.css +1 -0
  27. package/dist/es2019/ui/block-controls-left-surface.js +56 -10
  28. package/dist/es2019/ui/block-controls-right-surface.compiled.css +1 -0
  29. package/dist/es2019/ui/block-controls-right-surface.js +43 -8
  30. package/dist/esm/blockControlsPlugin.js +6 -2
  31. package/dist/esm/pm-plugins/sparse-gutter-hover.js +23 -2
  32. package/dist/esm/pm-plugins/sparse-surfaces-view.js +10 -1
  33. package/dist/esm/surface-lifecycle/are-block-controls-surface-contexts-equal.js +33 -0
  34. package/dist/esm/surface-lifecycle/block-controls-surface-descriptors.js +76 -0
  35. package/dist/esm/surface-lifecycle/block-controls-surface-with-cls-fix.js +39 -0
  36. package/dist/esm/surface-lifecycle/block-controls-surfaces.js +72 -0
  37. package/dist/esm/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +280 -0
  38. package/dist/esm/surface-lifecycle/surface-lifecycle.js +199 -0
  39. package/dist/esm/surface-lifecycle/use-measured-surface-placements.js +192 -0
  40. package/dist/esm/ui/block-controls-left-surface.compiled.css +1 -0
  41. package/dist/esm/ui/block-controls-left-surface.js +61 -16
  42. package/dist/esm/ui/block-controls-right-surface.compiled.css +1 -0
  43. package/dist/esm/ui/block-controls-right-surface.js +48 -14
  44. package/dist/types/pm-plugins/sparse-surfaces-view.d.ts +2 -1
  45. package/dist/types/surface-lifecycle/are-block-controls-surface-contexts-equal.d.ts +19 -0
  46. package/dist/types/surface-lifecycle/block-controls-surface-descriptors.d.ts +28 -0
  47. package/dist/types/surface-lifecycle/block-controls-surface-with-cls-fix.d.ts +26 -0
  48. package/dist/types/surface-lifecycle/block-controls-surfaces.d.ts +10 -0
  49. package/dist/types/surface-lifecycle/sparse-surfaces-view-with-lifecycle.d.ts +21 -0
  50. package/dist/types/surface-lifecycle/surface-lifecycle.d.ts +46 -0
  51. package/dist/types/surface-lifecycle/use-measured-surface-placements.d.ts +12 -0
  52. package/package.json +4 -5
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useMeasuredSurfacePlacements = exports.getSurfaceKey = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _react = require("react");
12
+ var _bindEventListener = require("bind-event-listener");
13
+ var _browserApis = require("@atlaskit/browser-apis");
14
+ var _nativeAnchor = require("@atlaskit/editor-common/styles/native-anchor");
15
+ var _decorationsCommon = require("../pm-plugins/decorations-common");
16
+ var _getNodeContentElement = require("../ui/utils/get-node-content-element");
17
+ var _getSurfacePlacement = require("../ui/utils/get-surface-placement");
18
+ 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; }
19
+ 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; }
20
+ 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; } } }; }
21
+ 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; } }
22
+ 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; }
23
+ var EMPTY_PLACEMENTS = new Map();
24
+ var getSurfaceKey = exports.getSurfaceKey = function getSurfaceKey(side, descriptor) {
25
+ return "".concat(side, ":").concat(descriptor.anchorName);
26
+ };
27
+
28
+ /**
29
+ * Measures surface placements from DOM geometry when the browser cannot position surfaces with CSS
30
+ * anchors. Returns an empty map and binds nothing when anchors are supported. Both sides share one
31
+ * set of listeners, and measuring reruns only when a side's descriptor list changes, which the
32
+ * descriptor resolver keeps stable across unrelated updates.
33
+ */
34
+ var useMeasuredSurfacePlacements = exports.useMeasuredSurfacePlacements = function useMeasuredSurfacePlacements(editorView, left, right) {
35
+ var _useState = (0, _react.useState)(EMPTY_PLACEMENTS),
36
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
+ placements = _useState2[0],
38
+ setPlacements = _useState2[1];
39
+ var animationFrameRef = (0, _react.useRef)(undefined);
40
+ (0, _react.useLayoutEffect)(function () {
41
+ var _getDocument;
42
+ // Anchor support is fixed for the session, so anchored surfaces never set measured state.
43
+ if ((0, _nativeAnchor.isCSSAnchorSupported)()) {
44
+ return;
45
+ }
46
+ var descriptors = [].concat((0, _toConsumableArray2.default)((left !== null && left !== void 0 ? left : []).map(function (descriptor) {
47
+ return {
48
+ descriptor: descriptor,
49
+ side: 'left'
50
+ };
51
+ })), (0, _toConsumableArray2.default)((right !== null && right !== void 0 ? right : []).map(function (descriptor) {
52
+ return {
53
+ descriptor: descriptor,
54
+ side: 'right'
55
+ };
56
+ })));
57
+ if (descriptors.length === 0) {
58
+ // Clear only when there is something to clear, so an empty map does not commit a render.
59
+ setPlacements(function (previous) {
60
+ return previous.size > 0 ? EMPTY_PLACEMENTS : previous;
61
+ });
62
+ return;
63
+ }
64
+ var measurementTargets = descriptors.flatMap(function (_ref) {
65
+ var descriptor = _ref.descriptor,
66
+ side = _ref.side;
67
+ var blockControlsContext = descriptor.blockControlsContext;
68
+ var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
69
+ var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
70
+ if (!targetElementRoot) {
71
+ return [];
72
+ }
73
+ return [{
74
+ descriptor: descriptor,
75
+ side: side,
76
+ targetElement: (0, _getNodeContentElement.getNodeContentElement)(targetElementRoot, blockControlsContext.targetNode.type.name),
77
+ targetElementRoot: targetElementRoot
78
+ }];
79
+ });
80
+ var offsetParent = editorView.dom.offsetParent;
81
+ var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
82
+ var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
83
+ var updatePositions = function updatePositions() {
84
+ var _scrollingOffsetParen, _scrollingOffsetParen2;
85
+ animationFrameRef.current = undefined;
86
+ var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
87
+ var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
88
+ var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
89
+ var nextPlacements = new Map();
90
+ var _iterator = _createForOfIteratorHelper(measurementTargets),
91
+ _step;
92
+ try {
93
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
94
+ var _targetElementRoot$ge, _offsetParentRect$lef;
95
+ var _step$value = _step.value,
96
+ descriptor = _step$value.descriptor,
97
+ side = _step$value.side,
98
+ targetElement = _step$value.targetElement,
99
+ targetElementRoot = _step$value.targetElementRoot;
100
+ if (!targetElementRoot.isConnected || !targetElement.isConnected) {
101
+ continue;
102
+ }
103
+ var blockControlsContext = descriptor.blockControlsContext,
104
+ isTopLevel = descriptor.isTopLevel;
105
+ var options = {
106
+ layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
107
+ nodeRect: targetElement.getBoundingClientRect(),
108
+ nodeType: blockControlsContext.targetNode.type.name,
109
+ nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
110
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
111
+ };
112
+ var placement = side === 'left' && isTopLevel ? (0, _getSurfacePlacement.getLeftGutterSurfacePlacement)(_objectSpread(_objectSpread({}, options), {}, {
113
+ leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
114
+ })) : (0, _getSurfacePlacement.getSurfacePlacement)(_objectSpread(_objectSpread({}, options), {}, {
115
+ side: side
116
+ }));
117
+ nextPlacements.set(getSurfaceKey(side, descriptor), (0, _getSurfacePlacement.toMeasuredSurfaceWrapperPlacement)((0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
118
+ offsetParentRect: offsetParentRect,
119
+ offsetParentScrollLeft: offsetParentScrollLeft,
120
+ offsetParentScrollTop: offsetParentScrollTop,
121
+ placement: placement
122
+ })));
123
+ }
124
+ } catch (err) {
125
+ _iterator.e(err);
126
+ } finally {
127
+ _iterator.f();
128
+ }
129
+ setPlacements(nextPlacements);
130
+ };
131
+ var schedulePositionUpdate = function schedulePositionUpdate() {
132
+ if (animationFrameRef.current === undefined) {
133
+ animationFrameRef.current = requestAnimationFrame(updatePositions);
134
+ }
135
+ };
136
+ updatePositions();
137
+ var resizeObserver = new ResizeObserver(schedulePositionUpdate);
138
+ var observedElements = new Set([editorView.dom]);
139
+ var _iterator2 = _createForOfIteratorHelper(measurementTargets),
140
+ _step2;
141
+ try {
142
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
143
+ var targetElement = _step2.value.targetElement;
144
+ observedElements.add(targetElement);
145
+ }
146
+ } catch (err) {
147
+ _iterator2.e(err);
148
+ } finally {
149
+ _iterator2.f();
150
+ }
151
+ if (offsetParent instanceof HTMLElement) {
152
+ observedElements.add(offsetParent);
153
+ }
154
+ observedElements.forEach(function (element) {
155
+ return resizeObserver.observe(element);
156
+ });
157
+ var unbindWindowResize = (0, _bindEventListener.bind)(window, {
158
+ type: 'resize',
159
+ listener: schedulePositionUpdate
160
+ });
161
+ var unbindWindowScroll = (0, _bindEventListener.bind)(window, {
162
+ type: 'scroll',
163
+ listener: schedulePositionUpdate,
164
+ options: {
165
+ capture: true,
166
+ passive: true
167
+ }
168
+ });
169
+ var visualViewport = window.visualViewport;
170
+ var unbindVisualViewportResize = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
171
+ type: 'resize',
172
+ listener: schedulePositionUpdate
173
+ }) : undefined;
174
+ var unbindVisualViewportScroll = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
175
+ type: 'scroll',
176
+ listener: schedulePositionUpdate
177
+ }) : undefined;
178
+ var unbindTransitionEnd = (0, _bindEventListener.bind)(editorView.dom, {
179
+ type: 'transitionend',
180
+ listener: schedulePositionUpdate,
181
+ options: {
182
+ capture: true
183
+ }
184
+ });
185
+ return function () {
186
+ if (animationFrameRef.current !== undefined) {
187
+ cancelAnimationFrame(animationFrameRef.current);
188
+ animationFrameRef.current = undefined;
189
+ }
190
+ resizeObserver.disconnect();
191
+ unbindWindowResize();
192
+ unbindWindowScroll();
193
+ unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
194
+ unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
195
+ unbindTransitionEnd();
196
+ };
197
+ }, [editorView, left, right]);
198
+ return placements;
199
+ };
@@ -5,6 +5,7 @@
5
5
  ._1e0c1txw{display:flex}
6
6
  ._1f38ffwv{container-name:block-controls-left-gutter}
7
7
  ._1pbyb4wl{z-index:100}
8
+ ._3um015vq{visibility:hidden}
8
9
  ._4cvr1h6o{align-items:center}
9
10
  ._7cca15wb{container-type:inline-size}
10
11
  ._kqsw1if8{position:sticky}
@@ -13,14 +13,25 @@ var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/blo
13
13
  var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
14
14
  var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
15
15
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
16
+ var _blockControlsSurfaceWithClsFix = require("../surface-lifecycle/block-controls-surface-with-cls-fix");
16
17
  var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
17
18
  var _blockControlsSurfaceContext = require("./block-controls-surface-context");
18
19
  var _visibilityContainer = require("./visibility-container");
20
+ var leftSurfaceHiddenWrapperStyles = null;
19
21
  var leftSurfaceOuterStyles = null;
20
22
  var leftSurfaceGutterStyles = {
21
23
  container: "_1f38ffwv _7cca15wb _lcxvglyw",
22
24
  row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
23
25
  };
26
+
27
+ // Nested surfaces (e.g. a table inside an expand) can span the target node's full height and sit
28
+ // over controls rendered in the node's own gutter, such as the table row insert button. Let pointer
29
+ // events pass through the wrapper and row so those controls stay interactive, matching the top-level
30
+ // gutter behaviour without applying its container query sizing.
31
+ var nestedSurfacePointerEventsStyles = {
32
+ container: "_lcxvglyw",
33
+ row: "_lcxvglyw _w1y61wug"
34
+ };
24
35
  var leftSurfaceRowStyles = null;
25
36
 
26
37
  // Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
@@ -49,6 +60,7 @@ var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_
49
60
  useCssStyles = _useBlockControlsVisi.useCssStyles;
50
61
  var isSticky = placement.isSticky;
51
62
  var isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
63
+ var shouldPassThroughNestedPointerEvents = !isTopLevel && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_nested_left_surface_pointer_fix');
52
64
  return /*#__PURE__*/_react.default.createElement("div", {
53
65
  "data-editor-block-controls-surface": true,
54
66
  "data-editor-block-controls-side": "left",
@@ -56,9 +68,9 @@ var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_
56
68
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved per target node, from its runtime DOM geometry or from its CSS anchor.
57
69
  ,
58
70
  style: placement.style,
59
- className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
71
+ className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.container])
60
72
  }, /*#__PURE__*/_react.default.createElement("div", {
61
- className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
73
+ className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.row, isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
62
74
  }, /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceComponents.BlockControlsVisibilityProvider, {
63
75
  shouldHideHoverControls: shouldHideHoverControls,
64
76
  useCssStyles: useCssStyles
@@ -68,24 +80,57 @@ var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_
68
80
  surfaceContext: surfaceContext
69
81
  }))));
70
82
  };
71
-
72
- /** Renders one left block-controls surface at a document position. */
73
- var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref2) {
74
- var api = _ref2.api,
75
- components = _ref2.components,
76
- forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
83
+ var BlockControlsLeftSurfaceWrapper = function BlockControlsLeftSurfaceWrapper(_ref2) {
84
+ var children = _ref2.children,
77
85
  placement = _ref2.placement,
78
86
  source = _ref2.source,
79
87
  surfaceContext = _ref2.surfaceContext;
88
+ var blockControlsContext = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
89
+ var isSticky = placement.isSticky;
90
+ var isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
91
+ return /*#__PURE__*/_react.default.createElement("div", {
92
+ "data-editor-block-controls-surface": true,
93
+ "data-editor-block-controls-side": "left",
94
+ "data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
95
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved per target node, from its runtime DOM geometry or from its CSS anchor.
96
+ ,
97
+ style: placement.style,
98
+ className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container, "_3um015vq"])
99
+ }, /*#__PURE__*/_react.default.createElement("div", {
100
+ className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
101
+ }, children));
102
+ };
103
+
104
+ /** Renders one left block-controls surface at a document position. */
105
+ var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref3) {
106
+ var api = _ref3.api,
107
+ components = _ref3.components,
108
+ forceVisibleOnMouseOut = _ref3.forceVisibleOnMouseOut,
109
+ placement = _ref3.placement,
110
+ source = _ref3.source,
111
+ surfaceContext = _ref3.surfaceContext;
80
112
  if (!placement) {
81
113
  return null;
82
114
  }
83
- return /*#__PURE__*/_react.default.createElement(BlockControlsLeftSurfaceContent, {
84
- api: api,
85
- components: components,
86
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
87
- placement: placement,
88
- source: source,
89
- surfaceContext: surfaceContext
90
- });
115
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_cls_fix')) {
116
+ return /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceWithClsFix.BlockControlsSurfaceWithClsFix, {
117
+ side: "left",
118
+ SurfaceWrapper: BlockControlsLeftSurfaceWrapper,
119
+ api: api,
120
+ components: components,
121
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
122
+ placement: placement,
123
+ source: source,
124
+ surfaceContext: surfaceContext
125
+ });
126
+ } else {
127
+ return /*#__PURE__*/_react.default.createElement(BlockControlsLeftSurfaceContent, {
128
+ api: api,
129
+ components: components,
130
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
131
+ placement: placement,
132
+ source: source,
133
+ surfaceContext: surfaceContext
134
+ });
135
+ }
91
136
  };
@@ -3,6 +3,7 @@
3
3
  ._17c61i8t{position-visibility:anchors-valid}
4
4
  ._1e0c1txw{display:flex}
5
5
  ._1pbyb4wl{z-index:100}
6
+ ._3um015vq{visibility:hidden}
6
7
  ._4cvr1h6o{align-items:center}
7
8
  ._kqsw1if8{position:sticky}
8
9
  ._kqswstnw{position:absolute}
@@ -13,8 +13,10 @@ var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/blo
13
13
  var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
14
14
  var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
15
15
  var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
16
+ var _blockControlsSurfaceWithClsFix = require("../surface-lifecycle/block-controls-surface-with-cls-fix");
16
17
  var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
17
18
  var _visibilityContainer = require("./visibility-container");
19
+ var rightSurfaceHiddenWrapperStyles = null;
18
20
  var rightSurfaceOuterStyles = null;
19
21
  var rightSurfaceRowStyles = null;
20
22
 
@@ -61,24 +63,56 @@ var BlockControlsRightSurfaceContent = function BlockControlsRightSurfaceContent
61
63
  surfaceContext: surfaceContext
62
64
  }))));
63
65
  };
64
-
65
- /** Renders one right block-controls surface at a document position. */
66
- var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref2) {
67
- var api = _ref2.api,
68
- components = _ref2.components,
69
- forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
66
+ var BlockControlsRightSurfaceWrapper = function BlockControlsRightSurfaceWrapper(_ref2) {
67
+ var children = _ref2.children,
70
68
  placement = _ref2.placement,
71
69
  source = _ref2.source,
72
70
  surfaceContext = _ref2.surfaceContext;
71
+ var blockControlsContext = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
72
+ var isSticky = placement.isSticky;
73
+ return /*#__PURE__*/_react.default.createElement("div", {
74
+ "data-editor-block-controls-surface": true,
75
+ "data-editor-block-controls-side": "right",
76
+ "data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
77
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved per target node, from its runtime DOM geometry or from its CSS anchor.
78
+ ,
79
+ style: placement.style,
80
+ className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl", "_3um015vq"])
81
+ }, /*#__PURE__*/_react.default.createElement("div", {
82
+ className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
83
+ }, children));
84
+ };
85
+
86
+ /** Renders one right block-controls surface at a document position. */
87
+ var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref3) {
88
+ var api = _ref3.api,
89
+ components = _ref3.components,
90
+ forceVisibleOnMouseOut = _ref3.forceVisibleOnMouseOut,
91
+ placement = _ref3.placement,
92
+ source = _ref3.source,
93
+ surfaceContext = _ref3.surfaceContext;
73
94
  if (!placement) {
74
95
  return null;
75
96
  }
76
- return /*#__PURE__*/_react.default.createElement(BlockControlsRightSurfaceContent, {
77
- api: api,
78
- components: components,
79
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
80
- placement: placement,
81
- source: source,
82
- surfaceContext: surfaceContext
83
- });
97
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_controls_cls_fix')) {
98
+ return /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceWithClsFix.BlockControlsSurfaceWithClsFix, {
99
+ side: "right",
100
+ SurfaceWrapper: BlockControlsRightSurfaceWrapper,
101
+ api: api,
102
+ components: components,
103
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
104
+ placement: placement,
105
+ source: source,
106
+ surfaceContext: surfaceContext
107
+ });
108
+ } else {
109
+ return /*#__PURE__*/_react.default.createElement(BlockControlsRightSurfaceContent, {
110
+ api: api,
111
+ components: components,
112
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
113
+ placement: placement,
114
+ source: source,
115
+ surfaceContext: surfaceContext
116
+ });
117
+ }
84
118
  };
@@ -23,6 +23,7 @@ import { createSelectionPreservationPlugin } from './pm-plugins/selection-preser
23
23
  import { createSparseSurfacesPlugin, sparseSurfacesKey } from './pm-plugins/sparse-surfaces';
24
24
  import { expandAndUpdateSelection } from './pm-plugins/utils/expand-and-update-selection';
25
25
  import { selectNode } from './pm-plugins/utils/getSelection';
26
+ import { CommittedBlockControlsSurfaces } from './surface-lifecycle/block-controls-surfaces';
26
27
  import { BlockControlsLeftSurfaces } from './ui/block-controls-left-surfaces';
27
28
  import { BlockControlsRightSurfaces } from './ui/block-controls-right-surfaces';
28
29
  import { getBlockControlsSurfaceDragHandleComponents } from './ui/block-controls-surface-drag-handle-registration';
@@ -495,13 +496,16 @@ export const blockControlsPlugin = ({
495
496
  api: api
496
497
  }), registryBlockControlsEnabled && editorView && api ? /*#__PURE__*/React.createElement(SurfaceEditorViewContext.Provider, {
497
498
  value: editorView
498
- }, /*#__PURE__*/React.createElement(BlockControlsLeftSurfaces, {
499
+ }, isExperimentEnabled('platform_editor_block_controls_cls_fix') ? /*#__PURE__*/React.createElement(CommittedBlockControlsSurfaces, {
500
+ api: api,
501
+ editorView: editorView
502
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BlockControlsLeftSurfaces, {
499
503
  api: api,
500
504
  editorView: editorView
501
505
  }), /*#__PURE__*/React.createElement(BlockControlsRightSurfaces, {
502
506
  api: api,
503
507
  editorView: editorView
504
- })) : null);
508
+ }))) : null);
505
509
  }
506
510
  };
507
511
  };
@@ -1,6 +1,7 @@
1
1
  import { bind } from 'bind-event-listener';
2
2
  import { DRAG_HANDLE_WIDTH } from '@atlaskit/editor-common/styles/drag-handle';
3
3
  import { akEditorFullPageNarrowBreakout, akEditorGutterPaddingDynamic, akEditorGutterPaddingReduced } from '@atlaskit/editor-shared-styles/constants';
4
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
4
5
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
5
6
  import { BLOCK_CONTROLS_SURFACE_SELECTOR, DRAG_HANDLE_MAX_WIDTH_PLUS_GAP } from '../ui/consts';
6
7
  import { handleSparseHoverTarget, isSparseHoverSuppressed } from './handle-sparse-hover-target';
@@ -294,8 +295,28 @@ export const bindSparseGutterHover = ({
294
295
  passive: true
295
296
  }
296
297
  });
297
- const unbindMouseOver = bindMouseListener('mouseover', onMouseOver);
298
- const unbindMouseMove = bindMouseListener('mousemove', onMouseMove);
298
+ let unbindMouseOver;
299
+ let unbindMouseMove;
300
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
301
+ // Match the legacy ignoreRestingPointerHover guard until the pointer first moves.
302
+ let pointerHasMoved = false;
303
+ unbindMouseOver = bindMouseListener('mouseover', event => {
304
+ if (!pointerHasMoved) {
305
+ return;
306
+ }
307
+ onMouseOver(event);
308
+ });
309
+ unbindMouseMove = bindMouseListener('mousemove', event => {
310
+ if (!pointerHasMoved) {
311
+ pointerHasMoved = true;
312
+ onMouseOver(event);
313
+ }
314
+ onMouseMove(event);
315
+ });
316
+ } else {
317
+ unbindMouseOver = bindMouseListener('mouseover', onMouseOver);
318
+ unbindMouseMove = bindMouseListener('mousemove', onMouseMove);
319
+ }
299
320
  return () => {
300
321
  unbindMouseOver();
301
322
  unbindMouseMove();
@@ -1,13 +1,15 @@
1
1
  import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
2
2
  import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor-provider';
3
3
  import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
4
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
5
+ import { createSparseSurfacesViewWithLifecycle } from '../surface-lifecycle/sparse-surfaces-view-with-lifecycle';
4
6
  import { createSurfaceAnchorDecorations } from './decorations-surface-anchor';
5
7
  import { key as blockControlsKey } from './main';
6
8
  import { bindSparseGutterHover } from './sparse-gutter-hover';
7
9
  import { reconcileSparseSurfaceCandidates } from './utils/sparse-surface-candidates';
8
10
  import { observeSurfaceViewport } from './utils/surface-viewport';
9
11
  const haveAnchorPositionsChanged = (positions, anchors) => positions.length !== anchors.size || positions.some(position => !anchors.has(position));
10
- export const createSparseSurfacesView = ({
12
+ const createLegacySparseSurfacesView = ({
11
13
  api,
12
14
  pluginKey,
13
15
  view
@@ -124,4 +126,11 @@ export const createSparseSurfacesView = ({
124
126
  unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
125
127
  }
126
128
  };
129
+ };
130
+ export const createSparseSurfacesView = options => {
131
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
132
+ return createSparseSurfacesViewWithLifecycle(options);
133
+ } else {
134
+ return createLegacySparseSurfacesView(options);
135
+ }
127
136
  };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Resolves to `T` only when `Compared` lists every key of `T`. Adding a field to the context types
3
+ * turns the comparators' parameters into `never`, so callers stop compiling until the comparison
4
+ * handles the new field.
5
+ */
6
+
7
+ /**
8
+ * `controlVisibility` is derived from component predicates after the context is created, never by
9
+ * `createBlockControlsSurfaceContextForPosition`, so it is not compared.
10
+ */
11
+
12
+ /**
13
+ * ProseMirror preserves immutable node objects for unchanged content, so node identity detects
14
+ * content changes without a deep comparison. Position and ancestry must also match: an unchanged
15
+ * node can move or gain a different parent, which changes the context supplied to its controls.
16
+ * The ancestor comparison is O(depth); it never walks document children or reads DOM geometry.
17
+ */
18
+ const areNodeContextsEqual = (a, b) => {
19
+ var _a$rootType, _b$rootType;
20
+ return a === b || Boolean(a && b && a.node === b.node && a.pos === b.pos && a.depth === b.depth && a.parentType === b.parentType && a.type.name === b.type.name && a.rootPos === b.rootPos && ((_a$rootType = a.rootType) === null || _a$rootType === void 0 ? void 0 : _a$rootType.name) === ((_b$rootType = b.rootType) === null || _b$rootType === void 0 ? void 0 : _b$rootType.name) && a.ancestors.length === b.ancestors.length && a.ancestors.every((ancestor, index) => {
21
+ const other = b.ancestors[index];
22
+ return ancestor.pos === other.pos && ancestor.depth === other.depth && ancestor.type.name === other.type.name;
23
+ }));
24
+ };
25
+
26
+ /**
27
+ * Compares contexts produced by `createBlockControlsSurfaceContextForPosition`. Includes root and
28
+ * active-node context because controls can depend on more than the target itself, for example a
29
+ * changed containing block or a different active control.
30
+ */
31
+ export const areBlockControlsSurfaceContextsEqual = (a, b) => a.activeControlKey === b.activeControlKey && areNodeContextsEqual(a.targetNode, b.targetNode) && areNodeContextsEqual(a.rootNode, b.rootNode) && areNodeContextsEqual(a.activeNode, b.activeNode);
@@ -0,0 +1,67 @@
1
+ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
2
+ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
3
+ import { getBlockControlsLeftSurfaceComponents, getBlockControlsRightSurfaceComponents } from '../ui/block-controls-surface-components';
4
+ import { createBlockControlsSurfaceContextForPosition } from '../ui/block-controls-surface-context';
5
+ import { areBlockControlsSurfaceContextsEqual } from './are-block-controls-surface-contexts-equal';
6
+ /**
7
+ * Resolves each target into the controls, context and anchor information needed to render a surface.
8
+ * When a previous descriptor still matches, reuse it without rerunning component visibility
9
+ * predicates. The caller must omit `previous` when registry or external state changes invalidate
10
+ * those results. Targets without an anchor, a valid context or renderable components are omitted.
11
+ */
12
+ const createDescriptors = ({
13
+ activeNode,
14
+ components,
15
+ state,
16
+ surfaceActiveNodes,
17
+ surfaceAnchors,
18
+ targets
19
+ }, resolveComponents, previous) => targets.flatMap(target => {
20
+ var _surfaceActiveNodes$g;
21
+ const anchorName = surfaceAnchors.get(target.position);
22
+ if (!anchorName) {
23
+ return [];
24
+ }
25
+ const context = createBlockControlsSurfaceContextForPosition(state, target.position, (_surfaceActiveNodes$g = surfaceActiveNodes === null || surfaceActiveNodes === void 0 ? void 0 : surfaceActiveNodes.get(target.position)) !== null && _surfaceActiveNodes$g !== void 0 ? _surfaceActiveNodes$g : activeNode);
26
+ if (!context) {
27
+ return [];
28
+ }
29
+ const cached = previous === null || previous === void 0 ? void 0 : previous.get(anchorName);
30
+ if (cached && cached.position === target.position && cached.source === target.source && areBlockControlsSurfaceContextsEqual(cached.blockControlsContext, context)) {
31
+ return [cached];
32
+ }
33
+ const surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
34
+ const surfaceComponents = resolveComponents(components, surfaceContext);
35
+ if (!surfaceComponents) {
36
+ return [];
37
+ }
38
+ return [{
39
+ ...target,
40
+ anchorName,
41
+ blockControlsContext: context,
42
+ isTopLevel: context.targetNode.parentType === 'doc',
43
+ surfaceComponents,
44
+ surfaceContext
45
+ }];
46
+ });
47
+
48
+ /**
49
+ * Creates a cache owned by one editor view and surface side on the gated CLS fix path.
50
+ * Unchanged descriptors let memoized surfaces skip rendering; preserving the array reference also
51
+ * lets SurfaceLifecycle skip publishing an otherwise unchanged snapshot. Registry changes or
52
+ * explicit invalidation force predicates to run again, even if the document context is unchanged.
53
+ */
54
+ export const createSurfaceDescriptorResolver = side => {
55
+ let descriptors = [];
56
+ let components = [];
57
+ return (input, invalidated) => {
58
+ const registryUnchanged = components.length === input.components.length && components.every((component, index) => component === input.components[index]);
59
+ const previous = !invalidated && registryUnchanged ? new Map(descriptors.map(descriptor => [descriptor.anchorName, descriptor])) : undefined;
60
+ const next = createDescriptors(input, side === 'left' ? getBlockControlsLeftSurfaceComponents : getBlockControlsRightSurfaceComponents, previous);
61
+ components = input.components;
62
+ if (next.length !== descriptors.length || next.some((descriptor, index) => descriptor !== descriptors[index])) {
63
+ descriptors = next;
64
+ }
65
+ return descriptors;
66
+ };
67
+ };