@atlaskit/editor-plugin-block-controls 17.1.3 → 17.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/blockControlsPlugin.js +8 -3
- package/dist/cjs/pm-plugins/main.js +30 -4
- package/dist/cjs/pm-plugins/utils/surface-node-positions.js +71 -0
- package/dist/cjs/ui/block-controls-left-surface-targets.js +45 -0
- package/dist/cjs/ui/block-controls-left-surface.js +45 -0
- package/dist/cjs/ui/block-controls-left-surfaces.js +216 -0
- package/dist/cjs/ui/block-controls-surface-context.js +23 -17
- package/dist/es2019/blockControlsPlugin.js +8 -3
- package/dist/es2019/pm-plugins/main.js +31 -6
- package/dist/es2019/pm-plugins/utils/surface-node-positions.js +56 -0
- package/dist/es2019/ui/block-controls-left-surface-targets.js +25 -0
- package/dist/es2019/ui/block-controls-left-surface.js +39 -0
- package/dist/es2019/ui/block-controls-left-surfaces.js +181 -0
- package/dist/es2019/ui/block-controls-surface-context.js +21 -15
- package/dist/esm/blockControlsPlugin.js +8 -3
- package/dist/esm/pm-plugins/main.js +30 -4
- package/dist/esm/pm-plugins/utils/surface-node-positions.js +64 -0
- package/dist/esm/ui/block-controls-left-surface-targets.js +39 -0
- package/dist/esm/ui/block-controls-left-surface.js +38 -0
- package/dist/esm/ui/block-controls-left-surfaces.js +207 -0
- package/dist/esm/ui/block-controls-surface-context.js +22 -16
- package/dist/types/blockControlsPluginType.d.ts +2 -0
- package/dist/types/pm-plugins/main.d.ts +6 -2
- package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +14 -0
- package/dist/types/ui/block-controls-left-surface-targets.d.ts +7 -0
- package/dist/types/ui/block-controls-left-surface.d.ts +23 -0
- package/dist/types/ui/{block-controls-surface.d.ts → block-controls-left-surfaces.d.ts} +1 -1
- package/dist/types/ui/block-controls-surface-context.d.ts +2 -0
- package/package.json +4 -4
- package/dist/cjs/ui/block-controls-surface.js +0 -185
- package/dist/es2019/ui/block-controls-surface.js +0 -170
- package/dist/esm/ui/block-controls-surface.js +0 -176
- /package/dist/cjs/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
- /package/dist/es2019/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
- /package/dist/esm/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 17.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`0841b102bfe4a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0841b102bfe4a) -
|
|
8
|
+
Add a PM-state-backed multi-location left block-controls surface and register the display-only
|
|
9
|
+
heading collapse button behind `platform_editor_block_control_migration` and
|
|
10
|
+
`platform_editor_collapsible_headings`.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 17.1.4
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 17.1.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -31,7 +31,7 @@ var _pluginKey = require("./pm-plugins/selection-preservation/plugin-key");
|
|
|
31
31
|
var _pmPlugin2 = require("./pm-plugins/selection-preservation/pm-plugin");
|
|
32
32
|
var _expandAndUpdateSelection2 = require("./pm-plugins/utils/expand-and-update-selection");
|
|
33
33
|
var _getSelection = require("./pm-plugins/utils/getSelection");
|
|
34
|
-
var
|
|
34
|
+
var _blockControlsLeftSurfaces = require("./ui/block-controls-left-surfaces");
|
|
35
35
|
var _blockControlsSurfaceDragHandleRegistration = require("./ui/block-controls-surface-drag-handle-registration");
|
|
36
36
|
var _globalStyles = require("./ui/global-styles");
|
|
37
37
|
var _surfaceEditorViewContext = require("./ui/surface-editor-view-context");
|
|
@@ -45,6 +45,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
45
45
|
var rightSideControlsEnabled = (_config$rightSideCont = config === null || config === void 0 ? void 0 : config.rightSideControlsEnabled) !== null && _config$rightSideCont !== void 0 ? _config$rightSideCont : false;
|
|
46
46
|
var quickInsertButtonEnabled = (_config$quickInsertBu = config === null || config === void 0 ? void 0 : config.quickInsertButtonEnabled) !== null && _config$quickInsertBu !== void 0 ? _config$quickInsertBu : true;
|
|
47
47
|
var registryBlockControlsEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_block_control_migration');
|
|
48
|
+
var surfaceNodePositionsEnabled = registryBlockControlsEnabled && (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_collapsible_headings');
|
|
48
49
|
var legacyBlockControlsEnabled = !registryBlockControlsEnabled;
|
|
49
50
|
if (registryBlockControlsEnabled) {
|
|
50
51
|
var _api$uiControlRegistr;
|
|
@@ -128,7 +129,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
128
129
|
plugin: function plugin(_ref2) {
|
|
129
130
|
var getIntl = _ref2.getIntl,
|
|
130
131
|
nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
|
|
131
|
-
return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled && legacyBlockControlsEnabled, legacyBlockControlsEnabled);
|
|
132
|
+
return (0, _main.createPlugin)(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled && legacyBlockControlsEnabled, legacyBlockControlsEnabled, surfaceNodePositionsEnabled);
|
|
132
133
|
}
|
|
133
134
|
}];
|
|
134
135
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
@@ -430,6 +431,10 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
430
431
|
isEditing: (_interactionTrackingP = _pmPlugin.interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP === void 0 ? void 0 : _interactionTrackingP.isEditing,
|
|
431
432
|
isSelectedViaDragHandle: (_key$getState$isSelec = (_key$getState10 = _main.key.getState(editorState)) === null || _key$getState10 === void 0 ? void 0 : _key$getState10.isSelectedViaDragHandle) !== null && _key$getState$isSelec !== void 0 ? _key$getState$isSelec : false
|
|
432
433
|
};
|
|
434
|
+
if (surfaceNodePositionsEnabled) {
|
|
435
|
+
var _key$getState$surface, _key$getState11;
|
|
436
|
+
sharedState.surfaceNodePositions = (_key$getState$surface = (_key$getState11 = _main.key.getState(editorState)) === null || _key$getState11 === void 0 ? void 0 : _key$getState11.surfaceNodePositions) !== null && _key$getState$surface !== void 0 ? _key$getState$surface : [];
|
|
437
|
+
}
|
|
433
438
|
if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
434
439
|
var _interactionTrackingP2, _interactionTrackingP3, _interactionTrackingP4;
|
|
435
440
|
sharedState.isMouseOut = (_interactionTrackingP2 = (_interactionTrackingP3 = _pmPlugin.interactionTrackingPluginKey.getState(editorState)) === null || _interactionTrackingP3 === void 0 ? void 0 : _interactionTrackingP3.isMouseOut) !== null && _interactionTrackingP2 !== void 0 ? _interactionTrackingP2 : false;
|
|
@@ -449,7 +454,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
449
454
|
api: api
|
|
450
455
|
}), registryBlockControlsEnabled && editorView && api ? /*#__PURE__*/_react.default.createElement(_surfaceEditorViewContext.SurfaceEditorViewContext.Provider, {
|
|
451
456
|
value: editorView
|
|
452
|
-
}, /*#__PURE__*/_react.default.createElement(
|
|
457
|
+
}, /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurfaces.BlockControlsLeftSurfaces, {
|
|
453
458
|
api: api,
|
|
454
459
|
editorView: editorView
|
|
455
460
|
})) : null);
|
|
@@ -9,6 +9,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
10
10
|
var _browserApis = require("@atlaskit/browser-apis");
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
12
13
|
var _browser = require("@atlaskit/editor-common/browser");
|
|
13
14
|
var _nodeAnchor = require("@atlaskit/editor-common/node-anchor");
|
|
14
15
|
var _performanceMeasures = require("@atlaskit/editor-common/performance-measures");
|
|
@@ -19,6 +20,7 @@ var _ui = require("@atlaskit/editor-common/ui");
|
|
|
19
20
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
20
21
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
21
22
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
23
|
+
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
22
24
|
var _fg = require("@atlaskit/platform-feature-flags/fg");
|
|
23
25
|
var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
|
|
24
26
|
var _combine = require("@atlaskit/pragmatic-drag-and-drop/utils/combine");
|
|
@@ -40,6 +42,7 @@ var _analytics2 = require("./utils/analytics");
|
|
|
40
42
|
var _anchorUtils = require("./utils/anchor-utils");
|
|
41
43
|
var _getSelection = require("./utils/getSelection");
|
|
42
44
|
var _selection = require("./utils/selection");
|
|
45
|
+
var _surfaceNodePositions = require("./utils/surface-node-positions");
|
|
43
46
|
var _transactions = require("./utils/transactions");
|
|
44
47
|
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; } } }; }
|
|
45
48
|
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; } }
|
|
@@ -205,6 +208,7 @@ var destroyFn = function destroyFn(api, editorView) {
|
|
|
205
208
|
};
|
|
206
209
|
var initialState = {
|
|
207
210
|
decorations: _view.DecorationSet.empty,
|
|
211
|
+
surfaceNodePositions: [],
|
|
208
212
|
activeNode: undefined,
|
|
209
213
|
isDragging: false,
|
|
210
214
|
isMenuOpen: false,
|
|
@@ -242,10 +246,13 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
242
246
|
var anchorRectCache = arguments.length > 10 ? arguments[10] : undefined;
|
|
243
247
|
var resizeObserverWidth = arguments.length > 11 ? arguments[11] : undefined;
|
|
244
248
|
var pragmaticCleanup = arguments.length > 12 ? arguments[12] : undefined;
|
|
249
|
+
var resolvedSurface = arguments.length > 13 ? arguments[13] : undefined;
|
|
245
250
|
var activeNode = currentState.activeNode,
|
|
246
251
|
decorations = currentState.decorations,
|
|
247
252
|
isResizerResizing = currentState.isResizerResizing,
|
|
248
|
-
multiSelectDnD = currentState.multiSelectDnD
|
|
253
|
+
multiSelectDnD = currentState.multiSelectDnD,
|
|
254
|
+
surfaceNodePositions = currentState.surfaceNodePositions;
|
|
255
|
+
var previousActiveNode = activeNode;
|
|
249
256
|
var editorHeight = currentState.editorHeight,
|
|
250
257
|
editorWidthLeft = currentState.editorWidthLeft,
|
|
251
258
|
editorWidthRight = currentState.editorWidthRight,
|
|
@@ -810,6 +817,18 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
810
817
|
var _latestActiveNode13, _latestActiveNode14;
|
|
811
818
|
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && flags.legacyDragHandleEnabled && (0, _decorationsDragHandle.findHandleDec)(decorations, (_latestActiveNode13 = latestActiveNode) === null || _latestActiveNode13 === void 0 ? void 0 : _latestActiveNode13.pos, (_latestActiveNode14 = latestActiveNode) === null || _latestActiveNode14 === void 0 ? void 0 : _latestActiveNode14.pos).length === 0 ? null : latestActiveNode;
|
|
812
819
|
}
|
|
820
|
+
if (flags.surfaceNodePositionsEnabled && resolvedSurface) {
|
|
821
|
+
surfaceNodePositions = (0, _surfaceNodePositions.updateSurfaceNodePositions)({
|
|
822
|
+
activeNode: newActiveNode,
|
|
823
|
+
currentPositions: surfaceNodePositions,
|
|
824
|
+
from: from,
|
|
825
|
+
newState: newState,
|
|
826
|
+
previousActiveNode: previousActiveNode,
|
|
827
|
+
resolvedSurface: resolvedSurface,
|
|
828
|
+
to: to,
|
|
829
|
+
tr: tr
|
|
830
|
+
});
|
|
831
|
+
}
|
|
813
832
|
var isMenuOpenNew = isMenuOpen;
|
|
814
833
|
if ((0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
|
|
815
834
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
@@ -829,6 +848,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
829
848
|
}
|
|
830
849
|
return {
|
|
831
850
|
decorations: decorations,
|
|
851
|
+
surfaceNodePositions: surfaceNodePositions,
|
|
832
852
|
activeNode: newActiveNode,
|
|
833
853
|
activeDropTargetNode: currentActiveDropTargetNode,
|
|
834
854
|
isDragging: (_meta$isDragging3 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging3 !== void 0 ? _meta$isDragging3 : isDragging,
|
|
@@ -853,9 +873,11 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
|
|
|
853
873
|
};
|
|
854
874
|
};
|
|
855
875
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
876
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
856
877
|
var rightSideControlsEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
857
878
|
var quickInsertButtonEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
858
879
|
var legacyDragHandleEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
880
|
+
var surfaceNodePositionsEnabled = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
859
881
|
var _getIntl = getIntl(),
|
|
860
882
|
formatMessage = _getIntl.formatMessage;
|
|
861
883
|
var isAdvancedLayoutEnabled = (0, _experiments.editorExperiment)('advanced_layouts', true, {
|
|
@@ -864,8 +886,10 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
864
886
|
var toolbarFlagsEnabled = (0, _toolbarFlagCheck.areToolbarFlagsEnabled)(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
865
887
|
var flags = {
|
|
866
888
|
legacyDragHandleEnabled: legacyDragHandleEnabled,
|
|
889
|
+
surfaceNodePositionsEnabled: surfaceNodePositionsEnabled,
|
|
867
890
|
toolbarFlagsEnabled: toolbarFlagsEnabled
|
|
868
891
|
};
|
|
892
|
+
var resolvedSurface = surfaceNodePositionsEnabled ? (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(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE) : undefined;
|
|
869
893
|
var anchorRectCache;
|
|
870
894
|
if (!(0, _anchorUtils.isAnchorSupported)()) {
|
|
871
895
|
anchorRectCache = new _anchorUtils.AnchorRectCache();
|
|
@@ -875,11 +899,13 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
|
|
|
875
899
|
return new _safePlugin.SafePlugin({
|
|
876
900
|
key: key,
|
|
877
901
|
state: {
|
|
878
|
-
init: function init() {
|
|
879
|
-
return initialState
|
|
902
|
+
init: function init(_config, editorState) {
|
|
903
|
+
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
904
|
+
surfaceNodePositions: resolvedSurface ? (0, _surfaceNodePositions.getSurfaceNodePositions)(editorState, resolvedSurface) : []
|
|
905
|
+
});
|
|
880
906
|
},
|
|
881
907
|
apply: function apply(tr, currentState, _, newState) {
|
|
882
|
-
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup);
|
|
908
|
+
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurface);
|
|
883
909
|
}
|
|
884
910
|
},
|
|
885
911
|
props: {
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.updateSurfaceNodePositions = exports.getSurfaceNodePositions = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
|
|
10
|
+
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
11
|
+
var _types = require("@atlaskit/editor-ui-control-model/types");
|
|
12
|
+
var _blockControlsSurfaceContext = require("../../ui/block-controls-surface-context");
|
|
13
|
+
var createSurfaceContextAtPosition = function createSurfaceContextAtPosition(state, position, activeNode) {
|
|
14
|
+
var blockControlsContext = (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(state, position, activeNode);
|
|
15
|
+
return blockControlsContext ? (0, _types.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
|
|
16
|
+
};
|
|
17
|
+
var getSurfaceNodePositions = exports.getSurfaceNodePositions = function getSurfaceNodePositions(state, resolvedSurface, activeNode) {
|
|
18
|
+
var from = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
19
|
+
var to = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : state.doc.content.size;
|
|
20
|
+
var root = resolvedSurface.root,
|
|
21
|
+
childrenMap = resolvedSurface.childrenMap;
|
|
22
|
+
if (!root) {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
var positions = [];
|
|
26
|
+
var start = Math.max(0, from);
|
|
27
|
+
var end = Math.min(state.doc.content.size, Math.max(start, to));
|
|
28
|
+
state.doc.nodesBetween(start, end, function (node, position) {
|
|
29
|
+
if (node.isBlock && (0, _surfaceRenderer.willComponentRender)(root, childrenMap, createSurfaceContextAtPosition(state, position, activeNode))) {
|
|
30
|
+
positions.push(position);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return positions;
|
|
34
|
+
};
|
|
35
|
+
var hasActiveNodeChanged = function hasActiveNodeChanged(previousActiveNode, activeNode) {
|
|
36
|
+
return (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) || (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) || (previousActiveNode === null || previousActiveNode === void 0 ? void 0 : previousActiveNode.rootPos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.rootPos);
|
|
37
|
+
};
|
|
38
|
+
var updateSurfaceNodePositions = exports.updateSurfaceNodePositions = function updateSurfaceNodePositions(_ref) {
|
|
39
|
+
var activeNode = _ref.activeNode,
|
|
40
|
+
currentPositions = _ref.currentPositions,
|
|
41
|
+
from = _ref.from,
|
|
42
|
+
newState = _ref.newState,
|
|
43
|
+
previousActiveNode = _ref.previousActiveNode,
|
|
44
|
+
resolvedSurface = _ref.resolvedSurface,
|
|
45
|
+
to = _ref.to,
|
|
46
|
+
tr = _ref.tr;
|
|
47
|
+
var activeNodeChanged = hasActiveNodeChanged(previousActiveNode, activeNode);
|
|
48
|
+
if (!tr.docChanged && !activeNodeChanged) {
|
|
49
|
+
return currentPositions;
|
|
50
|
+
}
|
|
51
|
+
var nextActiveNode = activeNode !== null && activeNode !== void 0 ? activeNode : undefined;
|
|
52
|
+
if (activeNodeChanged) {
|
|
53
|
+
return getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode);
|
|
54
|
+
}
|
|
55
|
+
var root = resolvedSurface.root,
|
|
56
|
+
childrenMap = resolvedSurface.childrenMap;
|
|
57
|
+
var mappedPositions = currentPositions.map(function (position) {
|
|
58
|
+
return tr.mapping.mapResult(position, -1);
|
|
59
|
+
}).filter(function (result) {
|
|
60
|
+
return !result.deleted;
|
|
61
|
+
}).map(function (result) {
|
|
62
|
+
return result.pos;
|
|
63
|
+
}).filter(function (position) {
|
|
64
|
+
var node = newState.doc.nodeAt(position);
|
|
65
|
+
return Boolean((node === null || node === void 0 ? void 0 : node.isBlock) && root && (0, _surfaceRenderer.willComponentRender)(root, childrenMap, createSurfaceContextAtPosition(newState, position, nextActiveNode)));
|
|
66
|
+
});
|
|
67
|
+
var changedPositions = getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode, from - 1, to + 1);
|
|
68
|
+
return Array.from(new Set([].concat((0, _toConsumableArray2.default)(mappedPositions), (0, _toConsumableArray2.default)(changedPositions)))).sort(function (first, second) {
|
|
69
|
+
return first - second;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBlockControlsLeftSurfaceTargets = void 0;
|
|
7
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
8
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
/** Combines hover-driven and stored surface positions into one deduplicated list. */
|
|
11
|
+
var getBlockControlsLeftSurfaceTargets = exports.getBlockControlsLeftSurfaceTargets = function getBlockControlsLeftSurfaceTargets(activeNode, storedPositions) {
|
|
12
|
+
var targetsByPosition = new Map();
|
|
13
|
+
var _iterator = _createForOfIteratorHelper(storedPositions),
|
|
14
|
+
_step;
|
|
15
|
+
try {
|
|
16
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
17
|
+
var position = _step.value;
|
|
18
|
+
targetsByPosition.set(position, {
|
|
19
|
+
position: position,
|
|
20
|
+
source: 'stored'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
} catch (err) {
|
|
24
|
+
_iterator.e(err);
|
|
25
|
+
} finally {
|
|
26
|
+
_iterator.f();
|
|
27
|
+
}
|
|
28
|
+
if (activeNode) {
|
|
29
|
+
var _activeNode$rootPos;
|
|
30
|
+
var rootPosition = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
|
|
31
|
+
targetsByPosition.set(rootPosition, {
|
|
32
|
+
position: rootPosition,
|
|
33
|
+
source: 'root'
|
|
34
|
+
});
|
|
35
|
+
if (activeNode.pos !== rootPosition) {
|
|
36
|
+
targetsByPosition.set(activeNode.pos, {
|
|
37
|
+
position: activeNode.pos,
|
|
38
|
+
source: 'active'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return Array.from(targetsByPosition.values()).sort(function (first, second) {
|
|
43
|
+
return first.position - second.position;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* block-controls-left-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.BlockControlsLeftSurface = void 0;
|
|
9
|
+
require("./block-controls-left-surface.compiled.css");
|
|
10
|
+
var _runtime = require("@compiled/react/runtime");
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
|
|
13
|
+
var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
|
|
14
|
+
var _visibilityContainer = require("./visibility-container");
|
|
15
|
+
var leftSurfaceStyles = null;
|
|
16
|
+
/** Renders one left block-controls surface at a document position. */
|
|
17
|
+
var BlockControlsLeftSurface = exports.BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
|
|
18
|
+
var api = _ref.api,
|
|
19
|
+
components = _ref.components,
|
|
20
|
+
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
21
|
+
placement = _ref.placement,
|
|
22
|
+
source = _ref.source,
|
|
23
|
+
surfaceContext = _ref.surfaceContext;
|
|
24
|
+
if (!placement || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
var surface = /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
|
|
28
|
+
components: components,
|
|
29
|
+
surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
|
|
30
|
+
surfaceContext: surfaceContext
|
|
31
|
+
});
|
|
32
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
33
|
+
"data-editor-block-controls-surface": true,
|
|
34
|
+
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
|
|
35
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the target node's runtime DOM geometry.
|
|
36
|
+
,
|
|
37
|
+
style: placement,
|
|
38
|
+
className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
|
|
39
|
+
}, /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
|
|
40
|
+
api: api,
|
|
41
|
+
controlSide: "left",
|
|
42
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
43
|
+
shouldUseDisplayContents: true
|
|
44
|
+
}, surface));
|
|
45
|
+
};
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/* block-controls-left-surfaces.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
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 _hooks = require("@atlaskit/editor-common/hooks");
|
|
19
|
+
var _types = require("@atlaskit/editor-ui-control-model/types");
|
|
20
|
+
var _decorationsCommon = require("../pm-plugins/decorations-common");
|
|
21
|
+
var _blockControlsSurfaceContext = require("./block-controls-surface-context");
|
|
22
|
+
var _blockControlsLeftSurface = require("./block-controls-left-surface");
|
|
23
|
+
var _blockControlsLeftSurfaceTargets = require("./block-controls-left-surface-targets");
|
|
24
|
+
var _getNodeContentElement = require("./utils/get-node-content-element");
|
|
25
|
+
var _getSurfacePlacement = require("./utils/get-surface-placement");
|
|
26
|
+
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); }
|
|
27
|
+
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; } } }; }
|
|
28
|
+
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; } }
|
|
29
|
+
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; }
|
|
30
|
+
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; }
|
|
31
|
+
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; }
|
|
32
|
+
var EMPTY_SURFACE_POSITIONS = [];
|
|
33
|
+
var EMPTY_SURFACE_COMPONENTS = [];
|
|
34
|
+
var BlockControlsLeftSurfaces = exports.BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
|
|
35
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
36
|
+
var api = _ref.api,
|
|
37
|
+
editorView = _ref.editorView;
|
|
38
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
|
|
39
|
+
var _states$blockControls, _states$blockControls2, _states$blockControls3;
|
|
40
|
+
return {
|
|
41
|
+
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
|
|
42
|
+
surfaceNodePositions: (_states$blockControls2 = (_states$blockControls3 = states.blockControlsState) === null || _states$blockControls3 === void 0 ? void 0 : _states$blockControls3.surfaceNodePositions) !== null && _states$blockControls2 !== void 0 ? _states$blockControls2 : EMPTY_SURFACE_POSITIONS
|
|
43
|
+
};
|
|
44
|
+
}),
|
|
45
|
+
activeNode = _useSharedPluginState.activeNode,
|
|
46
|
+
surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
|
|
47
|
+
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;
|
|
48
|
+
var targets = (0, _react.useMemo)(function () {
|
|
49
|
+
return (0, _blockControlsLeftSurfaceTargets.getBlockControlsLeftSurfaceTargets)(activeNode, surfaceNodePositions);
|
|
50
|
+
}, [activeNode, surfaceNodePositions]);
|
|
51
|
+
var surfaces = (0, _react.useMemo)(function () {
|
|
52
|
+
return targets.flatMap(function (target) {
|
|
53
|
+
var context = target.source === 'stored' ? (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContextForPosition)(editorView.state, target.position, activeNode) : (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContext)(editorView, activeNode, target.source);
|
|
54
|
+
if (!context) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
var surfaceContext = (0, _types.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, context);
|
|
58
|
+
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
59
|
+
blockControlsContext: context,
|
|
60
|
+
surfaceContext: surfaceContext
|
|
61
|
+
})];
|
|
62
|
+
});
|
|
63
|
+
}, [activeNode, editorView, targets]);
|
|
64
|
+
var _useState = (0, _react.useState)(new Map()),
|
|
65
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
66
|
+
placements = _useState2[0],
|
|
67
|
+
setPlacements = _useState2[1];
|
|
68
|
+
var animationFrameRef = (0, _react.useRef)(undefined);
|
|
69
|
+
(0, _react.useLayoutEffect)(function () {
|
|
70
|
+
var _getDocument;
|
|
71
|
+
if (surfaces.length === 0) {
|
|
72
|
+
setPlacements(new Map());
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var measurementTargets = surfaces.flatMap(function (_ref2) {
|
|
76
|
+
var blockControlsContext = _ref2.blockControlsContext,
|
|
77
|
+
position = _ref2.position;
|
|
78
|
+
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
79
|
+
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
80
|
+
if (!targetElementRoot) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return [{
|
|
84
|
+
blockControlsContext: blockControlsContext,
|
|
85
|
+
position: position,
|
|
86
|
+
targetElement: (0, _getNodeContentElement.getNodeContentElement)(targetElementRoot, blockControlsContext.targetNode.type.name),
|
|
87
|
+
targetElementRoot: targetElementRoot
|
|
88
|
+
}];
|
|
89
|
+
});
|
|
90
|
+
var offsetParent = editorView.dom.offsetParent;
|
|
91
|
+
var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
|
|
92
|
+
var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
|
|
93
|
+
var updatePositions = function updatePositions() {
|
|
94
|
+
var _scrollingOffsetParen, _scrollingOffsetParen2;
|
|
95
|
+
animationFrameRef.current = undefined;
|
|
96
|
+
var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
|
|
97
|
+
var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
|
|
98
|
+
var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
|
|
99
|
+
var nextPlacements = new Map();
|
|
100
|
+
var _iterator = _createForOfIteratorHelper(measurementTargets),
|
|
101
|
+
_step;
|
|
102
|
+
try {
|
|
103
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
104
|
+
var _targetElementRoot$ge;
|
|
105
|
+
var _step$value = _step.value,
|
|
106
|
+
blockControlsContext = _step$value.blockControlsContext,
|
|
107
|
+
position = _step$value.position,
|
|
108
|
+
targetElement = _step$value.targetElement,
|
|
109
|
+
targetElementRoot = _step$value.targetElementRoot;
|
|
110
|
+
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
var placement = (0, _getSurfacePlacement.getSurfacePlacement)({
|
|
114
|
+
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
115
|
+
nodeRect: targetElement.getBoundingClientRect(),
|
|
116
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
117
|
+
nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
|
|
118
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
119
|
+
});
|
|
120
|
+
nextPlacements.set(position, (0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
|
|
121
|
+
offsetParentRect: offsetParentRect,
|
|
122
|
+
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
123
|
+
offsetParentScrollTop: offsetParentScrollTop,
|
|
124
|
+
placement: placement
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
_iterator.e(err);
|
|
129
|
+
} finally {
|
|
130
|
+
_iterator.f();
|
|
131
|
+
}
|
|
132
|
+
setPlacements(nextPlacements);
|
|
133
|
+
};
|
|
134
|
+
var schedulePositionUpdate = function schedulePositionUpdate() {
|
|
135
|
+
if (animationFrameRef.current === undefined) {
|
|
136
|
+
animationFrameRef.current = requestAnimationFrame(updatePositions);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
updatePositions();
|
|
140
|
+
var resizeObserver = new ResizeObserver(schedulePositionUpdate);
|
|
141
|
+
var observedElements = new Set([editorView.dom]);
|
|
142
|
+
var _iterator2 = _createForOfIteratorHelper(measurementTargets),
|
|
143
|
+
_step2;
|
|
144
|
+
try {
|
|
145
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
146
|
+
var targetElement = _step2.value.targetElement;
|
|
147
|
+
observedElements.add(targetElement);
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
_iterator2.e(err);
|
|
151
|
+
} finally {
|
|
152
|
+
_iterator2.f();
|
|
153
|
+
}
|
|
154
|
+
if (offsetParent instanceof HTMLElement) {
|
|
155
|
+
observedElements.add(offsetParent);
|
|
156
|
+
}
|
|
157
|
+
observedElements.forEach(function (element) {
|
|
158
|
+
return resizeObserver.observe(element);
|
|
159
|
+
});
|
|
160
|
+
var unbindWindowResize = (0, _bindEventListener.bind)(window, {
|
|
161
|
+
type: 'resize',
|
|
162
|
+
listener: schedulePositionUpdate
|
|
163
|
+
});
|
|
164
|
+
var unbindWindowScroll = (0, _bindEventListener.bind)(window, {
|
|
165
|
+
type: 'scroll',
|
|
166
|
+
listener: schedulePositionUpdate,
|
|
167
|
+
options: {
|
|
168
|
+
capture: true,
|
|
169
|
+
passive: true
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
var visualViewport = window.visualViewport;
|
|
173
|
+
var unbindVisualViewportResize = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
|
|
174
|
+
type: 'resize',
|
|
175
|
+
listener: schedulePositionUpdate
|
|
176
|
+
}) : undefined;
|
|
177
|
+
var unbindVisualViewportScroll = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
|
|
178
|
+
type: 'scroll',
|
|
179
|
+
listener: schedulePositionUpdate
|
|
180
|
+
}) : undefined;
|
|
181
|
+
var unbindTransitionEnd = (0, _bindEventListener.bind)(editorView.dom, {
|
|
182
|
+
type: 'transitionend',
|
|
183
|
+
listener: schedulePositionUpdate,
|
|
184
|
+
options: {
|
|
185
|
+
capture: true
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return function () {
|
|
189
|
+
if (animationFrameRef.current !== undefined) {
|
|
190
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
191
|
+
animationFrameRef.current = undefined;
|
|
192
|
+
}
|
|
193
|
+
resizeObserver.disconnect();
|
|
194
|
+
unbindWindowResize();
|
|
195
|
+
unbindWindowScroll();
|
|
196
|
+
unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
|
|
197
|
+
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
198
|
+
unbindTransitionEnd();
|
|
199
|
+
};
|
|
200
|
+
}, [editorView, surfaces]);
|
|
201
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, surfaces.map(function (_ref3) {
|
|
202
|
+
var _activeNode$handleOpt;
|
|
203
|
+
var position = _ref3.position,
|
|
204
|
+
source = _ref3.source,
|
|
205
|
+
surfaceContext = _ref3.surfaceContext;
|
|
206
|
+
return /*#__PURE__*/_react.default.createElement(_blockControlsLeftSurface.BlockControlsLeftSurface, {
|
|
207
|
+
api: api,
|
|
208
|
+
components: components,
|
|
209
|
+
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
210
|
+
key: position,
|
|
211
|
+
placement: placements.get(position),
|
|
212
|
+
source: source,
|
|
213
|
+
surfaceContext: surfaceContext
|
|
214
|
+
});
|
|
215
|
+
}));
|
|
216
|
+
};
|
|
@@ -4,16 +4,16 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.createBlockControlsSurfaceContext = void 0;
|
|
7
|
+
exports.createBlockControlsSurfaceContextForPosition = exports.createBlockControlsSurfaceContext = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
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; }
|
|
10
10
|
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; }
|
|
11
|
-
var getNodeContext = function getNodeContext(
|
|
12
|
-
var node =
|
|
11
|
+
var getNodeContext = function getNodeContext(state, pos) {
|
|
12
|
+
var node = state.doc.nodeAt(pos);
|
|
13
13
|
if (!node) {
|
|
14
14
|
return undefined;
|
|
15
15
|
}
|
|
16
|
-
var $pos =
|
|
16
|
+
var $pos = state.doc.resolve(pos);
|
|
17
17
|
var ancestors = [];
|
|
18
18
|
for (var depth = 0; depth <= $pos.depth; depth++) {
|
|
19
19
|
var ancestor = $pos.node(depth);
|
|
@@ -36,26 +36,32 @@ var getNodeContext = function getNodeContext(view, pos) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
|
-
var
|
|
40
|
-
var _activeNode$rootPos, _activeNode$rootNodeT;
|
|
41
|
-
var
|
|
42
|
-
if (!
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
var rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
|
|
46
|
-
var activeNodeContext = getNodeContext(view, activeNode.pos);
|
|
47
|
-
var rootNodeContext = getNodeContext(view, rootPos);
|
|
48
|
-
if (!activeNodeContext || !rootNodeContext) {
|
|
39
|
+
var createBlockControlsSurfaceContextForPosition = exports.createBlockControlsSurfaceContextForPosition = function createBlockControlsSurfaceContextForPosition(state, targetPos, activeNode) {
|
|
40
|
+
var _activeNode$rootPos, _getNodeContext, _activeNode$rootNodeT;
|
|
41
|
+
var targetNodeContext = getNodeContext(state, targetPos);
|
|
42
|
+
if (!targetNodeContext) {
|
|
49
43
|
return undefined;
|
|
50
44
|
}
|
|
45
|
+
var activeNodeContext = activeNode ? getNodeContext(state, activeNode.pos) : undefined;
|
|
46
|
+
var rootPos = activeNode ? (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos : targetPos;
|
|
47
|
+
var rootNodeContext = (_getNodeContext = getNodeContext(state, rootPos)) !== null && _getNodeContext !== void 0 ? _getNodeContext : targetNodeContext;
|
|
51
48
|
return {
|
|
52
|
-
activeNode: _objectSpread(_objectSpread({}, activeNodeContext), {}, {
|
|
49
|
+
activeNode: activeNode && activeNodeContext ? _objectSpread(_objectSpread({}, activeNodeContext), {}, {
|
|
53
50
|
rootPos: rootPos,
|
|
54
51
|
rootType: {
|
|
55
52
|
name: (_activeNode$rootNodeT = activeNode.rootNodeType) !== null && _activeNode$rootNodeT !== void 0 ? _activeNode$rootNodeT : rootNodeContext.type.name
|
|
56
53
|
}
|
|
57
|
-
}),
|
|
54
|
+
}) : undefined,
|
|
58
55
|
rootNode: rootNodeContext,
|
|
59
|
-
targetNode:
|
|
56
|
+
targetNode: targetNodeContext
|
|
60
57
|
};
|
|
58
|
+
};
|
|
59
|
+
var createBlockControlsSurfaceContext = exports.createBlockControlsSurfaceContext = function createBlockControlsSurfaceContext(view, activeNode) {
|
|
60
|
+
var _activeNode$rootPos2;
|
|
61
|
+
var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'root';
|
|
62
|
+
if (!activeNode) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
var rootPos = (_activeNode$rootPos2 = activeNode.rootPos) !== null && _activeNode$rootPos2 !== void 0 ? _activeNode$rootPos2 : activeNode.pos;
|
|
66
|
+
return createBlockControlsSurfaceContextForPosition(view.state, target === 'active' ? activeNode.pos : rootPos, activeNode);
|
|
61
67
|
};
|