@atlaskit/editor-plugin-block-controls 31.0.5 → 31.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +22 -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 +2 -2
@@ -6,14 +6,25 @@ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls
6
6
  import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
7
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 { BlockControlsSurfaceWithClsFix } from '../surface-lifecycle/block-controls-surface-with-cls-fix';
9
10
  import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
10
11
  import { getBlockControlsSurfaceControlSide } from './block-controls-surface-context';
11
12
  import { useBlockControlsVisibility } from './visibility-container';
13
+ const leftSurfaceHiddenWrapperStyles = null;
12
14
  const leftSurfaceOuterStyles = null;
13
15
  const leftSurfaceGutterStyles = {
14
16
  container: "_1f38ffwv _7cca15wb _lcxvglyw",
15
17
  row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
16
18
  };
19
+
20
+ // Nested surfaces (e.g. a table inside an expand) can span the target node's full height and sit
21
+ // over controls rendered in the node's own gutter, such as the table row insert button. Let pointer
22
+ // events pass through the wrapper and row so those controls stay interactive, matching the top-level
23
+ // gutter behaviour without applying its container query sizing.
24
+ const nestedSurfacePointerEventsStyles = {
25
+ container: "_lcxvglyw",
26
+ row: "_lcxvglyw _w1y61wug"
27
+ };
17
28
  const leftSurfaceRowStyles = null;
18
29
 
19
30
  // Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
@@ -44,6 +55,7 @@ const BlockControlsLeftSurfaceContent = ({
44
55
  });
45
56
  const isSticky = placement.isSticky;
46
57
  const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
58
+ const shouldPassThroughNestedPointerEvents = !isTopLevel && isExperimentEnabled('platform_editor_nested_left_surface_pointer_fix');
47
59
  return /*#__PURE__*/React.createElement("div", {
48
60
  "data-editor-block-controls-surface": true,
49
61
  "data-editor-block-controls-side": "left",
@@ -51,9 +63,9 @@ const BlockControlsLeftSurfaceContent = ({
51
63
  // 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.
52
64
  ,
53
65
  style: placement.style,
54
- className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container])
66
+ className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.container])
55
67
  }, /*#__PURE__*/React.createElement("div", {
56
- className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
68
+ className: 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' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
57
69
  }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
58
70
  shouldHideHoverControls: shouldHideHoverControls,
59
71
  useCssStyles: useCssStyles
@@ -63,6 +75,27 @@ const BlockControlsLeftSurfaceContent = ({
63
75
  surfaceContext: surfaceContext
64
76
  }))));
65
77
  };
78
+ const BlockControlsLeftSurfaceWrapper = ({
79
+ children,
80
+ placement,
81
+ source,
82
+ surfaceContext
83
+ }) => {
84
+ const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
85
+ const isSticky = placement.isSticky;
86
+ const isTopLevel = (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.parentType) === 'doc';
87
+ return /*#__PURE__*/React.createElement("div", {
88
+ "data-editor-block-controls-surface": true,
89
+ "data-editor-block-controls-side": "left",
90
+ "data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
91
+ // 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.
92
+ ,
93
+ style: placement.style,
94
+ className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container, "_3um015vq"])
95
+ }, /*#__PURE__*/React.createElement("div", {
96
+ className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isTopLevel && leftSurfaceGutterStyles.row, isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
97
+ }, children));
98
+ };
66
99
 
67
100
  /** Renders one left block-controls surface at a document position. */
68
101
  export const BlockControlsLeftSurface = ({
@@ -76,12 +109,25 @@ export const BlockControlsLeftSurface = ({
76
109
  if (!placement) {
77
110
  return null;
78
111
  }
79
- return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
80
- api: api,
81
- components: components,
82
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
83
- placement: placement,
84
- source: source,
85
- surfaceContext: surfaceContext
86
- });
112
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
113
+ return /*#__PURE__*/React.createElement(BlockControlsSurfaceWithClsFix, {
114
+ side: "left",
115
+ SurfaceWrapper: BlockControlsLeftSurfaceWrapper,
116
+ api: api,
117
+ components: components,
118
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
119
+ placement: placement,
120
+ source: source,
121
+ surfaceContext: surfaceContext
122
+ });
123
+ } else {
124
+ return /*#__PURE__*/React.createElement(BlockControlsLeftSurfaceContent, {
125
+ api: api,
126
+ components: components,
127
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
128
+ placement: placement,
129
+ source: source,
130
+ surfaceContext: surfaceContext
131
+ });
132
+ }
87
133
  };
