@atlaskit/editor-plugin-block-controls 20.1.2 → 20.1.4

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 +18 -0
  2. package/dist/cjs/pm-plugins/selection-preservation/pm-plugin.js +17 -34
  3. package/dist/cjs/ui/block-controls-left-surface.compiled.css +7 -1
  4. package/dist/cjs/ui/block-controls-left-surface.js +41 -27
  5. package/dist/cjs/ui/block-controls-left-surfaces.js +32 -12
  6. package/dist/cjs/ui/block-controls-right-surface.js +32 -24
  7. package/dist/cjs/ui/block-controls-right-surfaces.js +6 -4
  8. package/dist/cjs/ui/block-controls-surface-components.js +142 -0
  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/pm-plugins/selection-preservation/pm-plugin.js +17 -34
  12. package/dist/es2019/ui/block-controls-left-surface.compiled.css +7 -1
  13. package/dist/es2019/ui/block-controls-left-surface.js +44 -29
  14. package/dist/es2019/ui/block-controls-left-surfaces.js +41 -16
  15. package/dist/es2019/ui/block-controls-right-surface.js +35 -26
  16. package/dist/es2019/ui/block-controls-right-surfaces.js +6 -4
  17. package/dist/es2019/ui/block-controls-surface-components.js +129 -0
  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/pm-plugins/selection-preservation/pm-plugin.js +17 -34
  21. package/dist/esm/ui/block-controls-left-surface.compiled.css +7 -1
  22. package/dist/esm/ui/block-controls-left-surface.js +43 -29
  23. package/dist/esm/ui/block-controls-left-surfaces.js +33 -13
  24. package/dist/esm/ui/block-controls-right-surface.js +34 -26
  25. package/dist/esm/ui/block-controls-right-surfaces.js +6 -4
  26. package/dist/esm/ui/block-controls-surface-components.js +133 -0
  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 +3 -3
@@ -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
  var leftSurfaceOuterStyles = null;
13
+ var leftSurfaceGutterStyles = {
14
+ container: "_1f38ffwv _7cca15wb _lcxvglyw",
15
+ row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
16
+ };
13
17
  var leftSurfaceRowStyles = null;
14
18
 
15
19
  // Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
@@ -17,23 +21,24 @@ var 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
  var leftSurfaceStickyStyles = null;
20
- /** Renders one left block-controls surface at a document position. */
21
- export var BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
24
+ var BlockControlsLeftSurfaceContent = function BlockControlsLeftSurfaceContent(_ref) {
22
25
  var api = _ref.api,
23
26
  components = _ref.components,
24
27
  forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
25
28
  placement = _ref.placement,
26
29
  source = _ref.source,
27
30
  surfaceContext = _ref.surfaceContext;
28
- if (!placement || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
29
- return null;
30
- }
31
- var _partitionComponentsB = partitionComponentsByPersistence(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext),
32
- hoverOnlyComponents = _partitionComponentsB.hoverOnlyComponents,
33
- persistentComponents = _partitionComponentsB.persistentComponents;
34
- var willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
35
- var willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
31
+ var blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
32
+ var controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor'));
33
+ var _useBlockControlsVisi = useBlockControlsVisibility({
34
+ api: api,
35
+ controlSide: controlSide,
36
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut
37
+ }),
38
+ shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
39
+ useCssStyles = _useBlockControlsVisi.useCssStyles;
36
40
  var isSticky = placement.isSticky;
41
+ var isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
37
42
  return /*#__PURE__*/React.createElement("div", {
38
43
  "data-editor-block-controls-surface": true,
39
44
  "data-editor-block-controls-side": "left",
@@ -41,27 +46,36 @@ export var BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
41
46
  // 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.
42
47
  ,
43
48
  style: placement.style,
44
- className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
49
+ className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
45
50
  }, /*#__PURE__*/React.createElement("div", {
46
- className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
47
- }, willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
48
- api: api,
49
- controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
50
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
51
- shouldUseDisplayContents: true
51
+ className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc"])
52
+ }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
53
+ shouldHideHoverControls: shouldHideHoverControls,
54
+ useCssStyles: useCssStyles
52
55
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
53
- components: hoverOnlyComponents,
56
+ components: components,
54
57
  surface: BLOCK_CONTROLS_LEFT_SURFACE,
55
58
  surfaceContext: surfaceContext
56
- })), willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
59
+ }))));
60
+ };
61
+
62
+ /** Renders one left block-controls surface at a document position. */
63
+ export var BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref2) {
64
+ var api = _ref2.api,
65
+ components = _ref2.components,
66
+ forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
67
+ placement = _ref2.placement,
68
+ source = _ref2.source,
69
+ surfaceContext = _ref2.surfaceContext;
70
+ if (!placement) {
71
+ return null;
72
+ }
73
+ return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
57
74
  api: api,
58
- controlSide: getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')),
75
+ components: components,
59
76
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
60
- isPersistent: true,
61
- shouldUseDisplayContents: true
62
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
63
- components: persistentComponents,
64
- surface: BLOCK_CONTROLS_LEFT_SURFACE,
77
+ placement: placement,
78
+ source: source,
65
79
  surfaceContext: surfaceContext
66
- }))));
80
+ });
67
81
  };
