@atlaskit/editor-plugin-block-controls 18.2.1 → 18.2.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.
- package/CHANGELOG.md +26 -0
- package/dist/cjs/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/cjs/ui/block-controls-left-surface.js +4 -4
- package/dist/cjs/ui/block-controls-left-surfaces.js +61 -15
- package/dist/cjs/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/cjs/ui/block-controls-right-surface.js +4 -4
- package/dist/cjs/ui/block-controls-right-surfaces.js +68 -18
- package/dist/cjs/ui/global-styles.js +27 -1
- package/dist/cjs/ui/utils/get-node-content-element.js +4 -1
- package/dist/cjs/ui/utils/get-surface-placement.js +65 -1
- package/dist/es2019/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/es2019/ui/block-controls-left-surface.js +4 -4
- package/dist/es2019/ui/block-controls-left-surfaces.js +51 -11
- package/dist/es2019/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/es2019/ui/block-controls-right-surface.js +4 -4
- package/dist/es2019/ui/block-controls-right-surfaces.js +58 -14
- package/dist/es2019/ui/global-styles.js +31 -2
- package/dist/es2019/ui/utils/get-node-content-element.js +1 -0
- package/dist/es2019/ui/utils/get-surface-placement.js +67 -0
- package/dist/esm/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/esm/ui/block-controls-left-surface.js +4 -4
- package/dist/esm/ui/block-controls-left-surfaces.js +63 -17
- package/dist/esm/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/esm/ui/block-controls-right-surface.js +4 -4
- package/dist/esm/ui/block-controls-right-surfaces.js +70 -20
- package/dist/esm/ui/global-styles.js +28 -2
- package/dist/esm/ui/utils/get-node-content-element.js +3 -0
- package/dist/esm/ui/utils/get-surface-placement.js +64 -0
- package/dist/types/ui/block-controls-left-surface.d.ts +2 -2
- package/dist/types/ui/block-controls-right-surface.d.ts +2 -2
- package/dist/types/ui/block-controls-right-surfaces.d.ts +7 -3
- package/dist/types/ui/utils/get-node-content-element.d.ts +1 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +30 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 18.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5403eacb2945d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5403eacb2945d) -
|
|
8
|
+
[ux] Position the left and right block controls surfaces with CSS anchor positioning instead of
|
|
9
|
+
measured pixel offsets. Anchored surfaces stay attached to their block without re-rendering and
|
|
10
|
+
bind no scroll or resize listeners. This applies within the existing
|
|
11
|
+
`platform_editor_block_control_migration` rollout, which is the only place these surfaces render,
|
|
12
|
+
and falls back to the measured path on browsers without `anchor-name` support. Nodes whose visible
|
|
13
|
+
box belongs to an inner container, such as resized tables, media and extensions, stay on the
|
|
14
|
+
measured path.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
17
|
+
## 18.2.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies
|
|
22
|
+
|
|
23
|
+
## 18.2.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
|
|
3
29
|
## 18.2.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -40,15 +40,15 @@ var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function Block
|
|
|
40
40
|
persistentComponents = _partitionComponentsB.persistentComponents;
|
|
41
41
|
var willRenderPersistent = (0, _surfaceRenderer.willSurfaceRender)(persistentComponents, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
|
|
42
42
|
var willRenderHoverOnly = (0, _surfaceRenderer.willSurfaceRender)(hoverOnlyComponents, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
|
|
43
|
-
var isSticky = placement.
|
|
43
|
+
var isSticky = placement.isSticky;
|
|
44
44
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
45
45
|
"data-editor-block-controls-surface": true,
|
|
46
46
|
"data-editor-block-controls-side": "left",
|
|
47
47
|
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
|
|
48
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved
|
|
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.
|
|
49
49
|
,
|
|
50
|
-
style: placement,
|
|
51
|
-
className: (0, _runtime.ax)(["_kqswstnw _1pbyb4wl"])
|
|
50
|
+
style: placement.style,
|
|
51
|
+
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
52
52
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
53
53
|
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
54
54
|
}, willRenderHoverOnly && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
|
|
@@ -16,6 +16,7 @@ var _browserApis = require("@atlaskit/browser-apis");
|
|
|
16
16
|
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
17
17
|
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
18
18
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
19
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
19
20
|
var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
|
|
20
21
|
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
21
22
|
var _decorationsCommon = require("../pm-plugins/decorations-common");
|
|
@@ -33,6 +34,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
33
34
|
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; }
|
|
34
35
|
var EMPTY_SURFACE_POSITIONS = [];
|
|
35
36
|
var EMPTY_SURFACE_COMPONENTS = [];
|
|
37
|
+
var EMPTY_MEASURED_SURFACES = [];
|
|
36
38
|
var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
|
|
37
39
|
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
38
40
|
var api = _ref.api,
|
|
@@ -52,6 +54,7 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
52
54
|
}, [activeNode, surfaceNodePositions]);
|
|
53
55
|
var surfaces = (0, _react.useMemo)(function () {
|
|
54
56
|
return targets.flatMap(function (target) {
|
|
57
|
+
var _api$core;
|
|
55
58
|
var context = target.source === 'stored' ? (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(editorView.state, target.position, activeNode) : (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContext)(editorView, activeNode, target.source);
|
|
56
59
|
if (!context) {
|
|
57
60
|
return [];
|
|
@@ -60,12 +63,51 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
60
63
|
if (!(0, _hasSurfaceControls.hasSurfaceControls)(components) || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
|
|
61
64
|
return [];
|
|
62
65
|
}
|
|
66
|
+
// Resolved here rather than in the measurement effect so an anchored surface is placed
|
|
67
|
+
// in the same render that creates it — it never needs a second pass to find its node.
|
|
68
|
+
//
|
|
69
|
+
// At the moment, we only expect top-level nodes to have persistent controls.
|
|
70
|
+
// See surfaceAnchorStyles in global-styles
|
|
71
|
+
var anchorName = (0, _styles.isCSSAnchorSupported)() && context.targetNode.parentType === 'doc' && !(0, _getNodeContentElement.hasInnerContentContainer)(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
|
|
63
72
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
73
|
+
anchorName: anchorName,
|
|
64
74
|
blockControlsContext: context,
|
|
65
75
|
surfaceContext: surfaceContext
|
|
66
76
|
})];
|
|
67
77
|
});
|
|
68
|
-
}, [activeNode, components, editorView, targets]);
|
|
78
|
+
}, [activeNode, api, components, editorView, targets]);
|
|
79
|
+
/**
|
|
80
|
+
* Placements that need no measuring, so they are derived rather than stored: every inset is an
|
|
81
|
+
* `anchor()` the browser re-resolves on every layout change.
|
|
82
|
+
*/
|
|
83
|
+
var anchoredPlacements = (0, _react.useMemo)(function () {
|
|
84
|
+
return new Map(surfaces.flatMap(function (_ref2) {
|
|
85
|
+
var anchorName = _ref2.anchorName,
|
|
86
|
+
blockControlsContext = _ref2.blockControlsContext,
|
|
87
|
+
position = _ref2.position;
|
|
88
|
+
return anchorName ? [[position, (0, _getSurfacePlacement.getAnchoredSurfacePlacement)({
|
|
89
|
+
anchorName: anchorName,
|
|
90
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
91
|
+
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
92
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
93
|
+
side: 'left'
|
|
94
|
+
})]] : [];
|
|
95
|
+
}));
|
|
96
|
+
}, [surfaces]);
|
|
97
|
+
// Only the surfaces that still need measuring drive the effect below, so a document of anchored
|
|
98
|
+
// blocks binds no scroll or resize listeners at all.
|
|
99
|
+
//
|
|
100
|
+
// The shared empty array matters: `surfaces` gets a new identity on every hover, since
|
|
101
|
+
// `activeNode` is one of its dependencies. Returning a fresh `[]` would give the effect a
|
|
102
|
+
// changed dependency each time and re-run it for nothing, which is the cost the anchored path
|
|
103
|
+
// exists to avoid.
|
|
104
|
+
var measuredSurfaces = (0, _react.useMemo)(function () {
|
|
105
|
+
var measured = surfaces.filter(function (_ref3) {
|
|
106
|
+
var anchorName = _ref3.anchorName;
|
|
107
|
+
return !anchorName;
|
|
108
|
+
});
|
|
109
|
+
return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
|
|
110
|
+
}, [surfaces]);
|
|
69
111
|
var _useState = (0, _react.useState)(new Map()),
|
|
70
112
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
71
113
|
placements = _useState2[0],
|
|
@@ -73,13 +115,17 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
73
115
|
var animationFrameRef = (0, _react.useRef)(undefined);
|
|
74
116
|
(0, _react.useLayoutEffect)(function () {
|
|
75
117
|
var _getDocument;
|
|
76
|
-
if (
|
|
77
|
-
|
|
118
|
+
if (measuredSurfaces.length === 0) {
|
|
119
|
+
// Clear only when there is something to clear. Handing React a fresh Map every time would
|
|
120
|
+
// fail its identity check and commit a render to replace one empty map with another.
|
|
121
|
+
setPlacements(function (previous) {
|
|
122
|
+
return previous.size > 0 ? new Map() : previous;
|
|
123
|
+
});
|
|
78
124
|
return;
|
|
79
125
|
}
|
|
80
|
-
var measurementTargets =
|
|
81
|
-
var blockControlsContext =
|
|
82
|
-
position =
|
|
126
|
+
var measurementTargets = measuredSurfaces.flatMap(function (_ref4) {
|
|
127
|
+
var blockControlsContext = _ref4.blockControlsContext,
|
|
128
|
+
position = _ref4.position;
|
|
83
129
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
84
130
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
85
131
|
if (!targetElementRoot) {
|
|
@@ -123,12 +169,12 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
123
169
|
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
124
170
|
side: 'left'
|
|
125
171
|
});
|
|
126
|
-
nextPlacements.set(position, (0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
172
|
+
nextPlacements.set(position, (0, _getSurfacePlacement.toMeasuredSurfaceWrapperPlacement)((0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
127
173
|
offsetParentRect: offsetParentRect,
|
|
128
174
|
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
129
175
|
offsetParentScrollTop: offsetParentScrollTop,
|
|
130
176
|
placement: placement
|
|
131
|
-
}));
|
|
177
|
+
})));
|
|
132
178
|
}
|
|
133
179
|
} catch (err) {
|
|
134
180
|
_iterator.e(err);
|
|
@@ -203,18 +249,18 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
203
249
|
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
204
250
|
unbindTransitionEnd();
|
|
205
251
|
};
|
|
206
|
-
}, [editorView,
|
|
207
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (
|
|
208
|
-
var _activeNode$handleOpt;
|
|
209
|
-
var position =
|
|
210
|
-
source =
|
|
211
|
-
surfaceContext =
|
|
252
|
+
}, [editorView, measuredSurfaces]);
|
|
253
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref5) {
|
|
254
|
+
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
255
|
+
var position = _ref5.position,
|
|
256
|
+
source = _ref5.source,
|
|
257
|
+
surfaceContext = _ref5.surfaceContext;
|
|
212
258
|
return /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurface.BlockControlsLeftSurface, {
|
|
213
259
|
api: api,
|
|
214
260
|
components: components,
|
|
215
261
|
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
216
262
|
key: position,
|
|
217
|
-
placement: placements.get(position),
|
|
263
|
+
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
218
264
|
source: source,
|
|
219
265
|
surfaceContext: surfaceContext
|
|
220
266
|
});
|
|
@@ -37,15 +37,15 @@ var BlockControlsRightSurface = exports.BlockControlsRightSurface = function Blo
|
|
|
37
37
|
persistentComponents = _partitionComponentsB.persistentComponents;
|
|
38
38
|
var willRenderPersistent = (0, _surfaceRenderer.willSurfaceRender)(persistentComponents, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
|
|
39
39
|
var willRenderHoverOnly = (0, _surfaceRenderer.willSurfaceRender)(hoverOnlyComponents, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
|
|
40
|
-
var isSticky = placement.
|
|
40
|
+
var isSticky = placement.isSticky;
|
|
41
41
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
42
42
|
"data-editor-block-controls-surface": true,
|
|
43
43
|
"data-editor-block-controls-side": "right",
|
|
44
44
|
"data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
|
|
45
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved
|
|
45
|
+
// 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.
|
|
46
46
|
,
|
|
47
|
-
style: placement,
|
|
48
|
-
className: (0, _runtime.ax)(["_kqswstnw _1pbyb4wl"])
|
|
47
|
+
style: placement.style,
|
|
48
|
+
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
49
49
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
50
50
|
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
51
51
|
}, willRenderPersistent && /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
|
|
@@ -16,6 +16,7 @@ var _browserApis = require("@atlaskit/browser-apis");
|
|
|
16
16
|
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
17
17
|
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
18
18
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
19
|
+
var _styles = require("@atlaskit/editor-common/styles");
|
|
19
20
|
var _createSurfaceContext = require("@atlaskit/editor-ui-control-model/create-surface-context");
|
|
20
21
|
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
21
22
|
var _decorationsCommon = require("../pm-plugins/decorations-common");
|
|
@@ -33,10 +34,15 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
33
34
|
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; }
|
|
34
35
|
var EMPTY_SURFACE_POSITIONS = [];
|
|
35
36
|
var EMPTY_SURFACE_COMPONENTS = [];
|
|
37
|
+
var EMPTY_MEASURED_SURFACES = [];
|
|
36
38
|
/**
|
|
37
|
-
* Registry-backed right surface tree. Mirrors the left surface's single-tree,
|
|
38
|
-
*
|
|
39
|
-
*
|
|
39
|
+
* Registry-backed right surface tree. Mirrors the left surface's single-tree approach, but keeps its
|
|
40
|
+
* own components lookup, targets, placements and measurement lifecycle so the right surface never
|
|
41
|
+
* depends on the left surface's render pass.
|
|
42
|
+
*
|
|
43
|
+
* Targets are placed one of two ways. Where the node's anchor name can be relied on, the surface is
|
|
44
|
+
* positioned with `anchor()` and the browser keeps it attached with nothing re-rendering. Everything
|
|
45
|
+
* else is measured and kept honest by the observers below. See `hasInnerContentContainer`.
|
|
40
46
|
*/
|
|
41
47
|
var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref) {
|
|
42
48
|
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
@@ -57,6 +63,7 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
57
63
|
}, [activeNode, surfaceNodePositions]);
|
|
58
64
|
var surfaces = (0, _react.useMemo)(function () {
|
|
59
65
|
return targets.flatMap(function (target) {
|
|
66
|
+
var _api$core;
|
|
60
67
|
var context = target.source === 'stored' ? (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(editorView.state, target.position, activeNode) : (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContext)(editorView, activeNode, target.source);
|
|
61
68
|
if (!context) {
|
|
62
69
|
return [];
|
|
@@ -65,12 +72,51 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
65
72
|
if (!(0, _hasSurfaceControls.hasSurfaceControls)(components) || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
|
|
66
73
|
return [];
|
|
67
74
|
}
|
|
75
|
+
// Resolved here rather than in the measurement effect so an anchored surface is placed
|
|
76
|
+
// in the same render that creates it — it never needs a second pass to find its node.
|
|
77
|
+
//
|
|
78
|
+
// At the moment, we only expect top-level nodes to have persistent controls.
|
|
79
|
+
// See surfaceAnchorStyles in global-styles
|
|
80
|
+
var anchorName = (0, _styles.isCSSAnchorSupported)() && context.targetNode.parentType === 'doc' && !(0, _getNodeContentElement.hasInnerContentContainer)(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
|
|
68
81
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
82
|
+
anchorName: anchorName,
|
|
69
83
|
blockControlsContext: context,
|
|
70
84
|
surfaceContext: surfaceContext
|
|
71
85
|
})];
|
|
72
86
|
});
|
|
73
|
-
}, [activeNode, components, editorView, targets]);
|
|
87
|
+
}, [activeNode, api, components, editorView, targets]);
|
|
88
|
+
/**
|
|
89
|
+
* Placements that need no measuring, so they are derived rather than stored: every inset is an
|
|
90
|
+
* `anchor()` the browser re-resolves on every layout change.
|
|
91
|
+
*/
|
|
92
|
+
var anchoredPlacements = (0, _react.useMemo)(function () {
|
|
93
|
+
return new Map(surfaces.flatMap(function (_ref2) {
|
|
94
|
+
var anchorName = _ref2.anchorName,
|
|
95
|
+
blockControlsContext = _ref2.blockControlsContext,
|
|
96
|
+
position = _ref2.position;
|
|
97
|
+
return anchorName ? [[position, (0, _getSurfacePlacement.getAnchoredSurfacePlacement)({
|
|
98
|
+
anchorName: anchorName,
|
|
99
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
100
|
+
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
101
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
102
|
+
side: 'right'
|
|
103
|
+
})]] : [];
|
|
104
|
+
}));
|
|
105
|
+
}, [surfaces]);
|
|
106
|
+
// Only the surfaces that still need measuring drive the effect below, so a document of anchored
|
|
107
|
+
// blocks binds no scroll or resize listeners at all.
|
|
108
|
+
//
|
|
109
|
+
// The shared empty array matters: `surfaces` gets a new identity on every hover, since
|
|
110
|
+
// `activeNode` is one of its dependencies. Returning a fresh `[]` would give the effect a
|
|
111
|
+
// changed dependency each time and re-run it for nothing, which is the cost the anchored path
|
|
112
|
+
// exists to avoid.
|
|
113
|
+
var measuredSurfaces = (0, _react.useMemo)(function () {
|
|
114
|
+
var measured = surfaces.filter(function (_ref3) {
|
|
115
|
+
var anchorName = _ref3.anchorName;
|
|
116
|
+
return !anchorName;
|
|
117
|
+
});
|
|
118
|
+
return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
|
|
119
|
+
}, [surfaces]);
|
|
74
120
|
var _useState = (0, _react.useState)(new Map()),
|
|
75
121
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
76
122
|
placements = _useState2[0],
|
|
@@ -78,13 +124,17 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
78
124
|
var animationFrameRef = (0, _react.useRef)(undefined);
|
|
79
125
|
(0, _react.useLayoutEffect)(function () {
|
|
80
126
|
var _getDocument;
|
|
81
|
-
if (
|
|
82
|
-
|
|
127
|
+
if (measuredSurfaces.length === 0) {
|
|
128
|
+
// Clear only when there is something to clear. Handing React a fresh Map every time would
|
|
129
|
+
// fail its identity check and commit a render to replace one empty map with another.
|
|
130
|
+
setPlacements(function (previous) {
|
|
131
|
+
return previous.size > 0 ? new Map() : previous;
|
|
132
|
+
});
|
|
83
133
|
return;
|
|
84
134
|
}
|
|
85
|
-
var measurementTargets =
|
|
86
|
-
var blockControlsContext =
|
|
87
|
-
position =
|
|
135
|
+
var measurementTargets = measuredSurfaces.flatMap(function (_ref4) {
|
|
136
|
+
var blockControlsContext = _ref4.blockControlsContext,
|
|
137
|
+
position = _ref4.position;
|
|
88
138
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
89
139
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
90
140
|
if (!targetElementRoot) {
|
|
@@ -128,12 +178,12 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
128
178
|
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
129
179
|
side: 'right'
|
|
130
180
|
});
|
|
131
|
-
nextPlacements.set(position, (0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
181
|
+
nextPlacements.set(position, (0, _getSurfacePlacement.toMeasuredSurfaceWrapperPlacement)((0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
132
182
|
offsetParentRect: offsetParentRect,
|
|
133
183
|
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
134
184
|
offsetParentScrollTop: offsetParentScrollTop,
|
|
135
185
|
placement: placement
|
|
136
|
-
}));
|
|
186
|
+
})));
|
|
137
187
|
}
|
|
138
188
|
} catch (err) {
|
|
139
189
|
_iterator.e(err);
|
|
@@ -208,18 +258,18 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
208
258
|
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
209
259
|
unbindTransitionEnd();
|
|
210
260
|
};
|
|
211
|
-
}, [editorView,
|
|
212
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (
|
|
213
|
-
var _activeNode$handleOpt;
|
|
214
|
-
var position =
|
|
215
|
-
source =
|
|
216
|
-
surfaceContext =
|
|
261
|
+
}, [editorView, measuredSurfaces]);
|
|
262
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref5) {
|
|
263
|
+
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
264
|
+
var position = _ref5.position,
|
|
265
|
+
source = _ref5.source,
|
|
266
|
+
surfaceContext = _ref5.surfaceContext;
|
|
217
267
|
return /*#__PURE__*/_react.default.createElement(_blockControlsRightSurface.BlockControlsRightSurface, {
|
|
218
268
|
api: api,
|
|
219
269
|
components: components,
|
|
220
270
|
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
221
271
|
key: position,
|
|
222
|
-
placement: placements.get(position),
|
|
272
|
+
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
223
273
|
source: source,
|
|
224
274
|
surfaceContext: surfaceContext
|
|
225
275
|
});
|
|
@@ -12,6 +12,7 @@ var _styles = require("@atlaskit/editor-common/styles");
|
|
|
12
12
|
var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
|
|
13
13
|
var _whitespace = require("@atlaskit/editor-common/whitespace");
|
|
14
14
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
15
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
15
16
|
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
16
17
|
var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
|
|
17
18
|
var _consts = require("./consts");
|
|
@@ -376,6 +377,18 @@ var staticControlsAnchorStyles = (0, _react.css)({
|
|
|
376
377
|
}
|
|
377
378
|
});
|
|
378
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Names the CSS anchor on top-level nodes, so the block controls surfaces can anchor to the blocks
|
|
382
|
+
* they render against. Only top-level at the moment as we don't have use cases yet for persistent controls that are nested.
|
|
383
|
+
*/
|
|
384
|
+
var surfaceAnchorStyles = (0, _react.css)({
|
|
385
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
386
|
+
'.ProseMirror': (0, _defineProperty2.default)({}, "[".concat(_domAttrName.NODE_ANCHOR_ATTR_NAME, "]:not([").concat(_domAttrName.NODE_ANCHOR_ATTR_NAME, "] [").concat(_domAttrName.NODE_ANCHOR_ATTR_NAME, "]):not([").concat(_consts.ACTIVE_DRAG_HANDLE_ATTR, "], [").concat(_consts.ACTIVE_QUICK_INSERT_ATTR, "])"), {
|
|
387
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
388
|
+
anchorName: "var(".concat(_styles.ANCHOR_VARIABLE_NAME, ", attr(data-node-anchor type(<custom-ident>)))")
|
|
389
|
+
})
|
|
390
|
+
});
|
|
391
|
+
|
|
379
392
|
// Styles applied to nodes with anchors when dragging
|
|
380
393
|
var dragAnchorStyles = (0, _react.css)({
|
|
381
394
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
@@ -415,6 +428,16 @@ var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWra
|
|
|
415
428
|
isDraggingFromState = _useSharedPluginState.isDragging;
|
|
416
429
|
var isDragging = (0, _expValEquals.expValEquals)('platform_editor_block_controls_perf_optimization', 'isEnabled', true) ? isDraggingFromState : false;
|
|
417
430
|
var shouldRenderAnchors = (0, _styles.isCSSAnchorSupported)() && (0, _expValEquals.expValEquals)('platform_editor_native_anchor_with_dnd', 'isEnabled', true);
|
|
431
|
+
|
|
432
|
+
// The surfaces anchor to blocks they render against rather than only to the hovered one, so they
|
|
433
|
+
// need a name on every node. Added alongside whichever conditional rule applies rather than
|
|
434
|
+
// replacing it: this one matches only non-active nodes, so the two sets are disjoint.
|
|
435
|
+
//
|
|
436
|
+
// The migration check is what scopes this. Unlike the surfaces, this component renders for every
|
|
437
|
+
// editor, so without it the rule would name anchors on documents that have no surface to anchor.
|
|
438
|
+
var shouldRenderSurfaceAnchors =
|
|
439
|
+
// eslint-disable-next-line @atlaskit/platform/no-preconditioning -- browser capability, not a flag: an anchor name is meaningless where `anchor()` cannot resolve
|
|
440
|
+
Boolean((0, _styles.isCSSAnchorSupported)()) && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration');
|
|
418
441
|
var toolbarFlagsEnabled = (0, _toolbarFlagCheck.areToolbarFlagsEnabled)(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
419
442
|
return (0, _react.jsx)(_react.Global
|
|
420
443
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
@@ -427,6 +450,9 @@ var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWra
|
|
|
427
450
|
// dragAnchorStyles sets anchor-name on ALL nodes during drag (needed for drop target positioning).
|
|
428
451
|
// staticControlsAnchorStyles handles anchor-name via node decorations for non-drag state.
|
|
429
452
|
// shouldRenderAnchors guards both: only apply anchor styles on browsers that support CSS anchor positioning.
|
|
430
|
-
shouldRenderAnchors ? isDragging ? dragAnchorStyles : staticControlsAnchorStyles : false : shouldRenderAnchors && (isDragging ? dragAnchorStyles : dragHandlerAnchorStyles)
|
|
453
|
+
shouldRenderAnchors ? isDragging ? dragAnchorStyles : staticControlsAnchorStyles : false : shouldRenderAnchors && (isDragging ? dragAnchorStyles : dragHandlerAnchorStyles),
|
|
454
|
+
// Last so that, at equal specificity, the surfaces' own anchor names are the ones that
|
|
455
|
+
// stand. It cannot overlap the active-node rules above, which this selector excludes.
|
|
456
|
+
shouldRenderSurfaceAnchors && surfaceAnchorStyles]
|
|
431
457
|
});
|
|
432
458
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getNodeContentElement = void 0;
|
|
6
|
+
exports.hasInnerContentContainer = exports.getNodeContentElement = void 0;
|
|
7
7
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
8
8
|
var INNER_CONTAINER_SELECTORS = {
|
|
9
9
|
blockCard: '.datasourceView-content-inner-wrap',
|
|
@@ -14,6 +14,9 @@ var INNER_CONTAINER_SELECTORS = {
|
|
|
14
14
|
multiBodiedExtension: '.extension-container[data-layout]',
|
|
15
15
|
table: ".".concat(_styles.resizerItemClassName)
|
|
16
16
|
};
|
|
17
|
+
var hasInnerContentContainer = exports.hasInnerContentContainer = function hasInnerContentContainer(nodeType) {
|
|
18
|
+
return INNER_CONTAINER_SELECTORS[nodeType] !== undefined;
|
|
19
|
+
};
|
|
17
20
|
var getNodeContentElement = exports.getNodeContentElement = function getNodeContentElement(nodeElement, nodeType) {
|
|
18
21
|
var _nodeElement$querySel;
|
|
19
22
|
var selector = INNER_CONTAINER_SELECTORS[nodeType];
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.getSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
|
|
7
|
+
exports.toMeasuredSurfaceWrapperPlacement = exports.getSurfacePlacement = exports.getAnchoredSurfacePlacement = exports.getAbsoluteSurfacePlacement = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _dragHandlePositions = require("../../pm-plugins/utils/drag-handle-positions");
|
|
10
10
|
var _consts = require("../consts");
|
|
@@ -61,4 +61,68 @@ var getSurfacePlacement = exports.getSurfacePlacement = function getSurfacePlace
|
|
|
61
61
|
transform: "translateX(calc(-100% - ".concat(gap, "px))"),
|
|
62
62
|
height: height
|
|
63
63
|
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
|
|
68
|
+
*
|
|
69
|
+
* Two kinds of placement produce this. A measured one resolves to pixel numbers from a
|
|
70
|
+
* `getBoundingClientRect` snapshot, so it is only as fresh as the last render and needs observers
|
|
71
|
+
* to keep it honest. An anchored one resolves to `anchor()` functions that the browser re-evaluates
|
|
72
|
+
* on every layout change, so it stays attached to its node with nothing re-rendering.
|
|
73
|
+
*
|
|
74
|
+
* `isSticky` is carried alongside the style rather than read back out of it because the two variants
|
|
75
|
+
* express the same stretch differently — a measured `height` versus an anchored `bottom`.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Adapts a measured placement to the shape the surface components consume. Sticky-eligible node
|
|
80
|
+
* types are the ones `getSurfacePlacement` gave a `height` to.
|
|
81
|
+
*/
|
|
82
|
+
var toMeasuredSurfaceWrapperPlacement = exports.toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapperPlacement(placement) {
|
|
83
|
+
return {
|
|
84
|
+
isSticky: placement.height !== undefined,
|
|
85
|
+
style: {
|
|
86
|
+
height: placement.height,
|
|
87
|
+
left: placement.left,
|
|
88
|
+
top: placement.top,
|
|
89
|
+
transform: placement.transform
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
var getAnchoredSurfacePlacement = exports.getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref3) {
|
|
94
|
+
var anchorName = _ref3.anchorName,
|
|
95
|
+
nodeType = _ref3.nodeType,
|
|
96
|
+
nodeTypeWithLevel = _ref3.nodeTypeWithLevel,
|
|
97
|
+
parentNodeType = _ref3.parentNodeType,
|
|
98
|
+
side = _ref3.side;
|
|
99
|
+
if (nodeType === 'layoutColumn') {
|
|
100
|
+
// The column's horizontal midpoint, matching the measured `nodeRect.left + width / 2` and the
|
|
101
|
+
// legacy drag handle's own layout-column formula. Side-independent.
|
|
102
|
+
return {
|
|
103
|
+
isSticky: false,
|
|
104
|
+
style: {
|
|
105
|
+
left: "calc((anchor(".concat(anchorName, " left) + anchor(").concat(anchorName, " right)) / 2)"),
|
|
106
|
+
positionAnchor: anchorName,
|
|
107
|
+
top: "anchor(".concat(anchorName, " top)"),
|
|
108
|
+
transform: 'translate(-50%, -50%)'
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var gap = (0, _consts.dragHandleGap)(nodeType, parentNodeType);
|
|
113
|
+
var isSticky = (0, _dragHandlePositions.shouldBeSticky)(nodeType);
|
|
114
|
+
return {
|
|
115
|
+
isSticky: isSticky,
|
|
116
|
+
style: _objectSpread(_objectSpread({}, isSticky ? {
|
|
117
|
+
bottom: "anchor(".concat(anchorName, " bottom)")
|
|
118
|
+
} : {}), {}, {
|
|
119
|
+
left: side === 'right' ? "calc(anchor(".concat(anchorName, " right) + ").concat(gap, "px)") : "anchor(".concat(anchorName, " left)"),
|
|
120
|
+
positionAnchor: anchorName,
|
|
121
|
+
top: "calc(anchor(".concat(anchorName, " top) + ").concat((0, _consts.topPositionAdjustment)(nodeTypeWithLevel), "px)"),
|
|
122
|
+
// The left side grows away from the node without knowing its own width, so it pulls itself
|
|
123
|
+
// back past its own box and the gap. The right side grows into the margin, so the gap is
|
|
124
|
+
// already folded into `left` above.
|
|
125
|
+
transform: side === 'right' ? '' : "translateX(calc(-100% - ".concat(gap, "px))")
|
|
126
|
+
})
|
|
127
|
+
};
|
|
64
128
|
};
|
|
@@ -35,15 +35,15 @@ export const BlockControlsLeftSurface = ({
|
|
|
35
35
|
} = partitionComponentsByPersistence(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
|
|
36
36
|
const willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
|
|
37
37
|
const willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext);
|
|
38
|
-
const isSticky = placement.
|
|
38
|
+
const isSticky = placement.isSticky;
|
|
39
39
|
return /*#__PURE__*/React.createElement("div", {
|
|
40
40
|
"data-editor-block-controls-surface": true,
|
|
41
41
|
"data-editor-block-controls-side": "left",
|
|
42
42
|
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
|
|
43
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved
|
|
43
|
+
// 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
44
|
,
|
|
45
|
-
style: placement,
|
|
46
|
-
className: ax(["_kqswstnw _1pbyb4wl"])
|
|
45
|
+
style: placement.style,
|
|
46
|
+
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
47
47
|
}, /*#__PURE__*/React.createElement("div", {
|
|
48
48
|
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
49
49
|
}, willRenderHoverOnly && /*#__PURE__*/React.createElement(VisibilityContainer, {
|