@@ -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}
@@ -6,8 +6,10 @@ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls
6
6
  import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
7
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 { BlockControlsSurfaceWithClsFix } from '../surface-lifecycle/block-controls-surface-with-cls-fix';
9
10
  import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
10
11
  import { useBlockControlsVisibility } from './visibility-container';
12
+ const rightSurfaceHiddenWrapperStyles = null;
11
13
  const rightSurfaceOuterStyles = null;
12
14
  const rightSurfaceRowStyles = null;
13
15
 
@@ -56,6 +58,26 @@ const BlockControlsRightSurfaceContent = ({
56
58
  surfaceContext: surfaceContext
57
59
  }))));
58
60
  };
61
+ const BlockControlsRightSurfaceWrapper = ({
62
+ children,
63
+ placement,
64
+ source,
65
+ surfaceContext
66
+ }) => {
67
+ const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
68
+ const isSticky = placement.isSticky;
69
+ return /*#__PURE__*/React.createElement("div", {
70
+ "data-editor-block-controls-surface": true,
71
+ "data-editor-block-controls-side": "right",
72
+ "data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
73
+ // 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.
74
+ ,
75
+ style: placement.style,
76
+ className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", "_3um015vq"])
77
+ }, /*#__PURE__*/React.createElement("div", {
78
+ className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && isExperimentEnabled('platform_editor_block_controls_sticky_header_fix') && "_154i1ejb"])
79
+ }, children));
80
+ };
59
81
 
60
82
  /** Renders one right block-controls surface at a document position. */
61
83
  export const BlockControlsRightSurface = ({
@@ -69,12 +91,25 @@ export const BlockControlsRightSurface = ({
69
91
  if (!placement) {
70
92
  return null;
71
93
  }
72
- return /*#__PURE__*/React.createElement(BlockControlsRightSurfaceContent, {
73
- api: api,
74
- components: components,
75
- forceVisibleOnMouseOut: forceVisibleOnMouseOut,
76
- placement: placement,
77
- source: source,
78
- surfaceContext: surfaceContext
79
- });
94
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
95
+ return /*#__PURE__*/React.createElement(BlockControlsSurfaceWithClsFix, {
96
+ side: "right",
97
+ SurfaceWrapper: BlockControlsRightSurfaceWrapper,
98
+ api: api,
99
+ components: components,
100
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
101
+ placement: placement,
102
+ source: source,
103
+ surfaceContext: surfaceContext
104
+ });
105
+ } else {
106
+ return /*#__PURE__*/React.createElement(BlockControlsRightSurfaceContent, {
107
+ api: api,
108
+ components: components,
109
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
110
+ placement: placement,
111
+ source: source,
112
+ surfaceContext: surfaceContext
113
+ });
114
+ }
80
115
  };
@@ -27,6 +27,7 @@ import { createSelectionPreservationPlugin } from './pm-plugins/selection-preser
27
27
  import { createSparseSurfacesPlugin, sparseSurfacesKey } from './pm-plugins/sparse-surfaces';
28
28
  import { expandAndUpdateSelection as _expandAndUpdateSelection } from './pm-plugins/utils/expand-and-update-selection';
29
29
  import { selectNode } from './pm-plugins/utils/getSelection';
30
+ import { CommittedBlockControlsSurfaces } from './surface-lifecycle/block-controls-surfaces';
30
31
  import { BlockControlsLeftSurfaces } from './ui/block-controls-left-surfaces';
31
32
  import { BlockControlsRightSurfaces } from './ui/block-controls-right-surfaces';
32
33
  import { getBlockControlsSurfaceDragHandleComponents } from './ui/block-controls-surface-drag-handle-registration';
@@ -497,13 +498,16 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
497
498
  api: api
498
499
  }), registryBlockControlsEnabled && editorView && api ? /*#__PURE__*/React.createElement(SurfaceEditorViewContext.Provider, {
499
500
  value: editorView
500
- }, /*#__PURE__*/React.createElement(BlockControlsLeftSurfaces, {
501
+ }, isExperimentEnabled('platform_editor_block_controls_cls_fix') ? /*#__PURE__*/React.createElement(CommittedBlockControlsSurfaces, {
502
+ api: api,
503
+ editorView: editorView
504
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BlockControlsLeftSurfaces, {
501
505
  api: api,
502
506
  editorView: editorView
503
507
  }), /*#__PURE__*/React.createElement(BlockControlsRightSurfaces, {
504
508
  api: api,
505
509
  editorView: editorView
506
- })) : null);
510
+ }))) : null);
507
511
  }
