@atlaskit/editor-plugin-block-controls 20.1.3 → 20.1.5

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 (32) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/ui/block-controls-left-surface.compiled.css +7 -1
  3. package/dist/cjs/ui/block-controls-left-surface.js +41 -27
  4. package/dist/cjs/ui/block-controls-left-surfaces.js +32 -12
  5. package/dist/cjs/ui/block-controls-right-surface.js +32 -24
  6. package/dist/cjs/ui/block-controls-right-surfaces.js +6 -4
  7. package/dist/cjs/ui/block-controls-surface-components.js +142 -0
  8. package/dist/cjs/ui/global-styles.js +9 -2
  9. package/dist/cjs/ui/utils/get-surface-placement.js +63 -16
  10. package/dist/cjs/ui/visibility-container.js +42 -7
  11. package/dist/es2019/ui/block-controls-left-surface.compiled.css +7 -1
  12. package/dist/es2019/ui/block-controls-left-surface.js +44 -29
  13. package/dist/es2019/ui/block-controls-left-surfaces.js +41 -16
  14. package/dist/es2019/ui/block-controls-right-surface.js +35 -26
  15. package/dist/es2019/ui/block-controls-right-surfaces.js +6 -4
  16. package/dist/es2019/ui/block-controls-surface-components.js +129 -0
  17. package/dist/es2019/ui/global-styles.js +9 -2
  18. package/dist/es2019/ui/utils/get-surface-placement.js +59 -7
  19. package/dist/es2019/ui/visibility-container.js +44 -6
  20. package/dist/esm/ui/block-controls-left-surface.compiled.css +7 -1
  21. package/dist/esm/ui/block-controls-left-surface.js +43 -29
  22. package/dist/esm/ui/block-controls-left-surfaces.js +33 -13
  23. package/dist/esm/ui/block-controls-right-surface.js +34 -26
  24. package/dist/esm/ui/block-controls-right-surfaces.js +6 -4
  25. package/dist/esm/ui/block-controls-surface-components.js +133 -0
  26. package/dist/esm/ui/global-styles.js +9 -2
  27. package/dist/esm/ui/utils/get-surface-placement.js +62 -15
  28. package/dist/esm/ui/visibility-container.js +41 -6
  29. package/dist/types/ui/block-controls-surface-components.d.ts +13 -0
  30. package/dist/types/ui/utils/get-surface-placement.d.ts +13 -0
  31. package/dist/types/ui/visibility-container.d.ts +14 -0
  32. package/package.json +2 -2
@@ -4,10 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.toMeasuredSurfaceWrapperPlacement = exports.getSurfacePlacement = exports.getAnchoredSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
7
+ exports.toMeasuredSurfaceWrapperPlacement = exports.getSurfacePlacement = exports.getLeftGutterSurfacePlacement = exports.getAnchoredSurfacePlacement = exports.getAnchoredLeftGutterSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
8
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _dragHandlePositions = require("../../pm-plugins/utils/drag-handle-positions");
10
11
  var _consts = require("../consts");
12
+ var _excluded = ["leftGutterBoundary"];
11
13
  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; }
12
14
  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; }
