@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
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
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; }
|
|
4
|
-
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; }
|
|
5
|
-
import { BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
6
|
-
import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor-provider';
|
|
7
|
-
import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
8
|
-
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
9
|
-
import { createSparseSurfacesViewWithLifecycle } from '../surface-lifecycle/sparse-surfaces-view-with-lifecycle';
|
|
10
|
-
import { createSurfaceAnchorDecorations } from './decorations-surface-anchor';
|
|
11
|
-
import { key as blockControlsKey } from './main';
|
|
12
|
-
import { bindSparseGutterHover } from './sparse-gutter-hover';
|
|
13
|
-
import { reconcileSparseSurfaceCandidates } from './utils/sparse-surface-candidates';
|
|
14
|
-
import { observeSurfaceViewport } from './utils/surface-viewport';
|
|
15
|
-
var haveAnchorPositionsChanged = function haveAnchorPositionsChanged(positions, anchors) {
|
|
16
|
-
return positions.length !== anchors.size || positions.some(function (position) {
|
|
17
|
-
return !anchors.has(position);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
var createLegacySparseSurfacesView = function createLegacySparseSurfacesView(_ref) {
|
|
21
|
-
var _api$uiControlRegistr3, _api$editorDisabled, _api$editorViewMode, _api$limitedMode2, _api$showDiff, _api$userIntent;
|
|
22
|
-
var api = _ref.api,
|
|
23
|
-
pluginKey = _ref.pluginKey,
|
|
24
|
-
view = _ref.view;
|
|
25
|
-
var win = view.dom.ownerDocument.defaultView;
|
|
26
|
-
var frame;
|
|
27
|
-
var visiblePositions = [];
|
|
28
|
-
var registryChanged = true;
|
|
29
|
-
var reconcile = function reconcile() {
|
|
30
|
-
var _api$limitedMode;
|
|
31
|
-
frame = undefined;
|
|
32
|
-
var previous = pluginKey.getState(view.state);
|
|
33
|
-
if (!previous || 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 && _api$limitedMode.enabled) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
var controls = blockControlsKey.getState(view.state);
|
|
37
|
-
var activeNode = controls === null || controls === void 0 ? void 0 : controls.activeNode;
|
|
38
|
-
var activeNodesByPosition = new Map();
|
|
39
|
-
var menu = controls !== null && controls !== void 0 && controls.isMenuOpen ? controls.menuTriggerByNode : undefined;
|
|
40
|
-
if (menu && controls !== null && controls !== void 0 && controls.menuTriggerBy && view.state.doc.nodeAt(menu.pos)) {
|
|
41
|
-
var _menu$rootPos;
|
|
42
|
-
var menuNode = _objectSpread(_objectSpread({}, menu), {}, {
|
|
43
|
-
anchorName: controls.menuTriggerBy
|
|
44
|
-
});
|
|
45
|
-
activeNodesByPosition.set(menu.pos, menuNode);
|
|
46
|
-
activeNodesByPosition.set((_menu$rootPos = menu.rootPos) !== null && _menu$rootPos !== void 0 ? _menu$rootPos : menu.pos, menuNode);
|
|
47
|
-
}
|
|
48
|
-
var resolvedSurfaces = [BLOCK_CONTROLS_LEFT_SURFACE, BLOCK_CONTROLS_RIGHT_SURFACE].map(function (surface) {
|
|
49
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
50
|
-
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);
|
|
51
|
-
});
|
|
52
|
-
var candidates = reconcileSparseSurfaceCandidates({
|
|
53
|
-
activeNode: activeNode,
|
|
54
|
-
activeNodesByPosition: activeNodesByPosition,
|
|
55
|
-
newState: view.state,
|
|
56
|
-
state: previous.candidates,
|
|
57
|
-
visiblePositions: visiblePositions,
|
|
58
|
-
protectedPositions: _toConsumableArray(activeNodesByPosition.keys()),
|
|
59
|
-
resolvedSurfaces: resolvedSurfaces,
|
|
60
|
-
documentChanged: previous.documentChanged,
|
|
61
|
-
invalidation: _objectSpread(_objectSpread({}, previous.invalidation), {}, {
|
|
62
|
-
all: registryChanged
|
|
63
|
-
})
|
|
64
|
-
});
|
|
65
|
-
var visibilityChanged = registryChanged;
|
|
66
|
-
registryChanged = false;
|
|
67
|
-
var anchorPositions = candidates.positions;
|
|
68
|
-
if (!visibilityChanged && !haveAnchorPositionsChanged(anchorPositions, previous.anchors) && candidates === previous.candidates && !previous.documentChanged && !previous.invalidation) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
var nodeIdProvider = getNodeIdProvider(view);
|
|
72
|
-
var _createSurfaceAnchorD = createSurfaceAnchorDecorations(view.state, anchorPositions, function (node, position, previousAnchorName) {
|
|
73
|
-
if (previousAnchorName) {
|
|
74
|
-
nodeIdProvider.setIdForNode(node, previousAnchorName);
|
|
75
|
-
return previousAnchorName;
|
|
76
|
-
}
|
|
77
|
-
return nodeIdProvider.getOrGenerateId(node, position);
|
|
78
|
-
}, previous.anchors),
|
|
79
|
-
anchors = _createSurfaceAnchorD.anchors,
|
|
80
|
-
decorations = _createSurfaceAnchorD.decorations;
|
|
81
|
-
view.dispatch(view.state.tr.setMeta(pluginKey, {
|
|
82
|
-
reconciliation: {
|
|
83
|
-
activeNodesByPosition: activeNodesByPosition,
|
|
84
|
-
anchors: anchors,
|
|
85
|
-
candidates: candidates,
|
|
86
|
-
decorations: decorations
|
|
87
|
-
},
|
|
88
|
-
type: 'commitReconciliation'
|
|
89
|
-
}));
|
|
90
|
-
};
|
|
91
|
-
var schedule = function schedule() {
|
|
92
|
-
if (frame === undefined && win) {
|
|
93
|
-
frame = win.requestAnimationFrame(reconcile);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
var observer = observeSurfaceViewport(view, function (positions) {
|
|
97
|
-
visiblePositions = positions;
|
|
98
|
-
schedule();
|
|
99
|
-
});
|
|
100
|
-
var invalidate = function invalidate() {
|
|
101
|
-
registryChanged = true;
|
|
102
|
-
schedule();
|
|
103
|
-
};
|
|
104
|
-
var unsubscribe = api === null || api === void 0 || (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 ? void 0 : _api$uiControlRegistr3.actions.subscribe(invalidate);
|
|
105
|
-
var unbindGutterHover = bindSparseGutterHover({
|
|
106
|
-
api: api,
|
|
107
|
-
view: view
|
|
108
|
-
});
|
|
109
|
-
var unsubscribers = [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)];
|
|
110
|
-
return {
|
|
111
|
-
update: function update(currentView, previousState) {
|
|
112
|
-
observer.update();
|
|
113
|
-
var sparse = pluginKey.getState(currentView.state);
|
|
114
|
-
var controls = blockControlsKey.getState(currentView.state);
|
|
115
|
-
var previousControls = blockControlsKey.getState(previousState);
|
|
116
|
-
if ((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)) {
|
|
117
|
-
invalidate();
|
|
118
|
-
}
|
|
119
|
-
if (sparse !== null && sparse !== void 0 && sparse.documentChanged || sparse !== null && sparse !== 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)) {
|
|
120
|
-
schedule();
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
destroy: function destroy() {
|
|
124
|
-
if (frame !== undefined) {
|
|
125
|
-
win === null || win === void 0 || win.cancelAnimationFrame(frame);
|
|
126
|
-
}
|
|
127
|
-
observer.destroy();
|
|
128
|
-
unbindGutterHover === null || unbindGutterHover === void 0 || unbindGutterHover();
|
|
129
|
-
unsubscribe === null || unsubscribe === void 0 || unsubscribe();
|
|
130
|
-
unsubscribers.forEach(function (unsubscribe) {
|
|
131
|
-
return unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
export var createSparseSurfacesView = function createSparseSurfacesView(options) {
|
|
137
|
-
if (isExperimentEnabled('platform_editor_block_controls_cls_fix')) {
|
|
138
|
-
return createSparseSurfacesViewWithLifecycle(options);
|
|
139
|
-
} else {
|
|
140
|
-
return createLegacySparseSurfacesView(options);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
/* block-controls-left-surfaces.tsx generated by @compiled/babel-plugin v3.0.4 */
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
-
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; } } }; }
|
|
6
|
-
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; } }
|
|
7
|
-
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; }
|
|
8
|
-
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; }
|
|
9
|
-
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; }
|
|
10
|
-
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
-
import { bind } from 'bind-event-listener';
|
|
12
|
-
import { getDocument } from '@atlaskit/browser-apis';
|
|
13
|
-
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
14
|
-
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
15
|
-
import { isCSSAnchorSupported } from '@atlaskit/editor-common/styles/native-anchor';
|
|
16
|
-
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/useSharedPluginStateWithSelector';
|
|
17
|
-
import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
|
|
18
|
-
import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
|
|
19
|
-
import { BlockControlsLeftSurface } from './block-controls-left-surface';
|
|
20
|
-
import { getBlockControlsLeftSurfaceComponents } from './block-controls-surface-components';
|
|
21
|
-
import { createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
|
|
22
|
-
import { getBlockControlsSurfaceTargets } from './block-controls-surface-targets';
|
|
23
|
-
import { getNodeContentElement } from './utils/get-node-content-element';
|
|
24
|
-
import { getAbsoluteSurfacePlacement, getAnchoredLeftGutterSurfacePlacement, getAnchoredSurfacePlacement, getLeftGutterSurfacePlacement, getSurfacePlacement, toMeasuredSurfaceWrapperPlacement } from './utils/get-surface-placement';
|
|
25
|
-
var EMPTY_SURFACE_POSITIONS = [];
|
|
26
|
-
var EMPTY_SURFACE_ANCHORS = new Map();
|
|
27
|
-
var EMPTY_SURFACE_COMPONENTS = [];
|
|
28
|
-
var EMPTY_MEASURED_SURFACES = [];
|
|
29
|
-
export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
|
|
30
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
31
|
-
var api = _ref.api,
|
|
32
|
-
editorView = _ref.editorView;
|
|
33
|
-
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
|
|
34
|
-
var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$blockControls4, _states$blockControls5, _states$blockControls6;
|
|
35
|
-
return {
|
|
36
|
-
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
|
|
37
|
-
surfaceActiveNodes: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.surfaceActiveNodes,
|
|
38
|
-
surfaceAnchors: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.surfaceAnchors) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : EMPTY_SURFACE_ANCHORS,
|
|
39
|
-
surfaceNodePositions: (_states$blockControls5 = (_states$blockControls6 = states.blockControlsState) === null || _states$blockControls6 === void 0 ? void 0 : _states$blockControls6.surfaceNodePositions) !== null && _states$blockControls5 !== void 0 ? _states$blockControls5 : EMPTY_SURFACE_POSITIONS
|
|
40
|
-
};
|
|
41
|
-
}),
|
|
42
|
-
activeNode = _useSharedPluginState.activeNode,
|
|
43
|
-
surfaceAnchors = _useSharedPluginState.surfaceAnchors,
|
|
44
|
-
surfaceActiveNodes = _useSharedPluginState.surfaceActiveNodes,
|
|
45
|
-
surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
|
|
46
|
-
var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
|
|
47
|
-
var targets = useMemo(function () {
|
|
48
|
-
var candidates = new Set(surfaceNodePositions);
|
|
49
|
-
return getBlockControlsSurfaceTargets(activeNode, surfaceNodePositions).filter(function (_ref2) {
|
|
50
|
-
var position = _ref2.position;
|
|
51
|
-
return candidates.has(position);
|
|
52
|
-
});
|
|
53
|
-
}, [activeNode, surfaceNodePositions]);
|
|
54
|
-
var surfaces = useMemo(function () {
|
|
55
|
-
return targets.flatMap(function (target) {
|
|
56
|
-
var _surfaceActiveNodes$g;
|
|
57
|
-
var context = createBlockControlsSurfaceContextForPosition(editorView.state, target.position, (_surfaceActiveNodes$g = surfaceActiveNodes === null || surfaceActiveNodes === void 0 ? void 0 : surfaceActiveNodes.get(target.position)) !== null && _surfaceActiveNodes$g !== void 0 ? _surfaceActiveNodes$g : activeNode);
|
|
58
|
-
if (!context) {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
var surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
|
|
62
|
-
var surfaceComponents = getBlockControlsLeftSurfaceComponents(components, surfaceContext);
|
|
63
|
-
if (!surfaceComponents) {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
// The cache supplies the same anchor names used by ProseMirror decorations.
|
|
67
|
-
var anchorName = isCSSAnchorSupported() ? surfaceAnchors.get(target.position) : undefined;
|
|
68
|
-
// Top-level controls can respond to the available left gutter without the surface
|
|
69
|
-
// host knowing which controls are registered or how they adapt.
|
|
70
|
-
var isTopLevel = context.targetNode.parentType === 'doc';
|
|
71
|
-
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
72
|
-
anchorName: anchorName,
|
|
73
|
-
blockControlsContext: context,
|
|
74
|
-
isTopLevel: isTopLevel,
|
|
75
|
-
surfaceComponents: surfaceComponents,
|
|
76
|
-
surfaceContext: surfaceContext
|
|
77
|
-
})];
|
|
78
|
-
});
|
|
79
|
-
}, [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
|
|
80
|
-
/**
|
|
81
|
-
* Placements that need no measuring, so they are derived rather than stored: every inset is an
|
|
82
|
-
* `anchor()` the browser re-resolves on every layout change.
|
|
83
|
-
*/
|
|
84
|
-
var anchoredPlacements = useMemo(function () {
|
|
85
|
-
return new Map(surfaces.flatMap(function (_ref3) {
|
|
86
|
-
var anchorName = _ref3.anchorName,
|
|
87
|
-
blockControlsContext = _ref3.blockControlsContext,
|
|
88
|
-
isTopLevel = _ref3.isTopLevel,
|
|
89
|
-
position = _ref3.position;
|
|
90
|
-
if (!anchorName) {
|
|
91
|
-
return [];
|
|
92
|
-
}
|
|
93
|
-
var options = {
|
|
94
|
-
anchorName: anchorName,
|
|
95
|
-
layout: blockControlsContext.targetNode.node.attrs.layout,
|
|
96
|
-
nodeType: blockControlsContext.targetNode.type.name,
|
|
97
|
-
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
98
|
-
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
99
|
-
};
|
|
100
|
-
var placement = isTopLevel ? getAnchoredLeftGutterSurfacePlacement(options) : getAnchoredSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
|
|
101
|
-
side: 'left'
|
|
102
|
-
}));
|
|
103
|
-
return [[position, placement]];
|
|
104
|
-
}));
|
|
105
|
-
}, [surfaces]);
|
|
106
|
-
// Only the surfaces that still need measuring drive the effect below, so a document of anchored
|
|
107
|
-
// blocks binds no scroll or resize listeners at all.
|
|
108
|
-
//
|
|
109
|
-
// The shared empty array matters: `surfaces` gets a new identity on every hover, since
|
|
110
|
-
// `activeNode` is one of its dependencies. Returning a fresh `[]` would give the effect a
|
|
111
|
-
// changed dependency each time and re-run it for nothing, which is the cost the anchored path
|
|
112
|
-
// exists to avoid.
|
|
113
|
-
var measuredSurfaces = useMemo(function () {
|
|
114
|
-
var measured = surfaces.filter(function (_ref4) {
|
|
115
|
-
var anchorName = _ref4.anchorName;
|
|
116
|
-
return !anchorName;
|
|
117
|
-
});
|
|
118
|
-
return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
|
|
119
|
-
}, [surfaces]);
|
|
120
|
-
var _useState = useState(new Map()),
|
|
121
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
122
|
-
placements = _useState2[0],
|
|
123
|
-
setPlacements = _useState2[1];
|
|
124
|
-
var animationFrameRef = useRef(undefined);
|
|
125
|
-
useLayoutEffect(function () {
|
|
126
|
-
var _getDocument;
|
|
127
|
-
if (measuredSurfaces.length === 0) {
|
|
128
|
-
// Clear only when there is something to clear. Handing React a fresh Map every time would
|
|
129
|
-
// fail its identity check and commit a render to replace one empty map with another.
|
|
130
|
-
setPlacements(function (previous) {
|
|
131
|
-
return previous.size > 0 ? new Map() : previous;
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
|
|
136
|
-
var blockControlsContext = _ref5.blockControlsContext,
|
|
137
|
-
isTopLevel = _ref5.isTopLevel,
|
|
138
|
-
position = _ref5.position;
|
|
139
|
-
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
140
|
-
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
141
|
-
if (!targetElementRoot) {
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
return [{
|
|
145
|
-
blockControlsContext: blockControlsContext,
|
|
146
|
-
isTopLevel: isTopLevel,
|
|
147
|
-
position: position,
|
|
148
|
-
targetElement: getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name),
|
|
149
|
-
targetElementRoot: targetElementRoot
|
|
150
|
-
}];
|
|
151
|
-
});
|
|
152
|
-
var offsetParent = editorView.dom.offsetParent;
|
|
153
|
-
var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
|
|
154
|
-
var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
|
|
155
|
-
var updatePositions = function updatePositions() {
|
|
156
|
-
var _scrollingOffsetParen, _scrollingOffsetParen2;
|
|
157
|
-
animationFrameRef.current = undefined;
|
|
158
|
-
var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
|
|
159
|
-
var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
|
|
160
|
-
var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
|
|
161
|
-
var nextPlacements = new Map();
|
|
162
|
-
var _iterator = _createForOfIteratorHelper(measurementTargets),
|
|
163
|
-
_step;
|
|
164
|
-
try {
|
|
165
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
166
|
-
var _targetElementRoot$ge, _offsetParentRect$lef;
|
|
167
|
-
var _step$value = _step.value,
|
|
168
|
-
blockControlsContext = _step$value.blockControlsContext,
|
|
169
|
-
isTopLevel = _step$value.isTopLevel,
|
|
170
|
-
position = _step$value.position,
|
|
171
|
-
targetElement = _step$value.targetElement,
|
|
172
|
-
targetElementRoot = _step$value.targetElementRoot;
|
|
173
|
-
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
var options = {
|
|
177
|
-
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
178
|
-
nodeRect: targetElement.getBoundingClientRect(),
|
|
179
|
-
nodeType: blockControlsContext.targetNode.type.name,
|
|
180
|
-
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
181
|
-
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
182
|
-
};
|
|
183
|
-
var placement = isTopLevel ? getLeftGutterSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
|
|
184
|
-
leftGutterBoundary: (_offsetParentRect$lef = offsetParentRect === null || offsetParentRect === void 0 ? void 0 : offsetParentRect.left) !== null && _offsetParentRect$lef !== void 0 ? _offsetParentRect$lef : 0
|
|
185
|
-
})) : getSurfacePlacement(_objectSpread(_objectSpread({}, options), {}, {
|
|
186
|
-
side: 'left'
|
|
187
|
-
}));
|
|
188
|
-
nextPlacements.set(position, toMeasuredSurfaceWrapperPlacement(getAbsoluteSurfacePlacement({
|
|
189
|
-
offsetParentRect: offsetParentRect,
|
|
190
|
-
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
191
|
-
offsetParentScrollTop: offsetParentScrollTop,
|
|
192
|
-
placement: placement
|
|
193
|
-
})));
|
|
194
|
-
}
|
|
195
|
-
} catch (err) {
|
|
196
|
-
_iterator.e(err);
|
|
197
|
-
} finally {
|
|
198
|
-
_iterator.f();
|
|
199
|
-
}
|
|
200
|
-
setPlacements(nextPlacements);
|
|
201
|
-
};
|
|
202
|
-
var schedulePositionUpdate = function schedulePositionUpdate() {
|
|
203
|
-
if (animationFrameRef.current === undefined) {
|
|
204
|
-
animationFrameRef.current = requestAnimationFrame(updatePositions);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
updatePositions();
|
|
208
|
-
var resizeObserver = new ResizeObserver(schedulePositionUpdate);
|
|
209
|
-
var observedElements = new Set([editorView.dom]);
|
|
210
|
-
var _iterator2 = _createForOfIteratorHelper(measurementTargets),
|
|
211
|
-
_step2;
|
|
212
|
-
try {
|
|
213
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
214
|
-
var targetElement = _step2.value.targetElement;
|
|
215
|
-
observedElements.add(targetElement);
|
|
216
|
-
}
|
|
217
|
-
} catch (err) {
|
|
218
|
-
_iterator2.e(err);
|
|
219
|
-
} finally {
|
|
220
|
-
_iterator2.f();
|
|
221
|
-
}
|
|
222
|
-
if (offsetParent instanceof HTMLElement) {
|
|
223
|
-
observedElements.add(offsetParent);
|
|
224
|
-
}
|
|
225
|
-
observedElements.forEach(function (element) {
|
|
226
|
-
return resizeObserver.observe(element);
|
|
227
|
-
});
|
|
228
|
-
var unbindWindowResize = bind(window, {
|
|
229
|
-
type: 'resize',
|
|
230
|
-
listener: schedulePositionUpdate
|
|
231
|
-
});
|
|
232
|
-
var unbindWindowScroll = bind(window, {
|
|
233
|
-
type: 'scroll',
|
|
234
|
-
listener: schedulePositionUpdate,
|
|
235
|
-
options: {
|
|
236
|
-
capture: true,
|
|
237
|
-
passive: true
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
var visualViewport = window.visualViewport;
|
|
241
|
-
var unbindVisualViewportResize = visualViewport ? bind(visualViewport, {
|
|
242
|
-
type: 'resize',
|
|
243
|
-
listener: schedulePositionUpdate
|
|
244
|
-
}) : undefined;
|
|
245
|
-
var unbindVisualViewportScroll = visualViewport ? bind(visualViewport, {
|
|
246
|
-
type: 'scroll',
|
|
247
|
-
listener: schedulePositionUpdate
|
|
248
|
-
}) : undefined;
|
|
249
|
-
var unbindTransitionEnd = bind(editorView.dom, {
|
|
250
|
-
type: 'transitionend',
|
|
251
|
-
listener: schedulePositionUpdate,
|
|
252
|
-
options: {
|
|
253
|
-
capture: true
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
return function () {
|
|
257
|
-
if (animationFrameRef.current !== undefined) {
|
|
258
|
-
cancelAnimationFrame(animationFrameRef.current);
|
|
259
|
-
animationFrameRef.current = undefined;
|
|
260
|
-
}
|
|
261
|
-
resizeObserver.disconnect();
|
|
262
|
-
unbindWindowResize();
|
|
263
|
-
unbindWindowScroll();
|
|
264
|
-
unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
|
|
265
|
-
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
266
|
-
unbindTransitionEnd();
|
|
267
|
-
};
|
|
268
|
-
}, [editorView, measuredSurfaces]);
|
|
269
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref6) {
|
|
270
|
-
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
271
|
-
var position = _ref6.position,
|
|
272
|
-
source = _ref6.source,
|
|
273
|
-
surfaceComponents = _ref6.surfaceComponents,
|
|
274
|
-
surfaceContext = _ref6.surfaceContext;
|
|
275
|
-
return /*#__PURE__*/React.createElement(BlockControlsLeftSurface, {
|
|
276
|
-
api: api,
|
|
277
|
-
components: surfaceComponents,
|
|
278
|
-
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
279
|
-
key: position,
|
|
280
|
-
placement: (_anchoredPlacements$g = anchoredPlacements.get(position)) !== null && _anchoredPlacements$g !== void 0 ? _anchoredPlacements$g : placements.get(position),
|
|
281
|
-
source: source,
|
|
282
|
-
surfaceContext: surfaceContext
|
|
283
|
-
});
|
|
284
|
-
}));
|
|
285
|
-
};
|