@atlaskit/editor-plugin-block-controls 17.1.0 → 17.1.2
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 +15 -0
- package/dist/cjs/blockControlsPlugin.js +14 -6
- package/dist/cjs/pm-plugins/main.js +14 -6
- package/dist/cjs/ui/block-controls-surface-context.js +2 -1
- package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +37 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle-utils.js +45 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +296 -0
- package/dist/cjs/ui/block-controls-surface.compiled.css +2 -1
- package/dist/cjs/ui/block-controls-surface.js +49 -24
- package/dist/cjs/ui/consts.js +2 -1
- package/dist/cjs/ui/surface-editor-view-context.js +12 -0
- package/dist/cjs/ui/use-block-controls-surface-drag-source.js +172 -0
- package/dist/cjs/ui/utils/get-surface-placement.js +8 -1
- package/dist/es2019/blockControlsPlugin.js +13 -6
- package/dist/es2019/pm-plugins/main.js +14 -7
- package/dist/es2019/ui/block-controls-surface-context.js +2 -2
- package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +26 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle-utils.js +33 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +282 -0
- package/dist/es2019/ui/block-controls-surface.compiled.css +2 -1
- package/dist/es2019/ui/block-controls-surface.js +48 -22
- package/dist/es2019/ui/consts.js +1 -0
- package/dist/es2019/ui/surface-editor-view-context.js +4 -0
- package/dist/es2019/ui/use-block-controls-surface-drag-source.js +170 -0
- package/dist/es2019/ui/utils/get-surface-placement.js +15 -6
- package/dist/esm/blockControlsPlugin.js +14 -6
- package/dist/esm/pm-plugins/main.js +14 -6
- package/dist/esm/ui/block-controls-surface-context.js +2 -1
- package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +30 -0
- package/dist/esm/ui/block-controls-surface-drag-handle-utils.js +38 -0
- package/dist/esm/ui/block-controls-surface-drag-handle.compiled.css +32 -0
- package/dist/esm/ui/block-controls-surface-drag-handle.js +290 -0
- package/dist/esm/ui/block-controls-surface.compiled.css +2 -1
- package/dist/esm/ui/block-controls-surface.js +49 -24
- package/dist/esm/ui/consts.js +1 -0
- package/dist/esm/ui/surface-editor-view-context.js +6 -0
- package/dist/esm/ui/use-block-controls-surface-drag-source.js +166 -0
- package/dist/esm/ui/utils/get-surface-placement.js +9 -2
- package/dist/types/pm-plugins/main.d.ts +6 -1
- package/dist/types/ui/block-controls-surface-context.d.ts +1 -1
- package/dist/types/ui/block-controls-surface-drag-handle-registration.d.ts +6 -0
- package/dist/types/ui/block-controls-surface-drag-handle-utils.d.ts +14 -0
- package/dist/types/ui/block-controls-surface-drag-handle.d.ts +10 -0
- package/dist/types/ui/block-controls-surface.d.ts +1 -0
- package/dist/types/ui/consts.d.ts +1 -0
- package/dist/types/ui/surface-editor-view-context.d.ts +5 -0
- package/dist/types/ui/use-block-controls-surface-drag-source.d.ts +19 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +1 -1
- package/package.json +4 -3
|
@@ -17,16 +17,12 @@ import { getAbsoluteSurfacePlacement, getSurfacePlacement } from './utils/get-su
|
|
|
17
17
|
import { VisibilityContainer } from './visibility-container';
|
|
18
18
|
var BLOCK_CONTROLS_SURFACE_Z_INDEX = 100;
|
|
19
19
|
var surfaceStyles = null;
|
|
20
|
-
|
|
21
|
-
var _api$uiControlRegistr, _api$uiControlRegistr2;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode
|
|
28
|
-
};
|
|
29
|
-
}).activeNode;
|
|
20
|
+
var BlockControlsSurfaceAtTarget = function BlockControlsSurfaceAtTarget(_ref) {
|
|
21
|
+
var _api$uiControlRegistr, _api$uiControlRegistr2, _activeNode$handleOpt;
|
|
22
|
+
var activeNode = _ref.activeNode,
|
|
23
|
+
api = _ref.api,
|
|
24
|
+
editorView = _ref.editorView,
|
|
25
|
+
target = _ref.target;
|
|
30
26
|
var _useState = useState(),
|
|
31
27
|
_useState2 = _slicedToArray(_useState, 2),
|
|
32
28
|
position = _useState2[0],
|
|
@@ -34,8 +30,8 @@ export var BlockControlsSurface = function BlockControlsSurface(_ref) {
|
|
|
34
30
|
var animationFrameRef = useRef(undefined);
|
|
35
31
|
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 : [];
|
|
36
32
|
var blockControlsContext = useMemo(function () {
|
|
37
|
-
return createBlockControlsSurfaceContext(editorView, activeNode);
|
|
38
|
-
}, [activeNode, editorView]);
|
|
33
|
+
return createBlockControlsSurfaceContext(editorView, activeNode, target);
|
|
34
|
+
}, [activeNode, editorView, target]);
|
|
39
35
|
var surfaceContext = useMemo(function () {
|
|
40
36
|
return blockControlsContext ? createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
|
|
41
37
|
}, [blockControlsContext]);
|
|
@@ -45,29 +41,29 @@ export var BlockControlsSurface = function BlockControlsSurface(_ref) {
|
|
|
45
41
|
setPosition(undefined);
|
|
46
42
|
return;
|
|
47
43
|
}
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
if (!
|
|
44
|
+
var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
|
|
45
|
+
var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
|
|
46
|
+
if (!targetElementRoot) {
|
|
51
47
|
setPosition(undefined);
|
|
52
48
|
return;
|
|
53
49
|
}
|
|
54
|
-
var targetElement = getNodeContentElement(
|
|
50
|
+
var targetElement = getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name);
|
|
55
51
|
var offsetParent = editorView.dom.offsetParent;
|
|
56
52
|
var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
|
|
57
53
|
var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
|
|
58
54
|
var updatePosition = function updatePosition() {
|
|
59
|
-
var
|
|
55
|
+
var _targetElementRoot$ge, _scrollingOffsetParen, _scrollingOffsetParen2;
|
|
60
56
|
animationFrameRef.current = undefined;
|
|
61
|
-
if (!
|
|
57
|
+
if (!targetElementRoot.isConnected || !targetElement.isConnected) {
|
|
62
58
|
setPosition(undefined);
|
|
63
59
|
return;
|
|
64
60
|
}
|
|
65
61
|
var placement = getSurfacePlacement({
|
|
66
|
-
layout: (
|
|
62
|
+
layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
|
|
67
63
|
nodeRect: targetElement.getBoundingClientRect(),
|
|
68
|
-
nodeType: blockControlsContext.
|
|
69
|
-
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.
|
|
70
|
-
parentNodeType: blockControlsContext.
|
|
64
|
+
nodeType: blockControlsContext.targetNode.type.name,
|
|
65
|
+
nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
|
|
66
|
+
parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
|
|
71
67
|
});
|
|
72
68
|
var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
|
|
73
69
|
var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
|
|
@@ -135,17 +131,46 @@ export var BlockControlsSurface = function BlockControlsSurface(_ref) {
|
|
|
135
131
|
return null;
|
|
136
132
|
}
|
|
137
133
|
return /*#__PURE__*/React.createElement("div", {
|
|
134
|
+
"data-editor-block-controls-surface": true
|
|
138
135
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the active node's runtime DOM geometry.
|
|
136
|
+
,
|
|
139
137
|
style: position,
|
|
140
|
-
"data-testid":
|
|
141
|
-
className: ax(["_1e0c1txw _kqswstnw _1pbyb4wl"])
|
|
138
|
+
"data-testid": target === 'root' ? 'block-controls-left-surface' : 'block-controls-left-surface-active',
|
|
139
|
+
className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
|
|
142
140
|
}, /*#__PURE__*/React.createElement(VisibilityContainer, {
|
|
143
141
|
api: api,
|
|
144
142
|
controlSide: "left",
|
|
143
|
+
forceVisibleOnMouseOut: Boolean((_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
|
|
145
144
|
shouldUseDisplayContents: true
|
|
146
145
|
}, /*#__PURE__*/React.createElement(SurfaceRenderer, {
|
|
147
146
|
components: components,
|
|
148
147
|
surface: BLOCK_CONTROLS_LEFT_SURFACE,
|
|
149
148
|
surfaceContext: surfaceContext
|
|
150
149
|
})));
|
|
150
|
+
};
|
|
151
|
+
export var BlockControlsSurface = function BlockControlsSurface(_ref2) {
|
|
152
|
+
var _activeNode$rootPos;
|
|
153
|
+
var api = _ref2.api,
|
|
154
|
+
editorView = _ref2.editorView;
|
|
155
|
+
var activeNode = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
|
|
156
|
+
var _states$blockControls;
|
|
157
|
+
return {
|
|
158
|
+
activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode
|
|
159
|
+
};
|
|
160
|
+
}).activeNode;
|
|
161
|
+
if (!activeNode) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
var rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
|
|
165
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
|
|
166
|
+
activeNode: activeNode,
|
|
167
|
+
api: api,
|
|
168
|
+
editorView: editorView,
|
|
169
|
+
target: "root"
|
|
170
|
+
}), rootPos !== activeNode.pos ? /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
|
|
171
|
+
activeNode: activeNode,
|
|
172
|
+
api: api,
|
|
173
|
+
editorView: editorView,
|
|
174
|
+
target: "active"
|
|
175
|
+
}) : null);
|
|
151
176
|
};
|
package/dist/esm/ui/consts.js
CHANGED
|
@@ -10,6 +10,7 @@ import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equ
|
|
|
10
10
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
11
|
export var ACTIVE_DRAG_HANDLE_ATTR = 'data-active-drag-handle';
|
|
12
12
|
export var ACTIVE_QUICK_INSERT_ATTR = 'data-active-quick-insert';
|
|
13
|
+
export var BLOCK_CONTROLS_SURFACE_SELECTOR = '[data-editor-block-controls-surface]';
|
|
13
14
|
export var ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME = '--editor-block-controls-active-drag-handle-anchor';
|
|
14
15
|
export var ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME = '--editor-block-controls-active-quick-insert-anchor';
|
|
15
16
|
export var DRAG_HANDLE_HEIGHT = 24;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
/** Provides registered block-control surface contributors with their owning editor view. */
|
|
3
|
+
export var SurfaceEditorViewContext = /*#__PURE__*/createContext(undefined);
|
|
4
|
+
export var useSurfaceEditorView = function useSurfaceEditorView() {
|
|
5
|
+
return useContext(SurfaceEditorViewContext);
|
|
6
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
import { startMeasure } from '@atlaskit/editor-common/performance-measures';
|
|
4
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
+
import { draggable } from '@atlaskit/pragmatic-drag-and-drop/adapter/element-adapter';
|
|
6
|
+
import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/utils/set-custom-native-drag-preview';
|
|
7
|
+
import { defaultActiveAnchorTracker } from '../pm-plugins/utils/active-anchor-tracker';
|
|
8
|
+
import { getMultiSelectAnalyticsAttributes } from '../pm-plugins/utils/analytics';
|
|
9
|
+
import { isHandleCorrelatedToSelection, selectNode } from '../pm-plugins/utils/getSelection';
|
|
10
|
+
import { dragPreview } from './drag-preview';
|
|
11
|
+
import { getNodeMarginsForDragPreview, getNodeSpacingForDragPreview } from './block-controls-surface-drag-handle-utils';
|
|
12
|
+
var EDITOR_BLOCKS_DRAG_INIT = 'Editor Blocks Drag Initialization Time';
|
|
13
|
+
/**
|
|
14
|
+
* Registry surface drag source. This intentionally duplicates the stable widget handle's drag
|
|
15
|
+
* contract so the legacy implementation remains byte-for-byte unchanged during migration.
|
|
16
|
+
*/
|
|
17
|
+
export var useBlockControlsSurfaceDragSource = function useBlockControlsSurfaceDragSource(_ref) {
|
|
18
|
+
var api = _ref.api,
|
|
19
|
+
elementRef = _ref.elementRef,
|
|
20
|
+
getAnchorName = _ref.getAnchorName,
|
|
21
|
+
getPos = _ref.getPos,
|
|
22
|
+
nodeType = _ref.nodeType,
|
|
23
|
+
start = _ref.start,
|
|
24
|
+
view = _ref.view;
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
var element = elementRef.current;
|
|
27
|
+
if (!element || !view) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
return draggable({
|
|
31
|
+
element: element,
|
|
32
|
+
getInitialData: function getInitialData() {
|
|
33
|
+
return {
|
|
34
|
+
type: 'element',
|
|
35
|
+
start: start
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref2) {
|
|
39
|
+
var _api$core, _api$blockControls$sh;
|
|
40
|
+
var nativeSetDragImage = _ref2.nativeSetDragImage;
|
|
41
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref3) {
|
|
42
|
+
var tr = _ref3.tr;
|
|
43
|
+
var handlePos = getPos();
|
|
44
|
+
if (typeof handlePos !== 'number') {
|
|
45
|
+
return tr;
|
|
46
|
+
}
|
|
47
|
+
if (!tr.selection.empty && isHandleCorrelatedToSelection(view.state, tr.selection, handlePos)) {
|
|
48
|
+
var _api$blockControls;
|
|
49
|
+
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setMultiSelectPositions()({
|
|
50
|
+
tr: tr
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
tr = selectNode(tr, handlePos, nodeType, api);
|
|
54
|
+
}
|
|
55
|
+
return tr;
|
|
56
|
+
});
|
|
57
|
+
var startPos = getPos();
|
|
58
|
+
var _view$state = view.state,
|
|
59
|
+
doc = _view$state.doc,
|
|
60
|
+
selection = _view$state.selection;
|
|
61
|
+
var sliceFrom = selection.from;
|
|
62
|
+
var sliceTo = selection.to;
|
|
63
|
+
var multiSelect = api === null || api === void 0 || (_api$blockControls$sh = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh === void 0 ? void 0 : _api$blockControls$sh.multiSelectDnD;
|
|
64
|
+
if (multiSelect) {
|
|
65
|
+
sliceFrom = Math.min(multiSelect.anchor, multiSelect.head);
|
|
66
|
+
sliceTo = Math.max(multiSelect.anchor, multiSelect.head);
|
|
67
|
+
}
|
|
68
|
+
var expandedSlice = doc.slice(sliceFrom, sliceTo);
|
|
69
|
+
var isDraggingMultipleNodes = startPos !== undefined && startPos >= sliceFrom && startPos < sliceTo && expandedSlice.content.childCount > 1;
|
|
70
|
+
setCustomNativeDragPreview({
|
|
71
|
+
getOffset: function getOffset() {
|
|
72
|
+
if (!isDraggingMultipleNodes || startPos === undefined) {
|
|
73
|
+
return {
|
|
74
|
+
x: 0,
|
|
75
|
+
y: 0
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
var domAtPos = view.domAtPos.bind(view);
|
|
79
|
+
var heightBeforeHandle = 0;
|
|
80
|
+
var nodeStart = sliceFrom;
|
|
81
|
+
var activeNodeMarginTop = 0;
|
|
82
|
+
for (var index = 0; index < expandedSlice.content.childCount; index++) {
|
|
83
|
+
var _node$nodeSize;
|
|
84
|
+
var node = expandedSlice.content.maybeChild(index);
|
|
85
|
+
var nodeEnd = nodeStart + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0);
|
|
86
|
+
if (nodeEnd <= startPos) {
|
|
87
|
+
var nodeElement = findDomRefAtPos(nodeStart, domAtPos);
|
|
88
|
+
var margins = getNodeMarginsForDragPreview(node);
|
|
89
|
+
heightBeforeHandle += (nodeElement instanceof HTMLElement ? nodeElement.offsetHeight : 0) + margins.top + margins.bottom;
|
|
90
|
+
} else {
|
|
91
|
+
activeNodeMarginTop = getNodeMarginsForDragPreview(node).top;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
nodeStart = nodeEnd;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
x: 0,
|
|
98
|
+
y: heightBeforeHandle + activeNodeMarginTop
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
render: function render(_ref4) {
|
|
102
|
+
var container = _ref4.container;
|
|
103
|
+
if (!isDraggingMultipleNodes && startPos !== undefined) {
|
|
104
|
+
var dom = findDomRefAtPos(startPos, view.domAtPos.bind(view));
|
|
105
|
+
return dom instanceof HTMLElement ? dragPreview(container, {
|
|
106
|
+
dom: dom,
|
|
107
|
+
nodeType: nodeType
|
|
108
|
+
}) : undefined;
|
|
109
|
+
}
|
|
110
|
+
var previewContent = [];
|
|
111
|
+
expandedSlice.content.descendants(function (node, pos) {
|
|
112
|
+
var dom = findDomRefAtPos(sliceFrom + pos, view.domAtPos.bind(view));
|
|
113
|
+
if (dom instanceof HTMLElement) {
|
|
114
|
+
previewContent.push({
|
|
115
|
+
dom: dom,
|
|
116
|
+
nodeSpacing: getNodeSpacingForDragPreview(node),
|
|
117
|
+
nodeType: node.type.name
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
});
|
|
122
|
+
return previewContent.length > 0 ? dragPreview(container, previewContent) : undefined;
|
|
123
|
+
},
|
|
124
|
+
nativeSetDragImage: nativeSetDragImage
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
onDragStart: function onDragStart() {
|
|
128
|
+
var _api$core2;
|
|
129
|
+
if (start === undefined) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// This handle is outside ProseMirror, so it owns the side effects normally started by PM.
|
|
134
|
+
startMeasure(EDITOR_BLOCKS_DRAG_INIT);
|
|
135
|
+
defaultActiveAnchorTracker.reset();
|
|
136
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref5) {
|
|
137
|
+
var _api$blockControls$sh2, _resolvedMovingNode$n, _api$blockControls2, _api$analytics;
|
|
138
|
+
var tr = _ref5.tr;
|
|
139
|
+
var resolvedMovingNode = tr.doc.resolve(start);
|
|
140
|
+
var multiSelect = api === null || api === void 0 || (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) === null || _api$blockControls$sh2 === void 0 ? void 0 : _api$blockControls$sh2.multiSelectDnD;
|
|
141
|
+
var attributes = multiSelect ? getMultiSelectAnalyticsAttributes(tr, multiSelect.anchor, multiSelect.head) : {
|
|
142
|
+
hasSelectedMultipleNodes: false,
|
|
143
|
+
nodeTypes: (_resolvedMovingNode$n = resolvedMovingNode.nodeAfter) === null || _resolvedMovingNode$n === void 0 ? void 0 : _resolvedMovingNode$n.type.name
|
|
144
|
+
};
|
|
145
|
+
api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.setNodeDragged(getPos, getAnchorName(), nodeType)({
|
|
146
|
+
tr: tr
|
|
147
|
+
});
|
|
148
|
+
tr.setMeta('scrollIntoView', false);
|
|
149
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
|
|
150
|
+
action: ACTION.DRAGGED,
|
|
151
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
152
|
+
actionSubjectId: ACTION_SUBJECT_ID.ELEMENT_DRAG_HANDLE,
|
|
153
|
+
attributes: {
|
|
154
|
+
hasSelectedMultipleNodes: attributes.hasSelectedMultipleNodes,
|
|
155
|
+
nodeDepth: resolvedMovingNode.depth,
|
|
156
|
+
nodeTypes: attributes.nodeTypes || ''
|
|
157
|
+
},
|
|
158
|
+
eventType: EVENT_TYPE.UI
|
|
159
|
+
})(tr);
|
|
160
|
+
return tr;
|
|
161
|
+
});
|
|
162
|
+
view.focus();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}, [api, elementRef, getAnchorName, getPos, nodeType, start, view]);
|
|
166
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
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
|
-
import {
|
|
4
|
+
import { dragHandleGap, topPositionAdjustment } from '../consts';
|
|
5
5
|
export var getAbsoluteSurfacePlacement = function getAbsoluteSurfacePlacement(_ref) {
|
|
6
6
|
var _offsetParentRect$lef, _offsetParentRect$top;
|
|
7
7
|
var offsetParentRect = _ref.offsetParentRect,
|
|
@@ -24,9 +24,16 @@ export var getSurfacePlacement = function getSurfacePlacement(_ref2) {
|
|
|
24
24
|
nodeType = _ref2.nodeType,
|
|
25
25
|
nodeTypeWithLevel = _ref2.nodeTypeWithLevel,
|
|
26
26
|
parentNodeType = _ref2.parentNodeType;
|
|
27
|
+
if (nodeType === 'layoutColumn') {
|
|
28
|
+
return {
|
|
29
|
+
left: nodeRect.left + nodeRect.width / 2,
|
|
30
|
+
top: nodeRect.top,
|
|
31
|
+
transform: 'translate(-50%, -50%)'
|
|
32
|
+
};
|
|
33
|
+
}
|
|
27
34
|
return {
|
|
28
35
|
left: nodeRect.left,
|
|
29
36
|
top: nodeRect.top + topPositionAdjustment(nodeTypeWithLevel, layout),
|
|
30
|
-
transform: "translateX(calc(-100% - ".concat(dragHandleGap(nodeType, parentNodeType)
|
|
37
|
+
transform: "translateX(calc(-100% - ".concat(dragHandleGap(nodeType, parentNodeType), "px))")
|
|
31
38
|
};
|
|
32
39
|
};
|
|
@@ -9,6 +9,11 @@ import type { ActiveDropTargetNode, BlockControlsMeta, BlockControlsPlugin, Mult
|
|
|
9
9
|
import { AnchorRectCache } from './utils/anchor-utils';
|
|
10
10
|
export declare const key: PluginKey<PluginState>;
|
|
11
11
|
export interface FlagType {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the legacy widget-decoration drag handle is rendered. The registry surface renders
|
|
14
|
+
* its replacement when this is false.
|
|
15
|
+
*/
|
|
16
|
+
legacyDragHandleEnabled: boolean;
|
|
12
17
|
toolbarFlagsEnabled: boolean;
|
|
13
18
|
}
|
|
14
19
|
export declare const getDecorations: (state: EditorState) => DecorationSet | undefined;
|
|
@@ -36,7 +41,7 @@ export declare const apply: (api: ExtractInjectionAPI<BlockControlsPlugin> | und
|
|
|
36
41
|
menuTriggerByNode: any;
|
|
37
42
|
multiSelectDnD: MultiSelectDnD | undefined;
|
|
38
43
|
};
|
|
39
|
-
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean) => SafePlugin<PluginState | {
|
|
44
|
+
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape, nodeViewPortalProviderAPI: PortalProviderAPI, nodeDecorationRegistry: NodeDecorationFactory[], rightSideControlsEnabled?: boolean, quickInsertButtonEnabled?: boolean, legacyDragHandleEnabled?: boolean) => SafePlugin<PluginState | {
|
|
40
45
|
activeDropTargetNode: ActiveDropTargetNode | undefined;
|
|
41
46
|
activeNode: any;
|
|
42
47
|
blockMenuOptions: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { BlockControlUIContext } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
2
2
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
3
|
import type { ActiveNode } from '../blockControlsPluginType';
|
|
4
|
-
export declare const createBlockControlsSurfaceContext: (view: EditorView, activeNode: ActiveNode | undefined) => BlockControlUIContext | undefined;
|
|
4
|
+
export declare const createBlockControlsSurfaceContext: (view: EditorView, activeNode: ActiveNode | undefined, target?: 'active' | 'root') => BlockControlUIContext | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { RegisterButton } from '@atlaskit/editor-ui-control-model/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
4
|
+
export declare const getBlockControlsSurfaceDragHandleComponents: ({ api, }: {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
|
+
}) => RegisterButton[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export declare const buildLayoutColumnMenuMeta: (anchorPos: number, openedViaKeyboard: boolean) => {
|
|
3
|
+
anchorPos: number;
|
|
4
|
+
isOpen?: true;
|
|
5
|
+
openedViaKeyboard: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const getNodeSpacingForDragPreview: (node?: PMNode | null) => {
|
|
8
|
+
bottom: string;
|
|
9
|
+
top: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const getNodeMarginsForDragPreview: (node?: PMNode | null) => {
|
|
12
|
+
bottom: number;
|
|
13
|
+
top: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx } from '@atlaskit/css';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { SurfaceContext } from '@atlaskit/editor-ui-control-model/types';
|
|
4
|
+
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
5
|
+
type Props = {
|
|
6
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
7
|
+
surfaceContext?: SurfaceContext;
|
|
8
|
+
};
|
|
9
|
+
export declare const BlockControlsSurfaceDragHandle: ({ api, surfaceContext, }: Props) => jsx.JSX.Element | null;
|
|
10
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const ACTIVE_DRAG_HANDLE_ATTR = "data-active-drag-handle";
|
|
2
2
|
export declare const ACTIVE_QUICK_INSERT_ATTR = "data-active-quick-insert";
|
|
3
|
+
export declare const BLOCK_CONTROLS_SURFACE_SELECTOR = "[data-editor-block-controls-surface]";
|
|
3
4
|
export declare const ACTIVE_DRAG_HANDLE_FALLBACK_ANCHOR_NAME = "--editor-block-controls-active-drag-handle-anchor";
|
|
4
5
|
export declare const ACTIVE_QUICK_INSERT_FALLBACK_ANCHOR_NAME = "--editor-block-controls-active-quick-insert-anchor";
|
|
5
6
|
export declare const DRAG_HANDLE_HEIGHT = 24;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Context } from 'react';
|
|
2
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
/** Provides registered block-control surface contributors with their owning editor view. */
|
|
4
|
+
export declare const SurfaceEditorViewContext: Context<EditorView | undefined>;
|
|
5
|
+
export declare const useSurfaceEditorView: () => EditorView | undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { BlockControlsPlugin } from '../blockControlsPluginType';
|
|
5
|
+
type Options = {
|
|
6
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
7
|
+
elementRef: RefObject<HTMLElement>;
|
|
8
|
+
getAnchorName: () => string;
|
|
9
|
+
getPos: () => number | undefined;
|
|
10
|
+
nodeType: string;
|
|
11
|
+
start: number | undefined;
|
|
12
|
+
view: EditorView | undefined;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Registry surface drag source. This intentionally duplicates the stable widget handle's drag
|
|
16
|
+
* contract so the legacy implementation remains byte-for-byte unchanged during migration.
|
|
17
|
+
*/
|
|
18
|
+
export declare const useBlockControlsSurfaceDragSource: ({ api, elementRef, getAnchorName, getPos, nodeType, start, view, }: Options) => void;
|
|
19
|
+
export {};
|
|
@@ -5,7 +5,7 @@ export type SurfacePlacement = {
|
|
|
5
5
|
};
|
|
6
6
|
export type SurfacePlacementOptions = {
|
|
7
7
|
layout: string;
|
|
8
|
-
nodeRect: Pick<DOMRect, 'left' | 'top'>;
|
|
8
|
+
nodeRect: Pick<DOMRect, 'left' | 'top' | 'width'>;
|
|
9
9
|
nodeType: string;
|
|
10
10
|
nodeTypeWithLevel: string;
|
|
11
11
|
parentNodeType?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "17.1.
|
|
3
|
+
"version": "17.1.2",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -55,10 +55,11 @@
|
|
|
55
55
|
"@atlaskit/primitives": "^22.4.0",
|
|
56
56
|
"@atlaskit/section-message": "^10.1.0",
|
|
57
57
|
"@atlaskit/theme": "^28.1.0",
|
|
58
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
58
|
+
"@atlaskit/tmp-editor-statsig": "^162.0.0",
|
|
59
59
|
"@atlaskit/tokens": "^16.8.0",
|
|
60
60
|
"@atlaskit/tooltip": "^24.2.0",
|
|
61
61
|
"@babel/runtime": "^7.0.0",
|
|
62
|
+
"@compiled/react": "^1.0.2",
|
|
62
63
|
"@emotion/react": "^11.7.1",
|
|
63
64
|
"bind-event-listener": "^3.0.0",
|
|
64
65
|
"memoize-one": "^6.0.0",
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"uuid": "^3.1.0"
|
|
67
68
|
},
|
|
68
69
|
"peerDependencies": {
|
|
69
|
-
"@atlaskit/editor-common": "^120.
|
|
70
|
+
"@atlaskit/editor-common": "^120.3.0",
|
|
70
71
|
"react": "^18.2.0 || ^19.2.0",
|
|
71
72
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
72
73
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|