13
15
  var getAbsoluteSurfacePlacement = exports.getAbsoluteSurfacePlacement = function getAbsoluteSurfacePlacement(_ref) {
@@ -50,18 +52,40 @@ var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlace
50
52
  var gap = (0, _consts.dragHandleGap)(nodeType, parentNodeType);
51
53
  var top = nodeRect.top + (0, _consts.topPositionAdjustment)(nodeTypeWithLevel, layout);
52
54
  var height = (0, _dragHandlePositions.shouldBeSticky)(nodeType) ? nodeRect.height : undefined;
53
- return side === 'right' ? {
54
- left: nodeRect.right + gap,
55
- top: top,
56
- transform: '',
57
- height: height
58
- } : {
55
+ if (side === 'right') {
56
+ return {
57
+ left: nodeRect.right + gap,
58
+ top: top,
59
+ transform: '',
60
+ height: height
61
+ };
62
+ }
63
+ return {
59
64
  left: nodeRect.left,
60
65
  top: top,
61
66
  transform: "translateX(calc(-100% - ".concat(gap, "px))"),
62
67
  height: height
63
68
  };
64
69
  };
70
+ /**
71
+ * Expands a measured left surface from the available gutter boundary to the target node.
72
+ */
73
+ var getLeftGutterSurfacePlacement = exports.getLeftGutterSurfacePlacement = function getLeftGutterSurfacePlacement(_ref3) {
74
+ var leftGutterBoundary = _ref3.leftGutterBoundary,
75
+ options = (0, _objectWithoutProperties2.default)(_ref3, _excluded);
76
+ var placement = getSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
77
+ side: 'left'
78
+ }));
79
+ if (options.nodeType === 'layoutColumn') {
80
+ return placement;
81
+ }
82
+ var gap = (0, _consts.dragHandleGap)(options.nodeType, options.parentNodeType);
83
+ return _objectSpread(_objectSpread({}, placement), {}, {
84
+ left: leftGutterBoundary,
85
+ transform: '',
86
+ width: Math.max(0, options.nodeRect.left - leftGutterBoundary - gap)
87
+ });
88
+ };
65
89
 
66
90
  /**
67
91
  * The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
@@ -82,12 +106,14 @@ var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlace
82
106
  var toMeasuredSurfaceWrapperPlacement = exports.toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapperPlacement(placement) {
83
107
  return {
84
108
  isSticky: placement.height !== undefined,
85
- style: {
109
+ style: _objectSpread({
86
110
  height: placement.height,
87
111
  left: placement.left,
88
112
  top: placement.top,
89
113
  transform: placement.transform
90
- }
114
+ }, placement.width !== undefined ? {
115
+ width: placement.width
116
+ } : {})
91
117
  };
92
118
  };
93
119
 
@@ -103,13 +129,13 @@ var toMeasuredSurfaceWrapperPlacement = exports.toMeasuredSurfaceWrapperPlacemen
103
129
  var INVALID_ANCHOR_OFFSCREEN_PX = 9999;
104
130
  var INVALID_ANCHOR_FALLBACK_TOP = "-".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
105
131
  var INVALID_ANCHOR_FALLBACK_BOTTOM = "".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
106
- var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref3) {
107
- var anchorName = _ref3.anchorName,
108
- layout = _ref3.layout,
109
- nodeType = _ref3.nodeType,
110
- nodeTypeWithLevel = _ref3.nodeTypeWithLevel,
111
- parentNodeType = _ref3.parentNodeType,
112
- side = _ref3.side;
132
+ var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref4) {
133
+ var anchorName = _ref4.anchorName,
134
+ layout = _ref4.layout,
135
+ nodeType = _ref4.nodeType,
136
+ nodeTypeWithLevel = _ref4.nodeTypeWithLevel,
137
+ parentNodeType = _ref4.parentNodeType,
138
+ side = _ref4.side;
113
139
  if (nodeType === 'layoutColumn') {
114
140
  // The column's horizontal midpoint, matching the measured `nodeRect.left + width / 2` and the
115
141
  // legacy drag handle's own layout-column formula. Side-independent.
@@ -139,4 +165,25 @@ var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function
139
165
  transform: side === 'right' ? '' : "translateX(calc(-100% - ".concat(gap, "px))")
140
166
  })
141
167
  };
168
+ };
169
+ /**
170
+ * Expands an anchored left surface across the available gutter without runtime measurement.
171
+ */
172
+ var getAnchoredLeftGutterSurfacePlacement = exports.getAnchoredLeftGutterSurfacePlacement = function getAnchoredLeftGutterSurfacePlacement(options) {
173
+ var placement = getAnchoredSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
174
+ side: 'left'
175
+ }));
176
+ if (options.nodeType === 'layoutColumn') {
177
+ return placement;
178
+ }
179
+ var gap = (0, _consts.dragHandleGap)(options.nodeType, options.parentNodeType);
180
+ return _objectSpread(_objectSpread({}, placement), {}, {
181
+ style: _objectSpread(_objectSpread({}, placement.style), {}, {
182
+ left: 0,
183
+ // In a `right` inset, `anchor(... left)` resolves from the containing block's right edge
184
+ // to the anchor's left edge. Adding the gap ends this wrapper just before the node.
185
+ right: "calc(anchor(".concat(options.anchorName, " left) + ").concat(gap, "px)"),
186
+ transform: ''
187
+ })
188
+ });
142
189
  };
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.VisibilityContainer = void 0;
8
+ exports.useBlockControlsVisibility = exports.VisibilityWrapper = exports.VisibilityContainer = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
11
  var _react = _interopRequireWildcard(require("react"));