@@ -15,14 +15,13 @@ import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-contr
15
15
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
16
16
  import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles';
17
17
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
18
- import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
19
18
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
20
19
  import { BlockControlsLeftSurface } from './block-controls-left-surface';
20
+ import { getBlockControlsLeftSurfaceComponents } from './block-controls-surface-components';
21
21
  import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
22
22
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
23
23
  import { getNodeContentElement } from './utils/get-node-content-element';
24
- import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
25
- import { hasSurfaceControls } from './utils/has-surface-controls';
24
+ import { getAbsoluteSurfacePlacement, getAnchoredLeftGutterSurfacePlacement, getAnchoredSurfacePlacement, getLeftGutterSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
26
25
  var EMPTY_SURFACE_POSITIONS = [];
27
26
  var EMPTY_SURFACE_ANCHORS = new Map();
28
27
  var EMPTY_SURFACE_COMPONENTS = [];
@@ -60,14 +59,20 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
60
59
  return [];
61
60
  }
62
61
  var surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
63
- if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
62
+ var surfaceComponents = getBlockControlsLeftSurfaceComponents(components, surfaceContext);
63
+ if (!surfaceComponents) {
64
64
  return [];
65
65
  }
66
66
  // The cache supplies the same anchor names used by ProseMirror decorations.
67
67
  var anchorName = isCSSAnchorSupported() ? surfaceAnchors.get(target.position) : undefined;
68
+ // Top-level controls can respond to the available left gutter without the surface
69
+ // host knowing which controls are registered or how they adapt.
70
+ var isTopLevel = context.targetNode.parentType === 'doc';
68
71
  return [_objectSpread(_objectSpread({}, target), {}, {
69
72
  anchorName: anchorName,
70
73
  blockControlsContext: context,
74
+ isTopLevel: isTopLevel,
75
+ surfaceComponents: surfaceComponents,
71
76
  surfaceContext: surfaceContext
72
77
  })];
73
78
  });
@@ -80,15 +85,22 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
80
85
  return new Map(surfaces.flatMap(function (_ref3) {
81
86
  var anchorName = _ref3.anchorName,
82
87
  blockControlsContext = _ref3.blockControlsContext,
88
+ isTopLevel = _ref3.isTopLevel,
83
89
  position = _ref3.position;
84
- return anchorName ? [[position, getAnchoredSurfacePlacement({
90
+ if (!anchorName) {
91
+ return [];
92
+ }
93
+ var options = {
85
94
  anchorName: anchorName,
95
+ layout: blockControlsContext.targetNode.node.attrs.layout,
86
96
  nodeType: blockControlsContext.targetNode.type.name,
87
97
  nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
88
- layout: blockControlsContext.targetNode.node.attrs.layout,
89
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
98
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
99
+ };
100
+ var placement = isTopLevel ? getAnchoredLeftGutterSurfacePlacement(options) : getAnchoredSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
90
101
  side: 'left'
91
- })]] : [];
102
+ }));
103
+ return [[position, placement]];
92
104
  }));
93
105
  }, [surfaces]);
94
106
  // Only the surfaces that still need measuring drive the effect below, so a document of anchored
