@atlaskit/editor-plugin-block-controls 17.1.4 → 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 +10 -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 +2 -2
- 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
|
@@ -7,6 +7,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
7
7
|
import rafSchedule from 'raf-schd';
|
|
8
8
|
import { getDocument } from '@atlaskit/browser-apis';
|
|
9
9
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
10
|
+
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
10
11
|
import { getBrowserInfo } from '@atlaskit/editor-common/browser';
|
|
11
12
|
import { getNodeIdProvider } from '@atlaskit/editor-common/node-anchor';
|
|
12
13
|
import { isMeasuring, startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
|
|
@@ -17,6 +18,7 @@ import { EDIT_AREA_ID } from '@atlaskit/editor-common/ui';
|
|
|
17
18
|
import { isEmptyDocument } from '@atlaskit/editor-common/utils';
|
|
18
19
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
19
20
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
21
|
+
import { resolveSurface } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
20
22
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
21
23
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
22
24
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/utils/combine';
|
|
@@ -38,6 +40,7 @@ import { getMultiSelectAnalyticsAttributes } from './utils/analytics';
|
|
|
38
40
|
import { AnchorRectCache, isAnchorSupported } from './utils/anchor-utils';
|
|
39
41
|
import { selectNode } from './utils/getSelection';
|
|
40
42
|
import { getSelectedSlicePosition } from './utils/selection';
|
|
43
|
+
import { getSurfaceNodePositions, updateSurfaceNodePositions } from './utils/surface-node-positions';
|
|
41
44
|
import { getTrMetadata } from './utils/transactions';
|
|
42
45
|
export var key = new PluginKey('blockControls');
|
|
43
46
|
var EDITOR_BLOCKS_DRAG_INIT = 'Editor Blocks Drag Initialization Time';
|
|
@@ -198,6 +201,7 @@ var destroyFn = function destroyFn(api, editorView) {
|
|
|
198
201
|
};
|
|
199
202
|
var initialState = {
|
|
200
203
|
decorations: DecorationSet.empty,
|
|
204
|
+
surfaceNodePositions: [],
|
|
201
205
|
activeNode: undefined,
|
|
202
206
|
isDragging: false,
|
|
203
207
|
isMenuOpen: false,
|
|
@@ -235,10 +239,13 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
|
|
|
235
239
|
var anchorRectCache = arguments.length > 10 ? arguments[10] : undefined;
|
|
236
240
|
var resizeObserverWidth = arguments.length > 11 ? arguments[11] : undefined;
|
|
237
241
|
var pragmaticCleanup = arguments.length > 12 ? arguments[12] : undefined;
|
|
242
|
+
var resolvedSurface = arguments.length > 13 ? arguments[13] : undefined;
|
|
238
243
|
var activeNode = currentState.activeNode,
|
|
239
244
|
decorations = currentState.decorations,
|
|
240
245
|
isResizerResizing = currentState.isResizerResizing,
|
|
241
|
-
multiSelectDnD = currentState.multiSelectDnD
|
|
246
|
+
multiSelectDnD = currentState.multiSelectDnD,
|
|
247
|
+
surfaceNodePositions = currentState.surfaceNodePositions;
|
|
248
|
+
var previousActiveNode = activeNode;
|
|
242
249
|
var editorHeight = currentState.editorHeight,
|
|
243
250
|
editorWidthLeft = currentState.editorWidthLeft,
|
|
244
251
|
editorWidthRight = currentState.editorWidthRight,
|
|
@@ -803,6 +810,18 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
|
|
|
803
810
|
var _latestActiveNode13, _latestActiveNode14;
|
|
804
811
|
newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && flags.legacyDragHandleEnabled && 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;
|
|
805
812
|
}
|
|
813
|
+
if (flags.surfaceNodePositionsEnabled && resolvedSurface) {
|
|
814
|
+
surfaceNodePositions = updateSurfaceNodePositions({
|
|
815
|
+
activeNode: newActiveNode,
|
|
816
|
+
currentPositions: surfaceNodePositions,
|
|
817
|
+
from: from,
|
|
818
|
+
newState: newState,
|
|
819
|
+
previousActiveNode: previousActiveNode,
|
|
820
|
+
resolvedSurface: resolvedSurface,
|
|
821
|
+
to: to,
|
|
822
|
+
tr: tr
|
|
823
|
+
});
|
|
824
|
+
}
|
|
806
825
|
var isMenuOpenNew = isMenuOpen;
|
|
807
826
|
if (editorExperiment('platform_editor_block_menu', true)) {
|
|
808
827
|
if (meta !== null && meta !== void 0 && meta.closeMenu) {
|
|
@@ -822,6 +841,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
|
|
|
822
841
|
}
|
|
823
842
|
return {
|
|
824
843
|
decorations: decorations,
|
|
844
|
+
surfaceNodePositions: surfaceNodePositions,
|
|
825
845
|
activeNode: newActiveNode,
|
|
826
846
|
activeDropTargetNode: currentActiveDropTargetNode,
|
|
827
847
|
isDragging: (_meta$isDragging3 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging3 !== void 0 ? _meta$isDragging3 : isDragging,
|
|
@@ -847,9 +867,11 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
|
|
|
847
867
|
};
|
|
848
868
|
export { _apply as apply };
|
|
849
869
|
export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI, nodeDecorationRegistry) {
|
|
870
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
850
871
|
var rightSideControlsEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
851
872
|
var quickInsertButtonEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : true;
|
|
852
873
|
var legacyDragHandleEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
874
|
+
var surfaceNodePositionsEnabled = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
|
|
853
875
|
var _getIntl = getIntl(),
|
|
854
876
|
formatMessage = _getIntl.formatMessage;
|
|
855
877
|
var isAdvancedLayoutEnabled = editorExperiment('advanced_layouts', true, {
|
|
@@ -858,8 +880,10 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
858
880
|
var toolbarFlagsEnabled = areToolbarFlagsEnabled(Boolean(api === null || api === void 0 ? void 0 : api.toolbar));
|
|
859
881
|
var flags = {
|
|
860
882
|
legacyDragHandleEnabled: legacyDragHandleEnabled,
|
|
883
|
+
surfaceNodePositionsEnabled: surfaceNodePositionsEnabled,
|
|
861
884
|
toolbarFlagsEnabled: toolbarFlagsEnabled
|
|
862
885
|
};
|
|
886
|
+
var resolvedSurface = surfaceNodePositionsEnabled ? resolveSurface((_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [], BLOCK_CONTROLS_LEFT_SURFACE) : undefined;
|
|
863
887
|
var anchorRectCache;
|
|
864
888
|
if (!isAnchorSupported()) {
|
|
865
889
|
anchorRectCache = new AnchorRectCache();
|
|
@@ -869,11 +893,13 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
|
|
|
869
893
|
return new SafePlugin({
|
|
870
894
|
key: key,
|
|
871
895
|
state: {
|
|
872
|
-
init: function init() {
|
|
873
|
-
return initialState
|
|
896
|
+
init: function init(_config, editorState) {
|
|
897
|
+
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
898
|
+
surfaceNodePositions: resolvedSurface ? getSurfaceNodePositions(editorState, resolvedSurface) : []
|
|
899
|
+
});
|
|
874
900
|
},
|
|
875
901
|
apply: function apply(tr, currentState, _, newState) {
|
|
876
|
-
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup);
|
|
902
|
+
return _apply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, nodeDecorationRegistry, rightSideControlsEnabled, quickInsertButtonEnabled, anchorRectCache, resizeObserverWidth, pragmaticCleanup, resolvedSurface);
|
|
877
903
|
}
|
|
878
904
|
},
|
|
879
905
|
props: {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
3
|
+
import { willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
4
|
+
import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
5
|
+
import { createBlockControlsSurfaceContextForPosition } from '../../ui/block-controls-surface-context';
|
|
6
|
+
var createSurfaceContextAtPosition = function createSurfaceContextAtPosition(state, position, activeNode) {
|
|
7
|
+
var blockControlsContext = createBlockControlsSurfaceContextForPosition(state, position, activeNode);
|
|
8
|
+
return blockControlsContext ? createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
|
|
9
|
+
};
|
|
10
|
+
export var getSurfaceNodePositions = function getSurfaceNodePositions(state, resolvedSurface, activeNode) {
|
|
11
|
+
var from = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
|
12
|
+
var to = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : state.doc.content.size;
|
|
13
|
+
var root = resolvedSurface.root,
|
|
14
|
+
childrenMap = resolvedSurface.childrenMap;
|
|
15
|
+
if (!root) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
var positions = [];
|
|
19
|
+
var start = Math.max(0, from);
|
|
20
|
+
var end = Math.min(state.doc.content.size, Math.max(start, to));
|
|
21
|
+
state.doc.nodesBetween(start, end, function (node, position) {
|
|
22
|
+
if (node.isBlock && willComponentRender(root, childrenMap, createSurfaceContextAtPosition(state, position, activeNode))) {
|
|
23
|
+
positions.push(position);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return positions;
|
|
27
|
+
};
|
|
28
|
+
var hasActiveNodeChanged = function hasActiveNodeChanged(previousActiveNode, activeNode) {
|
|
29
|
+
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);
|
|
30
|
+
};
|
|
31
|
+
export var updateSurfaceNodePositions = function updateSurfaceNodePositions(_ref) {
|
|
32
|
+
var activeNode = _ref.activeNode,
|
|
33
|
+
currentPositions = _ref.currentPositions,
|
|
34
|
+
from = _ref.from,
|
|
35
|
+
newState = _ref.newState,
|
|
36
|
+
previousActiveNode = _ref.previousActiveNode,
|
|
37
|
+
resolvedSurface = _ref.resolvedSurface,
|
|
38
|
+
to = _ref.to,
|
|
39
|
+
tr = _ref.tr;
|
|
40
|
+
var activeNodeChanged = hasActiveNodeChanged(previousActiveNode, activeNode);
|
|
41
|
+
if (!tr.docChanged && !activeNodeChanged) {
|
|
42
|
+
return currentPositions;
|
|
43
|
+
}
|
|
44
|
+
var nextActiveNode = activeNode !== null && activeNode !== void 0 ? activeNode : undefined;
|
|
45
|
+
if (activeNodeChanged) {
|
|
46
|
+
return getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode);
|
|
47
|
+
}
|
|
48
|
+
var root = resolvedSurface.root,
|
|
49
|
+
childrenMap = resolvedSurface.childrenMap;
|
|
50
|
+
var mappedPositions = currentPositions.map(function (position) {
|
|
51
|
+
return tr.mapping.mapResult(position, -1);
|
|
52
|
+
}).filter(function (result) {
|
|
53
|
+
return !result.deleted;
|
|
54
|
+
}).map(function (result) {
|
|
55
|
+
return result.pos;
|
|
56
|
+
}).filter(function (position) {
|
|
57
|
+
var node = newState.doc.nodeAt(position);
|
|
58
|
+
return Boolean((node === null || node === void 0 ? void 0 : node.isBlock) && root && willComponentRender(root, childrenMap, createSurfaceContextAtPosition(newState, position, nextActiveNode)));
|
|
59
|
+
});
|
|
60
|
+
var changedPositions = getSurfaceNodePositions(newState, resolvedSurface, nextActiveNode, from - 1, to + 1);
|
|
61
|
+
return Array.from(new Set([].concat(_toConsumableArray(mappedPositions), _toConsumableArray(changedPositions)))).sort(function (first, second) {
|
|
62
|
+
return first - second;
|
|
63
|
+
});
|
|
64
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
+
/** Combines hover-driven and stored surface positions into one deduplicated list. */
|
|
5
|
+
export var getBlockControlsLeftSurfaceTargets = function getBlockControlsLeftSurfaceTargets(activeNode, storedPositions) {
|
|
6
|
+
var targetsByPosition = new Map();
|
|
7
|
+
var _iterator = _createForOfIteratorHelper(storedPositions),
|
|
8
|
+
_step;
|
|
9
|
+
try {
|
|
10
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
11
|
+
var position = _step.value;
|
|
12
|
+
targetsByPosition.set(position, {
|
|
13
|
+
position: position,
|
|
14
|
+
source: 'stored'
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
} catch (err) {
|
|
18
|
+
_iterator.e(err);
|
|
19
|
+
} finally {
|
|
20
|
+
_iterator.f();
|
|
21
|
+
}
|
|
22
|
+
if (activeNode) {
|
|
23
|
+
var _activeNode$rootPos;
|
|
24
|
+
var rootPosition = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
|
|
25
|
+
targetsByPosition.set(rootPosition, {
|
|
26
|
+
position: rootPosition,
|
|
27
|
+
source: 'root'
|
|
28
|
+
});
|
|
29
|
+
if (activeNode.pos !== rootPosition) {
|
|
30
|
+
targetsByPosition.set(activeNode.pos, {
|
|
31
|
+
position: activeNode.pos,
|
|
32
|
+
source: 'active'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return Array.from(targetsByPosition.values()).sort(function (first, second) {
|
|
37
|
+
return first.position - second.position;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* block-controls-left-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import "./block-controls-left-surface.compiled.css";
|
|
3
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
6
|
+
import { SurfaceRenderer, willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
7
|
+
import { VisibilityContainer } from './visibility-container';
|
|
8
|
+
var leftSurfaceStyles = null;
|
|
9
|
+
/** Renders one left block-controls surface at a document position. */
|
|
10
|
+
export var BlockControlsLeftSurface = function BlockControlsLeftSurface(_ref) {
|
|
11
|
+
var api = _ref.api,
|
|
12
|
+
components = _ref.components,
|
|
13
|
+
forceVisibleOnMouseOut = _ref.forceVisibleOnMouseOut,
|
|
14
|
+
placement = _ref.placement,
|
|
15
|
+
source = _ref.source,
|
|
16
|
+
surfaceContext = _ref.surfaceContext;
|
|
17
|
+
if (!placement || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var surface = /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
21
|
+
components: components,
|
|
22
|
+
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
23
|
+
surfaceContext: surfaceContext
|
|
24
|
+
});
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
"data-editor-block-controls-surface": true,
|
|
27
|
+
"data-testid": source === 'stored' ? 'block-controls-left-surface-stored' : source === 'active' ? 'block-controls-left-surface-active' : 'block-controls-left-surface'
|
|
28
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the target node's runtime DOM geometry.
|
|
29
|
+
,
|
|
30
|
+
style: placement,
|
|
31
|
+
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
|
|
32
|
+
}, /*#__PURE__*/React.createElement(VisibilityContainer, {
|
|
33
|
+
api: api,
|
|
34
|
+
controlSide: "left",
|
|
35
|
+
forceVisibleOnMouseOut: forceVisibleOnMouseOut,
|
|
36
|
+
shouldUseDisplayContents: true
|
|
37
|
+
}, surface));
|
|
38
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/* block-controls-left-surfaces.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import { ax, ix } from "@compiled/react/runtime";
|
|
5
|
+
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; } } }; }
|
|
6
|
+
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; } }
|
|
7
|
+
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; }
|
|
8
|
+
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; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { bind } from 'bind-event-listener';
|
|
12
|
+
import { getDocument } from '@atlaskit/browser-apis';
|
|
13
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
14
|
+
import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
|
|
15
|
+
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
16
|
+
import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
17
|
+
import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
|
|
18
|
+
import { createBlockControlsSurfaceContext, createBlockControlsSurfaceContextForPosition } from './block-controls-surface-context';
|
|
19
|
+
import { BlockControlsLeftSurface } from './block-controls-left-surface';
|
|
20
|
+
import { getBlockControlsLeftSurfaceTargets } from './block-controls-left-surface-targets';
|
|
21
|
+
import { getNodeContentElement } from './utils/get-node-content-element';
|
|
22
|
+
import { getAbsoluteSurfacePlacement, getSurfacePlacement } from './utils/get-surface-placement';
|
|
23
|
+
var EMPTY_SURFACE_POSITIONS = [];
|
|
24
|
+
var EMPTY_SURFACE_COMPONENTS = [];
|
|
25
|
+
export var BlockControlsLeftSurfaces = function BlockControlsLeftSurfaces(_ref) {
|
|
26
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
27
|
+
var api = _ref.api,
|
|
28
|
+
editorView = _ref.editorView;
|
|
29
|
+
var _useSharedPluginState = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
|
|
30
|
+
var _states$blockControls, _states$blockControls2, _states$blockControls3;
|
|
31
|
+
return {
|
|
32
|
+
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode,
|
|
33
|
+
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
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
activeNode = _useSharedPluginState.activeNode,
|
|
37
|
+
surfaceNodePositions = _useSharedPluginState.surfaceNodePositions;
|
|
38
|
+
var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : EMPTY_SURFACE_COMPONENTS;
|
|
39
|
+
var targets = useMemo(function () {
|
|
40
|
+
return getBlockControlsLeftSurfaceTargets(activeNode, surfaceNodePositions);
|
|
41
|
+
}, [activeNode, surfaceNodePositions]);
|
|
42
|
+
var surfaces = useMemo(function () {
|
|
43
|
+
return targets.flatMap(function (target) {
|
|
44
|
+
var context = target.source === 'stored' ? createBlockControlsSurfaceContextForPosition(editorView.state, target.position, activeNode) : createBlockControlsSurfaceContext(editorView, activeNode, target.source);
|
|
45
|
+
if (!context) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
var surfaceContext = createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, context);
|
|
49
|
+
return [_objectSpread(_objectSpread({}, target), {}, {
|
|
50
|
+
blockControlsContext: context,
|
|
51
|
+
surfaceContext: surfaceContext
|
|
52
|
+
})];
|
|
53
|
+
});
|
|
54
|
+
}, [activeNode, editorView, targets]);
|
|
55
|
+
var _useState = useState(new Map()),
|
|
56
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
57
|
+
placements = _useState2[0],
|
|
58
|
+
setPlacements = _useState2[1];
|
|
59
|
+
var animationFrameRef = useRef(undefined);
|
|
60
|
+
useLayoutEffect(function () {
|
|
61
|
+
var _getDocument;
|
|
62
|
+
if (surfaces.length === 0) {
|
|
63
|
+
setPlacements(new Map());
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
var measurementTargets = surfaces.flatMap(function (_ref2) {
|
|
67
|
+
var blockControlsContext = _ref2.blockControlsContext,
|
|
68
|
+
position = _ref2.position;
|
|
69
|
+
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
70
|
+
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
71
|
+
if (!targetElementRoot) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
return [{
|
|
75
|
+
blockControlsContext: blockControlsContext,
|
|
76
|
+
position: position,
|
|
77
|
+
targetElement: getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name),
|
|
78
|
+
targetElementRoot: targetElementRoot
|
|
79
|
+
}];
|
|
80
|
+
});
|
|
81
|
+
var offsetParent = editorView.dom.offsetParent;
|
|
82
|
+
var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
|
|
83
|
+
var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
|
|
84
|
+
var updatePositions = function updatePositions() {
|
|
85
|
+
var _scrollingOffsetParen, _scrollingOffsetParen2;
|
|
86
|
+
animationFrameRef.current = undefined;
|
|
87
|
+
var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
|
|
88
|
+
var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
|
|
89
|
+
var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
|
|
90
|
+
var nextPlacements = new Map();
|
|
91
|
+
var _iterator = _createForOfIteratorHelper(measurementTargets),
|
|
92
|
+
_step;
|
|
93
|
+
try {
|
|
94
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
95
|
+
var _targetElementRoot$ge;
|
|
96
|
+
var _step$value = _step.value,
|
|
97
|
+
blockControlsContext = _step$value.blockControlsContext,
|
|
98
|
+
position = _step$value.position,
|
|
99
|
+
targetElement = _step$value.targetElement,
|
|
100
|
+
targetElementRoot = _step$value.targetElementRoot;
|
|
101
|
+
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
var placement = getSurfacePlacement({
|
|
105
|
+
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
106
|
+
nodeRect: targetElement.getBoundingClientRect(),
|
|
107
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
108
|
+
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
109
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
110
|
+
});
|
|
111
|
+
nextPlacements.set(position, getAbsoluteSurfacePlacement({
|
|
112
|
+
offsetParentRect: offsetParentRect,
|
|
113
|
+
offsetParentScrollLeft: offsetParentScrollLeft,
|
|
114
|
+
offsetParentScrollTop: offsetParentScrollTop,
|
|
115
|
+
placement: placement
|
|
116
|
+
}));
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
_iterator.e(err);
|
|
120
|
+
} finally {
|
|
121
|
+
_iterator.f();
|
|
122
|
+
}
|
|
123
|
+
setPlacements(nextPlacements);
|
|
124
|
+
};
|
|
125
|
+
var schedulePositionUpdate = function schedulePositionUpdate() {
|
|
126
|
+
if (animationFrameRef.current === undefined) {
|
|
127
|
+
animationFrameRef.current = requestAnimationFrame(updatePositions);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
updatePositions();
|
|
131
|
+
var resizeObserver = new ResizeObserver(schedulePositionUpdate);
|
|
132
|
+
var observedElements = new Set([editorView.dom]);
|
|
133
|
+
var _iterator2 = _createForOfIteratorHelper(measurementTargets),
|
|
134
|
+
_step2;
|
|
135
|
+
try {
|
|
136
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
137
|
+
var targetElement = _step2.value.targetElement;
|
|
138
|
+
observedElements.add(targetElement);
|
|
139
|
+
}
|
|
140
|
+
} catch (err) {
|
|
141
|
+
_iterator2.e(err);
|
|
142
|
+
} finally {
|
|
143
|
+
_iterator2.f();
|
|
144
|
+
}
|
|
145
|
+
if (offsetParent instanceof HTMLElement) {
|
|
146
|
+
observedElements.add(offsetParent);
|
|
147
|
+
}
|
|
148
|
+
observedElements.forEach(function (element) {
|
|
149
|
+
return resizeObserver.observe(element);
|
|
150
|
+
});
|
|
151
|
+
var unbindWindowResize = bind(window, {
|
|
152
|
+
type: 'resize',
|
|
153
|
+
listener: schedulePositionUpdate
|
|
154
|
+
});
|
|
155
|
+
var unbindWindowScroll = bind(window, {
|
|
156
|
+
type: 'scroll',
|
|
157
|
+
listener: schedulePositionUpdate,
|
|
158
|
+
options: {
|
|
159
|
+
capture: true,
|
|
160
|
+
passive: true
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
var visualViewport = window.visualViewport;
|
|
164
|
+
var unbindVisualViewportResize = visualViewport ? bind(visualViewport, {
|
|
165
|
+
type: 'resize',
|
|
166
|
+
listener: schedulePositionUpdate
|
|
167
|
+
}) : undefined;
|
|
168
|
+
var unbindVisualViewportScroll = visualViewport ? bind(visualViewport, {
|
|
169
|
+
type: 'scroll',
|
|
170
|
+
listener: schedulePositionUpdate
|
|
171
|
+
}) : undefined;
|
|
172
|
+
var unbindTransitionEnd = bind(editorView.dom, {
|
|
173
|
+
type: 'transitionend',
|
|
174
|
+
listener: schedulePositionUpdate,
|
|
175
|
+
options: {
|
|
176
|
+
capture: true
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return function () {
|
|
180
|
+
if (animationFrameRef.current !== undefined) {
|
|
181
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
182
|
+
animationFrameRef.current = undefined;
|
|
183
|
+
}
|
|
184
|
+
resizeObserver.disconnect();
|
|
185
|
+
unbindWindowResize();
|
|
186
|
+
unbindWindowScroll();
|
|
187
|
+
unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
|
|
188
|
+
unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
|
|
189
|
+
unbindTransitionEnd();
|
|
190
|
+
};
|
|
191
|
+
}, [editorView, surfaces]);
|
|
192
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, surfaces.map(function (_ref3) {
|
|
193
|
+
var _activeNode$handleOpt;
|
|
194
|
+
var position = _ref3.position,
|
|
195
|
+
source = _ref3.source,
|
|
196
|
+
surfaceContext = _ref3.surfaceContext;
|
|
197
|
+
return /*#__PURE__*/React.createElement(BlockControlsLeftSurface, {
|
|
198
|
+
api: api,
|
|
199
|
+
components: components,
|
|
200
|
+
forceVisibleOnMouseOut: Boolean(activeNode === null || activeNode === void 0 || (_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
201
|
+
key: position,
|
|
202
|
+
placement: placements.get(position),
|
|
203
|
+
source: source,
|
|
204
|
+
surfaceContext: surfaceContext
|
|
205
|
+
});
|
|
206
|
+
}));
|
|
207
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
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; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
var getNodeContext = function getNodeContext(
|
|
5
|
-
var node =
|
|
4
|
+
var getNodeContext = function getNodeContext(state, pos) {
|
|
5
|
+
var node = state.doc.nodeAt(pos);
|
|
6
6
|
if (!node) {
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
9
|
-
var $pos =
|
|
9
|
+
var $pos = state.doc.resolve(pos);
|
|
10
10
|
var ancestors = [];
|
|
11
11
|
for (var depth = 0; depth <= $pos.depth; depth++) {
|
|
12
12
|
var ancestor = $pos.node(depth);
|
|
@@ -29,26 +29,32 @@ var getNodeContext = function getNodeContext(view, pos) {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
|
-
export var
|
|
33
|
-
var _activeNode$rootPos, _activeNode$rootNodeT;
|
|
34
|
-
var
|
|
35
|
-
if (!
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
var rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
|
|
39
|
-
var activeNodeContext = getNodeContext(view, activeNode.pos);
|
|
40
|
-
var rootNodeContext = getNodeContext(view, rootPos);
|
|
41
|
-
if (!activeNodeContext || !rootNodeContext) {
|
|
32
|
+
export var createBlockControlsSurfaceContextForPosition = function createBlockControlsSurfaceContextForPosition(state, targetPos, activeNode) {
|
|
33
|
+
var _activeNode$rootPos, _getNodeContext, _activeNode$rootNodeT;
|
|
34
|
+
var targetNodeContext = getNodeContext(state, targetPos);
|
|
35
|
+
if (!targetNodeContext) {
|
|
42
36
|
return undefined;
|
|
43
37
|
}
|
|
38
|
+
var activeNodeContext = activeNode ? getNodeContext(state, activeNode.pos) : undefined;
|
|
39
|
+
var rootPos = activeNode ? (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos : targetPos;
|
|
40
|
+
var rootNodeContext = (_getNodeContext = getNodeContext(state, rootPos)) !== null && _getNodeContext !== void 0 ? _getNodeContext : targetNodeContext;
|
|
44
41
|
return {
|
|
45
|
-
activeNode: _objectSpread(_objectSpread({}, activeNodeContext), {}, {
|
|
42
|
+
activeNode: activeNode && activeNodeContext ? _objectSpread(_objectSpread({}, activeNodeContext), {}, {
|
|
46
43
|
rootPos: rootPos,
|
|
47
44
|
rootType: {
|
|
48
45
|
name: (_activeNode$rootNodeT = activeNode.rootNodeType) !== null && _activeNode$rootNodeT !== void 0 ? _activeNode$rootNodeT : rootNodeContext.type.name
|
|
49
46
|
}
|
|
50
|
-
}),
|
|
47
|
+
}) : undefined,
|
|
51
48
|
rootNode: rootNodeContext,
|
|
52
|
-
targetNode:
|
|
49
|
+
targetNode: targetNodeContext
|
|
53
50
|
};
|
|
51
|
+
};
|
|
52
|
+
export var createBlockControlsSurfaceContext = function createBlockControlsSurfaceContext(view, activeNode) {
|
|
53
|
+
var _activeNode$rootPos2;
|
|
54
|
+
var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'root';
|
|
55
|
+
if (!activeNode) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
var rootPos = (_activeNode$rootPos2 = activeNode.rootPos) !== null && _activeNode$rootPos2 !== void 0 ? _activeNode$rootPos2 : activeNode.pos;
|
|
59
|
+
return createBlockControlsSurfaceContextForPosition(view.state, target === 'active' ? activeNode.pos : rootPos, activeNode);
|
|
54
60
|
};
|
|
@@ -78,6 +78,7 @@ export interface PluginState {
|
|
|
78
78
|
menuTriggerByNode?: TriggerByNode;
|
|
79
79
|
multiSelectDnD?: MultiSelectDnD;
|
|
80
80
|
preservedSelection?: Selection;
|
|
81
|
+
surfaceNodePositions: number[];
|
|
81
82
|
}
|
|
82
83
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
83
84
|
export type BlockControlsPluginConfig = {
|
|
@@ -109,6 +110,7 @@ export type BlockControlsSharedState = {
|
|
|
109
110
|
preservedSelection?: Selection;
|
|
110
111
|
/** Whether left/right hover split is enabled (from plugin config) */
|
|
111
112
|
rightSideControlsEnabled?: boolean;
|
|
113
|
+
surfaceNodePositions?: number[];
|
|
112
114
|
} | undefined;
|
|
113
115
|
export type HandleOptions = {
|
|
114
116
|
isFocused: boolean;
|
|
@@ -5,6 +5,7 @@ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
|
5
5
|
import type { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
8
|
+
import type { ResolvedSurface } from '@atlaskit/editor-ui-control-model/surface-renderer/types';
|
|
8
9
|
import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, MultiSelectDnD, NodeDecorationFactory, PluginState } from '../blockControlsPluginType';
|
|
9
10
|
import { AnchorRectCache } from './utils/anchor-utils';
|
|
10
11
|
export declare const key: PluginKey<PluginState>;
|
|
@@ -14,10 +15,11 @@ export interface FlagType {
|
|
|
14
15
|
* its replacement when this is false.
|
|
15
16
|
*/
|
|
16
17
|
legacyDragHandleEnabled: boolean;
|
|
18
|
+
surfaceNodePositionsEnabled: boolean;
|
|
17
19
|
toolbarFlagsEnabled: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
|
|
20
|
-
export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null) => PluginState | {
|
|
22
|
+
export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, formatMessage: IntlShape['formatMessage'], tr: ReadonlyTransaction, currentState: PluginState, newState: EditorState, flags: FlagType, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, anchorRectCache?: AnchorRectCache, resizeObserverWidth?: ResizeObserver, pragmaticCleanup?: (() => void) | null, resolvedSurface?: ResolvedSurface) => PluginState | {
|
|
21
23
|
activeDropTargetNode: ActiveDropTargetNode | undefined;
|
|
22
24
|
activeNode: any;
|
|
23
25
|
blockMenuOptions: {
|
|
@@ -40,8 +42,9 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
|
|
|
40
42
|
menuTriggerBy: any;
|
|
41
43
|
menuTriggerByNode: any;
|
|
42
44
|
multiSelectDnD: MultiSelectDnD | undefined;
|
|
45
|
+
surfaceNodePositions: number[];
|
|
43
46
|
};
|
|
44
|
-
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, legacyDragHandleEnabled?: boolean) => SafePlugin<PluginState | {
|
|
47
|
+
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, legacyDragHandleEnabled?: boolean, surfaceNodePositionsEnabled?: boolean) => SafePlugin<PluginState | {
|
|
45
48
|
activeDropTargetNode: ActiveDropTargetNode | undefined;
|
|
46
49
|
activeNode: any;
|
|
47
50
|
blockMenuOptions: {
|
|
@@ -64,5 +67,6 @@ export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin
|
|
|
64
67
|
menuTriggerBy: any;
|
|
65
68
|
menuTriggerByNode: any;
|
|
66
69
|
multiSelectDnD: MultiSelectDnD | undefined;
|
|
70
|
+
surfaceNodePositions: number[];
|
|
67
71
|
}>;
|
|
68
72
|
export declare const getBlockControlsMeta: (tr: Transaction | ReadonlyTransaction) => BlockControlsMeta | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { ResolvedSurface } from '@atlaskit/editor-ui-control-model/surface-renderer/types';
|
|
3
|
+
import type { ActiveNode } from '../../blockControlsPluginType';
|
|
4
|
+
export declare const getSurfaceNodePositions: (state: EditorState, resolvedSurface: ResolvedSurface, activeNode?: ActiveNode, from?: number, to?: number) => number[];
|
|
5
|
+
export declare const updateSurfaceNodePositions: ({ activeNode, currentPositions, from, newState, previousActiveNode, resolvedSurface, to, tr, }: {
|
|
6
|
+
activeNode: ActiveNode | null | undefined;
|
|
7
|
+
currentPositions: number[];
|
|
8
|
+
from: number;
|
|
9
|
+
newState: EditorState;
|
|
10
|
+
previousActiveNode: ActiveNode | null | undefined;
|
|
11
|
+
resolvedSurface: ResolvedSurface;
|
|
12
|
+
to: number;
|
|
13
|
+
tr: ReadonlyTransaction;
|
|
14
|
+
}) => number[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ActiveNode } from '../blockControlsPluginType';
|
|
2
|
+
export type BlockControlsLeftSurfaceTarget = {
|
|
3
|
+
position: number;
|
|
4
|
+
source: 'active' | 'root' | 'stored';
|
|
5
|
+
};
|
|
6
|
+
/** Combines hover-driven and stored surface positions into one deduplicated list. */
|
|
7
|
+
export declare const getBlockControlsLeftSurfaceTargets: (activeNode: ActiveNode | undefined, storedPositions: readonly number[]) => readonly BlockControlsLeftSurfaceTarget[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jsxRuntime classic
|
|
3
|
+
* @jsx jsx
|
|
4
|
+
* @jsxFrag React.Fragment
|
|
5
|
+
*/
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
8
|
+
import { SurfaceRenderer } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
9
|
+
import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
10
|
+
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
11
|
+
import type { BlockControlsLeftSurfaceTarget } from './block-controls-left-surface-targets';
|
|
12
|
+
import type { SurfacePlacement } from './utils/get-surface-placement';
|
|
13
|
+
type BlockControlsLeftSurfaceProps = {
|
|
14
|
+
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
15
|
+
components: React.ComponentProps<typeof SurfaceRenderer>['components'];
|
|
16
|
+
forceVisibleOnMouseOut: boolean;
|
|
17
|
+
placement: SurfacePlacement | undefined;
|
|
18
|
+
source: BlockControlsLeftSurfaceTarget['source'];
|
|
19
|
+
surfaceContext: SurfaceContext;
|
|
20
|
+
};
|
|
21
|
+
/** Renders one left block-controls surface at a document position. */
|
|
22
|
+
export declare const BlockControlsLeftSurface: ({ api, components, forceVisibleOnMouseOut, placement, source, surfaceContext, }: BlockControlsLeftSurfaceProps) => React.JSX.Element | null;
|
|
23
|
+
export {};
|
|
@@ -11,5 +11,5 @@ type Props = {
|
|
|
11
11
|
api: ExtractInjectionAPI<BlockControlsPlugin>;
|
|
12
12
|
editorView: EditorView;
|
|
13
13
|
};
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const BlockControlsLeftSurfaces: ({ api, editorView }: Props) => React.JSX.Element | null;
|
|
15
15
|
export {};
|