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