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