@@ -57,13 +57,16 @@ var hiddenStylesCSS = (0, _react2.css)({
57
57
  var displayContentsStylesCSS = (0, _react2.css)({
58
58
  display: 'contents'
59
59
  });
60
- var VisibilityContainer = exports.VisibilityContainer = function VisibilityContainer(_ref) {
60
+
61
+ /**
62
+ * Resolves visibility once so a surface can apply the same state to each rendered control without
63
+ * creating a plugin-state subscription and hide-delay timer for every control wrapper.
64
+ */
65
+ var useBlockControlsVisibility = exports.useBlockControlsVisibility = function useBlockControlsVisibility(_ref) {
61
66
  var api = _ref.api,
62
- children = _ref.children,
63
67
  controlSide = _ref.controlSide,
64
68
  forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
65
- isPersistent = _ref.isPersistent,
66
- shouldUseDisplayContents = _ref.shouldUseDisplayContents;
69
+ isPersistent = _ref.isPersistent;
67
70
  var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['typeAhead', 'blockControls', 'editorViewMode', 'userIntent', 'showDiff'], function (states) {
68
71
  var _states$typeAheadStat, _states$blockControls, _states$blockControls2, _states$blockControls3, _states$editorViewMod, _states$userIntentSta, _states$showDiffState, _states$blockControls4;
69
72
  return {
@@ -139,9 +142,20 @@ var VisibilityContainer = exports.VisibilityContainer = function VisibilityConta
139
142
  };
140
143
  }, [shouldHideImmediate, isRightControlViewMode]);
141
144
  var shouldHide = isRightControlViewMode ? delayedShouldHide : shouldHideImmediate;
142
- if ((0, _editorExperiment.editorExperiment)('platform_editor_preview_panel_responsiveness', true, {
145
+ var useCssStyles = (0, _editorExperiment.editorExperiment)('platform_editor_preview_panel_responsiveness', true, {
143
146
  exposure: true
144
- })) {
147
+ });
148
+ return {
149
+ shouldHide: shouldHide,
150
+ useCssStyles: useCssStyles
151
+ };
152
+ };
153
+ var VisibilityWrapper = exports.VisibilityWrapper = function VisibilityWrapper(_ref2) {
154
+ var children = _ref2.children,
155
+ shouldHide = _ref2.shouldHide,
156
+ shouldUseDisplayContents = _ref2.shouldUseDisplayContents,
157
+ useCssStyles = _ref2.useCssStyles;
158
+ if (useCssStyles) {
145
159
  return (0, _react2.jsx)("div", {
146
160
  css: [baseStylesCSS, shouldHide ? hiddenStylesCSS : visibleStylesCSS, shouldUseDisplayContents && displayContentsStylesCSS]
147
161
  }, children);
@@ -151,4 +165,25 @@ var VisibilityContainer = exports.VisibilityContainer = function VisibilityConta
151
165
  , {
152
166
  xcss: [baseStyles, shouldHide ? hiddenStyles : visibleStyles, shouldUseDisplayContents && displayContentsStyles]
153
167
  }, children);
168
+ };
169
+ var VisibilityContainer = exports.VisibilityContainer = function VisibilityContainer(_ref3) {
170
+ var api = _ref3.api,
171
+ children = _ref3.children,
172
+ controlSide = _ref3.controlSide,
173
+ forceVisibleOnMouseOut = _ref3.forceVisibleOnMouseOut,
174
+ isPersistent = _ref3.isPersistent,
175
+ shouldUseDisplayContents = _ref3.shouldUseDisplayContents;
176
+ var _useBlockControlsVisi = useBlockControlsVisibility({
177
+ api: api,
178
+ controlSide: controlSide,
179
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
180
+ isPersistent: isPersistent
181
+ }),
182
+ shouldHide = _useBlockControlsVisi.shouldHide,
183
+ useCssStyles = _useBlockControlsVisi.useCssStyles;
184
+ return (0, _react2.jsx)(VisibilityWrapper, {
185
+ shouldHide: shouldHide,
186
+ shouldUseDisplayContents: shouldUseDisplayContents,
187
+ useCssStyles: useCssStyles
188
+ }, children);
154
189
  };
@@ -1,7 +1,13 @@
1
1
  ._zulpv77o{gap:var(--ds-space-025,2px)}._154iu2gc{top:var(--ds-space-100,8px)}
2
2
  ._17c61i8t{position-visibility:anchors-valid}
3
+ ._1bahesu3{justify-content:flex-end}
3
4
  ._1e0c1txw{display:flex}
5
+ ._1f38ffwv{container-name:block-controls-left-gutter}
4
6
  ._1pbyb4wl{z-index:100}
5
7
  ._4cvr1h6o{align-items:center}
8
+ ._7cca15wb{container-type:inline-size}
6
9
  ._kqsw1if8{position:sticky}
7
- ._kqswstnw{position:absolute}
10
+ ._kqswstnw{position:absolute}
11
+ ._lcxvglyw{pointer-events:none}
12
+ ._w1y61wug>*{pointer-events:auto}
13
+ @container block-controls-left-gutter (max-width: 67px){._19vrglyw>[data-editor-block-control-item]:nth-last-child(n+3){display:none}}
@@ -4,12 +4,16 @@ import { ax, ix } from "@compiled/react/runtime";
4
4
  import React from 'react';
5
5
  import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
6
6
  import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
7
- import { SurfaceRenderer, willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
7
+ import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
8
8
  import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
9
+ import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
9
10
  import { getBlockControlsSurfaceControlSide } from './block-controls-surface-context';
10
- import { partitionComponentsByPersistence } from './utils/partition-components-by-persistence';
11
- import { VisibilityContainer } from './visibility-container';
11
+ import { useBlockControlsVisibility } from './visibility-container';
12
12
  const leftSurfaceOuterStyles = null;
13
+ const leftSurfaceGutterStyles = {
14
+ container: "_1f38ffwv _7cca15wb _lcxvglyw",
15
+ row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
16
+ };
13
17
  const leftSurfaceRowStyles = null;
14
18
 
15
19
  // Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
@@ -17,8 +21,7 @@ const leftSurfaceRowStyles = null;
17
21
  // can stick near the top of the viewport instead of scrolling off with the node's top edge.
18
22
  // Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
19
23
  const leftSurfaceStickyStyles = null;
20
- /** Renders one left block-controls surface at a document position. */
21
- export const BlockControlsLeftSurface = ({
24
+ const BlockControlsLeftSurfaceContent = ({
22
25
  api,
23
26
  components,
24
27
  forceVisibleOnMouseOut,
@@ -26,16 +29,18 @@ export const BlockControlsLeftSurface = ({
26
29
  source,
27
30
  surfaceContext
28
31
  }) => {
29
- if (!placement || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
30
- return null;
31
- }
32
+ const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
33
+ const controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor'));
32
34
  const {
33
- hoverOnlyComponents,
34
- persistentComponents
35
- } = partitionComponentsByPersistence(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
36
- const willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
37
- const willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
35
+ shouldHide: shouldHideHoverControls,
36
+ useCssStyles
37
+ } = useBlockControlsVisibility({
38
+ api,
39
+ controlSide,
40
+ forceVisibleOnMouseOut
41
+ });
38
42
  const isSticky = placement.isSticky;
43
+ const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
39
44
  return /*#__PURE__*/React.createElement("div", {
40
45
  "data-editor-block-controls-surface": true,
41
46
  "data-editor-block-controls-side": "left",
@@ -43,27 +48,37 @@ export const BlockControlsLeftSurface = ({
43
48
  // 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.
44
49
  ,
45
50
  style: placement.style,
46
- className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
51
+ className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
47
52
  }, /*#__PURE__*/React.createElement("div", {
48
- className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
49
- }, willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
50
- api: api,
51
- controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
52
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
53
- shouldUseDisplayContents: true
53
+ className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc"])
54
+ }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
55
+ shouldHideHoverControls: shouldHideHoverControls,
56
+ useCssStyles: useCssStyles
54
57
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
55
- components: hoverOnlyComponents,
58
+ components: components,
56
59
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
57
60
  surfaceContext: surfaceContext
58
- })), willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
61
+ }))));
62
+ };
63
+
64
+ /** Renders one left block-controls surface at a document position. */
65
+ export const BlockControlsLeftSurface = ({
66
+ api,
67
+ components,
68
+ forceVisibleOnMouseOut,
69
+ placement,
70
+ source,
71
+ surfaceContext
72
+ }) => {
73
+ if (!placement) {
74
+ return null;
75
+ }
76
+ return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
59
77
  api: api,
60
- controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
78
+ components: components,
61
79
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
62
- isPersistent: true,
63
- shouldUseDisplayContents: true
64
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
65
- components: persistentComponents,
66
- surface: BLOCK_CONTROLS_LEFT_SURFACE,
80
+ placement: placement,
81
+ source: source,
67
82
  surfaceContext: surfaceContext
68
- }))));
83
+ });
69
84
  };