508
512
  };
509
513
  };
@@ -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';
@@ -300,8 +301,28 @@ export var bindSparseGutterHover = function bindSparseGutterHover(_ref2) {
300
301
  }
301
302
  });
302
303
  };
303
- var unbindMouseOver = bindMouseListener('mouseover', onMouseOver);
304
- var unbindMouseMove = bindMouseListener('mousemove', onMouseMove);
304
+ var unbindMouseOver;
305
+ var unbindMouseMove;
306
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
307
+ // Match the legacy ignoreRestingPointerHover guard until the pointer first moves.
308
+ var pointerHasMoved = false;
309
+ unbindMouseOver = bindMouseListener('mouseover', function (event) {
310
+ if (!pointerHasMoved) {
311
+ return;
312
+ }
313
+ onMouseOver(event);
314
+ });
315
+ unbindMouseMove = bindMouseListener('mousemove', function (event) {
316
+ if (!pointerHasMoved) {
317
+ pointerHasMoved = true;
318
+ onMouseOver(event);
319
+ }
320
+ onMouseMove(event);
321
+ });
322
+ } else {
323
+ unbindMouseOver = bindMouseListener('mouseover', onMouseOver);
324
+ unbindMouseMove = bindMouseListener('mousemove', onMouseMove);
325
+ }
305
326
  return function () {
306
327
  unbindMouseOver();
307
328
  unbindMouseMove();
@@ -5,6 +5,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
6
6
  import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor-provider';
7
7
  import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
8
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
9
+ import { createSparseSurfacesViewWithLifecycle } from '../surface-lifecycle/sparse-surfaces-view-with-lifecycle';
8
10
  import { createSurfaceAnchorDecorations } from './decorations-surface-anchor';
9
11
  import { key as blockControlsKey } from './main';
10
12
  import { bindSparseGutterHover } from './sparse-gutter-hover';
@@ -15,7 +17,7 @@ var haveAnchorPositionsChanged = function haveAnchorPositionsChanged(positions,
15
17
  return !anchors.has(position);
16
18
  });
17
19
  };
18
- export var createSparseSurfacesView = function createSparseSurfacesView(_ref) {
20
+ var createLegacySparseSurfacesView = function createLegacySparseSurfacesView(_ref) {
19
21
  var _api$uiControlRegistr3, _api$editorDisabled, _api$editorViewMode, _api$limitedMode2, _api$showDiff, _api$userIntent;
20
22
  var api = _ref.api,
21
23
  pluginKey = _ref.pluginKey,
@@ -130,4 +132,11 @@ export var createSparseSurfacesView = function createSparseSurfacesView(_ref) {
130
132
  });
131
133
  }
132
134
  };
135
+ };
136
+ export var createSparseSurfacesView = function createSparseSurfacesView(options) {
137
+ if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
138
+ return createSparseSurfacesViewWithLifecycle(options);
139
+ } else {
140
+ return createLegacySparseSurfacesView(options);
141
+ }
133
142
  };