@@ -122,6 +134,7 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
122
134
  }
123
135
  var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
124
136
  var blockControlsContext = _ref5.blockControlsContext,
137
+ isTopLevel = _ref5.isTopLevel,
125
138
  position = _ref5.position;
126
139
  var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
127
140
  var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
@@ -130,6 +143,7 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
130
143
  }
131
144
  return [{
132
145
  blockControlsContext: blockControlsContext,
146
+ isTopLevel: isTopLevel,
133
147
  position: position,
134
148
  targetElement: getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name),
135
149
  targetElementRoot: targetElementRoot
@@ -149,23 +163,28 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
149
163
  _step;
150
164
  try {
151
165
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
152
- var _targetElementRoot$ge;
166
+ var _targetElementRoot$ge, _offsetParentRect$lef;
153
167
  var _step$value = _step.value,
154
168
  blockControlsContext = _step$value.blockControlsContext,
169
+ isTopLevel = _step$value.isTopLevel,
155
170
  position = _step$value.position,
156
171
  targetElement = _step$value.targetElement,
157
172
  targetElementRoot = _step$value.targetElementRoot;
158
173
  if (!targetElementRoot.isConnected || !targetElement.isConnected) {
159
174
  continue;
160
175
  }
161
- var placement = getSurfacePlacement({
176
+ var options = {
162
177
  layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
163
178
  nodeRect: targetElement.getBoundingClientRect(),
164
179
  nodeType: blockControlsContext.targetNode.type.name,
165
180
  nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
166
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
181
+ parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
182
+ };
183
+ var placement = isTopLevel ? getLeftGutterSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
184
+ leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
185
+ })) : getSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
167
186
  side: 'left'
168
- });
187
+ }));
169
188
  nextPlacements.set(position, toMeasuredSurfaceWrapperPlacement(getAbsoluteSurfacePlacement({
170
189
  offsetParentRect: offsetParentRect,
171
190
  offsetParentScrollLeft: offsetParentScrollLeft,
@@ -251,10 +270,11 @@ export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref)
251
270
  var _activeNode$handleOpt, _anchoredPlacements$g;
252
271
  var position = _ref6.position,
253
272
  source = _ref6.source,
273
+ surfaceComponents = _ref6.surfaceComponents,
254
274
  surfaceContext = _ref6.surfaceContext;
255
275
  return /*#__PURE__*/React.createElement(BlockControlsLeftSurface, {
256
276
  api: api,
257
- components: components,
277
+ components: surfaceComponents,
258
278
  forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
259
279
  key: position,
260
280
  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
  var rightSurfaceOuterStyles = null;
10
10
  var rightSurfaceRowStyles = null;
11
11
 
@@ -14,22 +14,20 @@ var 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
  var rightSurfaceStickyStyles = null;
17
- /** Renders one right block-controls surface at a document position. */
18
- export var BlockControlsRightSurface = function BlockControlsRightSurface(_ref) {
17
+ var BlockControlsRightSurfaceContent = function BlockControlsRightSurfaceContent(_ref) {
19
18
  var api = _ref.api,
20
19
  components = _ref.components,
21
20
  forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
22
21
  placement = _ref.placement,
23
22
  source = _ref.source,
24
23
  surfaceContext = _ref.surfaceContext;
25
- if (!placement || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
26
- return null;
27
- }
28
- var _partitionComponentsB = partitionComponentsByPersistence(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext),
29
- hoverOnlyComponents = _partitionComponentsB.hoverOnlyComponents,
30
- persistentComponents = _partitionComponentsB.persistentComponents;
31
- var willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
32
- var willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
24
+ var _useBlockControlsVisi = useBlockControlsVisibility({
25
+ api: api,
26
+ controlSide: 'right',
27
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut
28
+ }),
29
+ shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
30
+ useCssStyles = _useBlockControlsVisi.useCssStyles;
33
31
  var isSticky = placement.isSticky;
34
32
  return /*#__PURE__*/React.createElement("div", {
35
33
  "data-editor-block-controls-surface": true,
@@ -41,23 +39,33 @@ export var BlockControlsRightSurface = function BlockControlsRightSurface(_ref)
41
39
  className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
42
40
  }, /*#__PURE__*/React.createElement("div", {
43
41
  className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
44
- }, willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
45
- api: api,
46
- controlSide: "right",
47
- isPersistent: true,
48
- shouldUseDisplayContents: true
42
+ }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
43
+ shouldHideHoverControls: shouldHideHoverControls,
44
+ useCssStyles: useCssStyles
49
45
  }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
50
- components: persistentComponents,
46
+ components: components,
51
47
  surface: BLOCK_CONTROLS_RIGHT_SURFACE,
52
48
  surfaceContext: surfaceContext
53
- })), willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
49
+ }))));
50
+ };
51
+
52
+ /** Renders one right block-controls surface at a document position. */
53
+ export var BlockControlsRightSurface = function BlockControlsRightSurface(_ref2) {
54
+ var api = _ref2.api,
55
+ components = _ref2.components,
56
+ forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
57
+ placement = _ref2.placement,
58
+ source = _ref2.source,
59
+ surfaceContext = _ref2.surfaceContext;
60
+ if (!placement) {
61
+ return null;
62
+ }
63
+ return /*#__PURE__*/React.createElement(BlockControlsRightSurfaceContent, {
54
64
  api: api,
55
- controlSide: "right",
65
+ components: components,
56
66
  forceVisibleOnMouseOut: forceVisibleOnMouseOut,
57
- shouldUseDisplayContents: true
58
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
59
- components: hoverOnlyComponents,
60
- surface: BLOCK_CONTROLS_RIGHT_SURFACE,
67
+ placement: placement,
68
+ source: source,
61
69
  surfaceContext: surfaceContext
62
- }))));
70
+ });
63
71
  };
