@atlaskit/editor-plugin-block-controls 20.0.3 → 20.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 +19 -0
- package/dist/cjs/blockControlsPlugin.js +53 -17
- package/dist/cjs/editor-commands/show-drag-handle.js +17 -5
- package/dist/cjs/pm-plugins/decorations-anchor.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/cjs/pm-plugins/decorations-surface-anchor.js +72 -0
- package/dist/cjs/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/cjs/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/cjs/pm-plugins/handle-sparse-mouse-over.js +125 -0
- package/dist/cjs/pm-plugins/main.js +66 -54
- package/dist/cjs/pm-plugins/sparse-surfaces.js +49 -0
- package/dist/cjs/pm-plugins/utils/sparse-surface-candidates.js +419 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-mapping.js +108 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-state.js +53 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-view.js +134 -0
- package/dist/cjs/pm-plugins/utils/surface-viewport.js +223 -0
- package/dist/cjs/pm-plugins/utils/transactions.js +5 -0
- package/dist/cjs/ui/block-controls-left-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-right-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-surface-context.js +1 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +6 -7
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/cjs/ui/drag-handle.js +5 -3
- package/dist/cjs/ui/drop-target-layout.js +3 -2
- package/dist/cjs/ui/drop-target.js +3 -2
- package/dist/cjs/ui/global-styles.js +69 -27
- package/dist/cjs/ui/inline-drop-target.js +6 -5
- package/dist/cjs/ui/utils/anchor-name.js +2 -1
- package/dist/cjs/ui/utils/dom-attr-name.js +3 -2
- package/dist/cjs/ui/utils/get-surface-placement.js +2 -1
- package/dist/es2019/blockControlsPlugin.js +42 -8
- package/dist/es2019/editor-commands/show-drag-handle.js +14 -2
- package/dist/es2019/pm-plugins/decorations-anchor.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/es2019/pm-plugins/decorations-surface-anchor.js +56 -0
- package/dist/es2019/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/es2019/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/es2019/pm-plugins/handle-sparse-mouse-over.js +116 -0
- package/dist/es2019/pm-plugins/main.js +70 -54
- package/dist/es2019/pm-plugins/sparse-surfaces.js +37 -0
- package/dist/es2019/pm-plugins/utils/sparse-surface-candidates.js +305 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-mapping.js +78 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-state.js +39 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-view.js +121 -0
- package/dist/es2019/pm-plugins/utils/surface-viewport.js +192 -0
- package/dist/es2019/pm-plugins/utils/transactions.js +5 -0
- package/dist/es2019/ui/block-controls-left-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-right-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-surface-context.js +1 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +4 -5
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/es2019/ui/drag-handle.js +5 -3
- package/dist/es2019/ui/drop-target-layout.js +3 -2
- package/dist/es2019/ui/drop-target.js +3 -2
- package/dist/es2019/ui/global-styles.js +67 -28
- package/dist/es2019/ui/inline-drop-target.js +6 -5
- package/dist/es2019/ui/utils/anchor-name.js +2 -1
- package/dist/es2019/ui/utils/dom-attr-name.js +3 -2
- package/dist/es2019/ui/utils/get-surface-placement.js +2 -1
- package/dist/esm/blockControlsPlugin.js +53 -17
- package/dist/esm/editor-commands/show-drag-handle.js +17 -5
- package/dist/esm/pm-plugins/decorations-anchor.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/esm/pm-plugins/decorations-surface-anchor.js +65 -0
- package/dist/esm/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/esm/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/esm/pm-plugins/handle-sparse-mouse-over.js +119 -0
- package/dist/esm/pm-plugins/main.js +66 -54
- package/dist/esm/pm-plugins/sparse-surfaces.js +43 -0
- package/dist/esm/pm-plugins/utils/sparse-surface-candidates.js +413 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-mapping.js +101 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-state.js +46 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-view.js +127 -0
- package/dist/esm/pm-plugins/utils/surface-viewport.js +217 -0
- package/dist/esm/pm-plugins/utils/transactions.js +5 -0
- package/dist/esm/ui/block-controls-left-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-right-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-surface-context.js +1 -0
- package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +7 -8
- package/dist/esm/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/esm/ui/drag-handle.js +5 -3
- package/dist/esm/ui/drop-target-layout.js +3 -2
- package/dist/esm/ui/drop-target.js +3 -2
- package/dist/esm/ui/global-styles.js +70 -28
- package/dist/esm/ui/inline-drop-target.js +6 -5
- package/dist/esm/ui/utils/anchor-name.js +2 -1
- package/dist/esm/ui/utils/dom-attr-name.js +3 -2
- package/dist/esm/ui/utils/get-surface-placement.js +2 -1
- package/dist/types/blockControlsPluginType.d.ts +10 -3
- package/dist/types/pm-plugins/decorations-surface-anchor.d.ts +22 -0
- package/dist/types/pm-plugins/handle-sparse-mouse-over.d.ts +5 -0
- package/dist/types/pm-plugins/main.d.ts +2 -9
- package/dist/types/pm-plugins/sparse-surfaces.d.ts +8 -0
- package/dist/types/pm-plugins/utils/sparse-surface-candidates.d.ts +89 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-mapping.d.ts +20 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-state.d.ts +27 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-view.d.ts +15 -0
- package/dist/types/pm-plugins/utils/surface-viewport.d.ts +10 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +3 -2
- package/package.json +5 -5
- package/dist/cjs/pm-plugins/utils/surface-node-positions.js +0 -100
- package/dist/es2019/pm-plugins/utils/surface-node-positions.js +0 -78
- package/dist/esm/pm-plugins/utils/surface-node-positions.js +0 -93
- package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +0 -14
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createSparseSurfacesView = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
11
|
+
var _nodeAnchor = require("@atlaskit/editor-common/node-anchor");
|
|
12
|
+
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
13
|
+
var _decorationsSurfaceAnchor = require("../decorations-surface-anchor");
|
|
14
|
+
var _main = require("../main");
|
|
15
|
+
var _sparseSurfaceCandidates = require("./sparse-surface-candidates");
|
|
16
|
+
var _surfaceViewport = require("./surface-viewport");
|
|
17
|
+
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; }
|
|
18
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
19
|
+
var haveAnchorPositionsChanged = function haveAnchorPositionsChanged(positions, anchors) {
|
|
20
|
+
return positions.length !== anchors.size || positions.some(function (position) {
|
|
21
|
+
return !anchors.has(position);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var createSparseSurfacesView = exports.createSparseSurfacesView = function createSparseSurfacesView(_ref) {
|
|
25
|
+
var _api$uiControlRegistr3, _api$editorDisabled, _api$editorViewMode, _api$limitedMode2, _api$showDiff, _api$userIntent;
|
|
26
|
+
var api = _ref.api,
|
|
27
|
+
pluginKey = _ref.pluginKey,
|
|
28
|
+
view = _ref.view;
|
|
29
|
+
var win = view.dom.ownerDocument.defaultView;
|
|
30
|
+
var frame;
|
|
31
|
+
var visiblePositions = [];
|
|
32
|
+
var registryChanged = true;
|
|
33
|
+
var reconcile = function reconcile() {
|
|
34
|
+
var _api$limitedMode;
|
|
35
|
+
frame = undefined;
|
|
36
|
+
var previous = pluginKey.getState(view.state);
|
|
37
|
+
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) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var controls = _main.key.getState(view.state);
|
|
41
|
+
var activeNode = controls === null || controls === void 0 ? void 0 : controls.activeNode;
|
|
42
|
+
var activeNodesByPosition = new Map();
|
|
43
|
+
var menu = controls !== null && controls !== void 0 && controls.isMenuOpen ? controls.menuTriggerByNode : undefined;
|
|
44
|
+
if (menu && controls !== null && controls !== void 0 && controls.menuTriggerBy && view.state.doc.nodeAt(menu.pos)) {
|
|
45
|
+
var _menu$rootPos;
|
|
46
|
+
var menuNode = _objectSpread(_objectSpread({}, menu), {}, {
|
|
47
|
+
anchorName: controls.menuTriggerBy
|
|
48
|
+
});
|
|
49
|
+
activeNodesByPosition.set(menu.pos, menuNode);
|
|
50
|
+
activeNodesByPosition.set((_menu$rootPos = menu.rootPos) !== null && _menu$rootPos !== void 0 ? _menu$rootPos : menu.pos, menuNode);
|
|
51
|
+
}
|
|
52
|
+
var resolvedSurfaces = [_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE].map(function (surface) {
|
|
53
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
54
|
+
return (0, _surfaceRenderer.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);
|
|
55
|
+
});
|
|
56
|
+
var candidates = (0, _sparseSurfaceCandidates.reconcileSparseSurfaceCandidates)({
|
|
57
|
+
activeNode: activeNode,
|
|
58
|
+
activeNodesByPosition: activeNodesByPosition,
|
|
59
|
+
newState: view.state,
|
|
60
|
+
state: previous.candidates,
|
|
61
|
+
visiblePositions: visiblePositions,
|
|
62
|
+
protectedPositions: (0, _toConsumableArray2.default)(activeNodesByPosition.keys()),
|
|
63
|
+
resolvedSurfaces: resolvedSurfaces,
|
|
64
|
+
documentChanged: previous.documentChanged,
|
|
65
|
+
invalidation: _objectSpread(_objectSpread({}, previous.invalidation), {}, {
|
|
66
|
+
all: registryChanged
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
var visibilityChanged = registryChanged;
|
|
70
|
+
registryChanged = false;
|
|
71
|
+
var anchorPositions = candidates.positions;
|
|
72
|
+
if (!visibilityChanged && !haveAnchorPositionsChanged(anchorPositions, previous.anchors) && candidates === previous.candidates && !previous.documentChanged && !previous.invalidation) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var nodeIdProvider = (0, _nodeAnchor.getNodeIdProvider)(view);
|
|
76
|
+
var _createSurfaceAnchorD = (0, _decorationsSurfaceAnchor.createSurfaceAnchorDecorations)(view.state, anchorPositions, function (node, position, previousAnchorName) {
|
|
77
|
+
if (previousAnchorName) {
|
|
78
|
+
nodeIdProvider.setIdForNode(node, previousAnchorName);
|
|
79
|
+
return previousAnchorName;
|
|
80
|
+
}
|
|
81
|
+
return nodeIdProvider.getOrGenerateId(node, position);
|
|
82
|
+
}, previous.anchors),
|
|
83
|
+
anchors = _createSurfaceAnchorD.anchors,
|
|
84
|
+
decorations = _createSurfaceAnchorD.decorations;
|
|
85
|
+
view.dispatch(view.state.tr.setMeta(pluginKey, {
|
|
86
|
+
reconciliation: {
|
|
87
|
+
activeNodesByPosition: activeNodesByPosition,
|
|
88
|
+
anchors: anchors,
|
|
89
|
+
candidates: candidates,
|
|
90
|
+
decorations: decorations
|
|
91
|
+
},
|
|
92
|
+
type: 'commitReconciliation'
|
|
93
|
+
}));
|
|
94
|
+
};
|
|
95
|
+
var schedule = function schedule() {
|
|
96
|
+
if (frame === undefined && win) {
|
|
97
|
+
frame = win.requestAnimationFrame(reconcile);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
var observer = (0, _surfaceViewport.observeSurfaceViewport)(view, function (positions) {
|
|
101
|
+
visiblePositions = positions;
|
|
102
|
+
schedule();
|
|
103
|
+
});
|
|
104
|
+
var invalidate = function invalidate() {
|
|
105
|
+
registryChanged = true;
|
|
106
|
+
schedule();
|
|
107
|
+
};
|
|
108
|
+
var unsubscribe = api === null || api === void 0 || (_api$uiControlRegistr3 = api.uiControlRegistry) === null || _api$uiControlRegistr3 === void 0 ? void 0 : _api$uiControlRegistr3.actions.subscribe(invalidate);
|
|
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 = _main.key.getState(currentView.state);
|
|
115
|
+
var previousControls = _main.key.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
|
+
unsubscribe === null || unsubscribe === void 0 || unsubscribe();
|
|
129
|
+
unsubscribers.forEach(function (unsubscribe) {
|
|
130
|
+
return unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.observeSurfaceViewport = void 0;
|
|
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 NODE_NAME_ATTRIBUTE = 'data-prosemirror-node-name';
|
|
11
|
+
/**
|
|
12
|
+
* Tracks block DOM nodes that intersect the browser viewport. The browser owns clipping and
|
|
13
|
+
* visibility decisions; this helper only translates observer targets back to PM positions.
|
|
14
|
+
*/
|
|
15
|
+
var observeSurfaceViewport = exports.observeSurfaceViewport = function observeSurfaceViewport(view, onChange) {
|
|
16
|
+
var win = view.dom.ownerDocument.defaultView;
|
|
17
|
+
if (!win || typeof win.IntersectionObserver === 'undefined') {
|
|
18
|
+
return {
|
|
19
|
+
update: function update() {},
|
|
20
|
+
destroy: function destroy() {}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
var targets = new Map();
|
|
24
|
+
var visibleTargets = new Set();
|
|
25
|
+
var previousPositions = [];
|
|
26
|
+
var previousDoc = view.state.doc;
|
|
27
|
+
var destroyed = false;
|
|
28
|
+
var resolvePosition = function resolvePosition(element) {
|
|
29
|
+
try {
|
|
30
|
+
var domPosition = view.posAtDOM(element, 0);
|
|
31
|
+
var nodeName = element.getAttribute(NODE_NAME_ATTRIBUTE);
|
|
32
|
+
var directNode = view.state.doc.nodeAt(domPosition);
|
|
33
|
+
if (directNode !== null && directNode !== void 0 && directNode.isBlock && directNode.type.name === nodeName && view.nodeDOM(domPosition) === element) {
|
|
34
|
+
return domPosition;
|
|
35
|
+
}
|
|
36
|
+
var $position = view.state.doc.resolve(domPosition);
|
|
37
|
+
for (var depth = $position.depth; depth > 0; depth--) {
|
|
38
|
+
var node = $position.node(depth);
|
|
39
|
+
if (!node.isBlock || node.type.name !== nodeName) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
var position = $position.before(depth);
|
|
43
|
+
var nodeDOM = view.nodeDOM(position);
|
|
44
|
+
if (nodeDOM === element || nodeDOM instanceof Node && (nodeDOM.contains(element) || element.contains(nodeDOM))) {
|
|
45
|
+
return position;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
} catch (_unused) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var getVisiblePositions = function getVisiblePositions() {
|
|
54
|
+
var positions = new Set();
|
|
55
|
+
visibleTargets.forEach(function (element) {
|
|
56
|
+
var _targets$get;
|
|
57
|
+
var position = (_targets$get = targets.get(element)) === null || _targets$get === void 0 ? void 0 : _targets$get.position;
|
|
58
|
+
if (position !== undefined) {
|
|
59
|
+
positions.add(position);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return Array.from(positions).sort(function (first, second) {
|
|
63
|
+
return first - second;
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
var emit = function emit() {
|
|
67
|
+
if (destroyed) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
var positions = getVisiblePositions();
|
|
71
|
+
if (positions.length !== previousPositions.length || positions.some(function (position, index) {
|
|
72
|
+
return position !== previousPositions[index];
|
|
73
|
+
})) {
|
|
74
|
+
previousPositions = positions;
|
|
75
|
+
onChange(positions);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var intersectionObserver = new win.IntersectionObserver(function (entries) {
|
|
79
|
+
var changed = false;
|
|
80
|
+
var _iterator = _createForOfIteratorHelper(entries),
|
|
81
|
+
_step;
|
|
82
|
+
try {
|
|
83
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
84
|
+
var entry = _step.value;
|
|
85
|
+
var element = entry.target;
|
|
86
|
+
var target = targets.get(element);
|
|
87
|
+
if (!target || !view.dom.contains(element)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
var isIntersecting = entry.isIntersecting;
|
|
91
|
+
if (target.isIntersecting !== isIntersecting) {
|
|
92
|
+
target.isIntersecting = isIntersecting;
|
|
93
|
+
if (isIntersecting) {
|
|
94
|
+
target.position = resolvePosition(element);
|
|
95
|
+
if (target.position !== undefined) {
|
|
96
|
+
visibleTargets.add(element);
|
|
97
|
+
} else {
|
|
98
|
+
target.isIntersecting = false;
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
visibleTargets.delete(element);
|
|
102
|
+
}
|
|
103
|
+
changed = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (err) {
|
|
107
|
+
_iterator.e(err);
|
|
108
|
+
} finally {
|
|
109
|
+
_iterator.f();
|
|
110
|
+
}
|
|
111
|
+
if (changed) {
|
|
112
|
+
emit();
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
root: null,
|
|
116
|
+
threshold: 0
|
|
117
|
+
});
|
|
118
|
+
var removeTarget = function removeTarget(element) {
|
|
119
|
+
var target = targets.get(element);
|
|
120
|
+
if (!target) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
targets.delete(element);
|
|
124
|
+
visibleTargets.delete(element);
|
|
125
|
+
intersectionObserver.unobserve(element);
|
|
126
|
+
};
|
|
127
|
+
var observeElement = function observeElement(element) {
|
|
128
|
+
var _view$state$schema$no;
|
|
129
|
+
var nodeName = element.getAttribute(NODE_NAME_ATTRIBUTE);
|
|
130
|
+
if (element === view.dom || !nodeName || !((_view$state$schema$no = view.state.schema.nodes[nodeName]) !== null && _view$state$schema$no !== void 0 && _view$state$schema$no.isBlock) || !view.dom.contains(element)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (targets.has(element)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
targets.set(element, {
|
|
137
|
+
isIntersecting: false
|
|
138
|
+
});
|
|
139
|
+
intersectionObserver.observe(element);
|
|
140
|
+
};
|
|
141
|
+
var observeSubtree = function observeSubtree(node) {
|
|
142
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
var element = node;
|
|
146
|
+
observeElement(element);
|
|
147
|
+
var descendants = element.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
|
|
148
|
+
for (var index = 0; index < descendants.length; index++) {
|
|
149
|
+
observeElement(descendants[index]);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var unobserveSubtree = function unobserveSubtree(node) {
|
|
153
|
+
if (node.nodeType !== Node.ELEMENT_NODE) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
var element = node;
|
|
157
|
+
removeTarget(element);
|
|
158
|
+
var descendants = element.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
|
|
159
|
+
for (var index = 0; index < descendants.length; index++) {
|
|
160
|
+
removeTarget(descendants[index]);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var mutationObserver = new win.MutationObserver(function (records) {
|
|
164
|
+
var removedVisibleTarget = false;
|
|
165
|
+
var _iterator2 = _createForOfIteratorHelper(records),
|
|
166
|
+
_step2;
|
|
167
|
+
try {
|
|
168
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
169
|
+
var record = _step2.value;
|
|
170
|
+
for (var index = 0; index < record.removedNodes.length; index++) {
|
|
171
|
+
var node = record.removedNodes[index];
|
|
172
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
173
|
+
if (view.dom.contains(node)) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
var before = visibleTargets.size;
|
|
177
|
+
unobserveSubtree(node);
|
|
178
|
+
removedVisibleTarget || (removedVisibleTarget = before !== visibleTargets.size);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (var _index = 0; _index < record.addedNodes.length; _index++) {
|
|
182
|
+
observeSubtree(record.addedNodes[_index]);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
_iterator2.e(err);
|
|
187
|
+
} finally {
|
|
188
|
+
_iterator2.f();
|
|
189
|
+
}
|
|
190
|
+
if (removedVisibleTarget) {
|
|
191
|
+
emit();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
var initialTargets = view.dom.querySelectorAll("[".concat(NODE_NAME_ATTRIBUTE, "]"));
|
|
195
|
+
for (var index = 0; index < initialTargets.length; index++) {
|
|
196
|
+
observeElement(initialTargets[index]);
|
|
197
|
+
}
|
|
198
|
+
mutationObserver.observe(view.dom, {
|
|
199
|
+
childList: true,
|
|
200
|
+
subtree: true
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
update: function update() {
|
|
204
|
+
if (previousDoc !== view.state.doc) {
|
|
205
|
+
previousDoc = view.state.doc;
|
|
206
|
+
visibleTargets.forEach(function (element) {
|
|
207
|
+
var target = targets.get(element);
|
|
208
|
+
if (target) {
|
|
209
|
+
target.position = resolvePosition(element);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
emit();
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
destroy: function destroy() {
|
|
216
|
+
destroyed = true;
|
|
217
|
+
mutationObserver.disconnect();
|
|
218
|
+
intersectionObserver.disconnect();
|
|
219
|
+
targets.clear();
|
|
220
|
+
visibleTargets.clear();
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isStepText = exports.isStepDelete = exports.getTrMetadata = void 0;
|
|
7
7
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
8
|
+
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
|
|
8
9
|
/**
|
|
9
10
|
* Checks if step adds inline char
|
|
10
11
|
* @param s
|
|
@@ -34,6 +35,10 @@ var isStepDelete = exports.isStepDelete = function isStepDelete(s) {
|
|
|
34
35
|
var isStepContentReplacedWithAnotherOfSameSize = function isStepContentReplacedWithAnotherOfSameSize(s) {
|
|
35
36
|
if (s instanceof _transform.ReplaceAroundStep) {
|
|
36
37
|
var replacedContentSize = s.to - s.from;
|
|
38
|
+
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration')) {
|
|
39
|
+
var insertedContentSize = s.slice.size + (s.gapTo - s.gapFrom);
|
|
40
|
+
return insertedContentSize === replacedContentSize;
|
|
41
|
+
}
|
|
37
42
|
return s.slice.content.size === replacedContentSize;
|
|
38
43
|
}
|
|
39
44
|
return false;
|
|
@@ -33,6 +33,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
33
33
|
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; }
|
|
34
34
|
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) { (0, _defineProperty2.default)(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; }
|
|
35
35
|
var EMPTY_SURFACE_POSITIONS = [];
|
|
36
|
+
var EMPTY_SURFACE_ANCHORS = new Map();
|
|
36
37
|
var EMPTY_SURFACE_COMPONENTS = [];
|
|
37
38
|
var EMPTY_MEASURED_SURFACES = [];
|
|
38
39
|
var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
|
|
@@ -40,22 +41,30 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
40
41
|
var api = _ref.api,
|
|
41
42
|
editorView = _ref.editorView;
|
|
42
43
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
43
|
-
var _states$blockControls, _states$blockControls2, _states$blockControls3;
|
|
44
|
+
var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$blockControls4, _states$blockControls5, _states$blockControls6;
|
|
44
45
|
return {
|
|
45
46
|
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
|
|
46
|
-
|
|
47
|
+
surfaceActiveNodes: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.surfaceActiveNodes,
|
|
48
|
+
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,
|
|
49
|
+
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
|
|
47
50
|
};
|
|
48
51
|
}),
|
|
49
52
|
activeNode = _useSharedPluginState.activeNode,
|
|
53
|
+
surfaceAnchors = _useSharedPluginState.surfaceAnchors,
|
|
54
|
+
surfaceActiveNodes = _useSharedPluginState.surfaceActiveNodes,
|
|
50
55
|
surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
|
|
51
56
|
var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
|
|
52
57
|
var targets = (0, _react.useMemo)(function () {
|
|
53
|
-
|
|
58
|
+
var candidates = new Set(surfaceNodePositions);
|
|
59
|
+
return (0, _blockControlsSurfaceTargets.getBlockControlsSurfaceTargets)(activeNode, surfaceNodePositions).filter(function (_ref2) {
|
|
60
|
+
var position = _ref2.position;
|
|
61
|
+
return candidates.has(position);
|
|
62
|
+
});
|
|
54
63
|
}, [activeNode, surfaceNodePositions]);
|
|
55
64
|
var surfaces = (0, _react.useMemo)(function () {
|
|
56
65
|
return targets.flatMap(function (target) {
|
|
57
|
-
var
|
|
58
|
-
var context =
|
|
66
|
+
var _surfaceActiveNodes$g;
|
|
67
|
+
var context = (0, _blockControlsSurfaceContext.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);
|
|
59
68
|
if (!context) {
|
|
60
69
|
return [];
|
|
61
70
|
}
|
|
@@ -63,32 +72,29 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
63
72
|
if (!(0, _hasSurfaceControls.hasSurfaceControls)(components) || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
|
|
64
73
|
return [];
|
|
65
74
|
}
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
// At the moment, we only expect top-level nodes to have persistent controls.
|
|
70
|
-
// See surfaceAnchorStyles in global-styles
|
|
71
|
-
var anchorName = (0, _styles.isCSSAnchorSupported)() && context.targetNode.parentType === 'doc' && !(0, _getNodeContentElement.hasInnerContentContainer)(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
|
|
75
|
+
// The cache supplies the same anchor names used by ProseMirror decorations.
|
|
76
|
+
var anchorName = (0, _styles.isCSSAnchorSupported)() ? surfaceAnchors.get(target.position) : undefined;
|
|
72
77
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
73
78
|
anchorName: anchorName,
|
|
74
79
|
blockControlsContext: context,
|
|
75
80
|
surfaceContext: surfaceContext
|
|
76
81
|
})];
|
|
77
82
|
});
|
|
78
|
-
}, [activeNode,
|
|
83
|
+
}, [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
|
|
79
84
|
/**
|
|
80
85
|
* Placements that need no measuring, so they are derived rather than stored: every inset is an
|
|
81
86
|
* `anchor()` the browser re-resolves on every layout change.
|
|
82
87
|
*/
|
|
83
88
|
var anchoredPlacements = (0, _react.useMemo)(function () {
|
|
84
|
-
return new Map(surfaces.flatMap(function (
|
|
85
|
-
var anchorName =
|
|
86
|
-
blockControlsContext =
|
|
87
|
-
position =
|
|
89
|
+
return new Map(surfaces.flatMap(function (_ref3) {
|
|
90
|
+
var anchorName = _ref3.anchorName,
|
|
91
|
+
blockControlsContext = _ref3.blockControlsContext,
|
|
92
|
+
position = _ref3.position;
|
|
88
93
|
return anchorName ? [[position, (0, _getSurfacePlacement.getAnchoredSurfacePlacement)({
|
|
89
94
|
anchorName: anchorName,
|
|
90
95
|
nodeType: blockControlsContext.targetNode.type.name,
|
|
91
96
|
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
97
|
+
layout: blockControlsContext.targetNode.node.attrs.layout,
|
|
92
98
|
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
93
99
|
side: 'left'
|
|
94
100
|
})]] : [];
|
|
@@ -102,8 +108,8 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
102
108
|
// changed dependency each time and re-run it for nothing, which is the cost the anchored path
|
|
103
109
|
// exists to avoid.
|
|
104
110
|
var measuredSurfaces = (0, _react.useMemo)(function () {
|
|
105
|
-
var measured = surfaces.filter(function (
|
|
106
|
-
var anchorName =
|
|
111
|
+
var measured = surfaces.filter(function (_ref4) {
|
|
112
|
+
var anchorName = _ref4.anchorName;
|
|
107
113
|
return !anchorName;
|
|
108
114
|
});
|
|
109
115
|
return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
|
|
@@ -123,9 +129,9 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
123
129
|
});
|
|
124
130
|
return;
|
|
125
131
|
}
|
|
126
|
-
var measurementTargets = measuredSurfaces.flatMap(function (
|
|
127
|
-
var blockControlsContext =
|
|
128
|
-
position =
|
|
132
|
+
var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
|
|
133
|
+
var blockControlsContext = _ref5.blockControlsContext,
|
|
134
|
+
position = _ref5.position;
|
|
129
135
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
130
136
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
131
137
|
if (!targetElementRoot) {
|
|
@@ -250,11 +256,11 @@ var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function Blo
|
|
|
250
256
|
unbindTransitionEnd();
|
|
251
257
|
};
|
|
252
258
|
}, [editorView, measuredSurfaces]);
|
|
253
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (
|
|
259
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref6) {
|
|
254
260
|
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
255
|
-
var position =
|
|
256
|
-
source =
|
|
257
|
-
surfaceContext =
|
|
261
|
+
var position = _ref6.position,
|
|
262
|
+
source = _ref6.source,
|
|
263
|
+
surfaceContext = _ref6.surfaceContext;
|
|
258
264
|
return /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurface.BlockControlsLeftSurface, {
|
|
259
265
|
api: api,
|
|
260
266
|
components: components,
|
|
@@ -33,6 +33,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
33
33
|
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; }
|
|
34
34
|
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) { (0, _defineProperty2.default)(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; }
|
|
35
35
|
var EMPTY_SURFACE_POSITIONS = [];
|
|
36
|
+
var EMPTY_SURFACE_ANCHORS = new Map();
|
|
36
37
|
var EMPTY_SURFACE_COMPONENTS = [];
|
|
37
38
|
var EMPTY_MEASURED_SURFACES = [];
|
|
38
39
|
/**
|
|
@@ -49,22 +50,30 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
49
50
|
var api = _ref.api,
|
|
50
51
|
editorView = _ref.editorView;
|
|
51
52
|
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
52
|
-
var _states$blockControls, _states$blockControls2, _states$blockControls3;
|
|
53
|
+
var _states$blockControls, _states$blockControls2, _states$blockControls3, _states$blockControls4, _states$blockControls5, _states$blockControls6;
|
|
53
54
|
return {
|
|
54
55
|
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
|
|
55
|
-
|
|
56
|
+
surfaceActiveNodes: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.surfaceActiveNodes,
|
|
57
|
+
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,
|
|
58
|
+
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
|
|
56
59
|
};
|
|
57
60
|
}),
|
|
58
61
|
activeNode = _useSharedPluginState.activeNode,
|
|
62
|
+
surfaceAnchors = _useSharedPluginState.surfaceAnchors,
|
|
63
|
+
surfaceActiveNodes = _useSharedPluginState.surfaceActiveNodes,
|
|
59
64
|
surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
|
|
60
65
|
var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
|
|
61
66
|
var targets = (0, _react.useMemo)(function () {
|
|
62
|
-
|
|
67
|
+
var candidates = new Set(surfaceNodePositions);
|
|
68
|
+
return (0, _blockControlsSurfaceTargets.getBlockControlsSurfaceTargets)(activeNode, surfaceNodePositions).filter(function (_ref2) {
|
|
69
|
+
var position = _ref2.position;
|
|
70
|
+
return candidates.has(position);
|
|
71
|
+
});
|
|
63
72
|
}, [activeNode, surfaceNodePositions]);
|
|
64
73
|
var surfaces = (0, _react.useMemo)(function () {
|
|
65
74
|
return targets.flatMap(function (target) {
|
|
66
|
-
var
|
|
67
|
-
var context =
|
|
75
|
+
var _surfaceActiveNodes$g;
|
|
76
|
+
var context = (0, _blockControlsSurfaceContext.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);
|
|
68
77
|
if (!context) {
|
|
69
78
|
return [];
|
|
70
79
|
}
|
|
@@ -72,32 +81,29 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
72
81
|
if (!(0, _hasSurfaceControls.hasSurfaceControls)(components) || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_RIGHT_SURFACE, surfaceContext)) {
|
|
73
82
|
return [];
|
|
74
83
|
}
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
//
|
|
78
|
-
// At the moment, we only expect top-level nodes to have persistent controls.
|
|
79
|
-
// See surfaceAnchorStyles in global-styles
|
|
80
|
-
var anchorName = (0, _styles.isCSSAnchorSupported)() && context.targetNode.parentType === 'doc' && !(0, _getNodeContentElement.hasInnerContentContainer)(context.targetNode.type.name) ? (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.getAnchorIdForNode(context.targetNode.node, context.targetNode.pos) : undefined;
|
|
84
|
+
// The cache supplies the same anchor names used by ProseMirror decorations.
|
|
85
|
+
var anchorName = (0, _styles.isCSSAnchorSupported)() ? surfaceAnchors.get(target.position) : undefined;
|
|
81
86
|
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
82
87
|
anchorName: anchorName,
|
|
83
88
|
blockControlsContext: context,
|
|
84
89
|
surfaceContext: surfaceContext
|
|
85
90
|
})];
|
|
86
91
|
});
|
|
87
|
-
}, [activeNode,
|
|
92
|
+
}, [activeNode, components, editorView, targets, surfaceAnchors, surfaceActiveNodes]);
|
|
88
93
|
/**
|
|
89
94
|
* Placements that need no measuring, so they are derived rather than stored: every inset is an
|
|
90
95
|
* `anchor()` the browser re-resolves on every layout change.
|
|
91
96
|
*/
|
|
92
97
|
var anchoredPlacements = (0, _react.useMemo)(function () {
|
|
93
|
-
return new Map(surfaces.flatMap(function (
|
|
94
|
-
var anchorName =
|
|
95
|
-
blockControlsContext =
|
|
96
|
-
position =
|
|
98
|
+
return new Map(surfaces.flatMap(function (_ref3) {
|
|
99
|
+
var anchorName = _ref3.anchorName,
|
|
100
|
+
blockControlsContext = _ref3.blockControlsContext,
|
|
101
|
+
position = _ref3.position;
|
|
97
102
|
return anchorName ? [[position, (0, _getSurfacePlacement.getAnchoredSurfacePlacement)({
|
|
98
103
|
anchorName: anchorName,
|
|
99
104
|
nodeType: blockControlsContext.targetNode.type.name,
|
|
100
105
|
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
106
|
+
layout: blockControlsContext.targetNode.node.attrs.layout,
|
|
101
107
|
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType,
|
|
102
108
|
side: 'right'
|
|
103
109
|
})]] : [];
|
|
@@ -111,8 +117,8 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
111
117
|
// changed dependency each time and re-run it for nothing, which is the cost the anchored path
|
|
112
118
|
// exists to avoid.
|
|
113
119
|
var measuredSurfaces = (0, _react.useMemo)(function () {
|
|
114
|
-
var measured = surfaces.filter(function (
|
|
115
|
-
var anchorName =
|
|
120
|
+
var measured = surfaces.filter(function (_ref4) {
|
|
121
|
+
var anchorName = _ref4.anchorName;
|
|
116
122
|
return !anchorName;
|
|
117
123
|
});
|
|
118
124
|
return measured.length === 0 ? EMPTY_MEASURED_SURFACES : measured;
|
|
@@ -132,9 +138,9 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
132
138
|
});
|
|
133
139
|
return;
|
|
134
140
|
}
|
|
135
|
-
var measurementTargets = measuredSurfaces.flatMap(function (
|
|
136
|
-
var blockControlsContext =
|
|
137
|
-
position =
|
|
141
|
+
var measurementTargets = measuredSurfaces.flatMap(function (_ref5) {
|
|
142
|
+
var blockControlsContext = _ref5.blockControlsContext,
|
|
143
|
+
position = _ref5.position;
|
|
138
144
|
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
139
145
|
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
140
146
|
if (!targetElementRoot) {
|
|
@@ -259,11 +265,11 @@ var BlockControlsRightSurfaces = exports.BlockControlsRightSurfaces = function B
|
|
|
259
265
|
unbindTransitionEnd();
|
|
260
266
|
};
|
|
261
267
|
}, [editorView, measuredSurfaces]);
|
|
262
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (
|
|
268
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref6) {
|
|
263
269
|
var _activeNode$handleOpt, _anchoredPlacements$g;
|
|
264
|
-
var position =
|
|
265
|
-
source =
|
|
266
|
-
surfaceContext =
|
|
270
|
+
var position = _ref6.position,
|
|
271
|
+
source = _ref6.source,
|
|
272
|
+
surfaceContext = _ref6.surfaceContext;
|
|
267
273
|
return /*#__PURE__*/_react.default.createElement(_blockControlsRightSurface.BlockControlsRightSurface, {
|
|
268
274
|
api: api,
|
|
269
275
|
components: components,
|
|
@@ -49,6 +49,7 @@ var createBlockControlsSurfaceContextForPosition = exports.createBlockControlsSu
|
|
|
49
49
|
var rootPos = activeNode ? (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos : targetPos;
|
|
50
50
|
var rootNodeContext = (_getNodeContext = getNodeContext(state, rootPos)) !== null && _getNodeContext !== void 0 ? _getNodeContext : targetNodeContext;
|
|
51
51
|
return {
|
|
52
|
+
activeControlKey: activeNode === null || activeNode === void 0 ? void 0 : activeNode.controlKey,
|
|
52
53
|
activeNode: activeNode && activeNodeContext ? _objectSpread(_objectSpread({}, activeNodeContext), {}, {
|
|
53
54
|
rootPos: rootPos,
|
|
54
55
|
rootType: {
|