@atlaskit/editor-plugin-block-controls 34.0.3 → 34.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/blockControlsPlugin.js +2 -10
- package/dist/cjs/pm-plugins/interaction-tracking/handle-key-down.js +8 -0
- package/dist/cjs/pm-plugins/interaction-tracking/handle-mouse-move.js +121 -2
- package/dist/cjs/pm-plugins/interaction-tracking/pm-plugin.js +3 -0
- package/dist/cjs/pm-plugins/sparse-gutter-hover.js +17 -57
- package/dist/cjs/pm-plugins/sparse-surfaces.js +2 -2
- package/dist/cjs/pm-plugins/utils/after-render-scheduler.js +39 -0
- package/dist/cjs/ui/block-controls-left-surface.js +19 -83
- package/dist/cjs/ui/block-controls-right-surface.js +19 -70
- package/dist/cjs/ui/block-controls-surface-targets.js +1 -1
- package/dist/es2019/blockControlsPlugin.js +2 -10
- package/dist/es2019/pm-plugins/interaction-tracking/handle-key-down.js +8 -0
- package/dist/es2019/pm-plugins/interaction-tracking/handle-mouse-move.js +118 -1
- package/dist/es2019/pm-plugins/interaction-tracking/pm-plugin.js +4 -1
- package/dist/es2019/pm-plugins/sparse-gutter-hover.js +16 -56
- package/dist/es2019/pm-plugins/sparse-surfaces.js +2 -2
- package/dist/es2019/pm-plugins/utils/after-render-scheduler.js +33 -0
- package/dist/es2019/ui/block-controls-left-surface.js +10 -76
- package/dist/es2019/ui/block-controls-right-surface.js +10 -63
- package/dist/es2019/ui/block-controls-surface-targets.js +1 -1
- package/dist/esm/blockControlsPlugin.js +2 -10
- package/dist/esm/pm-plugins/interaction-tracking/handle-key-down.js +8 -0
- package/dist/esm/pm-plugins/interaction-tracking/handle-mouse-move.js +120 -1
- package/dist/esm/pm-plugins/interaction-tracking/pm-plugin.js +4 -1
- package/dist/esm/pm-plugins/sparse-gutter-hover.js +16 -56
- package/dist/esm/pm-plugins/sparse-surfaces.js +2 -2
- package/dist/esm/pm-plugins/utils/after-render-scheduler.js +33 -0
- package/dist/esm/ui/block-controls-left-surface.js +19 -83
- package/dist/esm/ui/block-controls-right-surface.js +19 -70
- package/dist/esm/ui/block-controls-surface-targets.js +1 -1
- package/dist/types/pm-plugins/interaction-tracking/handle-mouse-move.d.ts +1 -0
- package/dist/types/pm-plugins/utils/after-render-scheduler.d.ts +9 -0
- package/dist/types/ui/block-controls-left-surface.d.ts +1 -1
- package/dist/types/ui/block-controls-right-surface.d.ts +1 -1
- package/dist/types/ui/block-controls-surface-targets.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/pm-plugins/sparse-surfaces-view.js +0 -149
- package/dist/cjs/ui/block-controls-left-surfaces.js +0 -294
- package/dist/cjs/ui/block-controls-right-surfaces.js +0 -285
- package/dist/es2019/pm-plugins/sparse-surfaces-view.js +0 -136
- package/dist/es2019/ui/block-controls-left-surfaces.js +0 -259
- package/dist/es2019/ui/block-controls-right-surfaces.js +0 -245
- package/dist/esm/pm-plugins/sparse-surfaces-view.js +0 -142
- package/dist/esm/ui/block-controls-left-surfaces.js +0 -285
- package/dist/esm/ui/block-controls-right-surfaces.js +0 -276
- package/dist/types/pm-plugins/sparse-surfaces-view.d.ts +0 -16
- package/dist/types/ui/block-controls-left-surfaces.d.ts +0 -15
- package/dist/types/ui/block-controls-right-surfaces.d.ts +0 -24
|
@@ -10,12 +10,7 @@ require("./block-controls-right-surface.compiled.css");
|
|
|
10
10
|
var _runtime = require("@compiled/react/runtime");
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
12
12
|
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
13
|
-
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
14
|
-
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
15
|
-
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
16
13
|
var _blockControlsSurfaceWithClsFix = require("../surface-lifecycle/block-controls-surface-with-cls-fix");
|
|
17
|
-
var _blockControlsSurfaceComponents = require("./block-controls-surface-components");
|
|
18
|
-
var _visibilityContainer = require("./visibility-container");
|
|
19
14
|
var rightSurfaceHiddenWrapperStyles = null;
|
|
20
15
|
var rightSurfaceOuterStyles = null;
|
|
21
16
|
var rightSurfaceRowStyles = null;
|
|
@@ -28,47 +23,12 @@ var rightSurfaceStickyStyles = null;
|
|
|
28
23
|
|
|
29
24
|
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER in ./consts (must be a static literal here)
|
|
30
25
|
var rightSurfaceStickyTableHeaderStyles = null;
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
components = _ref.components,
|
|
34
|
-
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
26
|
+
var BlockControlsRightSurfaceWrapper = function BlockControlsRightSurfaceWrapper(_ref) {
|
|
27
|
+
var children = _ref.children,
|
|
35
28
|
placement = _ref.placement,
|
|
36
29
|
source = _ref.source,
|
|
37
30
|
surfaceContext = _ref.surfaceContext;
|
|
38
31
|
var blockControlsContext = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
39
|
-
var _useBlockControlsVisi = (0, _visibilityContainer.useBlockControlsVisibility)({
|
|
40
|
-
api: api,
|
|
41
|
-
controlSide: 'right',
|
|
42
|
-
forceVisibleOnMouseOut: forceVisibleOnMouseOut
|
|
43
|
-
}),
|
|
44
|
-
shouldHideHoverControls = _useBlockControlsVisi.shouldHide,
|
|
45
|
-
useCssStyles = _useBlockControlsVisi.useCssStyles;
|
|
46
|
-
var isSticky = placement.isSticky;
|
|
47
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
48
|
-
"data-editor-block-controls-surface": true,
|
|
49
|
-
"data-editor-block-controls-side": "right",
|
|
50
|
-
"data-testid": source === 'stored' ? 'block-controls-right-surface-stored' : source === 'active' ? 'block-controls-right-surface-active' : 'block-controls-right-surface'
|
|
51
|
-
// 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
|
-
,
|
|
53
|
-
style: placement.style,
|
|
54
|
-
className: (0, _runtime.ax)(["_kqswstnw _17c61i8t _1pbyb4wl"])
|
|
55
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
56
|
-
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw", isSticky && "_kqsw1if8 _154iu2gc", isSticky && (blockControlsContext === null || blockControlsContext === void 0 ? void 0 : blockControlsContext.targetNode.type.name) === 'table' && "_154i1ejb"])
|
|
57
|
-
}, /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceComponents.BlockControlsVisibilityProvider, {
|
|
58
|
-
shouldHideHoverControls: shouldHideHoverControls,
|
|
59
|
-
useCssStyles: useCssStyles
|
|
60
|
-
}, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
|
|
61
|
-
components: components,
|
|
62
|
-
surface: _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE,
|
|
63
|
-
surfaceContext: surfaceContext
|
|
64
|
-
}))));
|
|
65
|
-
};
|
|
66
|
-
var BlockControlsRightSurfaceWrapper = function BlockControlsRightSurfaceWrapper(_ref2) {
|
|
67
|
-
var children = _ref2.children,
|
|
68
|
-
placement = _ref2.placement,
|
|
69
|
-
source = _ref2.source,
|
|
70
|
-
surfaceContext = _ref2.surfaceContext;
|
|
71
|
-
var blockControlsContext = surfaceContext.get(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT);
|
|
72
32
|
var isSticky = placement.isSticky;
|
|
73
33
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
74
34
|
"data-editor-block-controls-surface": true,
|
|
@@ -84,35 +44,24 @@ var BlockControlsRightSurfaceWrapper = function BlockControlsRightSurfaceWrapper
|
|
|
84
44
|
};
|
|
85
45
|
|
|
86
46
|
/** Renders one right block-controls surface at a document position. */
|
|
87
|
-
var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(
|
|
88
|
-
var api =
|
|
89
|
-
components =
|
|
90
|
-
forceVisibleOnMouseOut =
|
|
91
|
-
placement =
|
|
92
|
-
source =
|
|
93
|
-
surfaceContext =
|
|
47
|
+
var BlockControlsRightSurface = exports.BlockControlsRightSurface = function BlockControlsRightSurface(_ref2) {
|
|
48
|
+
var api = _ref2.api,
|
|
49
|
+
components = _ref2.components,
|
|
50
|
+
forceVisibleOnMouseOut = _ref2.forceVisibleOnMouseOut,
|
|
51
|
+
placement = _ref2.placement,
|
|
52
|
+
source = _ref2.source,
|
|
53
|
+
surfaceContext = _ref2.surfaceContext;
|
|
94
54
|
if (!placement) {
|
|
95
55
|
return null;
|
|
96
56
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
return /*#__PURE__*/_react.default.createElement(BlockControlsRightSurfaceContent, {
|
|
110
|
-
api: api,
|
|
111
|
-
components: components,
|
|
112
|
-
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
113
|
-
placement: placement,
|
|
114
|
-
source: source,
|
|
115
|
-
surfaceContext: surfaceContext
|
|
116
|
-
});
|
|
117
|
-
}
|
|
57
|
+
return /*#__PURE__*/_react.default.createElement(_blockControlsSurfaceWithClsFix.BlockControlsSurfaceWithClsFix, {
|
|
58
|
+
side: "right",
|
|
59
|
+
SurfaceWrapper: BlockControlsRightSurfaceWrapper,
|
|
60
|
+
api: api,
|
|
61
|
+
components: components,
|
|
62
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
63
|
+
placement: placement,
|
|
64
|
+
source: source,
|
|
65
|
+
surfaceContext: surfaceContext
|
|
66
|
+
});
|
|
118
67
|
};
|
|
@@ -12,7 +12,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
12
12
|
* Shared by both the left and right surfaces: this is pure position bookkeeping with no
|
|
13
13
|
* surface-specific behavior, so there's nothing to keep independent between them. What *is*
|
|
14
14
|
* kept independent is each surface's own React tree (component lookup, measurement effects,
|
|
15
|
-
* observers) — see
|
|
15
|
+
* observers) — see ../surface-lifecycle/block-controls-surfaces.tsx.
|
|
16
16
|
*/
|
|
17
17
|
var getBlockControlsSurfaceTargets = exports.getBlockControlsSurfaceTargets = function getBlockControlsSurfaceTargets(activeNode, storedPositions) {
|
|
18
18
|
var targetsByPosition = new Map();
|
|
@@ -22,8 +22,6 @@ import { createSparseSurfacesPlugin, sparseSurfacesKey } from './pm-plugins/spar
|
|
|
22
22
|
import { expandAndUpdateSelection } from './pm-plugins/utils/expand-and-update-selection';
|
|
23
23
|
import { selectNode } from './pm-plugins/utils/getSelection';
|
|
24
24
|
import { CommittedBlockControlsSurfaces } from './surface-lifecycle/block-controls-surfaces';
|
|
25
|
-
import { BlockControlsLeftSurfaces } from './ui/block-controls-left-surfaces';
|
|
26
|
-
import { BlockControlsRightSurfaces } from './ui/block-controls-right-surfaces';
|
|
27
25
|
import { getBlockControlsSurfaceDragHandleComponents } from './ui/block-controls-surface-drag-handle-registration';
|
|
28
26
|
import { GlobalStylesWrapper } from './ui/global-styles';
|
|
29
27
|
import { SurfaceEditorViewContext } from './ui/surface-editor-view-context';
|
|
@@ -489,16 +487,10 @@ export const blockControlsPlugin = ({
|
|
|
489
487
|
api: api
|
|
490
488
|
}), registryBlockControlsEnabled && editorView && api ? /*#__PURE__*/React.createElement(SurfaceEditorViewContext.Provider, {
|
|
491
489
|
value: editorView
|
|
492
|
-
},
|
|
490
|
+
}, /*#__PURE__*/React.createElement(CommittedBlockControlsSurfaces, {
|
|
493
491
|
api: api,
|
|
494
492
|
editorView: editorView
|
|
495
|
-
}) :
|
|
496
|
-
api: api,
|
|
497
|
-
editorView: editorView
|
|
498
|
-
}), /*#__PURE__*/React.createElement(BlockControlsRightSurfaces, {
|
|
499
|
-
api: api,
|
|
500
|
-
editorView: editorView
|
|
501
|
-
}))) : null);
|
|
493
|
+
})) : null);
|
|
502
494
|
}
|
|
503
495
|
};
|
|
504
496
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
1
2
|
import { startEditing } from './commands';
|
|
3
|
+
import { clearPendingHoverSide } from './handle-mouse-move';
|
|
2
4
|
import { getInteractionTrackingState } from './pm-plugin';
|
|
3
5
|
export const handleKeyDown = (view, event) => {
|
|
4
6
|
// Check if this is a keyboard shortcut (Ctrl/Cmd + key)
|
|
@@ -16,6 +18,12 @@ export const handleKeyDown = (view, event) => {
|
|
|
16
18
|
if (!isTypingKey) {
|
|
17
19
|
return false;
|
|
18
20
|
}
|
|
21
|
+
|
|
22
|
+
// With the experiment, a queued mousemove clears the typing state when it finally runs. Typing
|
|
23
|
+
// is newer than that move, so drop it, even if we are already editing.
|
|
24
|
+
if (isExperimentEnabled('platform_editor_improve_inp_batch_3')) {
|
|
25
|
+
clearPendingHoverSide(view);
|
|
26
|
+
}
|
|
19
27
|
const state = getInteractionTrackingState(view.state);
|
|
20
28
|
|
|
21
29
|
// if user hasnt started typing yet, start timer
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
2
2
|
import { handleMouseOver } from '../handle-mouse-over';
|
|
3
|
+
import { createAfterRenderScheduler } from '../utils/after-render-scheduler';
|
|
3
4
|
import { clearHoverSide, mouseEnter, mouseLeave, setHoverSide, stopEditing } from './commands';
|
|
4
5
|
import { RIGHT_MARGIN_ROVO_GAP_PX } from './constants';
|
|
5
6
|
import { getInteractionTrackingState } from './pm-plugin';
|
|
@@ -16,9 +17,12 @@ const cancelScheduledProcessForView = view => {
|
|
|
16
17
|
rafIdByView.delete(view);
|
|
17
18
|
}
|
|
18
19
|
};
|
|
19
|
-
const clearPendingHoverSide = view => {
|
|
20
|
+
export const clearPendingHoverSide = view => {
|
|
20
21
|
pendingByView.delete(view);
|
|
21
22
|
cancelScheduledProcessForView(view);
|
|
23
|
+
if (isExperimentEnabled('platform_editor_improve_inp_batch_3')) {
|
|
24
|
+
cancelHoverSideAfterRender(view);
|
|
25
|
+
}
|
|
22
26
|
};
|
|
23
27
|
const BLOCK_SELECTORS = '[data-node-anchor], [data-drag-handler-anchor-name]';
|
|
24
28
|
const LEGACY_RIGHT_EDGE_SELECTOR = '[data-blocks-right-edge-button-container]';
|
|
@@ -56,6 +60,9 @@ const getRightMarginBoundary = view => {
|
|
|
56
60
|
// Classify where the cursor sits in the right margin beside the block at its height, running the
|
|
57
61
|
// block lookup once so the caller doesn't traverse the DOM twice per mousemove.
|
|
58
62
|
const classifyRightMarginPosition = (view, event) => {
|
|
63
|
+
if (isExperimentEnabled('platform_editor_improve_inp_batch_3')) {
|
|
64
|
+
return classifyRightMarginPositionByHitTest(view, event);
|
|
65
|
+
}
|
|
59
66
|
const found = findBlockAtY(view, event.clientY);
|
|
60
67
|
if (!found) {
|
|
61
68
|
return null;
|
|
@@ -166,6 +173,9 @@ const processHoverSide = (view, api) => {
|
|
|
166
173
|
}
|
|
167
174
|
};
|
|
168
175
|
export const handleMouseMove = (view, event, rightSideControlsEnabled, api) => {
|
|
176
|
+
if (rightSideControlsEnabled && event instanceof MouseEvent && isExperimentEnabled('platform_editor_improve_inp_batch_3')) {
|
|
177
|
+
return handleMouseMoveAfterRender(view, event, api);
|
|
178
|
+
}
|
|
169
179
|
const state = getInteractionTrackingState(view.state);
|
|
170
180
|
// if user has stopped editing and moved their mouse, show block controls again
|
|
171
181
|
if (state !== null && state !== void 0 && state.isEditing) {
|
|
@@ -197,4 +207,111 @@ export const handleMouseLeave = (view, rightSideControlsEnabled) => {
|
|
|
197
207
|
export const handleMouseEnter = view => {
|
|
198
208
|
mouseEnter(view);
|
|
199
209
|
return false;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/* -------------------------------------------------------------------------------------------------
|
|
213
|
+
* EDITOR-9730: platform_editor_improve_inp_batch_3
|
|
214
|
+
*
|
|
215
|
+
* Everything below is the treatment path, reached through these gates only:
|
|
216
|
+
* - handleMouseMove -> handleMouseMoveAfterRender
|
|
217
|
+
* - classifyRightMarginPosition -> classifyRightMarginPositionByHitTest
|
|
218
|
+
* - clearPendingHoverSide -> cancelHoverSideAfterRender
|
|
219
|
+
* Clean-up when the experiment ships: delete this section, take the treatment branch at each gate
|
|
220
|
+
* (dropping findBlockAtY, getRootBlocks, the rAF bookkeeping and the legacy handleMouseMove body),
|
|
221
|
+
* and remove the gated calls in pm-plugin.ts and handle-key-down.ts.
|
|
222
|
+
* ---------------------------------------------------------------------------------------------- */
|
|
223
|
+
|
|
224
|
+
/** Per-view scheduler plus the latest plugin API to use when it runs. */
|
|
225
|
+
const afterRenderByView = new WeakMap();
|
|
226
|
+
const cancelHoverSideAfterRender = view => {
|
|
227
|
+
var _afterRenderByView$ge;
|
|
228
|
+
(_afterRenderByView$ge = afterRenderByView.get(view)) === null || _afterRenderByView$ge === void 0 ? void 0 : _afterRenderByView$ge.scheduler.cancel();
|
|
229
|
+
};
|
|
230
|
+
const processHoverSideAfterRender = view => {
|
|
231
|
+
var _getInteractionTracki;
|
|
232
|
+
const state = afterRenderByView.get(view);
|
|
233
|
+
if (!state || view.isDestroyed || !pendingByView.has(view)) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
processHoverSide(view, state.api);
|
|
237
|
+
|
|
238
|
+
// The typing state is cleared last, after every read above has finished, so no layout read
|
|
239
|
+
// follows one of our own writes. Typing cancels pending work (see handle-key-down.ts), so this
|
|
240
|
+
// never undoes a newer keystroke.
|
|
241
|
+
if ((_getInteractionTracki = getInteractionTrackingState(view.state)) !== null && _getInteractionTracki !== void 0 && _getInteractionTracki.isEditing) {
|
|
242
|
+
stopEditing(view);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const handleMouseMoveAfterRender = (view, event, api) => {
|
|
246
|
+
const win = view.dom.ownerDocument.defaultView;
|
|
247
|
+
if (!win) {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
pendingByView.set(view, event);
|
|
251
|
+
let state = afterRenderByView.get(view);
|
|
252
|
+
if (!state) {
|
|
253
|
+
state = {
|
|
254
|
+
api,
|
|
255
|
+
scheduler: createAfterRenderScheduler(win, () => processHoverSideAfterRender(view))
|
|
256
|
+
};
|
|
257
|
+
afterRenderByView.set(view, state);
|
|
258
|
+
}
|
|
259
|
+
// The latest event and API win when several moves coalesce into one run.
|
|
260
|
+
state.api = api;
|
|
261
|
+
// Reads run after the next frame renders, giving the browser an opportunity to update layout
|
|
262
|
+
// first (other work can still dirty it).
|
|
263
|
+
state.scheduler.schedule();
|
|
264
|
+
return false;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// Walk up from a block to its top-level block (no block ancestor). Cost is bounded by nesting
|
|
268
|
+
// depth, matching getRootBlocks' filter without scanning the whole document.
|
|
269
|
+
const toRootBlock = block => {
|
|
270
|
+
var _root$parentElement;
|
|
271
|
+
let root = block;
|
|
272
|
+
let parent = (_root$parentElement = root.parentElement) === null || _root$parentElement === void 0 ? void 0 : _root$parentElement.closest(BLOCK_SELECTORS);
|
|
273
|
+
while (parent instanceof HTMLElement) {
|
|
274
|
+
var _root$parentElement2;
|
|
275
|
+
root = parent;
|
|
276
|
+
parent = (_root$parentElement2 = root.parentElement) === null || _root$parentElement2 === void 0 ? void 0 : _root$parentElement2.closest(BLOCK_SELECTORS);
|
|
277
|
+
}
|
|
278
|
+
return root;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Right-margin lookup without the document-wide scan (EDITOR-9730): when the cursor is past the
|
|
282
|
+
// right edge of the editor content, hit-test once just inside that edge at the cursor's height and
|
|
283
|
+
// resolve the top-level block there.
|
|
284
|
+
//
|
|
285
|
+
// This still reads layout (getBoundingClientRect and elementFromPoint), so like findBlockAtY it
|
|
286
|
+
// forces a synchronous layout if layout is dirty when it runs. What changes is how much and when:
|
|
287
|
+
// one rect and one hit test instead of a rect per top-level block, and it runs in the
|
|
288
|
+
// after-render callback, where the browser has had an opportunity to update layout first.
|
|
289
|
+
const findRootBlockBesideCursor = (view, event) => {
|
|
290
|
+
var _root$elementFromPoin;
|
|
291
|
+
const contentRight = view.dom.getBoundingClientRect().right;
|
|
292
|
+
if (event.clientX <= contentRight) {
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
const root = view.root;
|
|
296
|
+
if (typeof root.elementFromPoint !== 'function') {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
const block = (_root$elementFromPoin = root.elementFromPoint(contentRight - 1, event.clientY)) === null || _root$elementFromPoin === void 0 ? void 0 : _root$elementFromPoin.closest(BLOCK_SELECTORS);
|
|
300
|
+
if (!(block instanceof HTMLElement)) {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
const rootBlock = toRootBlock(block);
|
|
304
|
+
return view.dom.contains(rootBlock) ? rootBlock : null;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// Same classification as the legacy path, with the block found by a hit test.
|
|
308
|
+
const classifyRightMarginPositionByHitTest = (view, event) => {
|
|
309
|
+
const block = findRootBlockBesideCursor(view, event);
|
|
310
|
+
if (!block) {
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
type: 'active',
|
|
315
|
+
block
|
|
316
|
+
};
|
|
200
317
|
};
|
|
@@ -5,7 +5,7 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
5
5
|
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
6
6
|
import { RIGHT_MARGIN_ROVO_GAP_PX } from './constants';
|
|
7
7
|
import { handleKeyDown } from './handle-key-down';
|
|
8
|
-
import { handleMouseEnter, handleMouseLeave, handleMouseMove } from './handle-mouse-move';
|
|
8
|
+
import { clearPendingHoverSide, handleMouseEnter, handleMouseLeave, handleMouseMove } from './handle-mouse-move';
|
|
9
9
|
|
|
10
10
|
/** Elements that extend the editor hover area (block controls, right-edge button, etc.) */
|
|
11
11
|
const LEGACY_BLOCK_CONTROLS_HOVER_AREA_SELECTOR = '[data-blocks-right-edge-button-container], [data-blocks-drag-handle-container], [data-testid="block-ctrl-drag-handle"], [data-testid="block-ctrl-drag-handle-container"], [data-testid="block-ctrl-decorator-widget"], [data-testid="block-ctrl-quick-insert-button"]';
|
|
@@ -210,6 +210,9 @@ export const createInteractionTrackingPlugin = (rightSideControlsEnabled = false
|
|
|
210
210
|
var _unbindDocumentMouseM;
|
|
211
211
|
cancelScheduledMouseLeave();
|
|
212
212
|
(_unbindDocumentMouseM = unbindDocumentMouseMove) === null || _unbindDocumentMouseM === void 0 ? void 0 : _unbindDocumentMouseM();
|
|
213
|
+
if (isExperimentEnabled('platform_editor_improve_inp_batch_3')) {
|
|
214
|
+
clearPendingHoverSide(view);
|
|
215
|
+
}
|
|
213
216
|
}
|
|
214
217
|
(_unbindMouseEnter = unbindMouseEnter) === null || _unbindMouseEnter === void 0 ? void 0 : _unbindMouseEnter();
|
|
215
218
|
(_unbindMouseLeave = unbindMouseLeave) === null || _unbindMouseLeave === void 0 ? void 0 : _unbindMouseLeave();
|
|
@@ -1,13 +1,13 @@
|
|
|
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';
|
|
5
4
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
6
5
|
import { BLOCK_CONTROLS_SURFACE_SELECTOR, DRAG_HANDLE_MAX_WIDTH_PLUS_GAP } from '../ui/consts';
|
|
7
6
|
import { handleSparseHoverTarget, isSparseHoverSuppressed } from './handle-sparse-hover-target';
|
|
8
7
|
import { mouseEnter, setHoverSide, stopEditing } from './interaction-tracking/commands';
|
|
9
8
|
import { handleMouseLeave } from './interaction-tracking/handle-mouse-move';
|
|
10
9
|
import { getInteractionTrackingState } from './interaction-tracking/pm-plugin';
|
|
10
|
+
import { createAfterRenderScheduler } from './utils/after-render-scheduler';
|
|
11
11
|
import { getVisibleBox } from './utils/visible-box';
|
|
12
12
|
const BLOCK_SELECTOR = '[data-prosemirror-node-block="true"]';
|
|
13
13
|
const TABLE_STRUCTURE_NODES = new Set(['table', 'tableRow', 'tableCell', 'tableHeader']);
|
|
@@ -139,40 +139,6 @@ const classifyGutterHover = (view, findGutterBlock, {
|
|
|
139
139
|
};
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
-
/**
|
|
143
|
-
* Runs `callback` once after the next frame renders (`requestAnimationFrame`, then `setTimeout`).
|
|
144
|
-
* Layout is clean then, so reading positions never forces a synchronous layout. Calls made while a
|
|
145
|
-
* run is already scheduled are ignored.
|
|
146
|
-
*/
|
|
147
|
-
const createAfterRenderScheduler = (win, callback) => {
|
|
148
|
-
let frame;
|
|
149
|
-
let timeout;
|
|
150
|
-
return {
|
|
151
|
-
schedule: () => {
|
|
152
|
-
if (frame !== undefined || timeout !== undefined) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
frame = win.requestAnimationFrame(() => {
|
|
156
|
-
frame = undefined;
|
|
157
|
-
timeout = win.setTimeout(() => {
|
|
158
|
-
timeout = undefined;
|
|
159
|
-
callback();
|
|
160
|
-
}, 0);
|
|
161
|
-
});
|
|
162
|
-
},
|
|
163
|
-
cancel: () => {
|
|
164
|
-
if (frame !== undefined) {
|
|
165
|
-
win.cancelAnimationFrame(frame);
|
|
166
|
-
frame = undefined;
|
|
167
|
-
}
|
|
168
|
-
if (timeout !== undefined) {
|
|
169
|
-
win.clearTimeout(timeout);
|
|
170
|
-
timeout = undefined;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
142
|
/**
|
|
177
143
|
* Keeps interaction tracking in step with gutter hover, as the legacy hover zones did. They sat
|
|
178
144
|
* inside the block tree, so hovering one cleared the typing state, counted as inside the editor even
|
|
@@ -295,28 +261,22 @@ export const bindSparseGutterHover = ({
|
|
|
295
261
|
passive: true
|
|
296
262
|
}
|
|
297
263
|
});
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
264
|
+
|
|
265
|
+
// Ignore hover from a resting pointer until it first moves.
|
|
266
|
+
let pointerHasMoved = false;
|
|
267
|
+
const unbindMouseOver = bindMouseListener('mouseover', event => {
|
|
268
|
+
if (!pointerHasMoved) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
onMouseOver(event);
|
|
272
|
+
});
|
|
273
|
+
const unbindMouseMove = bindMouseListener('mousemove', event => {
|
|
274
|
+
if (!pointerHasMoved) {
|
|
275
|
+
pointerHasMoved = true;
|
|
307
276
|
onMouseOver(event);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
pointerHasMoved = true;
|
|
312
|
-
onMouseOver(event);
|
|
313
|
-
}
|
|
314
|
-
onMouseMove(event);
|
|
315
|
-
});
|
|
316
|
-
} else {
|
|
317
|
-
unbindMouseOver = bindMouseListener('mouseover', onMouseOver);
|
|
318
|
-
unbindMouseMove = bindMouseListener('mousemove', onMouseMove);
|
|
319
|
-
}
|
|
277
|
+
}
|
|
278
|
+
onMouseMove(event);
|
|
279
|
+
});
|
|
320
280
|
return () => {
|
|
321
281
|
unbindMouseOver();
|
|
322
282
|
unbindMouseMove();
|
|
@@ -2,8 +2,8 @@ import { BLOCK_CONTROLS_SURFACE_INVALIDATION } from '@atlaskit/editor-common/blo
|
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import { createSparseSurfacesViewWithLifecycle } from '../surface-lifecycle/sparse-surfaces-view-with-lifecycle';
|
|
5
6
|
import { key as blockControlsKey } from './main';
|
|
6
|
-
import { createSparseSurfacesView } from './sparse-surfaces-view';
|
|
7
7
|
import { emptySparseSurfaceCandidateState } from './utils/sparse-surface-candidates';
|
|
8
8
|
import { applySparseSurfacesTransaction, createInitialSparseSurfacesState } from './utils/sparse-surfaces-state';
|
|
9
9
|
export const sparseSurfacesKey = new PluginKey('blockControlsSparseSurfaces');
|
|
@@ -29,7 +29,7 @@ export const createSparseSurfacesPlugin = api => new SafePlugin({
|
|
|
29
29
|
return api !== null && api !== void 0 && (_api$limitedMode = api.limitedMode) !== null && _api$limitedMode !== void 0 && (_api$limitedMode$shar = _api$limitedMode.sharedState.currentState()) !== null && _api$limitedMode$shar !== void 0 && _api$limitedMode$shar.enabled || (_blockControlsKey$get = blockControlsKey.getState(state)) !== null && _blockControlsKey$get !== void 0 && _blockControlsKey$get.isDragging ? DecorationSet.empty : (_sparseSurfacesKey$ge = sparseSurfacesKey.getState(state)) === null || _sparseSurfacesKey$ge === void 0 ? void 0 : _sparseSurfacesKey$ge.decorations;
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
view: view =>
|
|
32
|
+
view: view => createSparseSurfacesViewWithLifecycle({
|
|
33
33
|
api,
|
|
34
34
|
pluginKey: sparseSurfacesKey,
|
|
35
35
|
view
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `callback` once after the next frame renders (`requestAnimationFrame`, then `setTimeout`).
|
|
3
|
+
* Deferring position reads gives the browser an opportunity to update layout first; other work
|
|
4
|
+
* can still invalidate layout before the callback. Calls made while a run is scheduled are ignored.
|
|
5
|
+
*/
|
|
6
|
+
export const createAfterRenderScheduler = (win, callback) => {
|
|
7
|
+
let frame;
|
|
8
|
+
let timeout;
|
|
9
|
+
return {
|
|
10
|
+
schedule: () => {
|
|
11
|
+
if (frame !== undefined || timeout !== undefined) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
frame = win.requestAnimationFrame(() => {
|
|
15
|
+
frame = undefined;
|
|
16
|
+
timeout = win.setTimeout(() => {
|
|
17
|
+
timeout = undefined;
|
|
18
|
+
callback();
|
|
19
|
+
}, 0);
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
cancel: () => {
|
|
23
|
+
if (frame !== undefined) {
|
|
24
|
+
win.cancelAnimationFrame(frame);
|
|
25
|
+
frame = undefined;
|
|
26
|
+
}
|
|
27
|
+
if (timeout !== undefined) {
|
|
28
|
+
win.clearTimeout(timeout);
|
|
29
|
+
timeout = undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -3,28 +3,13 @@ import "./block-controls-left-surface.compiled.css";
|
|
|
3
3
|
import { ax, ix } from "@compiled/react/runtime";
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
6
|
-
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
7
|
-
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
8
|
-
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
9
6
|
import { BlockControlsSurfaceWithClsFix } from '../surface-lifecycle/block-controls-surface-with-cls-fix';
|
|
10
|
-
import { BlockControlsVisibilityProvider } from './block-controls-surface-components';
|
|
11
|
-
import { getBlockControlsSurfaceControlSide } from './block-controls-surface-context';
|
|
12
|
-
import { useBlockControlsVisibility } from './visibility-container';
|
|
13
7
|
const leftSurfaceHiddenWrapperStyles = null;
|
|
14
8
|
const leftSurfaceOuterStyles = null;
|
|
15
9
|
const leftSurfaceGutterStyles = {
|
|
16
10
|
container: "_1f38ffwv _7cca15wb _lcxvglyw",
|
|
17
11
|
row: "_1bahesu3 _lcxvglyw _w1y61wug _19vrglyw"
|
|
18
12
|
};
|
|
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
|
-
};
|
|
28
13
|
const leftSurfaceRowStyles = null;
|
|
29
14
|
|
|
30
15
|
// Applied in addition to leftSurfaceRowStyles when the target node is sticky-eligible (e.g. long
|
|
@@ -35,46 +20,6 @@ const leftSurfaceStickyStyles = null;
|
|
|
35
20
|
|
|
36
21
|
// Keep in sync with STICKY_CONTROLS_TOP_MARGIN_FOR_STICKY_HEADER in ./consts (must be a static literal here)
|
|
37
22
|
const leftSurfaceStickyTableHeaderStyles = null;
|
|
38
|
-
const BlockControlsLeftSurfaceContent = ({
|
|
39
|
-
api,
|
|
40
|
-
components,
|
|
41
|
-
forceVisibleOnMouseOut,
|
|
42
|
-
placement,
|
|
43
|
-
source,
|
|
44
|
-
surfaceContext
|
|
45
|
-
}) => {
|
|
46
|
-
const blockControlsContext = surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT);
|
|
47
|
-
const controlSide = getBlockControlsSurfaceControlSide(blockControlsContext, isExperimentEnabled('platform_editor_controls_reliable_anchor'));
|
|
48
|
-
const {
|
|
49
|
-
shouldHide: shouldHideHoverControls,
|
|
50
|
-
useCssStyles
|
|
51
|
-
} = useBlockControlsVisibility({
|
|
52
|
-
api,
|
|
53
|
-
controlSide,
|
|
54
|
-
forceVisibleOnMouseOut
|
|
55
|
-
});
|
|
56
|
-
const isSticky = placement.isSticky;
|
|
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');
|
|
59
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
60
|
-
"data-editor-block-controls-surface": true,
|
|
61
|
-
"data-editor-block-controls-side": "left",
|
|
62
|
-
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
|
|
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.
|
|
64
|
-
,
|
|
65
|
-
style: placement.style,
|
|
66
|
-
className: ax(["_kqswstnw _17c61i8t _1pbyb4wl", isTopLevel && leftSurfaceGutterStyles.container, shouldPassThroughNestedPointerEvents && nestedSurfacePointerEventsStyles.container])
|
|
67
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
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' && "_154i1ejb"])
|
|
69
|
-
}, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
|
|
70
|
-
shouldHideHoverControls: shouldHideHoverControls,
|
|
71
|
-
useCssStyles: useCssStyles
|
|
72
|
-
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
73
|
-
components: components,
|
|
74
|
-
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
75
|
-
surfaceContext: surfaceContext
|
|
76
|
-
}))));
|
|
77
|
-
};
|
|
78
23
|
const BlockControlsLeftSurfaceWrapper = ({
|
|
79
24
|
children,
|
|
80
25
|
placement,
|
|
@@ -109,25 +54,14 @@ export const BlockControlsLeftSurface = ({
|
|
|
109
54
|
if (!placement) {
|
|
110
55
|
return null;
|
|
111
56
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
}
|
|
57
|
+
return /*#__PURE__*/React.createElement(BlockControlsSurfaceWithClsFix, {
|
|
58
|
+
side: "left",
|
|
59
|
+
SurfaceWrapper: BlockControlsLeftSurfaceWrapper,
|
|
60
|
+
api: api,
|
|
61
|
+
components: components,
|
|
62
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
63
|
+
placement: placement,
|
|
64
|
+
source: source,
|
|
65
|
+
surfaceContext: surfaceContext
|
|
66
|
+
});
|
|
133
67
|
};
|