@atlaskit/editor-plugin-block-controls 2.6.3 → 2.7.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 +14 -0
- package/dist/cjs/commands/move-to-layout.js +76 -0
- package/dist/cjs/consts.js +3 -2
- package/dist/cjs/plugin.js +2 -0
- package/dist/cjs/pm-plugins/decorations.js +7 -7
- package/dist/cjs/pm-plugins/main.js +10 -10
- package/dist/cjs/ui/consts.js +8 -1
- package/dist/cjs/ui/drop-target-v2.js +24 -17
- package/dist/cjs/ui/inline-drop-target.js +138 -0
- package/dist/cjs/utils/advanced-layouts-flags.js +11 -0
- package/dist/cjs/utils/anchor-utils.js +71 -15
- package/dist/cjs/utils/inline-drop-target.js +18 -0
- package/dist/es2019/commands/move-to-layout.js +69 -0
- package/dist/es2019/consts.js +2 -1
- package/dist/es2019/plugin.js +2 -0
- package/dist/es2019/pm-plugins/decorations.js +7 -7
- package/dist/es2019/pm-plugins/main.js +11 -11
- package/dist/es2019/ui/consts.js +7 -0
- package/dist/es2019/ui/drop-target-v2.js +24 -16
- package/dist/es2019/ui/inline-drop-target.js +130 -0
- package/dist/es2019/utils/advanced-layouts-flags.js +5 -0
- package/dist/es2019/utils/anchor-utils.js +55 -9
- package/dist/es2019/utils/inline-drop-target.js +12 -0
- package/dist/esm/commands/move-to-layout.js +70 -0
- package/dist/esm/consts.js +2 -1
- package/dist/esm/plugin.js +2 -0
- package/dist/esm/pm-plugins/decorations.js +7 -7
- package/dist/esm/pm-plugins/main.js +11 -11
- package/dist/esm/ui/consts.js +7 -0
- package/dist/esm/ui/drop-target-v2.js +24 -17
- package/dist/esm/ui/inline-drop-target.js +130 -0
- package/dist/esm/utils/advanced-layouts-flags.js +5 -0
- package/dist/esm/utils/anchor-utils.js +70 -14
- package/dist/esm/utils/inline-drop-target.js +12 -0
- package/dist/types/commands/move-to-layout.d.ts +3 -0
- package/dist/types/consts.d.ts +1 -0
- package/dist/types/pm-plugins/decorations.d.ts +3 -3
- package/dist/types/pm-plugins/main.d.ts +3 -3
- package/dist/types/types.d.ts +1 -0
- package/dist/types/ui/consts.d.ts +3 -0
- package/dist/types/ui/drop-target-v2.d.ts +3 -3
- package/dist/types/ui/inline-drop-target.d.ts +20 -0
- package/dist/types/utils/advanced-layouts-flags.d.ts +1 -0
- package/dist/types/utils/anchor-utils.d.ts +16 -3
- package/dist/types/utils/inline-drop-target.d.ts +2 -0
- package/dist/types-ts4.5/commands/move-to-layout.d.ts +3 -0
- package/dist/types-ts4.5/consts.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +3 -3
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -3
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/ui/consts.d.ts +3 -0
- package/dist/types-ts4.5/ui/drop-target-v2.d.ts +3 -3
- package/dist/types-ts4.5/ui/inline-drop-target.d.ts +20 -0
- package/dist/types-ts4.5/utils/advanced-layouts-flags.d.ts +1 -0
- package/dist/types-ts4.5/utils/anchor-utils.d.ts +16 -3
- package/dist/types-ts4.5/utils/inline-drop-target.d.ts +2 -0
- package/package.json +4 -1
|
@@ -7,34 +7,40 @@ export const isAnchorSupported = memoizeOne(() => {
|
|
|
7
7
|
}
|
|
8
8
|
return false;
|
|
9
9
|
});
|
|
10
|
-
export class
|
|
10
|
+
export class AnchorRectCache {
|
|
11
11
|
constructor() {
|
|
12
|
-
_defineProperty(this, "
|
|
12
|
+
_defineProperty(this, "anchorRectMap", {});
|
|
13
13
|
_defineProperty(this, "isAnchorSupported", isAnchorSupported());
|
|
14
14
|
_defineProperty(this, "isDirty", true);
|
|
15
15
|
_defineProperty(this, "view", null);
|
|
16
16
|
}
|
|
17
17
|
clear() {
|
|
18
18
|
this.isDirty = true;
|
|
19
|
-
this.
|
|
19
|
+
this.anchorRectMap = {};
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
getRects() {
|
|
22
22
|
if (this.isDirty) {
|
|
23
23
|
var _this$view;
|
|
24
24
|
const anchorElements = ((_this$view = this.view) === null || _this$view === void 0 ? void 0 : _this$view.dom.querySelectorAll('[data-drag-handler-anchor-name]')) || [];
|
|
25
|
-
this.
|
|
25
|
+
this.anchorRectMap = Array.from(anchorElements).reduce((prev, curr) => {
|
|
26
26
|
const anchorName = curr.getAttribute('data-drag-handler-anchor-name');
|
|
27
27
|
if (anchorName) {
|
|
28
28
|
return {
|
|
29
29
|
...prev,
|
|
30
|
-
[anchorName]:
|
|
30
|
+
[anchorName]: {
|
|
31
|
+
height: curr.clientHeight,
|
|
32
|
+
top: curr.offsetTop,
|
|
33
|
+
left: curr.offsetLeft,
|
|
34
|
+
right: curr.offsetLeft + curr.clientWidth,
|
|
35
|
+
width: curr.clientWidth
|
|
36
|
+
}
|
|
31
37
|
};
|
|
32
38
|
}
|
|
33
39
|
return prev;
|
|
34
40
|
}, {});
|
|
35
41
|
this.isDirty = false;
|
|
36
42
|
}
|
|
37
|
-
return this.
|
|
43
|
+
return this.anchorRectMap;
|
|
38
44
|
}
|
|
39
45
|
setEditorView(view) {
|
|
40
46
|
if (this.view !== view) {
|
|
@@ -42,10 +48,50 @@ export class AnchorHeightsCache {
|
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
getHeight(anchorName) {
|
|
51
|
+
var _rects$anchorName;
|
|
45
52
|
if (this.isAnchorSupported) {
|
|
46
53
|
return null;
|
|
47
54
|
}
|
|
48
|
-
const
|
|
49
|
-
return
|
|
55
|
+
const rects = this.getRects();
|
|
56
|
+
return (_rects$anchorName = rects[anchorName]) === null || _rects$anchorName === void 0 ? void 0 : _rects$anchorName.height;
|
|
57
|
+
}
|
|
58
|
+
getWidth(anchorName) {
|
|
59
|
+
var _rects$anchorName2;
|
|
60
|
+
if (this.isAnchorSupported) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const rects = this.getRects();
|
|
64
|
+
return (_rects$anchorName2 = rects[anchorName]) === null || _rects$anchorName2 === void 0 ? void 0 : _rects$anchorName2.width;
|
|
65
|
+
}
|
|
66
|
+
getLeft(anchorName) {
|
|
67
|
+
var _rects$anchorName3;
|
|
68
|
+
if (this.isAnchorSupported) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const rects = this.getRects();
|
|
72
|
+
return (_rects$anchorName3 = rects[anchorName]) === null || _rects$anchorName3 === void 0 ? void 0 : _rects$anchorName3.left;
|
|
73
|
+
}
|
|
74
|
+
getTop(anchorName) {
|
|
75
|
+
var _rects$anchorName4;
|
|
76
|
+
if (this.isAnchorSupported) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const rects = this.getRects();
|
|
80
|
+
return (_rects$anchorName4 = rects[anchorName]) === null || _rects$anchorName4 === void 0 ? void 0 : _rects$anchorName4.top;
|
|
81
|
+
}
|
|
82
|
+
getRight(anchorName) {
|
|
83
|
+
var _rects$anchorName5;
|
|
84
|
+
if (this.isAnchorSupported) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const rects = this.getRects();
|
|
88
|
+
return (_rects$anchorName5 = rects[anchorName]) === null || _rects$anchorName5 === void 0 ? void 0 : _rects$anchorName5.right;
|
|
89
|
+
}
|
|
90
|
+
getRect(anchorName) {
|
|
91
|
+
if (this.isAnchorSupported) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
const rects = this.getRects();
|
|
95
|
+
return rects[anchorName];
|
|
50
96
|
}
|
|
51
97
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
|
|
3
|
+
import { isPreRelease1 } from './advanced-layouts-flags';
|
|
4
|
+
export const shouldAllowInlineDropTarget = (isNested, node) => {
|
|
5
|
+
if (!isPreRelease1() || isNested) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
|
|
9
|
+
return node.childCount < MAX_LAYOUT_COLUMN_SUPPORTED;
|
|
10
|
+
}
|
|
11
|
+
return !isEmptyParagraph(node);
|
|
12
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
|
|
3
|
+
var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
4
|
+
// TODO update with constant
|
|
5
|
+
if (layoutContents.length === 0 || layoutContents.length > 5) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
var width = DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
|
|
9
|
+
if (!width) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
var _ref = schema.nodes || {},
|
|
13
|
+
layoutSection = _ref.layoutSection,
|
|
14
|
+
layoutColumn = _ref.layoutColumn;
|
|
15
|
+
try {
|
|
16
|
+
var layoutSectionNode = layoutSection.createChecked(undefined, Fragment.fromArray(layoutContents.map(function (layoutContent) {
|
|
17
|
+
return layoutColumn.createChecked({
|
|
18
|
+
width: width
|
|
19
|
+
}, layoutContent);
|
|
20
|
+
})));
|
|
21
|
+
return layoutSectionNode;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
// TODO analytics
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
};
|
|
27
|
+
export var moveToLayout = function moveToLayout(api) {
|
|
28
|
+
return function (from, to, position) {
|
|
29
|
+
return function (_ref2) {
|
|
30
|
+
var tr = _ref2.tr;
|
|
31
|
+
var _ref3 = tr.doc.type.schema.nodes || {},
|
|
32
|
+
layoutSection = _ref3.layoutSection,
|
|
33
|
+
layoutColumn = _ref3.layoutColumn,
|
|
34
|
+
doc = _ref3.doc;
|
|
35
|
+
|
|
36
|
+
// layout plugin does not exist
|
|
37
|
+
if (!layoutSection || !layoutColumn) {
|
|
38
|
+
return tr;
|
|
39
|
+
}
|
|
40
|
+
var $to = tr.doc.resolve(to);
|
|
41
|
+
|
|
42
|
+
// invalid to position or not top level.
|
|
43
|
+
if (!$to.nodeAfter || $to.parent.type !== doc) {
|
|
44
|
+
return tr;
|
|
45
|
+
}
|
|
46
|
+
var $from = tr.doc.resolve(from);
|
|
47
|
+
|
|
48
|
+
// invalid from position
|
|
49
|
+
if (!$from.nodeAfter) {
|
|
50
|
+
return tr;
|
|
51
|
+
}
|
|
52
|
+
var toNode = $to.nodeAfter;
|
|
53
|
+
var fromNode = $from.nodeAfter;
|
|
54
|
+
var fromNodeEndPos = from + fromNode.nodeSize;
|
|
55
|
+
var toNodeEndPos = to + toNode.nodeSize;
|
|
56
|
+
if ($to.nodeAfter.type !== layoutSection) {
|
|
57
|
+
var layoutContents = position === 'left' ? [fromNode, toNode] : [toNode, fromNode];
|
|
58
|
+
var newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
59
|
+
if (newLayout) {
|
|
60
|
+
tr.delete(from, fromNodeEndPos);
|
|
61
|
+
var mappedTo = tr.mapping.map(to);
|
|
62
|
+
tr.delete(mappedTo, toNodeEndPos);
|
|
63
|
+
tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
64
|
+
}
|
|
65
|
+
return tr;
|
|
66
|
+
}
|
|
67
|
+
return tr;
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
};
|
package/dist/esm/consts.js
CHANGED
package/dist/esm/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
4
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
5
5
|
import { moveNode } from './commands/move-node';
|
|
6
|
+
import { moveToLayout } from './commands/move-to-layout';
|
|
6
7
|
import { createEmptyBlockExperimentPlugin } from './pm-plugins/empty-block-experiment';
|
|
7
8
|
import { createPlugin, key } from './pm-plugins/main';
|
|
8
9
|
import { DragHandleMenu } from './ui/drag-handle-menu';
|
|
@@ -31,6 +32,7 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
|
|
|
31
32
|
},
|
|
32
33
|
commands: {
|
|
33
34
|
moveNode: moveNode(api),
|
|
35
|
+
moveToLayout: moveToLayout(api),
|
|
34
36
|
showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType, handleOptions) {
|
|
35
37
|
return function (_ref4) {
|
|
36
38
|
var tr = _ref4.tr;
|
|
@@ -122,7 +122,7 @@ export var findNodeDecs = function findNodeDecs(decorations, from, to) {
|
|
|
122
122
|
return spec.type === TYPE_NODE_DEC;
|
|
123
123
|
});
|
|
124
124
|
};
|
|
125
|
-
export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side,
|
|
125
|
+
export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
|
|
126
126
|
return Decoration.widget(pos, function (_, getPos) {
|
|
127
127
|
var element = document.createElement('div');
|
|
128
128
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
@@ -137,7 +137,7 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
|
|
|
137
137
|
if (fg('platform_editor_drag_and_drop_target_v2')) {
|
|
138
138
|
ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
|
|
139
139
|
getPos: getPos,
|
|
140
|
-
|
|
140
|
+
anchorRectCache: anchorRectCache
|
|
141
141
|
})), element);
|
|
142
142
|
} else {
|
|
143
143
|
ReactDOM.render( /*#__PURE__*/createElement(DropTarget, _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -150,7 +150,7 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
|
|
|
150
150
|
side: side
|
|
151
151
|
});
|
|
152
152
|
};
|
|
153
|
-
export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode,
|
|
153
|
+
export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
|
|
154
154
|
unmountDecorations('data-blocks-drop-target-container');
|
|
155
155
|
var decs = [];
|
|
156
156
|
var POS_END_OF_DOC = newState.doc.nodeSize - 2;
|
|
@@ -159,7 +159,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
159
159
|
var prevNode;
|
|
160
160
|
var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
161
161
|
var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
162
|
-
|
|
162
|
+
anchorRectCache === null || anchorRectCache === void 0 || anchorRectCache.clear();
|
|
163
163
|
var prevNodeStack = [];
|
|
164
164
|
var popNodeStack = function popNodeStack(depth) {
|
|
165
165
|
var result;
|
|
@@ -224,7 +224,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
224
224
|
parentNode: parent || undefined,
|
|
225
225
|
formatMessage: formatMessage,
|
|
226
226
|
dropTargetStyle: shouldShowFullHeight ? 'fullHeight' : 'default'
|
|
227
|
-
}, -1,
|
|
227
|
+
}, -1, anchorRectCache));
|
|
228
228
|
if (endPos !== undefined) {
|
|
229
229
|
decs.push(createDropTargetDecoration(endPos, {
|
|
230
230
|
api: api,
|
|
@@ -232,7 +232,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
232
232
|
parentNode: parent || undefined,
|
|
233
233
|
formatMessage: formatMessage,
|
|
234
234
|
dropTargetStyle: isInSupportedContainer ? 'fullHeight' : 'default'
|
|
235
|
-
}, -1,
|
|
235
|
+
}, -1, anchorRectCache));
|
|
236
236
|
}
|
|
237
237
|
if (fg('platform_editor_drag_and_drop_target_v2')) {
|
|
238
238
|
pushNodeStack(node, depth);
|
|
@@ -247,7 +247,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
|
|
|
247
247
|
formatMessage: formatMessage,
|
|
248
248
|
prevNode: newState.doc.lastChild || undefined,
|
|
249
249
|
parentNode: newState.doc
|
|
250
|
-
}, undefined,
|
|
250
|
+
}, undefined, anchorRectCache));
|
|
251
251
|
}
|
|
252
252
|
return decs;
|
|
253
253
|
};
|
|
@@ -12,7 +12,7 @@ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-sc
|
|
|
12
12
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
13
13
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
14
14
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
15
|
-
import {
|
|
15
|
+
import { AnchorRectCache, isAnchorSupported } from '../utils/anchor-utils';
|
|
16
16
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
17
17
|
import { getTrMetadata } from '../utils/transactions';
|
|
18
18
|
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, findDropTargetDecs, findHandleDec, findNodeDecs, nodeDecorations } from './decorations';
|
|
@@ -88,7 +88,7 @@ var initialState = {
|
|
|
88
88
|
isDocSizeLimitEnabled: null,
|
|
89
89
|
isPMDragging: false
|
|
90
90
|
};
|
|
91
|
-
export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags,
|
|
91
|
+
export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache) {
|
|
92
92
|
var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
93
93
|
var activeNode = currentState.activeNode,
|
|
94
94
|
decorations = currentState.decorations,
|
|
@@ -194,7 +194,7 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
194
194
|
// Add drop targets when dragging starts or some are missing
|
|
195
195
|
if (api) {
|
|
196
196
|
if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || isBlocksDragTargetDebug()) {
|
|
197
|
-
var decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode,
|
|
197
|
+
var decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorRectCache);
|
|
198
198
|
decorations = decorations.add(newState.doc, decs);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
@@ -219,7 +219,7 @@ export var newApply = function newApply(api, formatMessage, tr, currentState, ne
|
|
|
219
219
|
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
220
220
|
};
|
|
221
221
|
};
|
|
222
|
-
export var oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags,
|
|
222
|
+
export var oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache) {
|
|
223
223
|
var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
|
|
224
224
|
var isNestedEnabled = flags.isNestedEnabled;
|
|
225
225
|
var activeNode = currentState.activeNode,
|
|
@@ -382,7 +382,7 @@ export var oldApply = function oldApply(api, formatMessage, tr, currentState, ol
|
|
|
382
382
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
383
383
|
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
384
384
|
var _meta$activeNode7;
|
|
385
|
-
var _decs2 = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode,
|
|
385
|
+
var _decs2 = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorRectCache);
|
|
386
386
|
decorations = decorations.add(newState.doc, _decs2);
|
|
387
387
|
}
|
|
388
388
|
}
|
|
@@ -427,9 +427,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
427
427
|
if (fg('platform_editor_element_dnd_nested_fix_patch_2')) {
|
|
428
428
|
// TODO: Remove this once FG is used in code
|
|
429
429
|
}
|
|
430
|
-
var
|
|
430
|
+
var anchorRectCache;
|
|
431
431
|
if (!isAnchorSupported() && fg('platform_editor_drag_and_drop_target_v2')) {
|
|
432
|
-
|
|
432
|
+
anchorRectCache = new AnchorRectCache();
|
|
433
433
|
}
|
|
434
434
|
return new SafePlugin({
|
|
435
435
|
key: key,
|
|
@@ -439,9 +439,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
439
439
|
},
|
|
440
440
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
441
441
|
if (isOptimisedApply) {
|
|
442
|
-
return newApply(api, formatMessage, tr, currentState, newState, flags,
|
|
442
|
+
return newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache);
|
|
443
443
|
}
|
|
444
|
-
return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags,
|
|
444
|
+
return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache);
|
|
445
445
|
}
|
|
446
446
|
},
|
|
447
447
|
props: {
|
|
@@ -491,8 +491,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
491
491
|
return false;
|
|
492
492
|
},
|
|
493
493
|
dragstart: function dragstart(view) {
|
|
494
|
-
var
|
|
495
|
-
(
|
|
494
|
+
var _anchorRectCache;
|
|
495
|
+
(_anchorRectCache = anchorRectCache) === null || _anchorRectCache === void 0 || _anchorRectCache.setEditorView(view);
|
|
496
496
|
view.dispatch(view.state.tr.setMeta(key, {
|
|
497
497
|
isPMDragging: true
|
|
498
498
|
}));
|
package/dist/esm/ui/consts.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
/**
|
|
@@ -16,7 +17,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
16
17
|
import { getNodeAnchor } from '../pm-plugins/decorations';
|
|
17
18
|
import { isAnchorSupported } from '../utils/anchor-utils';
|
|
18
19
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
20
|
+
import { shouldAllowInlineDropTarget } from '../utils/inline-drop-target';
|
|
19
21
|
import { getNestedNodeLeftPaddingMargin } from './consts';
|
|
22
|
+
import { InlineDropTarget } from './inline-drop-target';
|
|
20
23
|
var DEFAULT_DROP_INDICATOR_WIDTH = 760;
|
|
21
24
|
var EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
|
|
22
25
|
var EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
|
|
@@ -72,7 +75,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
72
75
|
node = _ref.node,
|
|
73
76
|
parent = _ref.parent,
|
|
74
77
|
editorWidth = _ref.editorWidth,
|
|
75
|
-
|
|
78
|
+
anchorRectCache = _ref.anchorRectCache,
|
|
76
79
|
position = _ref.position,
|
|
77
80
|
isNestedDropTarget = _ref.isNestedDropTarget,
|
|
78
81
|
dropTargetStyle = _ref.dropTargetStyle;
|
|
@@ -91,7 +94,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
91
94
|
var anchorName = node ? getNodeAnchor(node) : '';
|
|
92
95
|
var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
|
|
93
96
|
var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
|
|
94
|
-
var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((
|
|
97
|
+
var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0) / 2, "px + ").concat(heightStyleOffset, ")") : '4px';
|
|
95
98
|
var transform = position === 'upper' ? "translateY(calc(-100% + ".concat(transformOffset, "))") : "translateY(".concat(transformOffset, ")");
|
|
96
99
|
return css({
|
|
97
100
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
@@ -101,7 +104,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
101
104
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
102
105
|
maxWidth: "".concat(editorWidth || 0, "px")
|
|
103
106
|
});
|
|
104
|
-
}, [
|
|
107
|
+
}, [anchorRectCache, editorWidth, node, position]);
|
|
105
108
|
var isFullHeight = useMemo(function () {
|
|
106
109
|
return dropTargetStyle === 'fullHeight';
|
|
107
110
|
}, [dropTargetStyle]);
|
|
@@ -121,16 +124,16 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
121
124
|
hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
|
|
122
125
|
});
|
|
123
126
|
};
|
|
124
|
-
export var DropTargetV2 = function DropTargetV2(
|
|
127
|
+
export var DropTargetV2 = function DropTargetV2(props) {
|
|
125
128
|
var _dynamicStyle;
|
|
126
|
-
var api =
|
|
127
|
-
getPos =
|
|
128
|
-
prevNode =
|
|
129
|
-
nextNode =
|
|
130
|
-
parentNode =
|
|
131
|
-
formatMessage =
|
|
132
|
-
|
|
133
|
-
dropTargetStyle =
|
|
129
|
+
var api = props.api,
|
|
130
|
+
getPos = props.getPos,
|
|
131
|
+
prevNode = props.prevNode,
|
|
132
|
+
nextNode = props.nextNode,
|
|
133
|
+
parentNode = props.parentNode,
|
|
134
|
+
formatMessage = props.formatMessage,
|
|
135
|
+
anchorRectCache = props.anchorRectCache,
|
|
136
|
+
dropTargetStyle = props.dropTargetStyle;
|
|
134
137
|
var _useState = useState(false),
|
|
135
138
|
_useState2 = _slicedToArray(_useState, 2),
|
|
136
139
|
isDraggedOver = _useState2[0],
|
|
@@ -140,8 +143,8 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
140
143
|
var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
|
|
141
144
|
var onDrop = function onDrop() {
|
|
142
145
|
var _api$blockControls;
|
|
143
|
-
var
|
|
144
|
-
activeNode =
|
|
146
|
+
var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
147
|
+
activeNode = _ref2.activeNode;
|
|
145
148
|
if (!activeNode) {
|
|
146
149
|
return;
|
|
147
150
|
}
|
|
@@ -166,7 +169,7 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
166
169
|
onDrop: onDrop,
|
|
167
170
|
node: prevNode,
|
|
168
171
|
editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
|
|
169
|
-
|
|
172
|
+
anchorRectCache: anchorRectCache,
|
|
170
173
|
position: "upper",
|
|
171
174
|
isNestedDropTarget: isNestedDropTarget
|
|
172
175
|
}), jsx("div", {
|
|
@@ -194,9 +197,13 @@ export var DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
194
197
|
node: nextNode,
|
|
195
198
|
parent: parentNode,
|
|
196
199
|
editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
|
|
197
|
-
|
|
200
|
+
anchorRectCache: anchorRectCache,
|
|
198
201
|
position: "lower",
|
|
199
202
|
isNestedDropTarget: isNestedDropTarget,
|
|
200
203
|
dropTargetStyle: dropTargetStyle
|
|
201
|
-
}))
|
|
204
|
+
}), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode) && jsx(Fragment, null, jsx(InlineDropTarget, _extends({}, props, {
|
|
205
|
+
position: "left"
|
|
206
|
+
})), jsx(InlineDropTarget, _extends({}, props, {
|
|
207
|
+
position: "right"
|
|
208
|
+
}))));
|
|
202
209
|
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
/* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
|
|
3
|
+
/* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
|
|
4
|
+
/**
|
|
5
|
+
* @jsxRuntime classic
|
|
6
|
+
* @jsx jsx
|
|
7
|
+
*/
|
|
8
|
+
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
11
|
+
import { css, jsx } from '@emotion/react';
|
|
12
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
13
|
+
import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
|
|
14
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
15
|
+
import { getNodeAnchor } from '../pm-plugins/decorations';
|
|
16
|
+
import { isAnchorSupported } from '../utils/anchor-utils';
|
|
17
|
+
var dropTargetCommonStyle = css({
|
|
18
|
+
position: 'absolute',
|
|
19
|
+
display: 'block'
|
|
20
|
+
});
|
|
21
|
+
var hideDropTargetStyle = css({
|
|
22
|
+
display: 'none'
|
|
23
|
+
});
|
|
24
|
+
var hoverZoneCommonStyle = css({
|
|
25
|
+
position: 'absolute',
|
|
26
|
+
// same value as block hover zone
|
|
27
|
+
zIndex: 110
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// gap between node boundary and drop indicator/drop zone
|
|
31
|
+
var GAP = 4;
|
|
32
|
+
var HOVER_ZONE_WIDTH_OFFSET = 40;
|
|
33
|
+
var HOVER_ZONE_HEIGHT_OFFSET = 10;
|
|
34
|
+
var HOVER_ZONE_DEFAULT_WIDTH = 40;
|
|
35
|
+
export var InlineDropTarget = function InlineDropTarget(_ref) {
|
|
36
|
+
var api = _ref.api,
|
|
37
|
+
nextNode = _ref.nextNode,
|
|
38
|
+
position = _ref.position,
|
|
39
|
+
anchorRectCache = _ref.anchorRectCache;
|
|
40
|
+
var _useSharedPluginState = useSharedPluginState(api, ['width']),
|
|
41
|
+
widthState = _useSharedPluginState.widthState;
|
|
42
|
+
var _useState = useState(false),
|
|
43
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
44
|
+
isDraggedOver = _useState2[0],
|
|
45
|
+
setIsDraggedOver = _useState2[1];
|
|
46
|
+
var anchorName = nextNode ? getNodeAnchor(nextNode) : '';
|
|
47
|
+
var handleDragEnter = useCallback(function () {
|
|
48
|
+
setIsDraggedOver(true);
|
|
49
|
+
}, []);
|
|
50
|
+
var handleDragLeave = useCallback(function () {
|
|
51
|
+
setIsDraggedOver(false);
|
|
52
|
+
}, []);
|
|
53
|
+
var dropTargetRectStyle = useMemo(function () {
|
|
54
|
+
if (isAnchorSupported()) {
|
|
55
|
+
return css({
|
|
56
|
+
height: "calc(anchor-size(".concat(anchorName, " height))"),
|
|
57
|
+
positionAnchor: anchorName,
|
|
58
|
+
left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
59
|
+
top: "calc(anchor(top))"
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
63
|
+
return css({
|
|
64
|
+
height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
|
|
65
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
66
|
+
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
|
|
67
|
+
});
|
|
68
|
+
}, [anchorName, anchorRectCache, position]);
|
|
69
|
+
return jsx(Fragment, null, jsx("div", {
|
|
70
|
+
"data-test-id": "block-ctrl-drop-target-".concat(position),
|
|
71
|
+
css: [dropTargetCommonStyle, dropTargetRectStyle, !isDraggedOver && hideDropTargetStyle]
|
|
72
|
+
}, jsx(DropIndicator, {
|
|
73
|
+
edge: position
|
|
74
|
+
})), jsx(InlineHoverZone, {
|
|
75
|
+
position: position,
|
|
76
|
+
node: nextNode,
|
|
77
|
+
editorWidthState: widthState,
|
|
78
|
+
anchorRectCache: anchorRectCache,
|
|
79
|
+
onDragEnter: handleDragEnter,
|
|
80
|
+
onDragLeave: handleDragLeave,
|
|
81
|
+
onDrop: function onDrop() {}
|
|
82
|
+
}));
|
|
83
|
+
};
|
|
84
|
+
export var InlineHoverZone = function InlineHoverZone(_ref2) {
|
|
85
|
+
var node = _ref2.node,
|
|
86
|
+
editorWidthState = _ref2.editorWidthState,
|
|
87
|
+
anchorRectCache = _ref2.anchorRectCache,
|
|
88
|
+
position = _ref2.position,
|
|
89
|
+
onDragEnter = _ref2.onDragEnter,
|
|
90
|
+
onDragLeave = _ref2.onDragLeave,
|
|
91
|
+
onDrop = _ref2.onDrop;
|
|
92
|
+
var ref = useRef(null);
|
|
93
|
+
var _ref3 = editorWidthState || {},
|
|
94
|
+
editorWith = _ref3.width;
|
|
95
|
+
var anchorName = node ? getNodeAnchor(node) : '';
|
|
96
|
+
useEffect(function () {
|
|
97
|
+
if (ref.current) {
|
|
98
|
+
return dropTargetForElements({
|
|
99
|
+
element: ref.current,
|
|
100
|
+
onDragEnter: onDragEnter,
|
|
101
|
+
onDragLeave: onDragLeave,
|
|
102
|
+
onDrop: onDrop
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}, [onDragEnter, onDragLeave, onDrop]);
|
|
106
|
+
var inlineHoverZoneRectStyle = useMemo(function () {
|
|
107
|
+
if (isAnchorSupported()) {
|
|
108
|
+
return css({
|
|
109
|
+
positionAnchor: anchorName,
|
|
110
|
+
left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
|
|
111
|
+
right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
|
|
112
|
+
top: "calc(anchor(top))",
|
|
113
|
+
width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
|
|
114
|
+
height: "calc(anchor-size(".concat(anchorName, " height))")
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
|
|
118
|
+
var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
|
|
119
|
+
return css({
|
|
120
|
+
left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
|
|
121
|
+
top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
|
|
122
|
+
width: "".concat(width, "px"),
|
|
123
|
+
height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
|
|
124
|
+
});
|
|
125
|
+
}, [anchorName, anchorRectCache, editorWith, position]);
|
|
126
|
+
return jsx("div", {
|
|
127
|
+
ref: ref,
|
|
128
|
+
css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
|
|
129
|
+
});
|
|
130
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
3
|
+
export var isPreRelease1 = function isPreRelease1() {
|
|
4
|
+
return editorExperiment('advanced_layouts', true) || fg('platform_editor_advanced_layouts_pre_release_1');
|
|
5
|
+
};
|