@atlaskit/editor-plugin-block-controls 18.2.3 → 18.2.6
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 +28 -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 +78 -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 +80 -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 +77 -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 +5 -4
|
@@ -30,15 +30,15 @@ export var BlockControlsRightSurface = function BlockControlsRightSurface(_ref)
|
|
|
30
30
|
persistentComponents = _partitionComponentsB.persistentComponents;
|
|
31
31
|
var willRenderPersistent = willSurfaceRender(persistentComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
|
|
32
32
|
var willRenderHoverOnly = willSurfaceRender(hoverOnlyComponents, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext);
|
|
33
|
-
var isSticky = placement.
|
|
33
|
+
var isSticky = placement.isSticky;
|
|
34
34
|
return /*#__PURE__*/React.createElement("div", {
|
|
35
35
|
"data-editor-block-controls-surface": true,
|
|
36
36
|
"data-editor-block-controls-side": "right",
|
|
37
37
|
"data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
|
|
38
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved
|
|
38
|
+
// 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.
|
|
39
39
|
,
|
|
40
|
-
style: placement,
|
|
41
|
-
className: ax(["_kqswstnw _1pbyb4wl"])
|
|
40
|
+
style: placement.style,
|
|
41
|
+
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
42
42
|
}, /*#__PURE__*/React.createElement("div", {
|
|
43
43
|
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc"])
|
|
44
44
|
}, willRenderPersistent && /*#__PURE__*/React.createElement(VisibilityContainer, {
|
|
@@ -13,21 +13,27 @@ import { getDocument } from '@atlaskit/browser-apis';
|
|
|
13
13
|
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
14
14
|
import { BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
15
15
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
16
|
+
import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles';
|
|
16
17
|
import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
|
|
17
18
|
import { willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
18
19
|
import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
|
|
19
20
|
import { BlockControlsRightSurface } from './block-controls-right-surface';
|
|
20
21
|
import { createBlockControlsSurfaceContext, createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
|
|
21
22
|
import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
|
|
22
|
-
import { getNodeContentElement } from './utils/get-node-content-element';
|
|
23
|
-
import { getAbsoluteSurfacePlacement, getSurfacePlacement } from './utils/get-surface-placement';
|
|
23
|
+
import { getNodeContentElement, hasInnerContentContainer } from './utils/get-node-content-element';
|
|
24
|
+
import { getAbsoluteSurfacePlacement, getAnchoredSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
|
|
24
25
|
import { hasSurfaceControls } from './utils/has-surface-controls';
|
|
25
26
|
var EMPTY_SURFACE_POSITIONS = [];
|
|
26
27
|
var EMPTY_SURFACE_COMPONENTS = [];
|
|
28
|
+
var EMPTY_MEASURED_SURFACES = [];
|
|
27
29
|
/**
|
|
28
|
-
* Registry-backed right surface tree. Mirrors the left surface's single-tree,
|
|
29
|
-
*
|
|
30
|
-
*
|
|
30
|
+
* Registry-backed right surface tree. Mirrors the left surface's single-tree approach, but keeps its
|
|
31
|
+
* own components lookup, targets, placements and measurement lifecycle so the right surface never
|
|
32
|
+
* depends on the left surface's render pass.
|
|
33
|
+
*
|
|
34
|
+
* Targets are placed one of two ways. Where the node's anchor name can be relied on, the surface is
|
|
35
|
+
* positioned with `anchor()` and the browser keeps it attached with nothing re-rendering. Everything
|
|
36
|
+
* else is measured and kept honest by the observers below. See `hasInnerContentContainer`.
|
|
31
37
|
*/
|
|
32
38
|
export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref) {
|
|
33
39
|
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
@@ -48,6 +54,7 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
|
|
|
48
54
|
}, [activeNode, surfaceNodePositions]);
|
|
49
55
|
var surfaces = useMemo(function () {
|
|
50
56
|
return targets.flatMap(function (target) {
|
|
57
|
+
var _api$core;
|
|
51
58
|
var context = target.source === 'stored' ? createBlockControlsSurfaceContextForPosition(editorView.state, target.position, activeNode) : createBlockControlsSurfaceContext(editorView, activeNode, target.source);
|
|
52
59
|
if (!context) {
|
|
53
60
|
return [];
|
|
@@ -56,12 +63,51 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
|
|
|
56
63
|
if (!hasSurfaceControls(components) || !willSurfaceRender(components, BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
|
|
57
64
|
return [];
|
|
58
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 = isCSSAnchorSupported() && context.targetNode.parentType === 'doc' && !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;
|
|
59
72
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
73
|
+
anchorName: anchorName,
|
|
60
74
|
blockControlsContext: context,
|
|
61
75
|
surfaceContext: surfaceContext
|
|
62
76
|
})];
|
|
63
77
|
});
|
|
64
|
-
}, [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 = 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, getAnchoredSurfacePlacement({
|
|
89
|
+
anchorName: anchorName,
|
|
90
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
91
|
+
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
92
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
93
|
+
side: 'right'
|
|
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 = 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]);
|
|
65
111
|
var _useState = useState(new Map()),
|
|
66
112
|
_useState2 = _slicedToArray(_useState, 2),
|
|
67
113
|
placements = _useState2[0],
|
|
@@ -69,13 +115,17 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
|
|
|
69
115
|
var animationFrameRef = useRef(undefined);
|
|
70
116
|
useLayoutEffect(function () {
|
|
71
117
|
var _getDocument;
|
|
72
|
-
if (
|
|
73
|
-
|
|
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
|
+
});
|
|
74
124
|
return;
|
|
75
125
|
}
|
|
76
|
-
var measurementTargets =
|
|
77
|
-
var blockControlsContext =
|
|
78
|
-
position =
|
|
126
|
+
var measurementTargets = measuredSurfaces.flatMap(function (_ref4) {
|
|
127
|
+
var blockControlsContext = _ref4.blockControlsContext,
|
|
128
|
+
position = _ref4.position;
|
|
79
129
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
80
130
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
81
131
|
if (!targetElementRoot) {
|
|
@@ -119,12 +169,12 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
|
|
|
119
169
|
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
120
170
|
side: 'right'
|
|
121
171
|
});
|
|
122
|
-
nextPlacements.set(position, getAbsoluteSurfacePlacement({
|
|
172
|
+
nextPlacements.set(position, toMeasuredSurfaceWrapperPlacement(getAbsoluteSurfacePlacement({
|
|
123
173
|
offsetParentRect: offsetParentRect,
|
|
124
174
|
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
125
175
|
offsetParentScrollTop: offsetParentScrollTop,
|
|
126
176
|
placement: placement
|
|
127
|
-
}));
|
|
177
|
+
})));
|
|
128
178
|
}
|
|
129
179
|
} catch (err) {
|
|
130
180
|
_iterator.e(err);
|
|
@@ -199,18 +249,18 @@ export var BlockControlsRightSurfaces = function BlockControlsRightSurfaces(_ref
|
|
|
199
249
|
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
200
250
|
unbindTransitionEnd();
|
|
201
251
|
};
|
|
202
|
-
}, [editorView,
|
|
203
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (
|
|
204
|
-
var _activeNode$handleOpt;
|
|
205
|
-
var position =
|
|
206
|
-
source =
|
|
207
|
-
surfaceContext =
|
|
252
|
+
}, [editorView, measuredSurfaces]);
|
|
253
|
+
return /*#__PURE__*/React.createElement(React.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;
|
|
208
258
|
return /*#__PURE__*/React.createElement(BlockControlsRightSurface, {
|
|
209
259
|
api: api,
|
|
210
260
|
components: components,
|
|
211
261
|
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
212
262
|
key: position,
|
|
213
|
-
placement: placements.get(position),
|
|
263
|
+
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
214
264
|
source: source,
|
|
215
265
|
surfaceContext: surfaceContext
|
|
216
266
|
});
|
|
@@ -10,9 +10,10 @@ import { ANCHOR_VARIABLE_NAME, DRAG_HANDLE_WIDTH, isCSSAnchorSupported } from '@
|
|
|
10
10
|
import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
|
|
11
11
|
import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
|
|
12
12
|
import { akEditorBreakoutPadding, akEditorCalculatedWideLayoutWidth, akEditorCalculatedWideLayoutWidthSmallViewport, akEditorFullPageNarrowBreakout, akEditorGutterPaddingDynamic, akEditorGutterPaddingReduced } from '@atlaskit/editor-shared-styles';
|
|
13
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
13
14
|
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
14
15
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
|
|
15
|
-
import { ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME, ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME, DRAG_HANDLE_MAX_WIDTH_PLUS_GAP } from './consts';
|
|
16
|
+
import { ACTIVE_DRAG_HANDLE_ATTR, ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME, ACTIVE_QUICK_INSERT_ATTR, ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME, DRAG_HANDLE_MAX_WIDTH_PLUS_GAP } from './consts';
|
|
16
17
|
import { NODE_ANCHOR_ATTR_NAME } from './utils/dom-attr-name';
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -369,6 +370,18 @@ var staticControlsAnchorStyles = css({
|
|
|
369
370
|
}
|
|
370
371
|
});
|
|
371
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Names the CSS anchor on top-level nodes, so the block controls surfaces can anchor to the blocks
|
|
375
|
+
* they render against. Only top-level at the moment as we don't have use cases yet for persistent controls that are nested.
|
|
376
|
+
*/
|
|
377
|
+
var surfaceAnchorStyles = css({
|
|
378
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
379
|
+
'.ProseMirror': _defineProperty({}, "[".concat(NODE_ANCHOR_ATTR_NAME, "]:not([").concat(NODE_ANCHOR_ATTR_NAME, "] [").concat(NODE_ANCHOR_ATTR_NAME, "]):not([").concat(ACTIVE_DRAG_HANDLE_ATTR, "], [").concat(ACTIVE_QUICK_INSERT_ATTR, "])"), {
|
|
380
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values, @atlaskit/ui-styling-standard/no-imported-style-values
|
|
381
|
+
anchorName: "var(".concat(ANCHOR_VARIABLE_NAME, ", attr(data-node-anchor type(<custom-ident>)))")
|
|
382
|
+
})
|
|
383
|
+
});
|
|
384
|
+
|
|
372
385
|
// Styles applied to nodes with anchors when dragging
|
|
373
386
|
var dragAnchorStyles = css({
|
|
374
387
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors
|
|
@@ -408,6 +421,16 @@ export var GlobalStylesWrapper = function GlobalStylesWrapper(_ref) {
|
|
|
408
421
|
isDraggingFromState = _useSharedPluginState.isDragging;
|
|
409
422
|
var isDragging = expValEquals('platform_editor_block_controls_perf_optimization', 'isEnabled', true) ? isDraggingFromState : false;
|
|
410
423
|
var shouldRenderAnchors = isCSSAnchorSupported() && expValEquals('platform_editor_native_anchor_with_dnd', 'isEnabled', true);
|
|
424
|
+
|
|
425
|
+
// The surfaces anchor to blocks they render against rather than only to the hovered one, so they
|
|
426
|
+
// need a name on every node. Added alongside whichever conditional rule applies rather than
|
|
427
|
+
// replacing it: this one matches only non-active nodes, so the two sets are disjoint.
|
|
428
|
+
//
|
|
429
|
+
// The migration check is what scopes this. Unlike the surfaces, this component renders for every
|
|
430
|
+
// editor, so without it the rule would name anchors on documents that have no surface to anchor.
|
|
431
|
+
var shouldRenderSurfaceAnchors =
|
|
432
|
+
// eslint-disable-next-line @atlaskit/platform/no-preconditioning -- browser capability, not a flag: an anchor name is meaningless where `anchor()` cannot resolve
|
|
433
|
+
Boolean(isCSSAnchorSupported()) && isExperimentEnabled('platform_editor_block_control_migration');
|
|
411
434
|
var toolbarFlagsEnabled = areToolbarFlagsEnabled(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
412
435
|
return jsx(Global
|
|
413
436
|
// eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
|
|
@@ -420,6 +443,9 @@ export var GlobalStylesWrapper = function GlobalStylesWrapper(_ref) {
|
|
|
420
443
|
// dragAnchorStyles sets anchor-name on ALL nodes during drag (needed for drop target positioning).
|
|
421
444
|
// staticControlsAnchorStyles handles anchor-name via node decorations for non-drag state.
|
|
422
445
|
// shouldRenderAnchors guards both: only apply anchor styles on browsers that support CSS anchor positioning.
|
|
423
|
-
shouldRenderAnchors ? isDragging ? dragAnchorStyles : staticControlsAnchorStyles : false : shouldRenderAnchors && (isDragging ? dragAnchorStyles : dragHandlerAnchorStyles)
|
|
446
|
+
shouldRenderAnchors ? isDragging ? dragAnchorStyles : staticControlsAnchorStyles : false : shouldRenderAnchors && (isDragging ? dragAnchorStyles : dragHandlerAnchorStyles),
|
|
447
|
+
// Last so that, at equal specificity, the surfaces' own anchor names are the ones that
|
|
448
|
+
// stand. It cannot overlap the active-node rules above, which this selector excludes.
|
|
449
|
+
shouldRenderSurfaceAnchors && surfaceAnchorStyles]
|
|
424
450
|
});
|
|
425
451
|
};
|
|
@@ -8,6 +8,9 @@ var INNER_CONTAINER_SELECTORS = {
|
|
|
8
8
|
multiBodiedExtension: '.extension-container[data-layout]',
|
|
9
9
|
table: ".".concat(resizerItemClassName)
|
|
10
10
|
};
|
|
11
|
+
export var hasInnerContentContainer = function hasInnerContentContainer(nodeType) {
|
|
12
|
+
return INNER_CONTAINER_SELECTORS[nodeType] !== undefined;
|
|
13
|
+
};
|
|
11
14
|
export var getNodeContentElement = function getNodeContentElement(nodeElement, nodeType) {
|
|
12
15
|
var _nodeElement$querySel;
|
|
13
16
|
var selector = INNER_CONTAINER_SELECTORS[nodeType];
|
|
@@ -54,4 +54,81 @@ export var getSurfacePlacement = function getSurfacePlacement(_ref2) {
|
|
|
54
54
|
transform: "translateX(calc(-100% - ".concat(gap, "px))"),
|
|
55
55
|
height: height
|
|
56
56
|
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
|
|
61
|
+
*
|
|
62
|
+
* Two kinds of placement produce this. A measured one resolves to pixel numbers from a
|
|
63
|
+
* `getBoundingClientRect` snapshot, so it is only as fresh as the last render and needs observers
|
|
64
|
+
* to keep it honest. An anchored one resolves to `anchor()` functions that the browser re-evaluates
|
|
65
|
+
* on every layout change, so it stays attached to its node with nothing re-rendering.
|
|
66
|
+
*
|
|
67
|
+
* `isSticky` is carried alongside the style rather than read back out of it because the two variants
|
|
68
|
+
* express the same stretch differently — a measured `height` versus an anchored `bottom`.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Adapts a measured placement to the shape the surface components consume. Sticky-eligible node
|
|
73
|
+
* types are the ones `getSurfacePlacement` gave a `height` to.
|
|
74
|
+
*/
|
|
75
|
+
export var toMeasuredSurfaceWrapperPlacement = function toMeasuredSurfaceWrapperPlacement(placement) {
|
|
76
|
+
return {
|
|
77
|
+
isSticky: placement.height !== undefined,
|
|
78
|
+
style: {
|
|
79
|
+
height: placement.height,
|
|
80
|
+
left: placement.left,
|
|
81
|
+
top: placement.top,
|
|
82
|
+
transform: placement.transform
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Where a surface goes when its anchor stops resolving, as the fallback argument to the block-axis
|
|
89
|
+
* `anchor()` calls below.
|
|
90
|
+
*
|
|
91
|
+
* An anchor is invalid once its element stops generating a box e.g. (`display: none`) / removed node
|
|
92
|
+
* Currently, anchor fallback is not unstable with some of the position-visibility options, so here
|
|
93
|
+
* we manually set a fallback of -9999 so that it will render offscreen out of the viewport
|
|
94
|
+
* without causing extra overflows
|
|
95
|
+
*/
|
|
96
|
+
var INVALID_ANCHOR_OFFSCREEN_PX = 9999;
|
|
97
|
+
var INVALID_ANCHOR_FALLBACK_TOP = "-".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
|
|
98
|
+
var INVALID_ANCHOR_FALLBACK_BOTTOM = "".concat(INVALID_ANCHOR_OFFSCREEN_PX, "px");
|
|
99
|
+
export var getAnchoredSurfacePlacement = function getAnchoredSurfacePlacement(_ref3) {
|
|
100
|
+
var anchorName = _ref3.anchorName,
|
|
101
|
+
nodeType = _ref3.nodeType,
|
|
102
|
+
nodeTypeWithLevel = _ref3.nodeTypeWithLevel,
|
|
103
|
+
parentNodeType = _ref3.parentNodeType,
|
|
104
|
+
side = _ref3.side;
|
|
105
|
+
if (nodeType === 'layoutColumn') {
|
|
106
|
+
// The column's horizontal midpoint, matching the measured `nodeRect.left + width / 2` and the
|
|
107
|
+
// legacy drag handle's own layout-column formula. Side-independent.
|
|
108
|
+
return {
|
|
109
|
+
isSticky: false,
|
|
110
|
+
style: {
|
|
111
|
+
left: "calc((anchor(".concat(anchorName, " left) + anchor(").concat(anchorName, " right)) / 2)"),
|
|
112
|
+
positionAnchor: anchorName,
|
|
113
|
+
top: "anchor(".concat(anchorName, " top, ").concat(INVALID_ANCHOR_FALLBACK_TOP, ")"),
|
|
114
|
+
transform: 'translate(-50%, -50%)'
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
var gap = dragHandleGap(nodeType, parentNodeType);
|
|
119
|
+
var isSticky = shouldBeSticky(nodeType);
|
|
120
|
+
return {
|
|
121
|
+
isSticky: isSticky,
|
|
122
|
+
style: _objectSpread(_objectSpread({}, isSticky ? {
|
|
123
|
+
bottom: "anchor(".concat(anchorName, " bottom, ").concat(INVALID_ANCHOR_FALLBACK_BOTTOM, ")")
|
|
124
|
+
} : {}), {}, {
|
|
125
|
+
left: side === 'right' ? "calc(anchor(".concat(anchorName, " right) + ").concat(gap, "px)") : "anchor(".concat(anchorName, " left)"),
|
|
126
|
+
positionAnchor: anchorName,
|
|
127
|
+
top: "calc(anchor(".concat(anchorName, " top, ").concat(INVALID_ANCHOR_FALLBACK_TOP, ") + ").concat(topPositionAdjustment(nodeTypeWithLevel), "px)"),
|
|
128
|
+
// The left side grows away from the node without knowing its own width, so it pulls itself
|
|
129
|
+
// back past its own box and the gap. The right side grows into the margin, so the gap is
|
|
130
|
+
// already folded into `left` above.
|
|
131
|
+
transform: side === 'right' ? '' : "translateX(calc(-100% - ".concat(gap, "px))")
|
|
132
|
+
})
|
|
133
|
+
};
|
|
57
134
|
};
|
|
@@ -9,12 +9,12 @@ import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-rende
|
|
|
9
9
|
import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
10
10
|
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
11
11
|
import type { BlockControlsSurfaceTarget } from './block-controls-surface-targets';
|
|
12
|
-
import type {
|
|
12
|
+
import type { SurfaceWrapperPlacement } from './utils/get-surface-placement';
|
|
13
13
|
type BlockControlsLeftSurfaceProps = {
|
|
14
14
|
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
15
15
|
components: React.ComponentProps<typeof SurfaceRenderer>['components'];
|
|
16
16
|
forceVisibleOnMouseOut: boolean;
|
|
17
|
-
placement:
|
|
17
|
+
placement: SurfaceWrapperPlacement | undefined;
|
|
18
18
|
source: BlockControlsSurfaceTarget['source'];
|
|
19
19
|
surfaceContext: SurfaceContext;
|
|
20
20
|
};
|
|
@@ -9,12 +9,12 @@ import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-rende
|
|
|
9
9
|
import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
10
10
|
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
11
11
|
import type { BlockControlsSurfaceTarget } from './block-controls-surface-targets';
|
|
12
|
-
import type {
|
|
12
|
+
import type { SurfaceWrapperPlacement } from './utils/get-surface-placement';
|
|
13
13
|
type BlockControlsRightSurfaceProps = {
|
|
14
14
|
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
15
15
|
components: React.ComponentProps<typeof SurfaceRenderer>['components'];
|
|
16
16
|
forceVisibleOnMouseOut: boolean;
|
|
17
|
-
placement:
|
|
17
|
+
placement: SurfaceWrapperPlacement | undefined;
|
|
18
18
|
source: BlockControlsSurfaceTarget['source'];
|
|
19
19
|
surfaceContext: SurfaceContext;
|
|
20
20
|
};
|
|
@@ -12,9 +12,13 @@ type Props = {
|
|
|
12
12
|
editorView: EditorView;
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
|
-
* Registry-backed right surface tree. Mirrors the left surface's single-tree,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* Registry-backed right surface tree. Mirrors the left surface's single-tree approach, but keeps its
|
|
16
|
+
* own components lookup, targets, placements and measurement lifecycle so the right surface never
|
|
17
|
+
* depends on the left surface's render pass.
|
|
18
|
+
*
|
|
19
|
+
* Targets are placed one of two ways. Where the node's anchor name can be relied on, the surface is
|
|
20
|
+
* positioned with `anchor()` and the browser keeps it attached with nothing re-rendering. Everything
|
|
21
|
+
* else is measured and kept honest by the observers below. See `hasInnerContentContainer`.
|
|
18
22
|
*/
|
|
19
23
|
export declare const BlockControlsRightSurfaces: ({ api, editorView, }: Props) => React.JSX.Element | null;
|
|
20
24
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
export type SurfacePlacement = {
|
|
2
3
|
/**
|
|
3
4
|
* Set only for sticky-eligible node types (long tables, panels, expands, etc.): the target
|
|
@@ -36,3 +37,32 @@ export declare const getAbsoluteSurfacePlacement: ({ offsetParentRect, offsetPar
|
|
|
36
37
|
* can be folded straight into `left` with no transform needed.
|
|
37
38
|
*/
|
|
38
39
|
export declare const getSurfacePlacement: ({ layout, nodeRect, nodeType, nodeTypeWithLevel, parentNodeType, side, }: SurfacePlacementOptions) => SurfacePlacement;
|
|
40
|
+
/**
|
|
41
|
+
* The insets to apply to a surface wrapper, plus whether that wrapper spans its target node.
|
|
42
|
+
*
|
|
43
|
+
* Two kinds of placement produce this. A measured one resolves to pixel numbers from a
|
|
44
|
+
* `getBoundingClientRect` snapshot, so it is only as fresh as the last render and needs observers
|
|
45
|
+
* to keep it honest. An anchored one resolves to `anchor()` functions that the browser re-evaluates
|
|
46
|
+
* on every layout change, so it stays attached to its node with nothing re-rendering.
|
|
47
|
+
*
|
|
48
|
+
* `isSticky` is carried alongside the style rather than read back out of it because the two variants
|
|
49
|
+
* express the same stretch differently — a measured `height` versus an anchored `bottom`.
|
|
50
|
+
*/
|
|
51
|
+
export type SurfaceWrapperPlacement = {
|
|
52
|
+
isSticky: boolean;
|
|
53
|
+
style: CSSProperties;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Adapts a measured placement to the shape the surface components consume. Sticky-eligible node
|
|
57
|
+
* types are the ones `getSurfacePlacement` gave a `height` to.
|
|
58
|
+
*/
|
|
59
|
+
export declare const toMeasuredSurfaceWrapperPlacement: (placement: SurfacePlacement) => SurfaceWrapperPlacement;
|
|
60
|
+
export type AnchoredSurfacePlacementOptions = {
|
|
61
|
+
/** The target node's CSS anchor name, i.e. its `data-node-anchor` value. */
|
|
62
|
+
anchorName: string;
|
|
63
|
+
nodeType: string;
|
|
64
|
+
nodeTypeWithLevel: string;
|
|
65
|
+
parentNodeType?: string;
|
|
66
|
+
side: SurfaceSide;
|
|
67
|
+
};
|
|
68
|
+
export declare const getAnchoredSurfacePlacement: ({ anchorName, nodeType, nodeTypeWithLevel, parentNodeType, side, }: AnchoredSurfacePlacementOptions) => SurfaceWrapperPlacement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "18.2.
|
|
3
|
+
"version": "18.2.6",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@atlaskit/editor-plugin-width": "^18.0.0",
|
|
44
44
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
45
45
|
"@atlaskit/editor-shared-styles": "^4.1.0",
|
|
46
|
-
"@atlaskit/editor-tables": "^3.
|
|
46
|
+
"@atlaskit/editor-tables": "^3.2.0",
|
|
47
47
|
"@atlaskit/editor-ui-control-model": "^2.9.0",
|
|
48
48
|
"@atlaskit/icon": "^37.6.0",
|
|
49
49
|
"@atlaskit/icon-lab": "^7.8.0",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@atlaskit/primitives": "^22.5.0",
|
|
57
57
|
"@atlaskit/section-message": "^10.2.0",
|
|
58
58
|
"@atlaskit/theme": "^28.2.0",
|
|
59
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
59
|
+
"@atlaskit/tmp-editor-statsig": "^184.0.0",
|
|
60
60
|
"@atlaskit/tokens": "^16.11.0",
|
|
61
61
|
"@atlaskit/tooltip": "^24.3.0",
|
|
62
62
|
"@babel/runtime": "^7.0.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"uuid": "^11.1.1"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@atlaskit/editor-common": "^121.
|
|
71
|
+
"@atlaskit/editor-common": "^121.2.0",
|
|
72
72
|
"react": "^18.2.0 || ^19.2.0",
|
|
73
73
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
74
74
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
112
|
+
"@atlassian/workbench": "workspace:*",
|
|
112
113
|
"react": "^19.2.0",
|
|
113
114
|
"react-dom": "^19.2.0",
|
|
114
115
|
"react-intl": "^7.0.0"
|