@atlaskit/editor-plugin-block-controls 2.6.2 → 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 +26 -0
- package/dist/cjs/commands/move-to-layout.js +76 -0
- package/dist/cjs/consts.js +3 -2
- package/dist/cjs/plugin.js +3 -12
- package/dist/cjs/pm-plugins/decorations.js +15 -11
- package/dist/cjs/pm-plugins/handle-mouse-over.js +2 -12
- package/dist/cjs/pm-plugins/main.js +14 -18
- 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 -10
- package/dist/es2019/pm-plugins/decorations.js +15 -11
- package/dist/es2019/pm-plugins/handle-mouse-over.js +2 -12
- package/dist/es2019/pm-plugins/main.js +15 -21
- 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 +3 -12
- package/dist/esm/pm-plugins/decorations.js +15 -11
- package/dist/esm/pm-plugins/handle-mouse-over.js +2 -12
- package/dist/esm/pm-plugins/main.js +15 -19
- 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 -4
- package/dist/types/types.d.ts +1 -1
- 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 -4
- package/dist/types-ts4.5/types.d.ts +1 -1
- 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 +8 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#151244](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151244)
|
|
8
|
+
[`10ba5860e515c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/10ba5860e515c) -
|
|
9
|
+
ED-25281 Implement DnD API for Advanced Layout
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#153270](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/153270)
|
|
14
|
+
[`311428de27cbc`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/311428de27cbc) -
|
|
15
|
+
[ux] [ED-25068] Implement inline drop zone and drop target (edge case excluded) behind FG
|
|
16
|
+
|
|
17
|
+
## 2.6.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [#153087](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/153087)
|
|
22
|
+
[`a29ea6551ed67`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a29ea6551ed67) -
|
|
23
|
+
ED-24902: Change display from inline to block to fix focus issues with drag handle
|
|
24
|
+
- [#152414](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/152414)
|
|
25
|
+
[`893c9f74cb700`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/893c9f74cb700) -
|
|
26
|
+
Use getPos instead of pos when rendering drag handle
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
|
|
3
29
|
## 2.6.2
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveToLayout = void 0;
|
|
7
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
8
|
+
var _consts = require("../ui/consts");
|
|
9
|
+
var createNewLayout = function createNewLayout(schema, layoutContents) {
|
|
10
|
+
// TODO update with constant
|
|
11
|
+
if (layoutContents.length === 0 || layoutContents.length > 5) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
var width = _consts.DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
|
|
15
|
+
if (!width) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
var _ref = schema.nodes || {},
|
|
19
|
+
layoutSection = _ref.layoutSection,
|
|
20
|
+
layoutColumn = _ref.layoutColumn;
|
|
21
|
+
try {
|
|
22
|
+
var layoutSectionNode = layoutSection.createChecked(undefined, _model.Fragment.fromArray(layoutContents.map(function (layoutContent) {
|
|
23
|
+
return layoutColumn.createChecked({
|
|
24
|
+
width: width
|
|
25
|
+
}, layoutContent);
|
|
26
|
+
})));
|
|
27
|
+
return layoutSectionNode;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// TODO analytics
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
var moveToLayout = exports.moveToLayout = function moveToLayout(api) {
|
|
34
|
+
return function (from, to, position) {
|
|
35
|
+
return function (_ref2) {
|
|
36
|
+
var tr = _ref2.tr;
|
|
37
|
+
var _ref3 = tr.doc.type.schema.nodes || {},
|
|
38
|
+
layoutSection = _ref3.layoutSection,
|
|
39
|
+
layoutColumn = _ref3.layoutColumn,
|
|
40
|
+
doc = _ref3.doc;
|
|
41
|
+
|
|
42
|
+
// layout plugin does not exist
|
|
43
|
+
if (!layoutSection || !layoutColumn) {
|
|
44
|
+
return tr;
|
|
45
|
+
}
|
|
46
|
+
var $to = tr.doc.resolve(to);
|
|
47
|
+
|
|
48
|
+
// invalid to position or not top level.
|
|
49
|
+
if (!$to.nodeAfter || $to.parent.type !== doc) {
|
|
50
|
+
return tr;
|
|
51
|
+
}
|
|
52
|
+
var $from = tr.doc.resolve(from);
|
|
53
|
+
|
|
54
|
+
// invalid from position
|
|
55
|
+
if (!$from.nodeAfter) {
|
|
56
|
+
return tr;
|
|
57
|
+
}
|
|
58
|
+
var toNode = $to.nodeAfter;
|
|
59
|
+
var fromNode = $from.nodeAfter;
|
|
60
|
+
var fromNodeEndPos = from + fromNode.nodeSize;
|
|
61
|
+
var toNodeEndPos = to + toNode.nodeSize;
|
|
62
|
+
if ($to.nodeAfter.type !== layoutSection) {
|
|
63
|
+
var layoutContents = position === 'left' ? [fromNode, toNode] : [toNode, fromNode];
|
|
64
|
+
var newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
|
|
65
|
+
if (newLayout) {
|
|
66
|
+
tr.delete(from, fromNodeEndPos);
|
|
67
|
+
var mappedTo = tr.mapping.map(to);
|
|
68
|
+
tr.delete(mappedTo, toNodeEndPos);
|
|
69
|
+
tr.insert(mappedTo, newLayout); // insert the content at the new position
|
|
70
|
+
}
|
|
71
|
+
return tr;
|
|
72
|
+
}
|
|
73
|
+
return tr;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
package/dist/cjs/consts.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.DIRECTION = void 0;
|
|
6
|
+
exports.MAX_LAYOUT_COLUMN_SUPPORTED = exports.DIRECTION = void 0;
|
|
7
7
|
var DIRECTION = exports.DIRECTION = /*#__PURE__*/function (DIRECTION) {
|
|
8
8
|
DIRECTION["UP"] = "up";
|
|
9
9
|
DIRECTION["DOWN"] = "down";
|
|
10
10
|
DIRECTION["LEFT"] = "left";
|
|
11
11
|
DIRECTION["RIGHT"] = "right";
|
|
12
12
|
return DIRECTION;
|
|
13
|
-
}({});
|
|
13
|
+
}({});
|
|
14
|
+
var MAX_LAYOUT_COLUMN_SUPPORTED = exports.MAX_LAYOUT_COLUMN_SUPPORTED = 3;
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -10,6 +10,7 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
10
10
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
11
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
12
12
|
var _moveNode = require("./commands/move-node");
|
|
13
|
+
var _moveToLayout = require("./commands/move-to-layout");
|
|
13
14
|
var _emptyBlockExperiment = require("./pm-plugins/empty-block-experiment");
|
|
14
15
|
var _main = require("./pm-plugins/main");
|
|
15
16
|
var _dragHandleMenu = require("./ui/drag-handle-menu");
|
|
@@ -38,6 +39,7 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
38
39
|
},
|
|
39
40
|
commands: {
|
|
40
41
|
moveNode: (0, _moveNode.moveNode)(api),
|
|
42
|
+
moveToLayout: (0, _moveToLayout.moveToLayout)(api),
|
|
41
43
|
showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType, handleOptions) {
|
|
42
44
|
return function (_ref4) {
|
|
43
45
|
var tr = _ref4.tr;
|
|
@@ -52,20 +54,9 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
|
|
|
52
54
|
return tr;
|
|
53
55
|
};
|
|
54
56
|
},
|
|
55
|
-
|
|
57
|
+
setNodeDragged: function setNodeDragged(getPos, anchorName, nodeType) {
|
|
56
58
|
return function (_ref5) {
|
|
57
59
|
var tr = _ref5.tr;
|
|
58
|
-
if ((0, _platformFeatureFlags.fg)('confluence_frontend_page_title_enter_improvements')) {
|
|
59
|
-
tr.setMeta(_main.key, {
|
|
60
|
-
hideDragHandle: true
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return tr;
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
setNodeDragged: function setNodeDragged(getPos, anchorName, nodeType) {
|
|
67
|
-
return function (_ref6) {
|
|
68
|
-
var tr = _ref6.tr;
|
|
69
60
|
var pos = getPos();
|
|
70
61
|
if (pos === undefined) {
|
|
71
62
|
return tr;
|
|
@@ -129,7 +129,7 @@ var findNodeDecs = exports.findNodeDecs = function findNodeDecs(decorations, fro
|
|
|
129
129
|
return spec.type === TYPE_NODE_DEC;
|
|
130
130
|
});
|
|
131
131
|
};
|
|
132
|
-
var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side,
|
|
132
|
+
var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
|
|
133
133
|
return _view.Decoration.widget(pos, function (_, getPos) {
|
|
134
134
|
var element = document.createElement('div');
|
|
135
135
|
element.setAttribute('data-blocks-drop-target-container', 'true');
|
|
@@ -144,7 +144,7 @@ var createDropTargetDecoration = exports.createDropTargetDecoration = function c
|
|
|
144
144
|
if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
|
|
145
145
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTargetV.DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
|
|
146
146
|
getPos: getPos,
|
|
147
|
-
|
|
147
|
+
anchorRectCache: anchorRectCache
|
|
148
148
|
})), element);
|
|
149
149
|
} else {
|
|
150
150
|
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dropTarget.DropTarget, _objectSpread(_objectSpread({}, props), {}, {
|
|
@@ -157,7 +157,7 @@ var createDropTargetDecoration = exports.createDropTargetDecoration = function c
|
|
|
157
157
|
side: side
|
|
158
158
|
});
|
|
159
159
|
};
|
|
160
|
-
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode,
|
|
160
|
+
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
|
|
161
161
|
unmountDecorations('data-blocks-drop-target-container');
|
|
162
162
|
var decs = [];
|
|
163
163
|
var POS_END_OF_DOC = newState.doc.nodeSize - 2;
|
|
@@ -166,7 +166,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
166
166
|
var prevNode;
|
|
167
167
|
var activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
|
|
168
168
|
var activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
|
|
169
|
-
|
|
169
|
+
anchorRectCache === null || anchorRectCache === void 0 || anchorRectCache.clear();
|
|
170
170
|
var prevNodeStack = [];
|
|
171
171
|
var popNodeStack = function popNodeStack(depth) {
|
|
172
172
|
var result;
|
|
@@ -231,7 +231,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
231
231
|
parentNode: parent || undefined,
|
|
232
232
|
formatMessage: formatMessage,
|
|
233
233
|
dropTargetStyle: shouldShowFullHeight ? 'fullHeight' : 'default'
|
|
234
|
-
}, -1,
|
|
234
|
+
}, -1, anchorRectCache));
|
|
235
235
|
if (endPos !== undefined) {
|
|
236
236
|
decs.push(createDropTargetDecoration(endPos, {
|
|
237
237
|
api: api,
|
|
@@ -239,7 +239,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
239
239
|
parentNode: parent || undefined,
|
|
240
240
|
formatMessage: formatMessage,
|
|
241
241
|
dropTargetStyle: isInSupportedContainer ? 'fullHeight' : 'default'
|
|
242
|
-
}, -1,
|
|
242
|
+
}, -1, anchorRectCache));
|
|
243
243
|
}
|
|
244
244
|
if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
|
|
245
245
|
pushNodeStack(node, depth);
|
|
@@ -254,7 +254,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
254
254
|
formatMessage: formatMessage,
|
|
255
255
|
prevNode: newState.doc.lastChild || undefined,
|
|
256
256
|
parentNode: newState.doc
|
|
257
|
-
}, undefined,
|
|
257
|
+
}, undefined, anchorRectCache));
|
|
258
258
|
}
|
|
259
259
|
return decs;
|
|
260
260
|
};
|
|
@@ -336,18 +336,22 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
|
|
|
336
336
|
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
337
337
|
var element = document.createElement('span');
|
|
338
338
|
// Need to set it to inline to avoid text being split when merging two paragraphs
|
|
339
|
-
|
|
339
|
+
// platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
|
|
340
|
+
element.style.display = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
|
|
340
341
|
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
341
342
|
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
342
343
|
var isTopLevelNode = true;
|
|
343
344
|
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
344
|
-
var
|
|
345
|
-
|
|
345
|
+
var newPos = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
|
|
346
|
+
if (typeof newPos === 'number') {
|
|
347
|
+
var $pos = view.state.doc.resolve(newPos);
|
|
348
|
+
isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
|
|
349
|
+
}
|
|
346
350
|
/*
|
|
347
351
|
* We disable mouseover event to fix flickering issue on hover
|
|
348
352
|
* However, the tooltip for nested drag handle is no long working.
|
|
349
353
|
*/
|
|
350
|
-
if (!isTopLevelNode) {
|
|
354
|
+
if (newPos === undefined || !isTopLevelNode) {
|
|
351
355
|
// This will also hide the tooltip.
|
|
352
356
|
unbind = (0, _bindEventListener.bind)(element, {
|
|
353
357
|
type: 'mouseover',
|
|
@@ -13,11 +13,6 @@ var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(t
|
|
|
13
13
|
}
|
|
14
14
|
return false;
|
|
15
15
|
};
|
|
16
|
-
var isDocFirstChildEmptyLine = function isDocFirstChildEmptyLine(elem) {
|
|
17
|
-
var _elem$firstElementChi;
|
|
18
|
-
var parentElement = elem.parentElement;
|
|
19
|
-
return (parentElement === null || parentElement === void 0 ? void 0 : parentElement.classList.contains('ProseMirror')) && (parentElement === null || parentElement === void 0 ? void 0 : parentElement.firstElementChild) === elem && ['P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6'].includes(elem.nodeName) && elem.childNodes.length === 1 && ((_elem$firstElementChi = elem.firstElementChild) === null || _elem$firstElementChi === void 0 ? void 0 : _elem$firstElementChi.classList.contains('ProseMirror-trailingBreak'));
|
|
20
|
-
};
|
|
21
16
|
var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, event, api) {
|
|
22
17
|
var _api$blockControls, _target$classList;
|
|
23
18
|
var _ref = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
@@ -36,11 +31,6 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
|
|
|
36
31
|
var rootElement = target === null || target === void 0 ? void 0 : target.closest('[data-drag-handler-anchor-name]');
|
|
37
32
|
if (rootElement) {
|
|
38
33
|
var _rootElement$parentEl;
|
|
39
|
-
if (isDocFirstChildEmptyLine(rootElement) && (0, _platformFeatureFlags.fg)('confluence_frontend_page_title_enter_improvements')) {
|
|
40
|
-
var _api$core, _api$blockControls2;
|
|
41
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.hideDragHandle());
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
34
|
// We want to exlude handles from showing for empty paragraph and heading nodes
|
|
45
35
|
if ((0, _experiments.editorExperiment)('nested-dnd', true) && isEmptyNestedParagraphOrHeading(rootElement)) {
|
|
46
36
|
return false;
|
|
@@ -89,8 +79,8 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
|
|
|
89
79
|
}
|
|
90
80
|
var nodeType = rootElement.getAttribute('data-drag-handler-node-type');
|
|
91
81
|
if (nodeType) {
|
|
92
|
-
var _api$
|
|
93
|
-
api === null || api === void 0 || (_api$
|
|
82
|
+
var _api$core, _api$blockControls2;
|
|
83
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.showDragHandleAt(rootPos, anchorName, nodeType));
|
|
94
84
|
}
|
|
95
85
|
}
|
|
96
86
|
};
|
|
@@ -95,9 +95,8 @@ var initialState = {
|
|
|
95
95
|
isDocSizeLimitEnabled: null,
|
|
96
96
|
isPMDragging: false
|
|
97
97
|
};
|
|
98
|
-
var newApply = exports.newApply = function newApply(api, formatMessage, tr, currentState, newState, flags,
|
|
98
|
+
var newApply = exports.newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache) {
|
|
99
99
|
var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
100
|
-
var isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
|
|
101
100
|
var activeNode = currentState.activeNode,
|
|
102
101
|
decorations = currentState.decorations,
|
|
103
102
|
editorHeight = currentState.editorHeight,
|
|
@@ -177,7 +176,7 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
177
176
|
var shouldRecreateHandle = latestActiveNode && (activeNodeChanged || isActiveNodeModified || editorSizeChanged || handleNeedsRedraw);
|
|
178
177
|
|
|
179
178
|
// Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
|
|
180
|
-
var shouldRemoveHandle = latestActiveNode && (
|
|
179
|
+
var shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
|
|
181
180
|
if (shouldRemoveHandle) {
|
|
182
181
|
var _activeNode3, _activeNode4;
|
|
183
182
|
var oldHandle = (0, _decorations.findHandleDec)(decorations, (_activeNode3 = activeNode) === null || _activeNode3 === void 0 ? void 0 : _activeNode3.pos, (_activeNode4 = activeNode) === null || _activeNode4 === void 0 ? void 0 : _activeNode4.pos);
|
|
@@ -202,7 +201,7 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
202
201
|
// Add drop targets when dragging starts or some are missing
|
|
203
202
|
if (api) {
|
|
204
203
|
if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
205
|
-
var decs = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, latestActiveNode,
|
|
204
|
+
var decs = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, latestActiveNode, anchorRectCache);
|
|
206
205
|
decorations = decorations.add(newState.doc, decs);
|
|
207
206
|
}
|
|
208
207
|
}
|
|
@@ -227,10 +226,9 @@ var newApply = exports.newApply = function newApply(api, formatMessage, tr, curr
|
|
|
227
226
|
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
228
227
|
};
|
|
229
228
|
};
|
|
230
|
-
var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags,
|
|
229
|
+
var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache) {
|
|
231
230
|
var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
|
|
232
|
-
var isNestedEnabled = flags.isNestedEnabled
|
|
233
|
-
isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
|
|
231
|
+
var isNestedEnabled = flags.isNestedEnabled;
|
|
234
232
|
var activeNode = currentState.activeNode,
|
|
235
233
|
decorations = currentState.decorations,
|
|
236
234
|
isMenuOpen = currentState.isMenuOpen,
|
|
@@ -265,7 +263,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
|
|
|
265
263
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
266
264
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
267
265
|
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
268
|
-
if (
|
|
266
|
+
if (isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
269
267
|
var oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
270
268
|
return spec.type === 'drag-handle';
|
|
271
269
|
});
|
|
@@ -391,7 +389,7 @@ var oldApply = exports.oldApply = function oldApply(api, formatMessage, tr, curr
|
|
|
391
389
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
392
390
|
if (shouldCreateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
393
391
|
var _meta$activeNode7;
|
|
394
|
-
var _decs2 = (0, _decorations.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,
|
|
392
|
+
var _decs2 = (0, _decorations.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);
|
|
395
393
|
decorations = decorations.add(newState.doc, _decs2);
|
|
396
394
|
}
|
|
397
395
|
}
|
|
@@ -429,18 +427,16 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
429
427
|
var isOptimisedApply = isNestedEnabled && (0, _experiments.editorExperiment)('optimised-apply-dnd', true, {
|
|
430
428
|
exposure: true
|
|
431
429
|
});
|
|
432
|
-
var isTitleEnterImprovementEnabled = (0, _platformFeatureFlags.fg)('confluence_frontend_page_title_enter_improvements');
|
|
433
430
|
var flags = {
|
|
434
431
|
isNestedEnabled: isNestedEnabled,
|
|
435
|
-
isOptimisedApply: isOptimisedApply
|
|
436
|
-
isTitleEnterImprovementEnabled: isTitleEnterImprovementEnabled
|
|
432
|
+
isOptimisedApply: isOptimisedApply
|
|
437
433
|
};
|
|
438
434
|
if ((0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2')) {
|
|
439
435
|
// TODO: Remove this once FG is used in code
|
|
440
436
|
}
|
|
441
|
-
var
|
|
437
|
+
var anchorRectCache;
|
|
442
438
|
if (!(0, _anchorUtils.isAnchorSupported)() && (0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
|
|
443
|
-
|
|
439
|
+
anchorRectCache = new _anchorUtils.AnchorRectCache();
|
|
444
440
|
}
|
|
445
441
|
return new _safePlugin.SafePlugin({
|
|
446
442
|
key: key,
|
|
@@ -450,9 +446,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
450
446
|
},
|
|
451
447
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
452
448
|
if (isOptimisedApply) {
|
|
453
|
-
return newApply(api, formatMessage, tr, currentState, newState, flags,
|
|
449
|
+
return newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache);
|
|
454
450
|
}
|
|
455
|
-
return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags,
|
|
451
|
+
return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache);
|
|
456
452
|
}
|
|
457
453
|
},
|
|
458
454
|
props: {
|
|
@@ -502,8 +498,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
502
498
|
return false;
|
|
503
499
|
},
|
|
504
500
|
dragstart: function dragstart(view) {
|
|
505
|
-
var
|
|
506
|
-
(
|
|
501
|
+
var _anchorRectCache;
|
|
502
|
+
(_anchorRectCache = anchorRectCache) === null || _anchorRectCache === void 0 || _anchorRectCache.setEditorView(view);
|
|
507
503
|
view.dispatch(view.state.tr.setMeta(key, {
|
|
508
504
|
isPMDragging: true
|
|
509
505
|
}));
|
package/dist/cjs/ui/consts.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.getNestedNodeLeftPaddingMargin = exports.dropTargetMarginMap = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_NARROW_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DEFAULT_GAP = exports.DRAG_HANDLE_BORDER_RADIUS = void 0;
|
|
7
|
+
exports.topPositionAdjustment = exports.spaceLookupMap = exports.nodeMargins = exports.getNestedNodeLeftPaddingMargin = exports.dropTargetMarginMap = exports.dragHandleGap = exports.DRAG_HANDLE_ZINDEX = exports.DRAG_HANDLE_WIDTH = exports.DRAG_HANDLE_NARROW_GAP = exports.DRAG_HANDLE_MAX_WIDTH_PLUS_GAP = exports.DRAG_HANDLE_MAX_GAP = exports.DRAG_HANDLE_HEIGHT = exports.DRAG_HANDLE_DIVIDER_TOP_ADJUSTMENT = exports.DRAG_HANDLE_DEFAULT_GAP = exports.DRAG_HANDLE_BORDER_RADIUS = exports.DEFAULT_COLUMN_DISTRIBUTIONS = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
10
10
|
var _dropTargetMarginMap;
|
|
@@ -166,4 +166,11 @@ var nodeMargins = exports.nodeMargins = {
|
|
|
166
166
|
top: 0,
|
|
167
167
|
bottom: 0
|
|
168
168
|
}
|
|
169
|
+
};
|
|
170
|
+
var DEFAULT_COLUMN_DISTRIBUTIONS = exports.DEFAULT_COLUMN_DISTRIBUTIONS = {
|
|
171
|
+
1: 100,
|
|
172
|
+
2: 50,
|
|
173
|
+
3: 33.33,
|
|
174
|
+
4: 25,
|
|
175
|
+
5: 20
|
|
169
176
|
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET = exports.EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP = exports.DropTargetV2 = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
8
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
11
|
var _react = require("react");
|
|
@@ -17,7 +18,9 @@ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
|
17
18
|
var _decorations = require("../pm-plugins/decorations");
|
|
18
19
|
var _anchorUtils = require("../utils/anchor-utils");
|
|
19
20
|
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
21
|
+
var _inlineDropTarget = require("../utils/inline-drop-target");
|
|
20
22
|
var _consts = require("./consts");
|
|
23
|
+
var _inlineDropTarget2 = require("./inline-drop-target");
|
|
21
24
|
/**
|
|
22
25
|
* @jsxRuntime classic
|
|
23
26
|
* @jsx jsx
|
|
@@ -80,7 +83,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
80
83
|
node = _ref.node,
|
|
81
84
|
parent = _ref.parent,
|
|
82
85
|
editorWidth = _ref.editorWidth,
|
|
83
|
-
|
|
86
|
+
anchorRectCache = _ref.anchorRectCache,
|
|
84
87
|
position = _ref.position,
|
|
85
88
|
isNestedDropTarget = _ref.isNestedDropTarget,
|
|
86
89
|
dropTargetStyle = _ref.dropTargetStyle;
|
|
@@ -99,7 +102,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
99
102
|
var anchorName = node ? (0, _decorations.getNodeAnchor)(node) : '';
|
|
100
103
|
var heightStyleOffset = "var(--editor-block-controls-drop-indicator-gap, 0)/2";
|
|
101
104
|
var transformOffset = "var(".concat(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, ", 0)");
|
|
102
|
-
var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? (0, _anchorUtils.isAnchorSupported)() ? "calc(anchor-size(".concat(anchorName, " height)/2 + ").concat(heightStyleOffset, ")") : "calc(".concat(((
|
|
105
|
+
var heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? (0, _anchorUtils.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';
|
|
103
106
|
var transform = position === 'upper' ? "translateY(calc(-100% + ".concat(transformOffset, "))") : "translateY(".concat(transformOffset, ")");
|
|
104
107
|
return (0, _react2.css)({
|
|
105
108
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
@@ -109,7 +112,7 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
109
112
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
|
|
110
113
|
maxWidth: "".concat(editorWidth || 0, "px")
|
|
111
114
|
});
|
|
112
|
-
}, [
|
|
115
|
+
}, [anchorRectCache, editorWidth, node, position]);
|
|
113
116
|
var isFullHeight = (0, _react.useMemo)(function () {
|
|
114
117
|
return dropTargetStyle === 'fullHeight';
|
|
115
118
|
}, [dropTargetStyle]);
|
|
@@ -129,16 +132,16 @@ var HoverZone = function HoverZone(_ref) {
|
|
|
129
132
|
hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
|
|
130
133
|
});
|
|
131
134
|
};
|
|
132
|
-
var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(
|
|
135
|
+
var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(props) {
|
|
133
136
|
var _dynamicStyle;
|
|
134
|
-
var api =
|
|
135
|
-
getPos =
|
|
136
|
-
prevNode =
|
|
137
|
-
nextNode =
|
|
138
|
-
parentNode =
|
|
139
|
-
formatMessage =
|
|
140
|
-
|
|
141
|
-
dropTargetStyle =
|
|
137
|
+
var api = props.api,
|
|
138
|
+
getPos = props.getPos,
|
|
139
|
+
prevNode = props.prevNode,
|
|
140
|
+
nextNode = props.nextNode,
|
|
141
|
+
parentNode = props.parentNode,
|
|
142
|
+
formatMessage = props.formatMessage,
|
|
143
|
+
anchorRectCache = props.anchorRectCache,
|
|
144
|
+
dropTargetStyle = props.dropTargetStyle;
|
|
142
145
|
var _useState = (0, _react.useState)(false),
|
|
143
146
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
144
147
|
isDraggedOver = _useState2[0],
|
|
@@ -148,8 +151,8 @@ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
148
151
|
var isNestedDropTarget = (parentNode === null || parentNode === void 0 ? void 0 : parentNode.type.name) !== 'doc';
|
|
149
152
|
var onDrop = function onDrop() {
|
|
150
153
|
var _api$blockControls;
|
|
151
|
-
var
|
|
152
|
-
activeNode =
|
|
154
|
+
var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
155
|
+
activeNode = _ref2.activeNode;
|
|
153
156
|
if (!activeNode) {
|
|
154
157
|
return;
|
|
155
158
|
}
|
|
@@ -174,7 +177,7 @@ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
174
177
|
onDrop: onDrop,
|
|
175
178
|
node: prevNode,
|
|
176
179
|
editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
|
|
177
|
-
|
|
180
|
+
anchorRectCache: anchorRectCache,
|
|
178
181
|
position: "upper",
|
|
179
182
|
isNestedDropTarget: isNestedDropTarget
|
|
180
183
|
}), (0, _react2.jsx)("div", {
|
|
@@ -202,9 +205,13 @@ var DropTargetV2 = exports.DropTargetV2 = function DropTargetV2(_ref2) {
|
|
|
202
205
|
node: nextNode,
|
|
203
206
|
parent: parentNode,
|
|
204
207
|
editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
|
|
205
|
-
|
|
208
|
+
anchorRectCache: anchorRectCache,
|
|
206
209
|
position: "lower",
|
|
207
210
|
isNestedDropTarget: isNestedDropTarget,
|
|
208
211
|
dropTargetStyle: dropTargetStyle
|
|
209
|
-
}))
|
|
212
|
+
}), (0, _inlineDropTarget.shouldAllowInlineDropTarget)(isNestedDropTarget, nextNode) && (0, _react2.jsx)(_react.Fragment, null, (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget, (0, _extends2.default)({}, props, {
|
|
213
|
+
position: "left"
|
|
214
|
+
})), (0, _react2.jsx)(_inlineDropTarget2.InlineDropTarget, (0, _extends2.default)({}, props, {
|
|
215
|
+
position: "right"
|
|
216
|
+
}))));
|
|
210
217
|
};
|