@@ -0,0 +1,33 @@
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
+ var areNodeContextsEqual = function 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(function (ancestor, index) {
21
+ var 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 var areBlockControlsSurfaceContextsEqual = function areBlockControlsSurfaceContextsEqual(a, b) {
32
+ return a.activeControlKey === b.activeControlKey && areNodeContextsEqual(a.targetNode, b.targetNode) && areNodeContextsEqual(a.rootNode, b.rootNode) && areNodeContextsEqual(a.activeNode, b.activeNode);
33
+ };
@@ -0,0 +1,76 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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
+ 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
+ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
5
+ import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
6
+ import { getBlockControlsLeftSurfaceComponents, getBlockControlsRightSurfaceComponents } from '../ui/block-controls-surface-components';
7
+ import { createBlockControlsSurfaceContextForPosition } from '../ui/block-controls-surface-context';
8
+ import { areBlockControlsSurfaceContextsEqual } from './are-block-controls-surface-contexts-equal';
9
+ /**
10
+ * Resolves each target into the controls, context and anchor information needed to render a surface.
11
+ * When a previous descriptor still matches, reuse it without rerunning component visibility
12
+ * predicates. The caller must omit `previous` when registry or external state changes invalidate
13
+ * those results. Targets without an anchor, a valid context or renderable components are omitted.
14
+ */
15
+ var createDescriptors = function createDescriptors(_ref, resolveComponents, previous) {
16
+ var activeNode = _ref.activeNode,
17
+ components = _ref.components,
18
+ state = _ref.state,
19
+ surfaceActiveNodes = _ref.surfaceActiveNodes,
20
+ surfaceAnchors = _ref.surfaceAnchors,
21
+ targets = _ref.targets;
22
+ return targets.flatMap(function (target) {
23
+ var _surfaceActiveNodes$g;
24
+ var anchorName = surfaceAnchors.get(target.position);
25
+ if (!anchorName) {
26
+ return [];
27
+ }
28
+ var 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);
29
+ if (!context) {
30
+ return [];
31
+ }
32
+ var cached = previous === null || previous === void 0 ? void 0 : previous.get(anchorName);
33
+ if (cached && cached.position === target.position && cached.source === target.source && areBlockControlsSurfaceContextsEqual(cached.blockControlsContext, context)) {
34
+ return [cached];
35
+ }
36
+ var surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
37
+ var surfaceComponents = resolveComponents(components, surfaceContext);
38
+ if (!surfaceComponents) {
39
+ return [];
40
+ }
41
+ return [_objectSpread(_objectSpread({}, target), {}, {
42
+ anchorName: anchorName,
43
+ blockControlsContext: context,
44
+ isTopLevel: context.targetNode.parentType === 'doc',
45
+ surfaceComponents: surfaceComponents,
46
+ surfaceContext: surfaceContext
47
+ })];
48
+ });
49
+ };
50
+
51
+ /**
52
+ * Creates a cache owned by one editor view and surface side on the gated CLS fix path.
53
+ * Unchanged descriptors let memoized surfaces skip rendering; preserving the array reference also
54
+ * lets SurfaceLifecycle skip publishing an otherwise unchanged snapshot. Registry changes or
55
+ * explicit invalidation force predicates to run again, even if the document context is unchanged.
56
+ */
57
+ export var createSurfaceDescriptorResolver = function createSurfaceDescriptorResolver(side) {
58
+ var descriptors = [];
59
+ var components = [];
60
+ return function (input, invalidated) {
61
+ var registryUnchanged = components.length === input.components.length && components.every(function (component, index) {
62
+ return component === input.components[index];
63
+ });
64
+ var previous = !invalidated && registryUnchanged ? new Map(descriptors.map(function (descriptor) {
65
+ return [descriptor.anchorName, descriptor];
66
+ })) : undefined;
67
+ var next = createDescriptors(input, side === 'left' ? getBlockControlsLeftSurfaceComponents : getBlockControlsRightSurfaceComponents, previous);
68
+ components = input.components;
69
+ if (next.length !== descriptors.length || next.some(function (descriptor, index) {
70
+ return descriptor !== descriptors[index];
71
+ })) {
72
+ descriptors = next;
73
+ }
74
+ return descriptors;
75
+ };
76
+ };
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
3
+ import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
4
+ import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
5
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
6
+ import { BlockControlsVisibilityProvider } from '../ui/block-controls-surface-components';
7
+ import { getBlockControlsSurfaceControlSide } from '../ui/block-controls-surface-context';
8
+ import { useBlockControlsVisibility } from '../ui/visibility-container';
9
+ /** Renders one block-controls surface for either side on the CLS fix path. */
10
+ export var BlockControlsSurfaceWithClsFix = function BlockControlsSurfaceWithClsFix(_ref) {
11
+ var api = _ref.api,
12
+ components = _ref.components,
13
+ forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
14
+ placement = _ref.placement,
15
+ side = _ref.side,
16
+ source = _ref.source,
17
+ surfaceContext = _ref.surfaceContext,
18
+ SurfaceWrapper = _ref.SurfaceWrapper;
19
+ var controlSide = side === 'left' ? getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')) : 'right';
20
+ var _useBlockControlsVisi = useBlockControlsVisibility({
21
+ api: api,
22
+ controlSide: controlSide,
23
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut
24
+ }),
25
+ shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
26
+ useCssStyles = _useBlockControlsVisi.useCssStyles;
27
+ return /*#__PURE__*/React.createElement(SurfaceWrapper, {
28
+ placement: placement,
29
+ source: source,
30
+ surfaceContext: surfaceContext
31
+ }, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
32
+ shouldHideHoverControls: shouldHideHoverControls,
33
+ useCssStyles: useCssStyles
34
+ }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
35
+ components: components,
36
+ surface: side === 'left' ? BLOCK_CONTROLS_LEFT_SURFACE : BLOCK_CONTROLS_RIGHT_SURFACE,
37
+ surfaceContext: surfaceContext
38
+ })));
39
+ };
@@ -0,0 +1,72 @@
1
+ import React, { memo, useLayoutEffect, useMemo, useSyncExternalStore } from 'react';
2
+ import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles/native-anchor';
3
+ import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
4
+ import { BlockControlsLeftSurface } from '../ui/block-controls-left-surface';
5
+ import { BlockControlsRightSurface } from '../ui/block-controls-right-surface';
6
+ import { getAnchoredLeftGutterSurfacePlacement, getAnchoredSurfacePlacement } from '../ui/utils/get-surface-placement';
7
+ import { getSurfaceLifecycle } from './surface-lifecycle';
8
+ import { getSurfaceKey, useMeasuredSurfacePlacements } from './use-measured-surface-placements';
9
+ var CommittedSurface = /*#__PURE__*/memo(function (_ref) {
10
+ var api = _ref.api,
11
+ descriptor = _ref.descriptor,
12
+ side = _ref.side,
13
+ forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
14
+ measuredPlacement = _ref.measuredPlacement;
15
+ var anchorName = descriptor.anchorName,
16
+ blockControlsContext = descriptor.blockControlsContext,
17
+ isTopLevel = descriptor.isTopLevel;
18
+ var nodeType = blockControlsContext.targetNode.type.name;
19
+ var nodeTypeWithLevel = getNodeTypeWithLevel(blockControlsContext.targetNode.node);
20
+ var layout = blockControlsContext.targetNode.node.attrs.layout;
21
+ var parentNodeType = blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType;
22
+ var anchoredPlacement = useMemo(function () {
23
+ if (!isCSSAnchorSupported()) {
24
+ return undefined;
25
+ }
26
+ var options = {
27
+ anchorName: anchorName,
28
+ nodeType: nodeType,
29
+ nodeTypeWithLevel: nodeTypeWithLevel,
30
+ layout: layout,
31
+ parentNodeType: parentNodeType,
32
+ side: side
33
+ };
34
+ return side === 'left' && isTopLevel ? getAnchoredLeftGutterSurfacePlacement(options) : getAnchoredSurfacePlacement(options);
35
+ }, [anchorName, nodeType, nodeTypeWithLevel, layout, parentNodeType, side, isTopLevel]);
36
+ var Surface = side === 'left' ? BlockControlsLeftSurface : BlockControlsRightSurface;
37
+ return /*#__PURE__*/React.createElement(Surface, {
38
+ api: api,
39
+ components: descriptor.surfaceComponents,
40
+ forceVisibleOnMouseOut: forceVisibleOnMouseOut,
41
+ placement: anchoredPlacement !== null && anchoredPlacement !== void 0 ? anchoredPlacement : measuredPlacement,
42
+ source: descriptor.source,
43
+ surfaceContext: descriptor.surfaceContext
44
+ });
45
+ });
46
+ export var CommittedBlockControlsSurfaces = function CommittedBlockControlsSurfaces(props) {
47
+ var lifecycle = getSurfaceLifecycle(props.editorView);
48
+ var snapshot = useSyncExternalStore(lifecycle.subscribe, lifecycle.getSnapshot, function () {
49
+ return undefined;
50
+ });
51
+ var measuredPlacements = useMeasuredSurfacePlacements(props.editorView, snapshot === null || snapshot === void 0 ? void 0 : snapshot.left, snapshot === null || snapshot === void 0 ? void 0 : snapshot.right);
52
+ useLayoutEffect(function () {
53
+ if (snapshot) {
54
+ lifecycle.acknowledge(snapshot.revision);
55
+ }
56
+ }, [lifecycle, snapshot]);
57
+ if (!snapshot) {
58
+ return null;
59
+ }
60
+ return /*#__PURE__*/React.createElement(React.Fragment, null, ['left', 'right'].flatMap(function (side) {
61
+ return snapshot[side].map(function (descriptor) {
62
+ return /*#__PURE__*/React.createElement(CommittedSurface, {
63
+ key: getSurfaceKey(side, descriptor),
64
+ api: props.api,
65
+ descriptor: descriptor,
66
+ side: side,
67
+ forceVisibleOnMouseOut: snapshot.forceVisibleOnMouseOut,
68
+ measuredPlacement: measuredPlacements.get(getSurfaceKey(side, descriptor))
69
+ });
70
+ });
71
+ }));
72
+ };