@@ -15,14 +15,13 @@ import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-cont
15
15
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
16
16
  import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles';
17
17
  import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
18
- import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
19
18
  import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
20
19
  import { BlockControlsRightSurface } from './block-controls-right-surface';
20
+ import { getBlockControlsRightSurfaceComponents } from './block-controls-surface-components';
21
21
  import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
22
22
  import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
23
23
  import { getNodeContentElement } from './utils/get-node-content-element';
24
24
  import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
25
- import { hasSurfaceControls } from './utils/has-surface-controls';
26
25
  var EMPTY_SURFACE_POSITIONS = [];
27
26
  var EMPTY_SURFACE_ANCHORS = new Map();
28
27
  var EMPTY_SURFACE_COMPONENTS = [];
@@ -69,7 +68,8 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
69
68
  return [];
70
69
  }
71
70
  var surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
72
- if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
71
+ var surfaceComponents = getBlockControlsRightSurfaceComponents(components, surfaceContext);
72
+ if (!surfaceComponents) {
73
73
  return [];
74
74
  }
75
75
  // The cache supplies the same anchor names used by ProseMirror decorations.
@@ -77,6 +77,7 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
77
77
  return [_objectSpread(_objectSpread({}, target), {}, {
78
78
  anchorName: anchorName,
79
79
  blockControlsContext: context,
80
+ surfaceComponents: surfaceComponents,
80
81
  surfaceContext: surfaceContext
81
82
  })];
82
83
  });
@@ -260,10 +261,11 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
260
261
  var _activeNode$handleOpt, _anchoredPlacements$g;
261
262
  var position = _ref6.position,
262
263
  source = _ref6.source,
264
+ surfaceComponents = _ref6.surfaceComponents,
263
265
  surfaceContext = _ref6.surfaceContext;
