@atlaskit/editor-plugin-block-controls 31.0.5 → 31.1.0
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 +16 -0
- package/dist/cjs/blockControlsPlugin.js +6 -2
- package/dist/cjs/pm-plugins/sparse-gutter-hover.js +23 -2
- package/dist/cjs/pm-plugins/sparse-surfaces-view.js +10 -1
- package/dist/cjs/surface-lifecycle/are-block-controls-surface-contexts-equal.js +39 -0
- package/dist/cjs/surface-lifecycle/block-controls-surface-descriptors.js +83 -0
- package/dist/cjs/surface-lifecycle/block-controls-surface-with-cls-fix.js +46 -0
- package/dist/cjs/surface-lifecycle/block-controls-surfaces.js +80 -0
- package/dist/cjs/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +287 -0
- package/dist/cjs/surface-lifecycle/surface-lifecycle.js +206 -0
- package/dist/cjs/surface-lifecycle/use-measured-surface-placements.js +199 -0
- package/dist/cjs/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/cjs/ui/block-controls-left-surface.js +61 -16
- package/dist/cjs/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/cjs/ui/block-controls-right-surface.js +48 -14
- package/dist/es2019/blockControlsPlugin.js +6 -2
- package/dist/es2019/pm-plugins/sparse-gutter-hover.js +23 -2
- package/dist/es2019/pm-plugins/sparse-surfaces-view.js +10 -1
- package/dist/es2019/surface-lifecycle/are-block-controls-surface-contexts-equal.js +31 -0
- package/dist/es2019/surface-lifecycle/block-controls-surface-descriptors.js +67 -0
- package/dist/es2019/surface-lifecycle/block-controls-surface-with-cls-fix.js +41 -0
- package/dist/es2019/surface-lifecycle/block-controls-surfaces.js +69 -0
- package/dist/es2019/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +256 -0
- package/dist/es2019/surface-lifecycle/surface-lifecycle.js +125 -0
- package/dist/es2019/surface-lifecycle/use-measured-surface-placements.js +163 -0
- package/dist/es2019/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/es2019/ui/block-controls-left-surface.js +56 -10
- package/dist/es2019/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/es2019/ui/block-controls-right-surface.js +43 -8
- package/dist/esm/blockControlsPlugin.js +6 -2
- package/dist/esm/pm-plugins/sparse-gutter-hover.js +23 -2
- package/dist/esm/pm-plugins/sparse-surfaces-view.js +10 -1
- package/dist/esm/surface-lifecycle/are-block-controls-surface-contexts-equal.js +33 -0
- package/dist/esm/surface-lifecycle/block-controls-surface-descriptors.js +76 -0
- package/dist/esm/surface-lifecycle/block-controls-surface-with-cls-fix.js +39 -0
- package/dist/esm/surface-lifecycle/block-controls-surfaces.js +72 -0
- package/dist/esm/surface-lifecycle/sparse-surfaces-view-with-lifecycle.js +280 -0
- package/dist/esm/surface-lifecycle/surface-lifecycle.js +199 -0
- package/dist/esm/surface-lifecycle/use-measured-surface-placements.js +192 -0
- package/dist/esm/ui/block-controls-left-surface.compiled.css +1 -0
- package/dist/esm/ui/block-controls-left-surface.js +61 -16
- package/dist/esm/ui/block-controls-right-surface.compiled.css +1 -0
- package/dist/esm/ui/block-controls-right-surface.js +48 -14
- package/dist/types/pm-plugins/sparse-surfaces-view.d.ts +2 -1
- package/dist/types/surface-lifecycle/are-block-controls-surface-contexts-equal.d.ts +19 -0
- package/dist/types/surface-lifecycle/block-controls-surface-descriptors.d.ts +28 -0
- package/dist/types/surface-lifecycle/block-controls-surface-with-cls-fix.d.ts +26 -0
- package/dist/types/surface-lifecycle/block-controls-surfaces.d.ts +10 -0
- package/dist/types/surface-lifecycle/sparse-surfaces-view-with-lifecycle.d.ts +21 -0
- package/dist/types/surface-lifecycle/surface-lifecycle.d.ts +46 -0
- package/dist/types/surface-lifecycle/use-measured-surface-placements.d.ts +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
3
|
+
import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
4
|
+
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
5
|
+
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
6
|
+
import { BlockControlsVisibilityProvider } from '../ui/block-controls-surface-components';
|
|
7
|
+
import { getBlockControlsSurfaceControlSide } from '../ui/block-controls-surface-context';
|
|
8
|
+
import { useBlockControlsVisibility } from '../ui/visibility-container';
|
|
9
|
+
/** Renders one block-controls surface for either side on the CLS fix path. */
|
|
10
|
+
export const BlockControlsSurfaceWithClsFix = ({
|
|
11
|
+
api,
|
|
12
|
+
components,
|
|
13
|
+
forceVisibleOnMouseOut,
|
|
14
|
+
placement,
|
|
15
|
+
side,
|
|
16
|
+
source,
|
|
17
|
+
surfaceContext,
|
|
18
|
+
SurfaceWrapper
|
|
19
|
+
}) => {
|
|
20
|
+
const controlSide = side === 'left' ? getBlockControlsSurfaceControlSide(surfaceContext.get(BLOCK_CONTROL_UI_CONTEXT), isExperimentEnabled('platform_editor_controls_reliable_anchor')) : 'right';
|
|
21
|
+
const {
|
|
22
|
+
shouldHide: shouldHideHoverControls,
|
|
23
|
+
useCssStyles
|
|
24
|
+
} = useBlockControlsVisibility({
|
|
25
|
+
api,
|
|
26
|
+
controlSide,
|
|
27
|
+
forceVisibleOnMouseOut
|
|
28
|
+
});
|
|
29
|
+
return /*#__PURE__*/React.createElement(SurfaceWrapper, {
|
|
30
|
+
placement: placement,
|
|
31
|
+
source: source,
|
|
32
|
+
surfaceContext: surfaceContext
|
|
33
|
+
}, /*#__PURE__*/React.createElement(BlockControlsVisibilityProvider, {
|
|
34
|
+
shouldHideHoverControls: shouldHideHoverControls,
|
|
35
|
+
useCssStyles: useCssStyles
|
|
36
|
+
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
37
|
+
components: components,
|
|
38
|
+
surface: side === 'left' ? BLOCK_CONTROLS_LEFT_SURFACE : BLOCK_CONTROLS_RIGHT_SURFACE,
|
|
39
|
+
surfaceContext: surfaceContext
|
|
40
|
+
})));
|
|
41
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { memo, useLayoutEffect, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
+
import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles/native-anchor';
|
|
3
|
+
import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
|
|
4
|
+
import { BlockControlsLeftSurface } from '../ui/block-controls-left-surface';
|
|
5
|
+
import { BlockControlsRightSurface } from '../ui/block-controls-right-surface';
|
|
6
|
+
import { getAnchoredLeftGutterSurfacePlacement, getAnchoredSurfacePlacement } from '../ui/utils/get-surface-placement';
|
|
7
|
+
import { getSurfaceLifecycle } from './surface-lifecycle';
|
|
8
|
+
import { getSurfaceKey, useMeasuredSurfacePlacements } from './use-measured-surface-placements';
|
|
9
|
+
const CommittedSurface = /*#__PURE__*/memo(({
|
|
10
|
+
api,
|
|
11
|
+
descriptor,
|
|
12
|
+
side,
|
|
13
|
+
forceVisibleOnMouseOut,
|
|
14
|
+
measuredPlacement
|
|
15
|
+
}) => {
|
|
16
|
+
const {
|
|
17
|
+
anchorName,
|
|
18
|
+
blockControlsContext,
|
|
19
|
+
isTopLevel
|
|
20
|
+
} = descriptor;
|
|
21
|
+
const nodeType = blockControlsContext.targetNode.type.name;
|
|
22
|
+
const nodeTypeWithLevel = getNodeTypeWithLevel(blockControlsContext.targetNode.node);
|
|
23
|
+
const layout = blockControlsContext.targetNode.node.attrs.layout;
|
|
24
|
+
const parentNodeType = blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType;
|
|
25
|
+
const anchoredPlacement = useMemo(() => {
|
|
26
|
+
if (!isCSSAnchorSupported()) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const options = {
|
|
30
|
+
anchorName,
|
|
31
|
+
nodeType,
|
|
32
|
+
nodeTypeWithLevel,
|
|
33
|
+
layout,
|
|
34
|
+
parentNodeType,
|
|
35
|
+
side
|
|
36
|
+
};
|
|
37
|
+
return side === 'left' && isTopLevel ? getAnchoredLeftGutterSurfacePlacement(options) : getAnchoredSurfacePlacement(options);
|
|
38
|
+
}, [anchorName, nodeType, nodeTypeWithLevel, layout, parentNodeType, side, isTopLevel]);
|
|
39
|
+
const Surface = side === 'left' ? BlockControlsLeftSurface : BlockControlsRightSurface;
|
|
40
|
+
return /*#__PURE__*/React.createElement(Surface, {
|
|
41
|
+
api: api,
|
|
42
|
+
components: descriptor.surfaceComponents,
|
|
43
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
44
|
+
placement: anchoredPlacement !== null && anchoredPlacement !== void 0 ? anchoredPlacement : measuredPlacement,
|
|
45
|
+
source: descriptor.source,
|
|
46
|
+
surfaceContext: descriptor.surfaceContext
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
export const CommittedBlockControlsSurfaces = props => {
|
|
50
|
+
const lifecycle = getSurfaceLifecycle(props.editorView);
|
|
51
|
+
const snapshot = useSyncExternalStore(lifecycle.subscribe, lifecycle.getSnapshot, () => undefined);
|
|
52
|
+
const measuredPlacements = useMeasuredSurfacePlacements(props.editorView, snapshot === null || snapshot === void 0 ? void 0 : snapshot.left, snapshot === null || snapshot === void 0 ? void 0 : snapshot.right);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
if (snapshot) {
|
|
55
|
+
lifecycle.acknowledge(snapshot.revision);
|
|
56
|
+
}
|
|
57
|
+
}, [lifecycle, snapshot]);
|
|
58
|
+
if (!snapshot) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, ['left', 'right'].flatMap(side => snapshot[side].map(descriptor => /*#__PURE__*/React.createElement(CommittedSurface, {
|
|
62
|
+
key: getSurfaceKey(side, descriptor),
|
|
63
|
+
api: props.api,
|
|
64
|
+
descriptor: descriptor,
|
|
65
|
+
side: side,
|
|
66
|
+
forceVisibleOnMouseOut: snapshot.forceVisibleOnMouseOut,
|
|
67
|
+
measuredPlacement: measuredPlacements.get(getSurfaceKey(side, descriptor))
|
|
68
|
+
}))));
|
|
69
|
+
};
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
2
|
+
import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor-provider';
|
|
3
|
+
import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
4
|
+
import { createSurfaceAnchorDecorations, TYPE_SURFACE_ANCHOR_DEC } from '../pm-plugins/decorations-surface-anchor';
|
|
5
|
+
import { key as blockControlsKey } from '../pm-plugins/main';
|
|
6
|
+
import { bindSparseGutterHover } from '../pm-plugins/sparse-gutter-hover';
|
|
7
|
+
import { reconcileSparseSurfaceCandidates } from '../pm-plugins/utils/sparse-surface-candidates';
|
|
8
|
+
import { observeSurfaceViewport } from '../pm-plugins/utils/surface-viewport';
|
|
9
|
+
import { getBlockControlsSurfaceTargets } from '../ui/block-controls-surface-targets';
|
|
10
|
+
import { createSurfaceDescriptorResolver } from './block-controls-surface-descriptors';
|
|
11
|
+
import { getSurfaceLifecycle } from './surface-lifecycle';
|
|
12
|
+
const haveAnchorPositionsChanged = (positions, anchors) => positions.length !== anchors.size || positions.some(position => !anchors.has(position));
|
|
13
|
+
const areAnchorsEqual = (a, b) => a.size === b.size && [...a].every(([position, name]) => b.get(position) === name);
|
|
14
|
+
|
|
15
|
+
/** Limited mode and dragging remove every sparse anchor decoration from the document. */
|
|
16
|
+
const areSurfacesSuppressed = (api, state) => {
|
|
17
|
+
var _api$limitedMode, _api$limitedMode$shar, _blockControlsKey$get;
|
|
18
|
+
return Boolean((api === null || api === void 0 ? void 0 : (_api$limitedMode = api.limitedMode) === null || _api$limitedMode === void 0 ? void 0 : (_api$limitedMode$shar = _api$limitedMode.sharedState.currentState()) === null || _api$limitedMode$shar === void 0 ? void 0 : _api$limitedMode$shar.enabled) || ((_blockControlsKey$get = blockControlsKey.getState(state)) === null || _blockControlsKey$get === void 0 ? void 0 : _blockControlsKey$get.isDragging));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** An open block menu keeps its trigger node, and that node's root, as active surface positions. */
|
|
22
|
+
const getMenuActiveNodes = (controls, doc) => {
|
|
23
|
+
const activeNodesByPosition = new Map();
|
|
24
|
+
const menu = controls !== null && controls !== void 0 && controls.isMenuOpen ? controls.menuTriggerByNode : undefined;
|
|
25
|
+
if (menu && controls !== null && controls !== void 0 && controls.menuTriggerBy && doc.nodeAt(menu.pos)) {
|
|
26
|
+
var _menu$rootPos;
|
|
27
|
+
const menuNode = {
|
|
28
|
+
...menu,
|
|
29
|
+
anchorName: controls.menuTriggerBy
|
|
30
|
+
};
|
|
31
|
+
activeNodesByPosition.set(menu.pos, menuNode);
|
|
32
|
+
activeNodesByPosition.set((_menu$rootPos = menu.rootPos) !== null && _menu$rootPos !== void 0 ? _menu$rootPos : menu.pos, menuNode);
|
|
33
|
+
}
|
|
34
|
+
return activeNodesByPosition;
|
|
35
|
+
};
|
|
36
|
+
const reconcileCandidates = ({
|
|
37
|
+
activeNode,
|
|
38
|
+
activeNodesByPosition,
|
|
39
|
+
api,
|
|
40
|
+
previous,
|
|
41
|
+
registryChanged,
|
|
42
|
+
state,
|
|
43
|
+
visiblePositions
|
|
44
|
+
}) => reconcileSparseSurfaceCandidates({
|
|
45
|
+
activeNode,
|
|
46
|
+
activeNodesByPosition,
|
|
47
|
+
newState: state,
|
|
48
|
+
state: previous.candidates,
|
|
49
|
+
visiblePositions,
|
|
50
|
+
protectedPositions: [...activeNodesByPosition.keys()],
|
|
51
|
+
resolvedSurfaces: [BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE].map(surface => {
|
|
52
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
53
|
+
return resolveSurface((_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(surface)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], surface);
|
|
54
|
+
}),
|
|
55
|
+
documentChanged: previous.documentChanged,
|
|
56
|
+
invalidation: {
|
|
57
|
+
...previous.invalidation,
|
|
58
|
+
all: registryChanged
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
/** True when the committed state already matches the candidates and no anchor awaits retirement. */
|
|
63
|
+
const isReconciled = (previous, candidates, lifecycle) => !haveAnchorPositionsChanged(candidates.positions, previous.anchors) && candidates === previous.candidates && !previous.documentChanged && !previous.invalidation && !lifecycle.hasRetirableAnchors(previous.decorations);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Builds anchor decorations for the candidate positions, keeping each node's existing anchor name
|
|
67
|
+
* and any anchor a committed or pending surface still uses.
|
|
68
|
+
*/
|
|
69
|
+
const createReconciledDecorations = (view, previous, positions, lifecycle) => {
|
|
70
|
+
const previousAnchors = new Map(previous.decorations.find(undefined, undefined, spec => spec.type === TYPE_SURFACE_ANCHOR_DEC).map(decoration => [decoration.from, String(decoration.spec.anchorName)]));
|
|
71
|
+
const nodeIdProvider = getNodeIdProvider(view);
|
|
72
|
+
const {
|
|
73
|
+
anchors: nextAnchors,
|
|
74
|
+
decorations: desiredDecorations
|
|
75
|
+
} = createSurfaceAnchorDecorations(view.state, positions, (node, position, previousAnchorName) => {
|
|
76
|
+
if (previousAnchorName) {
|
|
77
|
+
nodeIdProvider.setIdForNode(node, previousAnchorName);
|
|
78
|
+
return previousAnchorName;
|
|
79
|
+
}
|
|
80
|
+
return nodeIdProvider.getOrGenerateId(node, position);
|
|
81
|
+
}, previousAnchors);
|
|
82
|
+
return {
|
|
83
|
+
// Retiring anchors after a commit leaves the anchor map unchanged, so keep its identity.
|
|
84
|
+
anchors: areAnchorsEqual(nextAnchors, previous.anchors) ? previous.anchors : nextAnchors,
|
|
85
|
+
decorations: lifecycle.retainAnchors(view.state.doc, desiredDecorations, previous.decorations)
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const resolveSurfaceSnapshot = ({
|
|
89
|
+
activeNode,
|
|
90
|
+
activeNodesByPosition,
|
|
91
|
+
anchors,
|
|
92
|
+
api,
|
|
93
|
+
invalidated,
|
|
94
|
+
positions,
|
|
95
|
+
resolvers,
|
|
96
|
+
state
|
|
97
|
+
}) => {
|
|
98
|
+
var _activeNode$handleOpt, _api$uiControlRegistr3, _api$uiControlRegistr4, _api$uiControlRegistr5, _api$uiControlRegistr6;
|
|
99
|
+
const candidatePositions = new Set(positions);
|
|
100
|
+
const input = {
|
|
101
|
+
activeNode,
|
|
102
|
+
state,
|
|
103
|
+
surfaceActiveNodes: activeNodesByPosition,
|
|
104
|
+
surfaceAnchors: anchors,
|
|
105
|
+
targets: getBlockControlsSurfaceTargets(activeNode, positions).filter(({
|
|
106
|
+
position
|
|
107
|
+
}) => candidatePositions.has(position))
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 ? void 0 : (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
111
|
+
left: resolvers.left({
|
|
112
|
+
...input,
|
|
113
|
+
components: (_api$uiControlRegistr3 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr4 = api.uiControlRegistry) === null || _api$uiControlRegistr4 === void 0 ? void 0 : _api$uiControlRegistr4.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr3 !== void 0 ? _api$uiControlRegistr3 : []
|
|
114
|
+
}, invalidated),
|
|
115
|
+
right: resolvers.right({
|
|
116
|
+
...input,
|
|
117
|
+
components: (_api$uiControlRegistr5 = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr6 = api.uiControlRegistry) === null || _api$uiControlRegistr6 === void 0 ? void 0 : _api$uiControlRegistr6.actions.getComponents(BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr5 !== void 0 ? _api$uiControlRegistr5 : []
|
|
118
|
+
}, invalidated)
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/** Changes that can add or remove anchor suppression, which also invalidates control visibility. */
|
|
123
|
+
const haveSuppressionInputsChanged = (controls, previousControls) => (controls === null || controls === void 0 ? void 0 : controls.isDragging) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isDragging) || (controls === null || controls === void 0 ? void 0 : controls.isResizerResizing) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isResizerResizing);
|
|
124
|
+
|
|
125
|
+
/** Changes that can move surfaces between blocks without invalidating control visibility. */
|
|
126
|
+
const haveSurfaceInputsChanged = (sparse, controls, previousControls) => Boolean((sparse === null || sparse === void 0 ? void 0 : sparse.documentChanged) || (sparse === null || sparse === void 0 ? void 0 : sparse.invalidation)) || (controls === null || controls === void 0 ? void 0 : controls.activeNode) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.activeNode) || (controls === null || controls === void 0 ? void 0 : controls.isMenuOpen) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.isMenuOpen) || (controls === null || controls === void 0 ? void 0 : controls.menuTriggerByNode) !== (previousControls === null || previousControls === void 0 ? void 0 : previousControls.menuTriggerByNode);
|
|
127
|
+
const subscribeToInvalidation = (api, invalidate) => {
|
|
128
|
+
var _api$uiControlRegistr7, _api$editorDisabled, _api$editorViewMode, _api$limitedMode2, _api$showDiff, _api$userIntent;
|
|
129
|
+
const unsubscribers = [api === null || api === void 0 ? void 0 : (_api$uiControlRegistr7 = api.uiControlRegistry) === null || _api$uiControlRegistr7 === void 0 ? void 0 : _api$uiControlRegistr7.actions.subscribe(invalidate), api === null || api === void 0 ? void 0 : (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.sharedState.onChange(invalidate), api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.sharedState.onChange(invalidate), api === null || api === void 0 ? void 0 : (_api$limitedMode2 = api.limitedMode) === null || _api$limitedMode2 === void 0 ? void 0 : _api$limitedMode2.sharedState.onChange(invalidate), api === null || api === void 0 ? void 0 : (_api$showDiff = api.showDiff) === null || _api$showDiff === void 0 ? void 0 : _api$showDiff.sharedState.onChange(invalidate), api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.sharedState.onChange(invalidate)];
|
|
130
|
+
return () => unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Sparse surfaces plugin view for the CLS fix. Each animation frame reconciles which blocks have
|
|
135
|
+
* surfaces, commits their anchor decorations, and publishes the surfaces React renders through
|
|
136
|
+
* `SurfaceLifecycle`, which retains anchors until React commits their replacement.
|
|
137
|
+
*/
|
|
138
|
+
export const createSparseSurfacesViewWithLifecycle = ({
|
|
139
|
+
api,
|
|
140
|
+
pluginKey,
|
|
141
|
+
view
|
|
142
|
+
}) => {
|
|
143
|
+
const win = view.dom.ownerDocument.defaultView;
|
|
144
|
+
const lifecycle = getSurfaceLifecycle(view);
|
|
145
|
+
const resolvers = {
|
|
146
|
+
left: createSurfaceDescriptorResolver('left'),
|
|
147
|
+
right: createSurfaceDescriptorResolver('right')
|
|
148
|
+
};
|
|
149
|
+
let frame;
|
|
150
|
+
let visiblePositions = [];
|
|
151
|
+
let registryChanged = true;
|
|
152
|
+
let surfaceStateChanged = false;
|
|
153
|
+
const updateAvailableAnchors = () => {
|
|
154
|
+
const sparse = pluginKey.getState(view.state);
|
|
155
|
+
if (sparse) {
|
|
156
|
+
lifecycle.updateAnchors(sparse.decorations, areSurfacesSuppressed(api, view.state));
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const reconcile = () => {
|
|
160
|
+
var _api$limitedMode3, _api$limitedMode3$sha;
|
|
161
|
+
frame = undefined;
|
|
162
|
+
const previous = pluginKey.getState(view.state);
|
|
163
|
+
if (!previous || api !== null && api !== void 0 && (_api$limitedMode3 = api.limitedMode) !== null && _api$limitedMode3 !== void 0 && (_api$limitedMode3$sha = _api$limitedMode3.sharedState.currentState()) !== null && _api$limitedMode3$sha !== void 0 && _api$limitedMode3$sha.enabled) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const controls = blockControlsKey.getState(view.state);
|
|
167
|
+
const activeNode = controls === null || controls === void 0 ? void 0 : controls.activeNode;
|
|
168
|
+
const activeNodesByPosition = getMenuActiveNodes(controls, view.state.doc);
|
|
169
|
+
const candidates = reconcileCandidates({
|
|
170
|
+
activeNode,
|
|
171
|
+
activeNodesByPosition,
|
|
172
|
+
api,
|
|
173
|
+
previous,
|
|
174
|
+
registryChanged,
|
|
175
|
+
state: view.state,
|
|
176
|
+
visiblePositions
|
|
177
|
+
});
|
|
178
|
+
const visibilityChanged = registryChanged;
|
|
179
|
+
registryChanged = false;
|
|
180
|
+
if (!surfaceStateChanged && !visibilityChanged && isReconciled(previous, candidates, lifecycle)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
surfaceStateChanged = false;
|
|
184
|
+
const {
|
|
185
|
+
anchors,
|
|
186
|
+
decorations
|
|
187
|
+
} = createReconciledDecorations(view, previous, candidates.positions, lifecycle);
|
|
188
|
+
view.dispatch(view.state.tr.setMeta(pluginKey, {
|
|
189
|
+
reconciliation: {
|
|
190
|
+
activeNodesByPosition,
|
|
191
|
+
anchors,
|
|
192
|
+
candidates,
|
|
193
|
+
decorations
|
|
194
|
+
},
|
|
195
|
+
type: 'commitReconciliation'
|
|
196
|
+
}));
|
|
197
|
+
lifecycle.publish(resolveSurfaceSnapshot({
|
|
198
|
+
activeNode,
|
|
199
|
+
activeNodesByPosition,
|
|
200
|
+
anchors,
|
|
201
|
+
api,
|
|
202
|
+
invalidated: visibilityChanged || Boolean(previous.invalidation),
|
|
203
|
+
positions: candidates.positions,
|
|
204
|
+
resolvers,
|
|
205
|
+
state: view.state
|
|
206
|
+
}), anchors);
|
|
207
|
+
};
|
|
208
|
+
const schedule = () => {
|
|
209
|
+
if (frame === undefined && win) {
|
|
210
|
+
frame = win.requestAnimationFrame(reconcile);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const invalidate = () => {
|
|
214
|
+
if (areSurfacesSuppressed(api, view.state)) {
|
|
215
|
+
updateAvailableAnchors();
|
|
216
|
+
}
|
|
217
|
+
registryChanged = true;
|
|
218
|
+
schedule();
|
|
219
|
+
};
|
|
220
|
+
updateAvailableAnchors();
|
|
221
|
+
// A committed tree may no longer need older anchors; the next reconcile retires them.
|
|
222
|
+
lifecycle.setOnCommit(schedule);
|
|
223
|
+
const observer = observeSurfaceViewport(view, positions => {
|
|
224
|
+
visiblePositions = positions;
|
|
225
|
+
schedule();
|
|
226
|
+
});
|
|
227
|
+
const unsubscribe = subscribeToInvalidation(api, invalidate);
|
|
228
|
+
const unbindGutterHover = bindSparseGutterHover({
|
|
229
|
+
api,
|
|
230
|
+
view
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
update(currentView, previousState) {
|
|
234
|
+
updateAvailableAnchors();
|
|
235
|
+
observer.update();
|
|
236
|
+
const controls = blockControlsKey.getState(currentView.state);
|
|
237
|
+
const previousControls = blockControlsKey.getState(previousState);
|
|
238
|
+
if (haveSuppressionInputsChanged(controls, previousControls)) {
|
|
239
|
+
invalidate();
|
|
240
|
+
}
|
|
241
|
+
if (haveSurfaceInputsChanged(pluginKey.getState(currentView.state), controls, previousControls)) {
|
|
242
|
+
surfaceStateChanged = true;
|
|
243
|
+
schedule();
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
destroy() {
|
|
247
|
+
if (frame !== undefined) {
|
|
248
|
+
win === null || win === void 0 ? void 0 : win.cancelAnimationFrame(frame);
|
|
249
|
+
}
|
|
250
|
+
lifecycle.destroy();
|
|
251
|
+
observer.destroy();
|
|
252
|
+
unbindGutterHover === null || unbindGutterHover === void 0 ? void 0 : unbindGutterHover();
|
|
253
|
+
unsubscribe();
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
const filterAvailable = (descriptors, available) => descriptors.every(descriptor => available.has(descriptor.anchorName)) ? descriptors : descriptors.filter(descriptor => available.has(descriptor.anchorName));
|
|
3
|
+
const areSameDescriptors = (a, b) => a.length === b.length && a.every((descriptor, index) => descriptor === b[index]);
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Keeps anchor decorations in step with the block-control surfaces React renders.
|
|
7
|
+
* - An anchor stays until React has committed a tree that no longer uses it.
|
|
8
|
+
* - Surfaces whose anchor is gone (deleted block, drag, limited mode) are left out of the snapshot,
|
|
9
|
+
* so React removes them before the browser paints.
|
|
10
|
+
*/
|
|
11
|
+
export class SurfaceLifecycle {
|
|
12
|
+
constructor() {
|
|
13
|
+
_defineProperty(this, "committedRevision", 0);
|
|
14
|
+
_defineProperty(this, "revision", 0);
|
|
15
|
+
_defineProperty(this, "lastUsedRevision", new Map());
|
|
16
|
+
_defineProperty(this, "listeners", new Set());
|
|
17
|
+
_defineProperty(this, "availableAnchors", new Set());
|
|
18
|
+
_defineProperty(this, "publishedAnchors", new Set());
|
|
19
|
+
_defineProperty(this, "suppressed", false);
|
|
20
|
+
_defineProperty(this, "getSnapshot", () => this.snapshot);
|
|
21
|
+
_defineProperty(this, "subscribe", listener => {
|
|
22
|
+
this.listeners.add(listener);
|
|
23
|
+
return () => this.listeners.delete(listener);
|
|
24
|
+
});
|
|
25
|
+
_defineProperty(this, "acknowledge", revision => {
|
|
26
|
+
var _this$published$revis, _this$published, _this$onCommit;
|
|
27
|
+
if (revision <= this.committedRevision || revision > ((_this$published$revis = (_this$published = this.published) === null || _this$published === void 0 ? void 0 : _this$published.revision) !== null && _this$published$revis !== void 0 ? _this$published$revis : 0)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
this.committedRevision = revision;
|
|
31
|
+
(_this$onCommit = this.onCommit) === null || _this$onCommit === void 0 ? void 0 : _this$onCommit.call(this);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
setOnCommit(onCommit) {
|
|
35
|
+
this.onCommit = onCommit;
|
|
36
|
+
}
|
|
37
|
+
publish(snapshot, anchors) {
|
|
38
|
+
var _this$published2;
|
|
39
|
+
if (((_this$published2 = this.published) === null || _this$published2 === void 0 ? void 0 : _this$published2.left) === snapshot.left && this.published.right === snapshot.right && this.published.forceVisibleOnMouseOut === snapshot.forceVisibleOnMouseOut && this.publishedAnchors.size === anchors.size && [...anchors.values()].every(name => this.publishedAnchors.has(name))) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
this.publishedAnchors = new Set(anchors.values());
|
|
43
|
+
const revision = ++this.revision;
|
|
44
|
+
for (const name of anchors.values()) {
|
|
45
|
+
this.lastUsedRevision.set(name, revision);
|
|
46
|
+
}
|
|
47
|
+
this.published = {
|
|
48
|
+
...snapshot,
|
|
49
|
+
revision
|
|
50
|
+
};
|
|
51
|
+
this.updateSnapshot(true);
|
|
52
|
+
}
|
|
53
|
+
retainAnchors(doc, desired, previous) {
|
|
54
|
+
const positions = new Set(desired.find().map(decoration => decoration.from));
|
|
55
|
+
const retained = previous.find().filter(decoration => !positions.has(decoration.from) && this.isRetained(decoration.spec.anchorName));
|
|
56
|
+
return retained.length ? desired.add(doc, retained) : desired;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Whether a reconcile would drop anchors that no committed or pending tree still uses. */
|
|
60
|
+
hasRetirableAnchors(decorations) {
|
|
61
|
+
return decorations.find().some(decoration => !this.isRetained(decoration.spec.anchorName));
|
|
62
|
+
}
|
|
63
|
+
isRetained(name) {
|
|
64
|
+
const revision = this.lastUsedRevision.get(name);
|
|
65
|
+
// Keep the committed tree and every newer published tree until a later commit replaces them.
|
|
66
|
+
return revision !== undefined && revision >= this.committedRevision;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Records which anchors the browser can currently resolve. Removes surfaces for missing or
|
|
71
|
+
* suppressed anchors from the snapshot synchronously, ahead of the next reconcile.
|
|
72
|
+
*/
|
|
73
|
+
updateAnchors(decorations, suppressed) {
|
|
74
|
+
if (decorations === this.decorations && suppressed === this.suppressed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.decorations = decorations;
|
|
78
|
+
this.suppressed = suppressed;
|
|
79
|
+
const names = new Set(decorations.find().map(decoration => decoration.spec.anchorName));
|
|
80
|
+
this.availableAnchors = suppressed ? new Set() : names;
|
|
81
|
+
for (const name of this.lastUsedRevision.keys()) {
|
|
82
|
+
if (!names.has(name)) {
|
|
83
|
+
this.lastUsedRevision.delete(name);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
this.updateSnapshot(false);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Derives the snapshot React reads, replacing it only when the rendered surfaces change. */
|
|
90
|
+
updateSnapshot(published) {
|
|
91
|
+
if (!this.published) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const left = filterAvailable(this.published.left, this.availableAnchors);
|
|
95
|
+
const right = filterAvailable(this.published.right, this.availableAnchors);
|
|
96
|
+
if (!published && this.snapshot && areSameDescriptors(left, this.snapshot.left) && areSameDescriptors(right, this.snapshot.right)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.snapshot = {
|
|
100
|
+
...this.published,
|
|
101
|
+
left,
|
|
102
|
+
right
|
|
103
|
+
};
|
|
104
|
+
this.listeners.forEach(listener => listener());
|
|
105
|
+
}
|
|
106
|
+
destroy() {
|
|
107
|
+
this.availableAnchors = new Set();
|
|
108
|
+
this.publishedAnchors.clear();
|
|
109
|
+
this.lastUsedRevision.clear();
|
|
110
|
+
this.onCommit = undefined;
|
|
111
|
+
this.decorations = undefined;
|
|
112
|
+
this.published = undefined;
|
|
113
|
+
this.snapshot = undefined;
|
|
114
|
+
this.listeners.forEach(listener => listener());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const lifecycles = new WeakMap();
|
|
118
|
+
export const getSurfaceLifecycle = view => {
|
|
119
|
+
let lifecycle = lifecycles.get(view);
|
|
120
|
+
if (!lifecycle) {
|
|
121
|
+
lifecycle = new SurfaceLifecycle();
|
|
122
|
+
lifecycles.set(view, lifecycle);
|
|
123
|
+
}
|
|
124
|
+
return lifecycle;
|
|
125
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
4
|
+
import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles/native-anchor';
|
|
5
|
+
import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
|
|
6
|
+
import { getNodeContentElement } from '../ui/utils/get-node-content-element';
|
|
7
|
+
import { getAbsoluteSurfacePlacement, getLeftGutterSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from '../ui/utils/get-surface-placement';
|
|
8
|
+
const EMPTY_PLACEMENTS = new Map();
|
|
9
|
+
export const getSurfaceKey = (side, descriptor) => `${side}:${descriptor.anchorName}`;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Measures surface placements from DOM geometry when the browser cannot position surfaces with CSS
|
|
13
|
+
* anchors. Returns an empty map and binds nothing when anchors are supported. Both sides share one
|
|
14
|
+
* set of listeners, and measuring reruns only when a side's descriptor list changes, which the
|
|
15
|
+
* descriptor resolver keeps stable across unrelated updates.
|
|
16
|
+
*/
|
|
17
|
+
export const useMeasuredSurfacePlacements = (editorView, left, right) => {
|
|
18
|
+
const [placements, setPlacements] = useState(EMPTY_PLACEMENTS);
|
|
19
|
+
const animationFrameRef = useRef(undefined);
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
var _getDocument;
|
|
22
|
+
// Anchor support is fixed for the session, so anchored surfaces never set measured state.
|
|
23
|
+
if (isCSSAnchorSupported()) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const descriptors = [...(left !== null && left !== void 0 ? left : []).map(descriptor => ({
|
|
27
|
+
descriptor,
|
|
28
|
+
side: 'left'
|
|
29
|
+
})), ...(right !== null && right !== void 0 ? right : []).map(descriptor => ({
|
|
30
|
+
descriptor,
|
|
31
|
+
side: 'right'
|
|
32
|
+
}))];
|
|
33
|
+
if (descriptors.length === 0) {
|
|
34
|
+
// Clear only when there is something to clear, so an empty map does not commit a render.
|
|
35
|
+
setPlacements(previous => previous.size > 0 ? EMPTY_PLACEMENTS : previous);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const measurementTargets = descriptors.flatMap(({
|
|
39
|
+
descriptor,
|
|
40
|
+
side
|
|
41
|
+
}) => {
|
|
42
|
+
const {
|
|
43
|
+
blockControlsContext
|
|
44
|
+
} = descriptor;
|
|
45
|
+
const targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
46
|
+
const targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
47
|
+
if (!targetElementRoot) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
return [{
|
|
51
|
+
descriptor,
|
|
52
|
+
side,
|
|
53
|
+
targetElement: getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name),
|
|
54
|
+
targetElementRoot
|
|
55
|
+
}];
|
|
56
|
+
});
|
|
57
|
+
const offsetParent = editorView.dom.offsetParent;
|
|
58
|
+
const isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
|
|
59
|
+
const scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
|
|
60
|
+
const updatePositions = () => {
|
|
61
|
+
var _scrollingOffsetParen, _scrollingOffsetParen2;
|
|
62
|
+
animationFrameRef.current = undefined;
|
|
63
|
+
const offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
|
|
64
|
+
const offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
|
|
65
|
+
const offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
|
|
66
|
+
const nextPlacements = new Map();
|
|
67
|
+
for (const {
|
|
68
|
+
descriptor,
|
|
69
|
+
side,
|
|
70
|
+
targetElement,
|
|
71
|
+
targetElementRoot
|
|
72
|
+
} of measurementTargets) {
|
|
73
|
+
var _targetElementRoot$ge, _offsetParentRect$lef;
|
|
74
|
+
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const {
|
|
78
|
+
blockControlsContext,
|
|
79
|
+
isTopLevel
|
|
80
|
+
} = descriptor;
|
|
81
|
+
const options = {
|
|
82
|
+
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
83
|
+
nodeRect: targetElement.getBoundingClientRect(),
|
|
84
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
85
|
+
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
86
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
87
|
+
};
|
|
88
|
+
const placement = side === 'left' && isTopLevel ? getLeftGutterSurfacePlacement({
|
|
89
|
+
...options,
|
|
90
|
+
leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
|
|
91
|
+
}) : getSurfacePlacement({
|
|
92
|
+
...options,
|
|
93
|
+
side
|
|
94
|
+
});
|
|
95
|
+
nextPlacements.set(getSurfaceKey(side, descriptor), toMeasuredSurfaceWrapperPlacement(getAbsoluteSurfacePlacement({
|
|
96
|
+
offsetParentRect,
|
|
97
|
+
offsetParentScrollLeft,
|
|
98
|
+
offsetParentScrollTop,
|
|
99
|
+
placement
|
|
100
|
+
})));
|
|
101
|
+
}
|
|
102
|
+
setPlacements(nextPlacements);
|
|
103
|
+
};
|
|
104
|
+
const schedulePositionUpdate = () => {
|
|
105
|
+
if (animationFrameRef.current === undefined) {
|
|
106
|
+
animationFrameRef.current = requestAnimationFrame(updatePositions);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
updatePositions();
|
|
110
|
+
const resizeObserver = new ResizeObserver(schedulePositionUpdate);
|
|
111
|
+
const observedElements = new Set([editorView.dom]);
|
|
112
|
+
for (const {
|
|
113
|
+
targetElement
|
|
114
|
+
} of measurementTargets) {
|
|
115
|
+
observedElements.add(targetElement);
|
|
116
|
+
}
|
|
117
|
+
if (offsetParent instanceof HTMLElement) {
|
|
118
|
+
observedElements.add(offsetParent);
|
|
119
|
+
}
|
|
120
|
+
observedElements.forEach(element => resizeObserver.observe(element));
|
|
121
|
+
const unbindWindowResize = bind(window, {
|
|
122
|
+
type: 'resize',
|
|
123
|
+
listener: schedulePositionUpdate
|
|
124
|
+
});
|
|
125
|
+
const unbindWindowScroll = bind(window, {
|
|
126
|
+
type: 'scroll',
|
|
127
|
+
listener: schedulePositionUpdate,
|
|
128
|
+
options: {
|
|
129
|
+
capture: true,
|
|
130
|
+
passive: true
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const visualViewport = window.visualViewport;
|
|
134
|
+
const unbindVisualViewportResize = visualViewport ? bind(visualViewport, {
|
|
135
|
+
type: 'resize',
|
|
136
|
+
listener: schedulePositionUpdate
|
|
137
|
+
}) : undefined;
|
|
138
|
+
const unbindVisualViewportScroll = visualViewport ? bind(visualViewport, {
|
|
139
|
+
type: 'scroll',
|
|
140
|
+
listener: schedulePositionUpdate
|
|
141
|
+
}) : undefined;
|
|
142
|
+
const unbindTransitionEnd = bind(editorView.dom, {
|
|
143
|
+
type: 'transitionend',
|
|
144
|
+
listener: schedulePositionUpdate,
|
|
145
|
+
options: {
|
|
146
|
+
capture: true
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return () => {
|
|
150
|
+
if (animationFrameRef.current !== undefined) {
|
|
151
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
152
|
+
animationFrameRef.current = undefined;
|
|
153
|
+
}
|
|
154
|
+
resizeObserver.disconnect();
|
|
155
|
+
unbindWindowResize();
|
|
156
|
+
unbindWindowScroll();
|
|
157
|
+
unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 ? void 0 : unbindVisualViewportResize();
|
|
158
|
+
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 ? void 0 : unbindVisualViewportScroll();
|
|
159
|
+
unbindTransitionEnd();
|
|
160
|
+
};
|
|
161
|
+
}, [editorView, left, right]);
|
|
162
|
+
return placements;
|
|
163
|
+
};
|