@atlaskit/editor-plugin-block-controls 2.5.0 → 2.6.0
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 +21 -0
- package/dist/cjs/commands/move-node.js +7 -6
- package/dist/cjs/commands/show-drag-handle.js +2 -1
- package/dist/cjs/pm-plugins/decorations.js +93 -32
- package/dist/cjs/pm-plugins/keymap.js +5 -2
- package/dist/cjs/pm-plugins/main.js +349 -203
- package/dist/cjs/ui/drag-handle.js +4 -6
- package/dist/cjs/ui/drop-target-v2.js +32 -6
- package/dist/cjs/ui/global-styles.js +1 -7
- package/dist/cjs/utils/transactions.js +63 -0
- package/dist/es2019/commands/move-node.js +7 -6
- package/dist/es2019/commands/show-drag-handle.js +2 -1
- package/dist/es2019/pm-plugins/decorations.js +86 -31
- package/dist/es2019/pm-plugins/keymap.js +5 -2
- package/dist/es2019/pm-plugins/main.js +332 -179
- package/dist/es2019/ui/drag-handle.js +4 -8
- package/dist/es2019/ui/drop-target-v2.js +32 -6
- package/dist/es2019/ui/global-styles.js +1 -7
- package/dist/es2019/utils/transactions.js +57 -0
- package/dist/esm/commands/move-node.js +7 -6
- package/dist/esm/commands/show-drag-handle.js +2 -1
- package/dist/esm/pm-plugins/decorations.js +92 -31
- package/dist/esm/pm-plugins/keymap.js +5 -2
- package/dist/esm/pm-plugins/main.js +350 -204
- package/dist/esm/ui/drag-handle.js +4 -6
- package/dist/esm/ui/drop-target-v2.js +32 -6
- package/dist/esm/ui/global-styles.js +1 -7
- package/dist/esm/utils/transactions.js +57 -0
- package/dist/types/pm-plugins/decorations.d.ts +24 -4
- package/dist/types/pm-plugins/main.d.ts +32 -0
- package/dist/types/ui/drag-handle.d.ts +5 -14
- package/dist/types/ui/drop-target-v2.d.ts +1 -1
- package/dist/types/ui/drop-target.d.ts +2 -0
- package/dist/types/utils/transactions.d.ts +29 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +24 -4
- package/dist/types-ts4.5/pm-plugins/main.d.ts +32 -0
- package/dist/types-ts4.5/ui/drag-handle.d.ts +5 -14
- package/dist/types-ts4.5/ui/drop-target-v2.d.ts +1 -1
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -0
- package/dist/types-ts4.5/utils/transactions.d.ts +29 -0
- package/package.json +4 -7
|
@@ -52,15 +52,28 @@ const nestedDropZoneStyle = css({
|
|
|
52
52
|
width: 'unset'
|
|
53
53
|
});
|
|
54
54
|
const enableDropZone = ['paragraph', 'mediaSingle', 'heading', 'codeBlock', 'decisionList', 'bulletList', 'orderedList', 'taskList', 'extension', 'blockCard'];
|
|
55
|
+
const fullHeightStyle = css({
|
|
56
|
+
top: '4px',
|
|
57
|
+
bottom: '4px',
|
|
58
|
+
height: 'unset',
|
|
59
|
+
zIndex: 10
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// This z index is used in container like layout
|
|
63
|
+
const fullHeightStyleAdjustZIndexStyle = css({
|
|
64
|
+
zIndex: 0
|
|
65
|
+
});
|
|
55
66
|
const HoverZone = ({
|
|
56
67
|
onDragEnter,
|
|
57
68
|
onDragLeave,
|
|
58
69
|
onDrop,
|
|
59
70
|
node,
|
|
71
|
+
parent,
|
|
60
72
|
editorWidth,
|
|
61
73
|
anchorHeightsCache,
|
|
62
74
|
position,
|
|
63
|
-
isNestedDropTarget
|
|
75
|
+
isNestedDropTarget,
|
|
76
|
+
dropTargetStyle
|
|
64
77
|
}) => {
|
|
65
78
|
const ref = useRef(null);
|
|
66
79
|
useEffect(() => {
|
|
@@ -88,14 +101,23 @@ const HoverZone = ({
|
|
|
88
101
|
maxWidth: `${editorWidth || 0}px`
|
|
89
102
|
});
|
|
90
103
|
}, [anchorHeightsCache, editorWidth, node, position]);
|
|
104
|
+
const isFullHeight = useMemo(() => {
|
|
105
|
+
return dropTargetStyle === 'fullHeight';
|
|
106
|
+
}, [dropTargetStyle]);
|
|
107
|
+
const isFullHeightInLayout = useMemo(() => {
|
|
108
|
+
return isFullHeight && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'layoutColumn';
|
|
109
|
+
}, [isFullHeight, parent === null || parent === void 0 ? void 0 : parent.type.name]);
|
|
91
110
|
return jsx("div", {
|
|
92
111
|
ref: ref
|
|
93
112
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop
|
|
94
113
|
,
|
|
95
|
-
className: `drop-target-hover-zone-${position}
|
|
114
|
+
className: `drop-target-hover-zone-${position}`,
|
|
115
|
+
"data-testid": `drop-target-zone-${position}`
|
|
96
116
|
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
97
117
|
,
|
|
98
|
-
css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle,
|
|
118
|
+
css: [dropZoneStyles, isNestedDropTarget && nestedDropZoneStyle,
|
|
119
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
120
|
+
hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
|
|
99
121
|
});
|
|
100
122
|
};
|
|
101
123
|
export const DropTargetV2 = ({
|
|
@@ -105,7 +127,8 @@ export const DropTargetV2 = ({
|
|
|
105
127
|
nextNode,
|
|
106
128
|
parentNode,
|
|
107
129
|
formatMessage,
|
|
108
|
-
anchorHeightsCache
|
|
130
|
+
anchorHeightsCache,
|
|
131
|
+
dropTargetStyle
|
|
109
132
|
}) => {
|
|
110
133
|
const [isDraggedOver, setIsDraggedOver] = useState(false);
|
|
111
134
|
const {
|
|
@@ -129,13 +152,14 @@ export const DropTargetV2 = ({
|
|
|
129
152
|
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : (_api$blockControls2$c = _api$blockControls2.commands) === null || _api$blockControls2$c === void 0 ? void 0 : _api$blockControls2$c.moveNode(start, pos, undefined, formatMessage));
|
|
130
153
|
}
|
|
131
154
|
};
|
|
155
|
+
const isFullHeight = dropTargetStyle === 'fullHeight';
|
|
132
156
|
const dynamicStyle = {
|
|
133
157
|
width: isNestedDropTarget ? 'unset' : '100%',
|
|
134
158
|
[EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH]: isNestedDropTarget ? '100%' : `${(widthState === null || widthState === void 0 ? void 0 : widthState.lineLength) || DEFAULT_DROP_INDICATOR_WIDTH}px`,
|
|
135
159
|
[EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN]: isNestedDropTarget ? getNestedNodeLeftPaddingMargin(parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) : '0',
|
|
136
160
|
[EDITOR_BLOCK_CONTROLS_DROP_TARGET_ZINDEX]: editorExperiment('nested-dnd', true) ? layers.navigation() : layers.card()
|
|
137
161
|
};
|
|
138
|
-
return jsx(Fragment, null, jsx(HoverZone, {
|
|
162
|
+
return jsx(Fragment, null, !isFullHeight && jsx(HoverZone, {
|
|
139
163
|
onDragEnter: () => setIsDraggedOver(true),
|
|
140
164
|
onDragLeave: () => setIsDraggedOver(false),
|
|
141
165
|
onDrop: onDrop,
|
|
@@ -163,9 +187,11 @@ export const DropTargetV2 = ({
|
|
|
163
187
|
onDragLeave: () => setIsDraggedOver(false),
|
|
164
188
|
onDrop: onDrop,
|
|
165
189
|
node: nextNode,
|
|
190
|
+
parent: parentNode,
|
|
166
191
|
editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
|
|
167
192
|
anchorHeightsCache: anchorHeightsCache,
|
|
168
193
|
position: "lower",
|
|
169
|
-
isNestedDropTarget: isNestedDropTarget
|
|
194
|
+
isNestedDropTarget: isNestedDropTarget,
|
|
195
|
+
dropTargetStyle: dropTargetStyle
|
|
170
196
|
}));
|
|
171
197
|
};
|
|
@@ -125,18 +125,12 @@ const withInlineNodeStyleWithChromeFix = css({
|
|
|
125
125
|
transform: 'scale(0)'
|
|
126
126
|
}
|
|
127
127
|
});
|
|
128
|
-
const globalStyles =
|
|
128
|
+
const globalStyles = css({
|
|
129
129
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
130
130
|
'.ProseMirror-widget:first-child + *:not([data-panel-type], .code-block, [data-node-type="nestedExpand"])': {
|
|
131
131
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
|
|
132
132
|
marginTop: '0 !important'
|
|
133
133
|
}
|
|
134
|
-
}) : css({
|
|
135
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
136
|
-
'.ProseMirror-widget:first-child + *': {
|
|
137
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
|
|
138
|
-
marginTop: '0 !important'
|
|
139
|
-
}
|
|
140
134
|
});
|
|
141
135
|
const withDividerInPanelStyleFix = css({
|
|
142
136
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if step adds inline char
|
|
4
|
+
* @param s
|
|
5
|
+
* @returns True if step adds inline char
|
|
6
|
+
*/
|
|
7
|
+
export const isStepText = s => {
|
|
8
|
+
const content = s.slice.content.firstChild;
|
|
9
|
+
return s.from === s.to && s.slice.content.childCount === 1 && !!content && !!content.text;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checks if step is an inline delete/backspace (replace range from -> from + 1 with empty content)
|
|
14
|
+
* @param s
|
|
15
|
+
* @returns True if delete/backspace
|
|
16
|
+
*/
|
|
17
|
+
export const isStepDelete = s => {
|
|
18
|
+
const content = s.slice.content;
|
|
19
|
+
return s.to === s.from + 1 && content.size === 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get metadata from the transaction.
|
|
24
|
+
* @param tr
|
|
25
|
+
* @returns Min 'from', max 'to' (from + slice size). If no steps, returns pos range of entire doc.
|
|
26
|
+
* Number of ReplaceStep and ReplaceAroundStep steps 'numReplaceSteps'.
|
|
27
|
+
* 'isAllText' if all steps are represent adding inline text or a backspace/delete or no-op
|
|
28
|
+
*/
|
|
29
|
+
export const getTrMetadata = tr => {
|
|
30
|
+
let from;
|
|
31
|
+
let to;
|
|
32
|
+
let numReplaceSteps = 0;
|
|
33
|
+
let isAllText = true;
|
|
34
|
+
tr.steps.forEach(s => {
|
|
35
|
+
if (s instanceof ReplaceStep || s instanceof ReplaceAroundStep) {
|
|
36
|
+
if (s instanceof ReplaceAroundStep || s instanceof ReplaceStep && !isStepText(s) && !isStepDelete(s)) {
|
|
37
|
+
isAllText = false;
|
|
38
|
+
}
|
|
39
|
+
const $to = s.from + s.slice.size;
|
|
40
|
+
from = from === undefined || from > s.from ? s.from : from;
|
|
41
|
+
to = to === undefined || to < $to ? $to : to;
|
|
42
|
+
numReplaceSteps++;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (from === undefined) {
|
|
46
|
+
from = 0;
|
|
47
|
+
}
|
|
48
|
+
if (to === undefined || to > tr.doc.nodeSize - 2) {
|
|
49
|
+
to = tr.doc.nodeSize - 2;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
numReplaceSteps,
|
|
55
|
+
isAllText
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -64,7 +64,7 @@ var getCurrentNodePos = function getCurrentNodePos(state, isParentNodeOfTypeLayo
|
|
|
64
64
|
// 2. caret cursor is inside the node
|
|
65
65
|
// 3. the start of the selection is inside the node
|
|
66
66
|
currentNodePos = selection.$from.before(1);
|
|
67
|
-
if (selection.$from.depth > 0 && fg('platform_editor_element_dnd_nested_a11y')) {
|
|
67
|
+
if (selection.$from.depth > 0 && editorExperiment('nested-dnd', true) && fg('platform_editor_element_dnd_nested_a11y')) {
|
|
68
68
|
currentNodePos = getNestedNodePosition(state);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -73,7 +73,8 @@ var getCurrentNodePos = function getCurrentNodePos(state, isParentNodeOfTypeLayo
|
|
|
73
73
|
export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, formatMessage) {
|
|
74
74
|
return function (state) {
|
|
75
75
|
var isParentNodeOfTypeLayout;
|
|
76
|
-
|
|
76
|
+
var shouldEnableNestedDndA11y = editorExperiment('nested-dnd', true) && fg('platform_editor_element_dnd_nested_a11y');
|
|
77
|
+
if (shouldEnableNestedDndA11y) {
|
|
77
78
|
isParentNodeOfTypeLayout = !!findParentNodeOfType([state.schema.nodes.layoutSection])(state.selection);
|
|
78
79
|
}
|
|
79
80
|
var currentNodePos = getCurrentNodePos(state, isParentNodeOfTypeLayout);
|
|
@@ -82,7 +83,7 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
82
83
|
var $pos = state.doc.resolve(currentNodePos);
|
|
83
84
|
var moveToPos = -1;
|
|
84
85
|
var nodeIndex = $pos.index();
|
|
85
|
-
if (direction === DIRECTION.LEFT &&
|
|
86
|
+
if (direction === DIRECTION.LEFT && shouldEnableNestedDndA11y) {
|
|
86
87
|
if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
|
|
87
88
|
return false;
|
|
88
89
|
}
|
|
@@ -92,13 +93,13 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
92
93
|
var grandParent = $pos.node($pos.depth - 1);
|
|
93
94
|
var previousNode = grandParent ? grandParent.maybeChild(index - 1) : null;
|
|
94
95
|
moveToPos = $pos.start() - ((previousNode === null || previousNode === void 0 ? void 0 : previousNode.nodeSize) || 1);
|
|
95
|
-
} else if (direction === DIRECTION.RIGHT &&
|
|
96
|
+
} else if (direction === DIRECTION.RIGHT && shouldEnableNestedDndA11y) {
|
|
96
97
|
if ($pos.depth < 2 || !isParentNodeOfTypeLayout) {
|
|
97
98
|
return false;
|
|
98
99
|
}
|
|
99
100
|
moveToPos = $pos.after($pos.depth) + 1;
|
|
100
101
|
} else if (direction === DIRECTION.UP) {
|
|
101
|
-
var nodeBefore = $pos.depth > 1 && nodeIndex === 0 &&
|
|
102
|
+
var nodeBefore = $pos.depth > 1 && nodeIndex === 0 && shouldEnableNestedDndA11y ? $pos.node($pos.depth) : $pos.nodeBefore;
|
|
102
103
|
if (nodeBefore) {
|
|
103
104
|
moveToPos = currentNodePos - nodeBefore.nodeSize;
|
|
104
105
|
}
|
|
@@ -114,7 +115,7 @@ export var moveNodeViaShortcut = function moveNodeViaShortcut(api, direction, fo
|
|
|
114
115
|
var nodeType = (_state$doc$nodeAt = state.doc.nodeAt(currentNodePos)) === null || _state$doc$nodeAt === void 0 ? void 0 : _state$doc$nodeAt.type.name;
|
|
115
116
|
|
|
116
117
|
// only move the node if the destination is at the same depth, not support moving a nested node to a parent node
|
|
117
|
-
var shouldMoveNode =
|
|
118
|
+
var shouldMoveNode = shouldEnableNestedDndA11y ? moveToPos > -1 && $pos.depth === state.doc.resolve(moveToPos).depth : moveToPos > -1;
|
|
118
119
|
if (shouldMoveNode) {
|
|
119
120
|
var _api$core;
|
|
120
121
|
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { isInTable } from '@atlaskit/editor-tables/utils';
|
|
2
2
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
3
4
|
import { key } from '../pm-plugins/main';
|
|
4
5
|
import { getNestedNodePosition } from '../utils';
|
|
5
6
|
export var showDragHandleAtSelection = function showDragHandleAtSelection(api, shouldFocusParentNode) {
|
|
6
7
|
return function (state, _, view) {
|
|
7
8
|
var $from = state.selection.$from;
|
|
8
9
|
var shouldFocusParentNode;
|
|
9
|
-
if ($from.depth > 1 && fg('platform_editor_element_dnd_nested_a11y')) {
|
|
10
|
+
if ($from.depth > 1 && editorExperiment('nested-dnd', true) && fg('platform_editor_element_dnd_nested_a11y')) {
|
|
10
11
|
var _activeNode$handleOpt, _view$domAtPos;
|
|
11
12
|
var _ref = key.getState(state) || {},
|
|
12
13
|
activeNode = _ref.activeNode;
|
|
@@ -6,7 +6,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
6
6
|
import { createElement } from 'react';
|
|
7
7
|
import { bind } from 'bind-event-listener';
|
|
8
8
|
import ReactDOM from 'react-dom';
|
|
9
|
-
import { RawIntlProvider } from 'react-intl-next';
|
|
10
9
|
import uuid from 'uuid';
|
|
11
10
|
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
12
11
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
@@ -22,6 +21,9 @@ var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'lis
|
|
|
22
21
|
var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
|
|
23
22
|
var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
|
|
24
23
|
var DISABLE_CHILD_DROP_TARGET = ['orderedList', 'bulletList'];
|
|
24
|
+
export var TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
|
|
25
|
+
export var TYPE_HANDLE_DEC = 'drag-handle';
|
|
26
|
+
export var TYPE_NODE_DEC = 'node-decoration';
|
|
25
27
|
var getNestedDepth = function getNestedDepth() {
|
|
26
28
|
return editorExperiment('nested-dnd', true) ? 100 : 0;
|
|
27
29
|
};
|
|
@@ -72,6 +74,54 @@ var shouldDescend = function shouldDescend(node) {
|
|
|
72
74
|
}
|
|
73
75
|
return true;
|
|
74
76
|
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Find drop target decorations in the pos range between from and to
|
|
80
|
+
* @param decorations
|
|
81
|
+
* @param from
|
|
82
|
+
* @param to
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
export var findDropTargetDecs = function findDropTargetDecs(decorations, from, to) {
|
|
86
|
+
return decorations.find(from, to, function (spec) {
|
|
87
|
+
return spec.type === TYPE_DROP_TARGET_DEC;
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
export var findHandleDec = function findHandleDec(decorations, from, to) {
|
|
91
|
+
return decorations.find(from, to, function (spec) {
|
|
92
|
+
return spec.type === TYPE_HANDLE_DEC;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Find node decorations in the pos range between from and to (non-inclusive)
|
|
98
|
+
* @param decorations
|
|
99
|
+
* @param from
|
|
100
|
+
* @param to
|
|
101
|
+
* @returns
|
|
102
|
+
*/
|
|
103
|
+
export var findNodeDecs = function findNodeDecs(decorations, from, to) {
|
|
104
|
+
var newfrom = from;
|
|
105
|
+
var newTo = to;
|
|
106
|
+
|
|
107
|
+
// make it non-inclusive
|
|
108
|
+
if (newfrom !== undefined) {
|
|
109
|
+
newfrom++;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// make it non-inclusive
|
|
113
|
+
if (newTo !== undefined) {
|
|
114
|
+
newTo--;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// return empty array if range reversed
|
|
118
|
+
if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
|
|
119
|
+
return new Array();
|
|
120
|
+
}
|
|
121
|
+
return decorations.find(newfrom, newTo, function (spec) {
|
|
122
|
+
return spec.type === TYPE_NODE_DEC;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
75
125
|
export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorHeightsCache) {
|
|
76
126
|
return Decoration.widget(pos, function (_, getPos) {
|
|
77
127
|
var element = document.createElement('div');
|
|
@@ -96,13 +146,16 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
|
|
|
96
146
|
}
|
|
97
147
|
return element;
|
|
98
148
|
}, {
|
|
99
|
-
type:
|
|
149
|
+
type: TYPE_DROP_TARGET_DEC,
|
|
100
150
|
side: side
|
|
101
151
|
});
|
|
102
152
|
};
|
|
103
|
-
export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorHeightsCache) {
|
|
104
|
-
var decs = [];
|
|
153
|
+
export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorHeightsCache, from, to) {
|
|
105
154
|
unmountDecorations('data-blocks-drop-target-container');
|
|
155
|
+
var decs = [];
|
|
156
|
+
var POS_END_OF_DOC = newState.doc.nodeSize - 2;
|
|
157
|
+
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
158
|
+
var docTo = to === undefined || to > POS_END_OF_DOC ? POS_END_OF_DOC : to;
|
|
106
159
|
var prevNode;
|
|
107
160
|
var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
108
161
|
var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
@@ -120,7 +173,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
120
173
|
popNodeStack(depth);
|
|
121
174
|
prevNodeStack.push(node);
|
|
122
175
|
};
|
|
123
|
-
newState.doc.
|
|
176
|
+
newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
|
|
124
177
|
var depth = 0;
|
|
125
178
|
// drop target deco at the end position
|
|
126
179
|
var endPos;
|
|
@@ -158,19 +211,27 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
158
211
|
}
|
|
159
212
|
}
|
|
160
213
|
var previousNode = fg('platform_editor_drag_and_drop_target_v2') ? popNodeStack(depth) : prevNode; // created scoped variable
|
|
214
|
+
|
|
215
|
+
// only table and layout need to render full height drop target
|
|
216
|
+
var isInSupportedContainer = fg('platform_editor_drag_and_drop_target_v2') && ['tableCell', 'tableHeader', 'layoutColumn'].includes((parent === null || parent === void 0 ? void 0 : parent.type.name) || '');
|
|
217
|
+
|
|
218
|
+
// container with only an empty paragrah
|
|
219
|
+
var shouldShowFullHeight = isInSupportedContainer && (parent === null || parent === void 0 ? void 0 : parent.lastChild) === node && (parent === null || parent === void 0 ? void 0 : parent.childCount) === 1 && isEmptyParagraph(node) && fg('platform_editor_drag_and_drop_target_v2');
|
|
161
220
|
decs.push(createDropTargetDecoration(pos, {
|
|
162
221
|
api: api,
|
|
163
222
|
prevNode: previousNode,
|
|
164
223
|
nextNode: node,
|
|
165
224
|
parentNode: parent || undefined,
|
|
166
|
-
formatMessage: formatMessage
|
|
225
|
+
formatMessage: formatMessage,
|
|
226
|
+
dropTargetStyle: shouldShowFullHeight ? 'fullHeight' : 'default'
|
|
167
227
|
}, -1, anchorHeightsCache));
|
|
168
228
|
if (endPos !== undefined) {
|
|
169
229
|
decs.push(createDropTargetDecoration(endPos, {
|
|
170
230
|
api: api,
|
|
171
231
|
prevNode: fg('platform_editor_drag_and_drop_target_v2') ? node : undefined,
|
|
172
232
|
parentNode: parent || undefined,
|
|
173
|
-
formatMessage: formatMessage
|
|
233
|
+
formatMessage: formatMessage,
|
|
234
|
+
dropTargetStyle: isInSupportedContainer ? 'fullHeight' : 'default'
|
|
174
235
|
}, -1, anchorHeightsCache));
|
|
175
236
|
}
|
|
176
237
|
if (fg('platform_editor_drag_and_drop_target_v2')) {
|
|
@@ -180,12 +241,14 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
180
241
|
}
|
|
181
242
|
return depth < getNestedDepth() && shouldDescend(node);
|
|
182
243
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
244
|
+
if (docTo === POS_END_OF_DOC) {
|
|
245
|
+
decs.push(createDropTargetDecoration(POS_END_OF_DOC, {
|
|
246
|
+
api: api,
|
|
247
|
+
formatMessage: formatMessage,
|
|
248
|
+
prevNode: newState.doc.lastChild || undefined,
|
|
249
|
+
parentNode: newState.doc
|
|
250
|
+
}, undefined, anchorHeightsCache));
|
|
251
|
+
}
|
|
189
252
|
return decs;
|
|
190
253
|
};
|
|
191
254
|
export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
@@ -194,7 +257,7 @@ export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecoration
|
|
|
194
257
|
return Decoration.node(0, 2, _defineProperty({
|
|
195
258
|
style: style
|
|
196
259
|
}, 'data-drag-handler-anchor-name', anchorName), {
|
|
197
|
-
type:
|
|
260
|
+
type: TYPE_NODE_DEC
|
|
198
261
|
});
|
|
199
262
|
};
|
|
200
263
|
var ObjHash = /*#__PURE__*/function () {
|
|
@@ -223,19 +286,17 @@ var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
|
223
286
|
}
|
|
224
287
|
return IGNORE_NODES.includes(node.type.name);
|
|
225
288
|
};
|
|
226
|
-
export var nodeDecorations = function nodeDecorations(newState) {
|
|
289
|
+
export var nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
227
290
|
var decs = [];
|
|
228
|
-
|
|
291
|
+
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
292
|
+
var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
|
|
293
|
+
newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
|
|
229
294
|
var _Decoration$node2;
|
|
230
295
|
var depth = 0;
|
|
231
296
|
var anchorName;
|
|
232
297
|
var shouldDescend = !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}) || editorExperiment('nested-dnd', true)) {
|
|
236
|
-
var handleId = ObjHash.getForNode(node);
|
|
237
|
-
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
238
|
-
}
|
|
298
|
+
var handleId = ObjHash.getForNode(node);
|
|
299
|
+
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
239
300
|
if (editorExperiment('nested-dnd', true)) {
|
|
240
301
|
var _anchorName;
|
|
241
302
|
// Doesn't descend into a node
|
|
@@ -254,7 +315,7 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
254
315
|
decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
255
316
|
style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;")
|
|
256
317
|
}, _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), _defineProperty(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node2), {
|
|
257
|
-
type:
|
|
318
|
+
type: TYPE_NODE_DEC,
|
|
258
319
|
anchorName: anchorName,
|
|
259
320
|
nodeType: node.type.name
|
|
260
321
|
}));
|
|
@@ -262,7 +323,8 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
262
323
|
});
|
|
263
324
|
return decs;
|
|
264
325
|
};
|
|
265
|
-
export var dragHandleDecoration = function dragHandleDecoration(api,
|
|
326
|
+
export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
|
|
327
|
+
unmountDecorations('data-blocks-drag-handle-container');
|
|
266
328
|
var unbind;
|
|
267
329
|
return Decoration.widget(pos, function (view, getPos) {
|
|
268
330
|
var element = document.createElement('span');
|
|
@@ -276,7 +338,7 @@ export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, po
|
|
|
276
338
|
isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
|
|
277
339
|
/*
|
|
278
340
|
* We disable mouseover event to fix flickering issue on hover
|
|
279
|
-
* However, the tooltip for nested drag handle is
|
|
341
|
+
* However, the tooltip for nested drag handle is no long working.
|
|
280
342
|
*/
|
|
281
343
|
if (!isTopLevelNode) {
|
|
282
344
|
// This will also hide the tooltip.
|
|
@@ -288,26 +350,25 @@ export var dragHandleDecoration = function dragHandleDecoration(api, getIntl, po
|
|
|
288
350
|
});
|
|
289
351
|
}
|
|
290
352
|
}
|
|
291
|
-
unmountDecorations('data-blocks-drag-handle-container');
|
|
292
353
|
|
|
293
354
|
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
294
355
|
// due to margins applied to other nodes eg. Headings
|
|
295
356
|
element.style.clear = 'unset';
|
|
296
|
-
ReactDOM.render( /*#__PURE__*/createElement(
|
|
297
|
-
value: getIntl()
|
|
298
|
-
}, /*#__PURE__*/createElement(DragHandle, {
|
|
357
|
+
ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
|
|
299
358
|
view: view,
|
|
300
359
|
api: api,
|
|
360
|
+
formatMessage: formatMessage,
|
|
301
361
|
getPos: getPos,
|
|
302
362
|
anchorName: anchorName,
|
|
303
363
|
nodeType: nodeType,
|
|
304
364
|
handleOptions: handleOptions,
|
|
305
365
|
isTopLevelNode: isTopLevelNode
|
|
306
|
-
})
|
|
366
|
+
}), element);
|
|
307
367
|
return element;
|
|
308
368
|
}, {
|
|
309
369
|
side: -1,
|
|
310
|
-
|
|
370
|
+
type: TYPE_HANDLE_DEC,
|
|
371
|
+
testid: "".concat(TYPE_HANDLE_DEC, "-").concat(uuid()),
|
|
311
372
|
destroy: function destroy() {
|
|
312
373
|
if (editorExperiment('nested-dnd', true)) {
|
|
313
374
|
unbind && unbind();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bindKeymapWithCommand, dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, showElementDragHandle } from '@atlaskit/editor-common/keymaps';
|
|
2
2
|
import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
|
|
3
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
4
5
|
import { moveNodeViaShortcut } from '../commands/move-node';
|
|
5
6
|
import { showDragHandleAtSelection } from '../commands/show-drag-handle';
|
|
6
7
|
import { DIRECTION } from '../consts';
|
|
@@ -14,8 +15,10 @@ function keymapList(api, formatMessage) {
|
|
|
14
15
|
}, keymapList);
|
|
15
16
|
bindKeymapWithCommand(dragToMoveUp.common, moveNodeViaShortcut(api, DIRECTION.UP, formatMessage), keymapList);
|
|
16
17
|
bindKeymapWithCommand(dragToMoveDown.common, moveNodeViaShortcut(api, DIRECTION.DOWN, formatMessage), keymapList);
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
if (editorExperiment('nested-dnd', true) && fg('platform_editor_element_dnd_nested_a11y')) {
|
|
19
|
+
bindKeymapWithCommand(dragToMoveLeft.common, moveNodeViaShortcut(api, DIRECTION.LEFT, formatMessage), keymapList);
|
|
20
|
+
bindKeymapWithCommand(dragToMoveRight.common, moveNodeViaShortcut(api, DIRECTION.RIGHT, formatMessage), keymapList);
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
return keymapList;
|
|
21
24
|
}
|