264
266
  return /*#__PURE__*/React.createElement(BlockControlsRightSurface, {
265
267
  api: api,
266
- components: components,
268
+ components: surfaceComponents,
267
269
  forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
268
270
  key: position,
269
271
  placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
@@ -0,0 +1,133 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
+ var _excluded = ["isHidden"];
5
+ 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; }
6
+ 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; }
7
+ import React, { createContext, useContext, useMemo } from 'react';
8
+ import { BLOCK_CONTROLS_LEFT_GROUP, BLOCK_CONTROLS_LEFT_SECTION, BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_GROUP, BLOCK_CONTROLS_RIGHT_SECTION, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
9
+ import { getComponentIdentity, resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
10
+ import { partitionComponentsByPersistence } from './utils/partition-components-by-persistence';
11
+ import { VisibilityWrapper } from './visibility-container';
12
+ var BlockControlsVisibilityContext = /*#__PURE__*/createContext({
13
+ shouldHideHoverControls: false,
14
+ useCssStyles: false
15
+ });
16
+ var BlockControlItem = function BlockControlItem(_ref) {
17
+ var children = _ref.children;
18
+ return /*#__PURE__*/React.createElement("div", {
19
+ "data-editor-block-control-item": true
20
+ }, children);
21
+ };
22
+ var HoverBlockControlItem = function HoverBlockControlItem(_ref2) {
23
+ var children = _ref2.children;
24
+ var _useContext = useContext(BlockControlsVisibilityContext),
25
+ shouldHideHoverControls = _useContext.shouldHideHoverControls,
26
+ useCssStyles = _useContext.useCssStyles;
27
+ return /*#__PURE__*/React.createElement(BlockControlItem, null, /*#__PURE__*/React.createElement(VisibilityWrapper, {
28
+ shouldHide: shouldHideHoverControls,
29
+ useCssStyles: useCssStyles
30
+ }, children));
31
+ };
32
+ var PersistentBlockControlItem = function PersistentBlockControlItem(_ref3) {
33
+ var children = _ref3.children;
34
+ var _useContext2 = useContext(BlockControlsVisibilityContext),
35
+ useCssStyles = _useContext2.useCssStyles;
36
+ return /*#__PURE__*/React.createElement(BlockControlItem, null, /*#__PURE__*/React.createElement(VisibilityWrapper, {
37
+ shouldHide: false,
38
+ useCssStyles: useCssStyles
39
+ }, children));
40
+ };
41
+ export var BlockControlsVisibilityProvider = function BlockControlsVisibilityProvider(_ref4) {
42
+ var children = _ref4.children,
43
+ shouldHideHoverControls = _ref4.shouldHideHoverControls,
44
+ useCssStyles = _ref4.useCssStyles;
45
+ var value = useMemo(function () {
46
+ return {
47
+ shouldHideHoverControls: shouldHideHoverControls,
48
+ useCssStyles: useCssStyles
49
+ };
50
+ }, [shouldHideHoverControls, useCssStyles]);
51
+ return /*#__PURE__*/React.createElement(BlockControlsVisibilityContext.Provider, {
52
+ value: value
53
+ }, children);
54
+ };
55
+ var withoutVisibilityPredicate = function withoutVisibilityPredicate(component) {
56
+ var _isHidden = component.isHidden,
57
+ visibleComponent = _objectWithoutProperties(component, _excluded);
58
+ return visibleComponent;
59
+ };
60
+
61
+ /**
62
+ * Replaces the shared surface group with one stable wrapper group per visible control. The wrappers
63
+ * inherit each control's rank, so SurfaceRenderer keeps the registry order without re-evaluating
64
+ * the controls' visibility predicates.
65
+ */
66
+ var getBlockControlsSurfaceComponents = function getBlockControlsSurfaceComponents(components, _ref5, surfaceContext) {
67
+ var _resolvedSurface$chil;
68
+ var group = _ref5.group,
69
+ section = _ref5.section,
70
+ surface = _ref5.surface;
71
+ var resolvedSurface = resolveSurface(components, surface);
72
+ var groupIdentity = getComponentIdentity(group);
73
+ var controls = (_resolvedSurface$chil = resolvedSurface.childrenMap.get(groupIdentity)) !== null && _resolvedSurface$chil !== void 0 ? _resolvedSurface$chil : [];
74
+ var visibleControls = controls.filter(function (control) {
75
+ var _control$isHidden, _control$isHidden2;
76
+ return !((_control$isHidden = (_control$isHidden2 = control.isHidden) === null || _control$isHidden2 === void 0 ? void 0 : _control$isHidden2.call(control, {
77
+ surfaceContext: surfaceContext
78
+ })) !== null && _control$isHidden !== void 0 ? _control$isHidden : false);
79
+ });
80
+ if (!resolvedSurface.root || visibleControls.length === 0) {
81
+ return undefined;
82
+ }
83
+ var controlIdentities = new Set(controls.map(getComponentIdentity));
84
+ var visibleControlIdentities = new Set(visibleControls.map(getComponentIdentity));
85
+ var _partitionComponentsB = partitionComponentsByPersistence(resolvedSurface.components.filter(function (component) {
86
+ var identity = getComponentIdentity(component);
87
+ return !controlIdentities.has(identity) || visibleControlIdentities.has(identity);
88
+ }), surface, surfaceContext),
89
+ persistentComponents = _partitionComponentsB.persistentComponents;
90
+ var persistentIdentities = new Set(persistentComponents.map(getComponentIdentity));
91
+ var structuralComponents = resolvedSurface.components.filter(function (component) {
92
+ var identity = getComponentIdentity(component);
93
+ return identity !== groupIdentity && !controlIdentities.has(identity);
94
+ }).map(withoutVisibilityPredicate);
95
+ var wrappedControls = visibleControls.flatMap(function (control) {
96
+ var _control$parents$find, _control$parents;
97
+ var identity = getComponentIdentity(control);
98
+ var rank = (_control$parents$find = (_control$parents = control.parents) === null || _control$parents === void 0 || (_control$parents = _control$parents.find(function (parent) {
99
+ return getComponentIdentity(parent) === groupIdentity;
100
+ })) === null || _control$parents === void 0 ? void 0 : _control$parents.rank) !== null && _control$parents$find !== void 0 ? _control$parents$find : 0;
101
+ var wrapper = {
102
+ component: persistentIdentities.has(identity) ? PersistentBlockControlItem : HoverBlockControlItem,
103
+ key: "block-control-item:".concat(identity),
104
+ parents: [_objectSpread(_objectSpread({}, section), {}, {
105
+ rank: rank
106
+ })],
107
+ type: 'group'
108
+ };
109
+ var visibleControl = _objectSpread(_objectSpread({}, withoutVisibilityPredicate(control)), {}, {
110
+ parents: [{
111
+ key: wrapper.key,
112
+ rank: 0,
113
+ type: wrapper.type
114
+ }]
115
+ });
116
+ return [wrapper, visibleControl];
117
+ });
118
+ return [].concat(_toConsumableArray(structuralComponents), _toConsumableArray(wrappedControls));
119
+ };
120
+ export var getBlockControlsLeftSurfaceComponents = function getBlockControlsLeftSurfaceComponents(components, surfaceContext) {
121
+ return getBlockControlsSurfaceComponents(components, {
122
+ group: BLOCK_CONTROLS_LEFT_GROUP,
123
+ section: BLOCK_CONTROLS_LEFT_SECTION,
124
+ surface: BLOCK_CONTROLS_LEFT_SURFACE
125
+ }, surfaceContext);
126
+ };
127
+ export var getBlockControlsRightSurfaceComponents = function getBlockControlsRightSurfaceComponents(components, surfaceContext) {
128
+ return getBlockControlsSurfaceComponents(components, {
129
+ group: BLOCK_CONTROLS_RIGHT_GROUP,
130
+ section: BLOCK_CONTROLS_RIGHT_SECTION,
131
+ surface: BLOCK_CONTROLS_RIGHT_SURFACE
132
+ }, surfaceContext);
133
+ };
@@ -1,4 +1,6 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
1
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ var _excluded = ["leftGutterBoundary"];
2
4
  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; }
3
5
  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; }