@@ -8,14 +8,13 @@ import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-contr
8
8
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
9
9
  import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles';
10
10
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
11
- import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
12
11
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
13
12
  import { BlockControlsLeftSurface } from './block-controls-left-surface';
13
+ import { getBlockControlsLeftSurfaceComponents } from './block-controls-surface-components';
14
14
  import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
15
15
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
16
16
  import { getNodeContentElement } from './utils/get-node-content-element';
17
- import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
18
- import { hasSurfaceControls } from './utils/has-surface-controls';
17
+ import { getAbsoluteSurfacePlacement, getAnchoredLeftGutterSurfacePlacement, getAnchoredSurfacePlacement, getLeftGutterSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
19
18
  const EMPTY_SURFACE_POSITIONS = [];
20
19
  const EMPTY_SURFACE_ANCHORS = new Map();
21
20
  const EMPTY_SURFACE_COMPONENTS = [];
@@ -53,15 +52,21 @@ export const BlockControlsLeftSurfaces = ({
53
52
  return [];
54
53
  }
55
54
  const surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
56
- if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
55
+ const surfaceComponents = getBlockControlsLeftSurfaceComponents(components, surfaceContext);
56
+ if (!surfaceComponents) {
57
57
  return [];
58
58
  }
59
59
  // The cache supplies the same anchor names used by ProseMirror decorations.
60
60
  const anchorName = isCSSAnchorSupported() ? surfaceAnchors.get(target.position) : undefined;
61
+ // Top-level controls can respond to the available left gutter without the surface
62
+ // host knowing which controls are registered or how they adapt.
63
+ const isTopLevel = context.targetNode.parentType === 'doc';
61
64
  return [{
62
65
  ...target,
63
66
  anchorName,
64
67
  blockControlsContext: context,
68
+ isTopLevel,
69
+ surfaceComponents,
65
70
  surfaceContext
66
71
  }];
67
72
  }), [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
@@ -72,15 +77,25 @@ export const BlockControlsLeftSurfaces = ({
72
77
  const anchoredPlacements = useMemo(() => new Map(surfaces.flatMap(({
73
78
  anchorName,
74
79
  blockControlsContext,
80
+ isTopLevel,
75
81
  position
76
- }) => anchorName ? [[position, getAnchoredSurfacePlacement({
77
- anchorName,
78
- nodeType: blockControlsContext.targetNode.type.name,
79
- nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
80
- layout: blockControlsContext.targetNode.node.attrs.layout,
81
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
82
- side: 'left'
83
- })]] : [])), [surfaces]);
82
+ }) => {
83
+ if (!anchorName) {
84
+ return [];
85
+ }
86
+ const options = {
87
+ anchorName,
88
+ layout: blockControlsContext.targetNode.node.attrs.layout,
89
+ nodeType: blockControlsContext.targetNode.type.name,
90
+ nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
91
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
92
+ };
93
+ const placement = isTopLevel ? getAnchoredLeftGutterSurfacePlacement(options) : getAnchoredSurfacePlacement({
94
+ ...options,
95
+ side: 'left'
96
+ });
97
+ return [[position, placement]];
98
+ })), [surfaces]);
84
99
  // Only the surfaces that still need measuring drive the effect below, so a document of anchored
