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