4
6
  import { shouldBeSticky } from '../../pm-plugins/utils/drag-handle-positions';
@@ -43,18 +45,40 @@ export var getSurfacePlacement = function getSurfacePlacement(_ref2) {
43
45
  var gap = dragHandleGap(nodeType, parentNodeType);
44
46
  var top = nodeRect.top + topPositionAdjustment(nodeTypeWithLevel, layout);
45
47
  var height = shouldBeSticky(nodeType) ? nodeRect.height : undefined;
46
- return side === 'right' ? {
47
- left: nodeRect.right + gap,
48
- top: top,
49
- transform: '',
50
- height: height
51
- } : {
48
+ if (side === 'right') {
49
+ return {
50
+ left: nodeRect.right + gap,
51
+ top: top,
52
+ transform: '',
53
+ height: height
54
+ };
55
+ }
56
+ return {
52
57
  left: nodeRect.left,
53
58
  top: top,
54
59
  transform: "translateX(calc(-100% - ".concat(gap, "px))"),
55
60
  height: height
56
61
  };
57
62
  };
63
+ /**
64
+ * Expands a measured left surface from the available gutter boundary to the target node.
65
+ */
66
+ export var getLeftGutterSurfacePlacement = function getLeftGutterSurfacePlacement(_ref3) {
67
+ var leftGutterBoundary = _ref3.leftGutterBoundary,
68
+ options = _objectWithoutProperties(_ref3, _excluded);
69
+ var placement = getSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
70
+ side: 'left'
71
+ }));
72
+ if (options.nodeType === 'layoutColumn') {
73
+ return placement;
74
+ }
75
+ var gap = dragHandleGap(options.nodeType, options.parentNodeType);
76
+ return _objectSpread(_objectSpread({}, placement), {}, {
77
+ left: leftGutterBoundary,
78
+ transform: '',
79
+ width: Math.max(0, options.nodeRect.left - leftGutterBoundary - gap)
80
+ });
81
+ };
58
82
 