85
100
  // blocks binds no scroll or resize listeners at all.
86
101
  //
@@ -106,6 +121,7 @@ export const BlockControlsLeftSurfaces = ({
106
121
  }
107
122
  const measurementTargets = measuredSurfaces.flatMap(({
108
123
  blockControlsContext,
124
+ isTopLevel,
109
125
  position
110
126
  }) => {
111
127
  const targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
@@ -115,6 +131,7 @@ export const BlockControlsLeftSurfaces = ({
115
131
  }
116
132
  return [{
117
133
  blockControlsContext,
134
+ isTopLevel,
118
135
  position,
119
136
  targetElement: getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name),
120
137
  targetElementRoot
@@ -132,20 +149,27 @@ export const BlockControlsLeftSurfaces = ({
132
149
  const nextPlacements = new Map();
133
150
  for (const {
134
151
  blockControlsContext,
152
+ isTopLevel,
135
153
  position,
136
154
  targetElement,
137
155
  targetElementRoot
138
156
  } of measurementTargets) {
139
- var _targetElementRoot$ge;
157
+ var _targetElementRoot$ge, _offsetParentRect$lef;
140
158
  if (!targetElementRoot.isConnected || !targetElement.isConnected) {
141
159
  continue;
142
160
  }
143
- const placement = getSurfacePlacement({
161
+ const options = {
144
162
  layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
145
163
  nodeRect: targetElement.getBoundingClientRect(),
146
164
  nodeType: blockControlsContext.targetNode.type.name,
147
165
  nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
148
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
166
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
167
+ };
168
+ const placement = isTopLevel ? getLeftGutterSurfacePlacement({
169
+ ...options,
170
+ leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
171
+ }) : getSurfacePlacement({
172
+ ...options,
149
173
  side: 'left'
150
174
  });
151
175
  nextPlacements.set(position, toMeasuredSurfaceWrapperPlacement(getAbsoluteSurfacePlacement({
@@ -218,12 +242,13 @@ export const BlockControlsLeftSurfaces = ({
218
242
  return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(({
219
243
  position,
220
244
  source,
245
+ surfaceComponents,
221
246
  surfaceContext
222
247
  }) => {
223
248
  var _activeNode$handleOpt, _anchoredPlacements$g;
224
249
  return /*#__PURE__*/React.createElement(BlockControlsLeftSurface, {
225
250
  api: api,
226
- components: components,
251
+ components: surfaceComponents,
227
252
  forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 ? void 0 : (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
228
253
  key: position,
229
254
  placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
@@ -3,9 +3,9 @@ import "./block-controls-right-surface.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
4
  import React from 'react';
5
5
  import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
6
- import { SurfaceRenderer, willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
7
- import { partitionComponentsByPersistence } from './utils/partition-components-by-persistence';
8
- import { VisibilityContainer } from './visibility-container';
6
+ import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
7
+ import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
8
+ import { useBlockControlsVisibility } from './visibility-container';
9
9
  const rightSurfaceOuterStyles = null;
10
10
  const rightSurfaceRowStyles = null;
11
11
 
@@ -14,8 +14,7 @@ const rightSurfaceRowStyles = null;
14
14
  // can stick near the top of the viewport instead of scrolling off with the node's top edge.
15
15
  // Keep in sync with STICKY_CONTROLS_TOP_MARGIN in ./consts (must be a static literal here).
16
16
  const rightSurfaceStickyStyles = null;
17
- /** Renders one right block-controls surface at a document position. */
18
- export const BlockControlsRightSurface = ({
17
+ const BlockControlsRightSurfaceContent = ({
19
18
  api,
20
19
  components,
21
20
  forceVisibleOnMouseOut,
@@ -23,15 +22,14 @@ export const BlockControlsRightSurface = ({
23
22
  source,
24
23
  surfaceContext
25
24
  }) => {
26
- if (!placement || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
27
- return null;
28
- }
29
25
  const {
30
- hoverOnlyComponents,
31
- persistentComponents
32
- } = partitionComponentsByPersistence(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
33
- const willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
34
- const willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
26
+ shouldHide: shouldHideHoverControls,
27
+ useCssStyles
28
+ } = useBlockControlsVisibility({
29
+ api,
30
+ controlSide: 'right',
31
+ forceVisibleOnMouseOut
32
+ });
35
33
  const isSticky = placement.isSticky;
36
34
  return /*#__PURE__*/React.createElement("div", {
37
35
  "data-editor-block-controls-surface": true,
@@ -43,23 +41,34 @@ export const BlockControlsRightSurface = ({
43
41
  className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
44
42
  }, /*#__PURE__*/React.createElement("div", {
45
43
  className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
46
- }, willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
47
- api: api,
48
- controlSide: "right",
49
- isPersistent: true,
50
- shouldUseDisplayContents: true
44
+ }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
45
+ shouldHideHoverControls: shouldHideHoverControls,
46
+ useCssStyles: useCssStyles
51
47
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
52
- components: persistentComponents,
48
+ components: components,
53
49
  surface: BLOCK_CONTROLS_RIGHT_SURFACE,
54
50
  surfaceContext: surfaceContext
55
- })), willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
51
+ }))));
52
+ };
53
+
54
+ /** Renders one right block-controls surface at a document position. */
55
+ export const BlockControlsRightSurface = ({
56
+ api,
57
+ components,
58
+ forceVisibleOnMouseOut,
59
+ placement,
60
+ source,
61
+ surfaceContext
62
+ }) => {
63
+ if (!placement) {
64
+ return null;
65
+ }
66
+ return /*#__PURE__*/React.createElement(BlockControlsRightSurfaceContent, {
56
67
  api: api,
57
- controlSide: "right",
68
+ components: components,
58
69
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
59
- shouldUseDisplayContents: true
60
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
61
- components: hoverOnlyComponents,
62
- surface: BLOCK_CONTROLS_RIGHT_SURFACE,
70
+ placement: placement,
71
+ source: source,
63
72
  surfaceContext: surfaceContext
64
- }))));
73
+ });
65
74
  };
@@ -8,14 +8,13 @@ import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-cont
8
8
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
9
9
  import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles';
10
10
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
11
- import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
12
11
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
13
12
  import { BlockControlsRightSurface } from './block-controls-right-surface';
13
+ import { getBlockControlsRightSurfaceComponents } from './block-controls-surface-components';
14
14
  import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
15
15
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
16
16
  import { getNodeContentElement } from './utils/get-node-content-element';
17
17
  import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
18
- import { hasSurfaceControls } from './utils/has-surface-controls';
19
18
  const EMPTY_SURFACE_POSITIONS = [];
20
19
  const EMPTY_SURFACE_ANCHORS = new Map();
21
20
  const EMPTY_SURFACE_COMPONENTS = [];
@@ -62,7 +61,8 @@ export const BlockControlsRightSurfaces = ({
62
61
  return [];
63
62
  }
64
63
  const surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
65
- if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
64
+ const surfaceComponents = getBlockControlsRightSurfaceComponents(components, surfaceContext);
65
+ if (!surfaceComponents) {
66
66
  return [];
67
67
  }
68
68
  // The cache supplies the same anchor names used by ProseMirror decorations.
@@ -71,6 +71,7 @@ export const BlockControlsRightSurfaces = ({
71
71
  ...target,
72
72
  anchorName,
73
73
  blockControlsContext: context,
74
+ surfaceComponents,
74
75
  surfaceContext
75
76
  }];
76
77
  }), [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
@@ -227,12 +228,13 @@ export const BlockControlsRightSurfaces = ({
227
228
  return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(({
228
229
  position,
229
230
  source,
231
+ surfaceComponents,
230
232
  surfaceContext
231
233
  }) => {
232
234
  var _activeNode$handleOpt, _anchoredPlacements$g;
233
235
  return /*#__PURE__*/React.createElement(BlockControlsRightSurface, {
234
236
  api: api,
235
- components: components,
237
+ components: surfaceComponents,
236
238
  forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 ? void 0 : (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
237
239
  key: position,
238
240
  placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),