@atlaskit/editor-plugin-block-controls 1.5.19 → 1.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 +24 -0
- package/dist/cjs/pm-plugins/decorations.js +10 -5
- package/dist/cjs/pm-plugins/main.js +12 -8
- package/dist/cjs/ui/consts.js +110 -1
- package/dist/cjs/ui/drop-target.js +59 -12
- package/dist/cjs/ui/global-styles.js +38 -4
- package/dist/cjs/utils/drag-target-debug.js +11 -0
- package/dist/es2019/pm-plugins/decorations.js +10 -5
- package/dist/es2019/pm-plugins/main.js +13 -9
- package/dist/es2019/ui/consts.js +124 -0
- package/dist/es2019/ui/drop-target.js +50 -6
- package/dist/es2019/ui/global-styles.js +50 -4
- package/dist/es2019/utils/drag-target-debug.js +5 -0
- package/dist/esm/pm-plugins/decorations.js +10 -5
- package/dist/esm/pm-plugins/main.js +12 -8
- package/dist/esm/ui/consts.js +108 -0
- package/dist/esm/ui/drop-target.js +60 -13
- package/dist/esm/ui/global-styles.js +38 -4
- package/dist/esm/utils/drag-target-debug.js +5 -0
- package/dist/types/ui/consts.d.ts +14 -0
- package/dist/types/ui/drop-target.d.ts +4 -1
- package/dist/types/utils/drag-target-debug.d.ts +1 -0
- package/dist/types-ts4.5/ui/consts.d.ts +14 -0
- package/dist/types-ts4.5/ui/drop-target.d.ts +4 -1
- package/dist/types-ts4.5/utils/drag-target-debug.d.ts +1 -0
- package/package.json +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#121589](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121589)
|
|
8
|
+
[`c8c2209805321`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c8c2209805321) -
|
|
9
|
+
[ux] ED-23588 fix drop target alignments
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#119960](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/119960)
|
|
14
|
+
[`7b7393158a982`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7b7393158a982) -
|
|
15
|
+
ED-24136 fix composition input for chrome
|
|
16
|
+
- [#119250](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/119250)
|
|
17
|
+
[`dce4805f0326c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dce4805f0326c) -
|
|
18
|
+
Fix image cannot be dragged with ProseMirror native DnD in Firefox
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
21
|
+
## 1.5.20
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies
|
|
26
|
+
|
|
3
27
|
## 1.5.19
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
|
@@ -20,24 +20,29 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
20
20
|
// Decoration state is used to keep track of the position of the drop targets
|
|
21
21
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
22
22
|
var decorationState = [];
|
|
23
|
-
|
|
23
|
+
var prevNode;
|
|
24
|
+
oldState.doc.nodesBetween(0, newState.doc.nodeSize - 2, function (node, pos, _parent, index) {
|
|
24
25
|
decorationState.push({
|
|
25
26
|
index: index,
|
|
26
27
|
pos: pos
|
|
27
28
|
});
|
|
29
|
+
var dropTargetDec = /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, {
|
|
30
|
+
api: api,
|
|
31
|
+
index: index,
|
|
32
|
+
prevNode: prevNode,
|
|
33
|
+
nextNode: node
|
|
34
|
+
});
|
|
28
35
|
decs.push(_view.Decoration.widget(pos, function () {
|
|
29
36
|
var element = document.createElement('div');
|
|
30
37
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
31
38
|
element.style.clear = 'unset';
|
|
32
|
-
_reactDom.default.render(
|
|
33
|
-
api: api,
|
|
34
|
-
index: index
|
|
35
|
-
}), element);
|
|
39
|
+
_reactDom.default.render(dropTargetDec, element);
|
|
36
40
|
return element;
|
|
37
41
|
}, {
|
|
38
42
|
type: 'drop-target-decoration',
|
|
39
43
|
side: -1
|
|
40
44
|
}));
|
|
45
|
+
prevNode = node;
|
|
41
46
|
return false;
|
|
42
47
|
});
|
|
43
48
|
|
|
@@ -17,6 +17,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
17
17
|
var _element = require("@atlaskit/pragmatic-drag-and-drop-auto-scroll/element");
|
|
18
18
|
var _combine = require("@atlaskit/pragmatic-drag-and-drop/combine");
|
|
19
19
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
20
|
+
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
20
21
|
var _decorations = require("./decorations");
|
|
21
22
|
var _handleMouseOver = require("./handle-mouse-over");
|
|
22
23
|
var _keymap = require("./keymap");
|
|
@@ -240,14 +241,17 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
240
241
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
244
|
+
if (api) {
|
|
245
|
+
// Add drop targets when node is being dragged
|
|
246
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
247
|
+
var shouldShowDragTarget = (meta === null || meta === void 0 ? void 0 : meta.isDragging) && (!tr.docChanged || tr.docChanged && isAnalyticTr);
|
|
248
|
+
if (shouldShowDragTarget || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
249
|
+
var _dropTargetDecoration = (0, _decorations.dropTargetDecorations)(oldState, newState, api),
|
|
250
|
+
_decs2 = _dropTargetDecoration.decs,
|
|
251
|
+
updatedDecorationState = _dropTargetDecoration.decorationState;
|
|
252
|
+
decorationState = updatedDecorationState;
|
|
253
|
+
decorations = decorations.add(newState.doc, _decs2);
|
|
254
|
+
}
|
|
251
255
|
}
|
|
252
256
|
|
|
253
257
|
// Remove drop target decoration when dragging stops
|
package/dist/cjs/ui/consts.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
|
-
exports.topPositionAdjustment = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
7
|
+
exports.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
10
|
+
var _dropTargetMarginMap;
|
|
8
11
|
var DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_HEIGHT = 24;
|
|
9
12
|
var DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_WIDTH = 12;
|
|
10
13
|
var DRAG_HANDLE_BORDER_RADIUS = exports.DRAG_HANDLE_BORDER_RADIUS = 4;
|
|
@@ -28,4 +31,110 @@ var topPositionAdjustment = exports.topPositionAdjustment = function topPosition
|
|
|
28
31
|
default:
|
|
29
32
|
return 0;
|
|
30
33
|
}
|
|
34
|
+
};
|
|
35
|
+
var dropTargetMarginMap = (_dropTargetMarginMap = {}, (0, _defineProperty2.default)(_dropTargetMarginMap, -24, "var(--ds-space-negative-300, -24px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -20, "var(--ds-space-negative-250, -20px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -16, "var(--ds-space-negative-200, -16px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -12, "var(--ds-space-negative-150, -12px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -8, "var(--ds-space-negative-100, -8px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -6, "var(--ds-space-negative-075, -6px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -4, "var(--ds-space-negative-050, -4px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, -2, "var(--ds-space-negative-025, -2px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 0, "var(--ds-space-0, 0)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 2, "var(--ds-space-025, 2px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 4, "var(--ds-space-050, 4px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 6, "var(--ds-space-075, 6px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 8, "var(--ds-space-100, 8px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 12, "var(--ds-space-150, 12px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 16, "var(--ds-space-200, 16px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 20, "var(--ds-space-250, 20px)"), (0, _defineProperty2.default)(_dropTargetMarginMap, 24, "var(--ds-space-300, 24px)"), _dropTargetMarginMap);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This document serves as a quick reference map for correlating various space matches
|
|
39
|
+
* to the table provided above.
|
|
40
|
+
* For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
|
|
41
|
+
*/
|
|
42
|
+
var spaceLookupMap = exports.spaceLookupMap = Object.fromEntries(
|
|
43
|
+
// 49 = -24 -> 0 -> 24 totaling 49 entries.
|
|
44
|
+
Array.from({
|
|
45
|
+
length: 49
|
|
46
|
+
}, function (_, index) {
|
|
47
|
+
var currKeyValue = index - 24;
|
|
48
|
+
var keyValues = Object.keys(dropTargetMarginMap).map(Number);
|
|
49
|
+
var value = keyValues.reduce(function (acc, curr) {
|
|
50
|
+
return Math.abs(currKeyValue - curr) < Math.abs(currKeyValue - acc) ? curr : acc;
|
|
51
|
+
}, 1000);
|
|
52
|
+
return [currKeyValue, dropTargetMarginMap[value]];
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
// This table contains the "margins" of different nodes
|
|
56
|
+
// Note this is not the actually margin of the DOM elements,
|
|
57
|
+
// but a percepted margin, e.g. a paragraph has additional margin
|
|
58
|
+
// due to the line height and the white spaces.
|
|
59
|
+
var nodeMargins = exports.nodeMargins = {
|
|
60
|
+
table: {
|
|
61
|
+
top: 24,
|
|
62
|
+
bottom: 16
|
|
63
|
+
},
|
|
64
|
+
paragraph: {
|
|
65
|
+
top: 12,
|
|
66
|
+
bottom: 6
|
|
67
|
+
},
|
|
68
|
+
bulletList: {
|
|
69
|
+
top: 16,
|
|
70
|
+
bottom: 0
|
|
71
|
+
},
|
|
72
|
+
orderedList: {
|
|
73
|
+
top: 16,
|
|
74
|
+
bottom: 0
|
|
75
|
+
},
|
|
76
|
+
decisionList: {
|
|
77
|
+
top: 12,
|
|
78
|
+
bottom: 0
|
|
79
|
+
},
|
|
80
|
+
taskList: {
|
|
81
|
+
top: 8,
|
|
82
|
+
bottom: 0
|
|
83
|
+
},
|
|
84
|
+
codeBlock: {
|
|
85
|
+
top: 0,
|
|
86
|
+
bottom: 0
|
|
87
|
+
},
|
|
88
|
+
panel: {
|
|
89
|
+
top: 8,
|
|
90
|
+
bottom: 0
|
|
91
|
+
},
|
|
92
|
+
rule: {
|
|
93
|
+
top: 20,
|
|
94
|
+
bottom: 20
|
|
95
|
+
},
|
|
96
|
+
mediaSingle: {
|
|
97
|
+
top: 24,
|
|
98
|
+
bottom: 24
|
|
99
|
+
},
|
|
100
|
+
bodiedExtension: {
|
|
101
|
+
top: 0,
|
|
102
|
+
bottom: 0
|
|
103
|
+
},
|
|
104
|
+
extension: {
|
|
105
|
+
top: 12,
|
|
106
|
+
bottom: 12
|
|
107
|
+
},
|
|
108
|
+
heading1: {
|
|
109
|
+
top: 40,
|
|
110
|
+
bottom: 0
|
|
111
|
+
},
|
|
112
|
+
heading2: {
|
|
113
|
+
top: 40,
|
|
114
|
+
bottom: 0
|
|
115
|
+
},
|
|
116
|
+
heading3: {
|
|
117
|
+
top: 36,
|
|
118
|
+
bottom: 0
|
|
119
|
+
},
|
|
120
|
+
heading4: {
|
|
121
|
+
top: 22,
|
|
122
|
+
bottom: 0
|
|
123
|
+
},
|
|
124
|
+
heading5: {
|
|
125
|
+
top: 22,
|
|
126
|
+
bottom: 0
|
|
127
|
+
},
|
|
128
|
+
heading6: {
|
|
129
|
+
top: 18,
|
|
130
|
+
bottom: 0
|
|
131
|
+
},
|
|
132
|
+
layoutSection: {
|
|
133
|
+
top: 8,
|
|
134
|
+
bottom: 0
|
|
135
|
+
},
|
|
136
|
+
default: {
|
|
137
|
+
top: 0,
|
|
138
|
+
bottom: 0
|
|
139
|
+
}
|
|
31
140
|
};
|
|
@@ -9,8 +9,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _react2 = require("@emotion/react");
|
|
11
11
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
12
13
|
var _box = require("@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box");
|
|
13
14
|
var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
|
|
15
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
16
|
+
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
17
|
+
var _consts = require("./consts");
|
|
14
18
|
/** @jsx jsx */
|
|
15
19
|
|
|
16
20
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
@@ -23,17 +27,56 @@ var styleDropTarget = (0, _react2.css)({
|
|
|
23
27
|
width: '100%',
|
|
24
28
|
left: '0',
|
|
25
29
|
display: 'block',
|
|
26
|
-
zIndex:
|
|
30
|
+
zIndex: _constants.layers.card()
|
|
27
31
|
});
|
|
32
|
+
var marginLookupMap = Object.fromEntries(
|
|
33
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
34
|
+
Object.entries(_consts.spaceLookupMap).map(function (_ref, i) {
|
|
35
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
36
|
+
key = _ref2[0],
|
|
37
|
+
value = _ref2[1];
|
|
38
|
+
return [key, (0, _react2.css)({
|
|
39
|
+
marginTop: value
|
|
40
|
+
})];
|
|
41
|
+
}));
|
|
42
|
+
var BASE_LINE_MARGIN = -8;
|
|
43
|
+
var getNodeMargins = function getNodeMargins(node) {
|
|
44
|
+
if (!node) {
|
|
45
|
+
return _consts.nodeMargins['default'];
|
|
46
|
+
}
|
|
47
|
+
var nodeTypeName = node.type.name;
|
|
48
|
+
if (nodeTypeName === 'heading') {
|
|
49
|
+
return _consts.nodeMargins["heading".concat(node.attrs.level)] || _consts.nodeMargins['default'];
|
|
50
|
+
}
|
|
51
|
+
return _consts.nodeMargins[nodeTypeName] || _consts.nodeMargins['default'];
|
|
52
|
+
};
|
|
53
|
+
var getDropTargetPositionStyle = function getDropTargetPositionStyle(prevNode, nextNode) {
|
|
54
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_gap_fix')) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (!prevNode || !nextNode) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
var space = BASE_LINE_MARGIN - Math.round((getNodeMargins(prevNode).bottom - getNodeMargins(nextNode).top) / 2);
|
|
61
|
+
if (space < -24) {
|
|
62
|
+
return marginLookupMap[-24];
|
|
63
|
+
} else if (space > 24) {
|
|
64
|
+
return marginLookupMap[24];
|
|
65
|
+
} else {
|
|
66
|
+
return marginLookupMap[space];
|
|
67
|
+
}
|
|
68
|
+
};
|
|
28
69
|
var styleDropIndicator = (0, _react2.css)({
|
|
29
70
|
height: '100%',
|
|
30
71
|
width: '100%',
|
|
31
72
|
margin: '0 auto',
|
|
32
73
|
position: 'relative'
|
|
33
74
|
});
|
|
34
|
-
var DropTarget = exports.DropTarget = function DropTarget(
|
|
35
|
-
var api =
|
|
36
|
-
index =
|
|
75
|
+
var DropTarget = exports.DropTarget = function DropTarget(_ref3) {
|
|
76
|
+
var api = _ref3.api,
|
|
77
|
+
index = _ref3.index,
|
|
78
|
+
prevNode = _ref3.prevNode,
|
|
79
|
+
nextNode = _ref3.nextNode;
|
|
37
80
|
var ref = (0, _react.useRef)(null);
|
|
38
81
|
var _useState = (0, _react.useState)(false),
|
|
39
82
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -56,20 +99,20 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
56
99
|
setIsDraggedOver(true);
|
|
57
100
|
},
|
|
58
101
|
onDragLeave: function onDragLeave() {
|
|
59
|
-
|
|
102
|
+
setIsDraggedOver(false);
|
|
60
103
|
},
|
|
61
104
|
onDrop: function onDrop() {
|
|
62
105
|
var _api$blockControls;
|
|
63
|
-
var
|
|
64
|
-
activeNode =
|
|
65
|
-
decorationState =
|
|
106
|
+
var _ref4 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
107
|
+
activeNode = _ref4.activeNode,
|
|
108
|
+
decorationState = _ref4.decorationState;
|
|
66
109
|
if (!activeNode || !decorationState) {
|
|
67
110
|
return;
|
|
68
111
|
}
|
|
69
|
-
var
|
|
112
|
+
var _ref5 = decorationState.find(function (dec) {
|
|
70
113
|
return dec.index === index;
|
|
71
114
|
}) || {},
|
|
72
|
-
pos =
|
|
115
|
+
pos = _ref5.pos;
|
|
73
116
|
if (activeNode && pos !== undefined) {
|
|
74
117
|
var _api$core, _api$blockControls2;
|
|
75
118
|
var start = activeNode.pos;
|
|
@@ -78,15 +121,19 @@ var DropTarget = exports.DropTarget = function DropTarget(_ref) {
|
|
|
78
121
|
}
|
|
79
122
|
});
|
|
80
123
|
}, [index, api]);
|
|
124
|
+
var topTargetMarginStyle = (0, _react.useMemo)(function () {
|
|
125
|
+
return getDropTargetPositionStyle(prevNode, nextNode);
|
|
126
|
+
}, [prevNode, nextNode]);
|
|
81
127
|
return (
|
|
82
128
|
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
83
129
|
(0, _react2.jsx)("div", {
|
|
84
|
-
css
|
|
130
|
+
// eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
|
|
131
|
+
css: [styleDropTarget, topTargetMarginStyle],
|
|
85
132
|
ref: ref,
|
|
86
133
|
"data-testid": "block-ctrl-drop-target"
|
|
87
134
|
},
|
|
88
135
|
// 4px gap to clear expand node border
|
|
89
|
-
isDraggedOver && (0, _react2.jsx)("div", {
|
|
136
|
+
(isDraggedOver || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) && (0, _react2.jsx)("div", {
|
|
90
137
|
css: styleDropIndicator,
|
|
91
138
|
style: {
|
|
92
139
|
width: "".concat(lineLength, "px")
|
|
@@ -46,14 +46,34 @@ var paragraphWithTrailingBreak = '+ p > .ProseMirror-trailingBreak';
|
|
|
46
46
|
var paragraphWithCursorTarget = '+ p > .cursor-target';
|
|
47
47
|
var paragraphWithTrailingBreakAsOnlyChild = '+ p > .ProseMirror-trailingBreak:only-child';
|
|
48
48
|
var paragraphWithPlaceholder = '+ p > .placeholder-decoration';
|
|
49
|
-
var
|
|
49
|
+
var dragHandleContainer = '.ProseMirror-widget[data-blocks-drag-handle-container="true"]';
|
|
50
|
+
var dragHandleSelector = 'button[data-testid="block-ctrl-drag-handle"]';
|
|
51
|
+
var withoutInlineNodeStyle = (0, _react.css)((0, _defineProperty2.default)({}, ".ProseMirror-widget[data-blocks-drag-handle-container=\"true\"]:has(".concat(paragraphWithTrailingBreak, "):not(:has(").concat(paragraphWithCursorTarget, "))"), {
|
|
50
52
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
51
53
|
display: 'none !important'
|
|
52
54
|
}));
|
|
53
|
-
var
|
|
55
|
+
var withInlineNodeStyle = (0, _react.css)((0, _defineProperty2.default)({}, ".ProseMirror-widget[data-blocks-drag-handle-container=\"true\"]:has(".concat(paragraphWithTrailingBreakAsOnlyChild, "), .ProseMirror-widget[data-blocks-drag-handle-container=\"true\"]:has(").concat(paragraphWithPlaceholder, ")"), {
|
|
54
56
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
55
57
|
display: 'none !important'
|
|
56
58
|
}));
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Please do not change change transform to display:none, or visibility:hidden
|
|
62
|
+
* Otherwise it might break composition input for Chrome
|
|
63
|
+
* https://product-fabric.atlassian.net/browse/ED-24136
|
|
64
|
+
*/
|
|
65
|
+
var withoutInlineNodeStyleWithChromeFix = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(dragHandleContainer, ":has(").concat(paragraphWithTrailingBreak, "):not(:has(").concat(paragraphWithCursorTarget, ")) ").concat(dragHandleSelector), {
|
|
66
|
+
transform: 'scale(0)'
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Please do not change change transform to display:none, or visibility:hidden
|
|
71
|
+
* Otherwise it might break composition input for Chrome
|
|
72
|
+
* https://product-fabric.atlassian.net/browse/ED-24136
|
|
73
|
+
*/
|
|
74
|
+
var withInlineNodeStyleWithChromeFix = (0, _react.css)((0, _defineProperty2.default)({}, "".concat(dragHandleContainer, ":has(").concat(paragraphWithTrailingBreakAsOnlyChild, ") ").concat(dragHandleSelector, ",\n\t ").concat(dragHandleContainer, ":has(").concat(paragraphWithPlaceholder, ") ").concat(dragHandleSelector), {
|
|
75
|
+
transform: 'scale(0)'
|
|
76
|
+
}));
|
|
57
77
|
var globalStyles = (0, _react.css)({
|
|
58
78
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
59
79
|
'.ProseMirror-widget:first-child + *': {
|
|
@@ -61,12 +81,26 @@ var globalStyles = (0, _react.css)({
|
|
|
61
81
|
marginTop: '0 !important'
|
|
62
82
|
}
|
|
63
83
|
});
|
|
64
|
-
var withDeleteLinesStyleFix = (0, _react.css)((0, _defineProperty2.default)({}, "p[data-drag-handler-anchor-name] .
|
|
84
|
+
var withDeleteLinesStyleFix = (0, _react.css)((0, _defineProperty2.default)({}, "p[data-drag-handler-anchor-name] ".concat(dragHandleContainer), {
|
|
65
85
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
66
86
|
display: 'none !important'
|
|
67
87
|
}));
|
|
88
|
+
|
|
89
|
+
// Image dnd is broken in Firefox due to a previous fix for image caption https://product-fabric.atlassian.net/browse/ED-14034
|
|
90
|
+
// We could remove this fix if the previous issue is invalid
|
|
91
|
+
var withMediaSingleStyleFix = (0, _react.css)((0, _defineProperty2.default)({}, '.ProseMirror.ua-firefox .mediaSingleView-content-wrap[data-drag-handler-node-type="mediaSingle"][data-drag-handler-anchor-name], .ProseMirror.ua-firefox [data-drag-handler-anchor-name][data-drag-handler-node-type] .mediaSingleView-content-wrap', {
|
|
92
|
+
userSelect: 'auto',
|
|
93
|
+
cursor: 'pointer'
|
|
94
|
+
}));
|
|
95
|
+
var getTextNodeStyle = function getTextNodeStyle() {
|
|
96
|
+
if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-ed-23868')) {
|
|
97
|
+
return (0, _platformFeatureFlags.fg)('platform_editor_element_controls_chrome_input_fix') ? withInlineNodeStyleWithChromeFix : withInlineNodeStyle;
|
|
98
|
+
} else {
|
|
99
|
+
return (0, _platformFeatureFlags.fg)('platform_editor_element_controls_chrome_input_fix') ? withoutInlineNodeStyleWithChromeFix : withoutInlineNodeStyle;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
68
102
|
var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
69
103
|
return (0, _react.jsx)(_react.Global, {
|
|
70
|
-
styles: [globalStyles, (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') && extendedHoverZone, (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-ed-
|
|
104
|
+
styles: [globalStyles, (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') && extendedHoverZone, getTextNodeStyle(), (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-ed-23932') && withDeleteLinesStyleFix, (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24005') && withMediaSingleStyleFix]
|
|
71
105
|
});
|
|
72
106
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isBlocksDragTargetDebug = void 0;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
8
|
+
var IS_GEMINI_TEST_ENV = Boolean(process.env.NODE_ENV === 'development') && Boolean(window.__gemini_set_feature_flag__);
|
|
9
|
+
var isBlocksDragTargetDebug = exports.isBlocksDragTargetDebug = function isBlocksDragTargetDebug() {
|
|
10
|
+
return IS_GEMINI_TEST_ENV && (0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_gap_fix');
|
|
11
|
+
};
|
|
@@ -12,24 +12,29 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
12
12
|
// Decoration state is used to keep track of the position of the drop targets
|
|
13
13
|
// and allows us to easily map the updated position in the plugin apply method.
|
|
14
14
|
const decorationState = [];
|
|
15
|
-
|
|
15
|
+
let prevNode;
|
|
16
|
+
oldState.doc.nodesBetween(0, newState.doc.nodeSize - 2, (node, pos, _parent, index) => {
|
|
16
17
|
decorationState.push({
|
|
17
18
|
index,
|
|
18
19
|
pos
|
|
19
20
|
});
|
|
21
|
+
const dropTargetDec = /*#__PURE__*/createElement(DropTarget, {
|
|
22
|
+
api,
|
|
23
|
+
index,
|
|
24
|
+
prevNode,
|
|
25
|
+
nextNode: node
|
|
26
|
+
});
|
|
20
27
|
decs.push(Decoration.widget(pos, () => {
|
|
21
28
|
const element = document.createElement('div');
|
|
22
29
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
23
30
|
element.style.clear = 'unset';
|
|
24
|
-
ReactDOM.render(
|
|
25
|
-
api,
|
|
26
|
-
index
|
|
27
|
-
}), element);
|
|
31
|
+
ReactDOM.render(dropTargetDec, element);
|
|
28
32
|
return element;
|
|
29
33
|
}, {
|
|
30
34
|
type: 'drop-target-decoration',
|
|
31
35
|
side: -1
|
|
32
36
|
}));
|
|
37
|
+
prevNode = node;
|
|
33
38
|
return false;
|
|
34
39
|
});
|
|
35
40
|
|
|
@@ -9,6 +9,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
9
9
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
10
10
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
11
11
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
12
|
+
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
12
13
|
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
|
|
13
14
|
import { handleMouseOver } from './handle-mouse-over';
|
|
14
15
|
import { boundKeydownHandler } from './keymap';
|
|
@@ -228,15 +229,18 @@ export const createPlugin = (api, getIntl) => {
|
|
|
228
229
|
decorations = decorations.add(newState.doc, [decs]);
|
|
229
230
|
}
|
|
230
231
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
232
|
+
if (api) {
|
|
233
|
+
// Add drop targets when node is being dragged
|
|
234
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
235
|
+
const shouldShowDragTarget = (meta === null || meta === void 0 ? void 0 : meta.isDragging) && (!tr.docChanged || tr.docChanged && isAnalyticTr);
|
|
236
|
+
if (shouldShowDragTarget || isBlocksDragTargetDebug()) {
|
|
237
|
+
const {
|
|
238
|
+
decs,
|
|
239
|
+
decorationState: updatedDecorationState
|
|
240
|
+
} = dropTargetDecorations(oldState, newState, api);
|
|
241
|
+
decorationState = updatedDecorationState;
|
|
242
|
+
decorations = decorations.add(newState.doc, decs);
|
|
243
|
+
}
|
|
240
244
|
}
|
|
241
245
|
|
|
242
246
|
// Remove drop target decoration when dragging stops
|
package/dist/es2019/ui/consts.js
CHANGED
|
@@ -22,4 +22,128 @@ export const topPositionAdjustment = nodeType => {
|
|
|
22
22
|
default:
|
|
23
23
|
return 0;
|
|
24
24
|
}
|
|
25
|
+
};
|
|
26
|
+
const dropTargetMarginMap = {
|
|
27
|
+
[-24]: "var(--ds-space-negative-300, -24px)",
|
|
28
|
+
[-20]: "var(--ds-space-negative-250, -20px)",
|
|
29
|
+
[-16]: "var(--ds-space-negative-200, -16px)",
|
|
30
|
+
[-12]: "var(--ds-space-negative-150, -12px)",
|
|
31
|
+
[-8]: "var(--ds-space-negative-100, -8px)",
|
|
32
|
+
[-6]: "var(--ds-space-negative-075, -6px)",
|
|
33
|
+
[-4]: "var(--ds-space-negative-050, -4px)",
|
|
34
|
+
[-2]: "var(--ds-space-negative-025, -2px)",
|
|
35
|
+
0: "var(--ds-space-0, 0)",
|
|
36
|
+
2: "var(--ds-space-025, 2px)",
|
|
37
|
+
4: "var(--ds-space-050, 4px)",
|
|
38
|
+
6: "var(--ds-space-075, 6px)",
|
|
39
|
+
8: "var(--ds-space-100, 8px)",
|
|
40
|
+
12: "var(--ds-space-150, 12px)",
|
|
41
|
+
16: "var(--ds-space-200, 16px)",
|
|
42
|
+
20: "var(--ds-space-250, 20px)",
|
|
43
|
+
24: "var(--ds-space-300, 24px)"
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This document serves as a quick reference map for correlating various space matches
|
|
48
|
+
* to the table provided above.
|
|
49
|
+
* For instance, the number 1 will correspond to \{0: token('space.0', '0')\}.
|
|
50
|
+
*/
|
|
51
|
+
export const spaceLookupMap = Object.fromEntries(
|
|
52
|
+
// 49 = -24 -> 0 -> 24 totaling 49 entries.
|
|
53
|
+
Array.from({
|
|
54
|
+
length: 49
|
|
55
|
+
}, (_, index) => {
|
|
56
|
+
const currKeyValue = index - 24;
|
|
57
|
+
const keyValues = Object.keys(dropTargetMarginMap).map(Number);
|
|
58
|
+
const value = keyValues.reduce((acc, curr) => {
|
|
59
|
+
return Math.abs(currKeyValue - curr) < Math.abs(currKeyValue - acc) ? curr : acc;
|
|
60
|
+
}, 1000);
|
|
61
|
+
return [currKeyValue, dropTargetMarginMap[value]];
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
// This table contains the "margins" of different nodes
|
|
65
|
+
// Note this is not the actually margin of the DOM elements,
|
|
66
|
+
// but a percepted margin, e.g. a paragraph has additional margin
|
|
67
|
+
// due to the line height and the white spaces.
|
|
68
|
+
export const nodeMargins = {
|
|
69
|
+
table: {
|
|
70
|
+
top: 24,
|
|
71
|
+
bottom: 16
|
|
72
|
+
},
|
|
73
|
+
paragraph: {
|
|
74
|
+
top: 12,
|
|
75
|
+
bottom: 6
|
|
76
|
+
},
|
|
77
|
+
bulletList: {
|
|
78
|
+
top: 16,
|
|
79
|
+
bottom: 0
|
|
80
|
+
},
|
|
81
|
+
orderedList: {
|
|
82
|
+
top: 16,
|
|
83
|
+
bottom: 0
|
|
84
|
+
},
|
|
85
|
+
decisionList: {
|
|
86
|
+
top: 12,
|
|
87
|
+
bottom: 0
|
|
88
|
+
},
|
|
89
|
+
taskList: {
|
|
90
|
+
top: 8,
|
|
91
|
+
bottom: 0
|
|
92
|
+
},
|
|
93
|
+
codeBlock: {
|
|
94
|
+
top: 0,
|
|
95
|
+
bottom: 0
|
|
96
|
+
},
|
|
97
|
+
panel: {
|
|
98
|
+
top: 8,
|
|
99
|
+
bottom: 0
|
|
100
|
+
},
|
|
101
|
+
rule: {
|
|
102
|
+
top: 20,
|
|
103
|
+
bottom: 20
|
|
104
|
+
},
|
|
105
|
+
mediaSingle: {
|
|
106
|
+
top: 24,
|
|
107
|
+
bottom: 24
|
|
108
|
+
},
|
|
109
|
+
bodiedExtension: {
|
|
110
|
+
top: 0,
|
|
111
|
+
bottom: 0
|
|
112
|
+
},
|
|
113
|
+
extension: {
|
|
114
|
+
top: 12,
|
|
115
|
+
bottom: 12
|
|
116
|
+
},
|
|
117
|
+
heading1: {
|
|
118
|
+
top: 40,
|
|
119
|
+
bottom: 0
|
|
120
|
+
},
|
|
121
|
+
heading2: {
|
|
122
|
+
top: 40,
|
|
123
|
+
bottom: 0
|
|
124
|
+
},
|
|
125
|
+
heading3: {
|
|
126
|
+
top: 36,
|
|
127
|
+
bottom: 0
|
|
128
|
+
},
|
|
129
|
+
heading4: {
|
|
130
|
+
top: 22,
|
|
131
|
+
bottom: 0
|
|
132
|
+
},
|
|
133
|
+
heading5: {
|
|
134
|
+
top: 22,
|
|
135
|
+
bottom: 0
|
|
136
|
+
},
|
|
137
|
+
heading6: {
|
|
138
|
+
top: 18,
|
|
139
|
+
bottom: 0
|
|
140
|
+
},
|
|
141
|
+
layoutSection: {
|
|
142
|
+
top: 8,
|
|
143
|
+
bottom: 0
|
|
144
|
+
},
|
|
145
|
+
default: {
|
|
146
|
+
top: 0,
|
|
147
|
+
bottom: 0
|
|
148
|
+
}
|
|
25
149
|
};
|