59
83
  /**
60
84
  * The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
@@ -75,12 +99,14 @@ export var getSurfacePlacement = function getSurfacePlacement(_ref2) {
75
99
  export var toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapperPlacement(placement) {
76
100
  return {
77
101
  isSticky: placement.height !== undefined,
78
- style: {
102
+ style: _objectSpread({
79
103
  height: placement.height,
80
104
  left: placement.left,
81
105
  top: placement.top,
82
106
  transform: placement.transform
83
- }
107
+ }, placement.width !== undefined ? {
108
+ width: placement.width
109
+ } : {})
84
110
  };
85
111
  };
86
112
 
@@ -96,13 +122,13 @@ export var toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapper
96
122
  var INVALID_ANCHOR_OFFSCREEN_PX = 9999;
97
123
  var INVALID_ANCHOR_FALLBACK_TOP = "-".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
98
124
  var INVALID_ANCHOR_FALLBACK_BOTTOM = "".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
99
- export var getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref3) {
100
- var anchorName = _ref3.anchorName,
101
- layout = _ref3.layout,
102
- nodeType = _ref3.nodeType,
103
- nodeTypeWithLevel = _ref3.nodeTypeWithLevel,
104
- parentNodeType = _ref3.parentNodeType,
105
- side = _ref3.side;
125
+ export var getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref4) {
126
+ var anchorName = _ref4.anchorName,
127
+ layout = _ref4.layout,
128
+ nodeType = _ref4.nodeType,
129
+ nodeTypeWithLevel = _ref4.nodeTypeWithLevel,
130
+ parentNodeType = _ref4.parentNodeType,
131
+ side = _ref4.side;
106
132
  if (nodeType === 'layoutColumn') {
107
133
  // The column's horizontal midpoint, matching the measured `nodeRect.left + width / 2` and the
108
134
  // legacy drag handle's own layout-column formula. Side-independent.
@@ -132,4 +158,25 @@ export var getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_r
132
158
  transform: side === 'right' ? '' : "translateX(calc(-100% - ".concat(gap, "px))")
133
159
  })
134
160
  };
161
+ };
162
+ /**
163
+ * Expands an anchored left surface across the available gutter without runtime measurement.
164
+ */
165
+ export var getAnchoredLeftGutterSurfacePlacement = function getAnchoredLeftGutterSurfacePlacement(options) {
166
+ var placement = getAnchoredSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
167
+ side: 'left'
168
+ }));
169
+ if (options.nodeType === 'layoutColumn') {
170
+ return placement;
171
+ }
172
+ var gap = dragHandleGap(options.nodeType, options.parentNodeType);
173
+ return _objectSpread(_objectSpread({}, placement), {}, {
174
+ style: _objectSpread(_objectSpread({}, placement.style), {}, {
175
+ left: 0,
176
+ // In a `right` inset, `anchor(... left)` resolves from the containing block's right edge
177
+ // to the anchor's left edge. Adding the gap ends this wrapper just before the node.
178
+ right: "calc(anchor(".concat(options.anchorName, " left) + ").concat(gap, "px)"),
179
+ transform: ''
180
+ })
181
+ });
135
182
  };