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