@atlaskit/editor-plugin-block-controls 2.10.0 → 2.11.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 +19 -0
- package/dist/cjs/pm-plugins/decorations-anchor.js +97 -0
- package/dist/cjs/pm-plugins/decorations-common.js +49 -0
- package/dist/cjs/pm-plugins/decorations-drag-handle.js +88 -0
- package/dist/cjs/pm-plugins/{decorations.js → decorations-drop-target.js} +11 -209
- package/dist/cjs/pm-plugins/main.js +21 -19
- package/dist/cjs/ui/drop-target-v2.js +3 -3
- package/dist/cjs/ui/global-styles.js +101 -86
- package/dist/cjs/ui/inline-drop-target.js +3 -3
- package/dist/es2019/pm-plugins/decorations-anchor.js +89 -0
- package/dist/es2019/pm-plugins/decorations-common.js +31 -0
- package/dist/es2019/pm-plugins/decorations-drag-handle.js +79 -0
- package/dist/es2019/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -193
- package/dist/es2019/pm-plugins/main.js +3 -1
- package/dist/es2019/ui/drop-target-v2.js +1 -1
- package/dist/es2019/ui/global-styles.js +17 -6
- package/dist/es2019/ui/inline-drop-target.js +1 -1
- package/dist/esm/pm-plugins/decorations-anchor.js +90 -0
- package/dist/esm/pm-plugins/decorations-common.js +42 -0
- package/dist/esm/pm-plugins/decorations-drag-handle.js +81 -0
- package/dist/esm/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -204
- package/dist/esm/pm-plugins/main.js +3 -1
- package/dist/esm/ui/drop-target-v2.js +1 -1
- package/dist/esm/ui/global-styles.js +101 -86
- package/dist/esm/ui/inline-drop-target.js +1 -1
- package/dist/types/pm-plugins/decorations-anchor.d.ts +13 -0
- package/dist/types/pm-plugins/decorations-common.d.ts +7 -0
- package/dist/types/pm-plugins/decorations-drag-handle.d.ts +7 -0
- package/dist/types/pm-plugins/decorations-drop-target.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/decorations-anchor.d.ts +13 -0
- package/dist/types-ts4.5/pm-plugins/decorations-common.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/decorations-drag-handle.d.ts +7 -0
- package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +17 -0
- package/package.json +4 -4
- package/dist/types/pm-plugins/decorations.d.ts +0 -35
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#156360](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/156360)
|
|
8
|
+
[`482dbb03dbf68`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/482dbb03dbf68) -
|
|
9
|
+
[ux] Ignore embedCard nodes that have wrapped layout when creating node decs
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## 2.10.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`19a9f330504b9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/19a9f330504b9) -
|
|
20
|
+
ED-25120 refactor decorations file
|
|
21
|
+
|
|
3
22
|
## 2.10.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.shouldDescendIntoNode = exports.nodeDecorations = exports.findNodeDecs = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
11
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
12
|
+
var _decorationsCommon = require("./decorations-common");
|
|
13
|
+
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
|
|
14
|
+
var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
|
|
15
|
+
var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
|
|
16
|
+
// Optimisation to avoid drawing node decorations for empty table cells
|
|
17
|
+
if (['tableCell', 'tableHeader'].includes(node.type.name) && !(0, _experiments.editorExperiment)('table-nested-dnd', true) && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3')) {
|
|
18
|
+
var _node$firstChild;
|
|
19
|
+
if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
24
|
+
};
|
|
25
|
+
var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
26
|
+
var isEmbedCard = 'embedCard' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3');
|
|
27
|
+
|
|
28
|
+
// TODO use isWrappedMedia when clean up the feature flag
|
|
29
|
+
var isMediaSingle = 'mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1');
|
|
30
|
+
return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : IGNORE_NODES.includes(node.type.name);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Find node decorations in the pos range between from and to (non-inclusive)
|
|
35
|
+
* @param decorations
|
|
36
|
+
* @param from
|
|
37
|
+
* @param to
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
var findNodeDecs = exports.findNodeDecs = function findNodeDecs(decorations, from, to) {
|
|
41
|
+
var newfrom = from;
|
|
42
|
+
var newTo = to;
|
|
43
|
+
|
|
44
|
+
// make it non-inclusive
|
|
45
|
+
if (newfrom !== undefined) {
|
|
46
|
+
newfrom++;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// make it non-inclusive
|
|
50
|
+
if (newTo !== undefined) {
|
|
51
|
+
newTo--;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// return empty array if range reversed
|
|
55
|
+
if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
|
|
56
|
+
return new Array();
|
|
57
|
+
}
|
|
58
|
+
return decorations.find(newfrom, newTo, function (spec) {
|
|
59
|
+
return spec.type === _decorationsCommon.TYPE_NODE_DEC;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
63
|
+
var decs = [];
|
|
64
|
+
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
65
|
+
var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
|
|
66
|
+
newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
|
|
67
|
+
var _Decoration$node;
|
|
68
|
+
var depth = 0;
|
|
69
|
+
var anchorName;
|
|
70
|
+
var shouldDescend = shouldDescendIntoNode(node);
|
|
71
|
+
anchorName = (0, _decorationsCommon.getNodeAnchor)(node);
|
|
72
|
+
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
73
|
+
var _anchorName;
|
|
74
|
+
// Doesn't descend into a node
|
|
75
|
+
if (node.isInline) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (shouldIgnoreNode(node)) {
|
|
79
|
+
return shouldDescend; //skip over, don't consider it a valid depth
|
|
80
|
+
}
|
|
81
|
+
depth = newState.doc.resolve(pos).depth;
|
|
82
|
+
anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
|
|
83
|
+
} else {
|
|
84
|
+
var _anchorName2;
|
|
85
|
+
anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
86
|
+
}
|
|
87
|
+
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$node = {
|
|
88
|
+
style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', " ").concat((0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? '' : 'position: relative; z-index: 1;')
|
|
89
|
+
}, (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-node-type', node.type.name), (0, _defineProperty2.default)(_Decoration$node, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node), {
|
|
90
|
+
type: _decorationsCommon.TYPE_NODE_DEC,
|
|
91
|
+
anchorName: anchorName,
|
|
92
|
+
nodeType: node.type.name
|
|
93
|
+
}));
|
|
94
|
+
return shouldDescend && depth < (0, _decorationsCommon.getNestedDepth)();
|
|
95
|
+
});
|
|
96
|
+
return decs;
|
|
97
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.unmountDecorations = exports.getNodeAnchor = exports.getNestedDepth = exports.TYPE_NODE_DEC = exports.TYPE_HANDLE_DEC = exports.TYPE_DROP_TARGET_DEC = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
13
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
14
|
+
var TYPE_DROP_TARGET_DEC = exports.TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
|
|
15
|
+
var TYPE_HANDLE_DEC = exports.TYPE_HANDLE_DEC = 'drag-handle';
|
|
16
|
+
var TYPE_NODE_DEC = exports.TYPE_NODE_DEC = 'node-decoration';
|
|
17
|
+
var getNestedDepth = exports.getNestedDepth = function getNestedDepth() {
|
|
18
|
+
return (0, _experiments.editorExperiment)('nested-dnd', true) ? 100 : 0;
|
|
19
|
+
};
|
|
20
|
+
var getNodeAnchor = exports.getNodeAnchor = function getNodeAnchor(node) {
|
|
21
|
+
var handleId = ObjHash.getForNode(node);
|
|
22
|
+
return "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
23
|
+
};
|
|
24
|
+
var ObjHash = /*#__PURE__*/function () {
|
|
25
|
+
function ObjHash() {
|
|
26
|
+
(0, _classCallCheck2.default)(this, ObjHash);
|
|
27
|
+
}
|
|
28
|
+
(0, _createClass2.default)(ObjHash, null, [{
|
|
29
|
+
key: "getForNode",
|
|
30
|
+
value: function getForNode(node) {
|
|
31
|
+
if (this.caching.has(node)) {
|
|
32
|
+
return this.caching.get(node);
|
|
33
|
+
}
|
|
34
|
+
var uniqueId = (0, _uuid.default)();
|
|
35
|
+
this.caching.set(node, uniqueId);
|
|
36
|
+
return uniqueId;
|
|
37
|
+
}
|
|
38
|
+
}]);
|
|
39
|
+
return ObjHash;
|
|
40
|
+
}();
|
|
41
|
+
(0, _defineProperty2.default)(ObjHash, "caching", new WeakMap());
|
|
42
|
+
var unmountDecorations = exports.unmountDecorations = function unmountDecorations(selector) {
|
|
43
|
+
// Removing decorations manually instead of using native destroy function in prosemirror API
|
|
44
|
+
// as it was more responsive and causes less re-rendering
|
|
45
|
+
var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
|
|
46
|
+
decorationsToRemove.forEach(function (el) {
|
|
47
|
+
_reactDom.default.unmountComponentAtNode(el);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.findHandleDec = exports.emptyParagraphNodeDecorations = exports.dragHandleDecoration = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _bindEventListener = require("bind-event-listener");
|
|
11
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
13
|
+
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
14
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
16
|
+
var _dragHandle = require("../ui/drag-handle");
|
|
17
|
+
var _decorationsCommon = require("./decorations-common");
|
|
18
|
+
var emptyParagraphNodeDecorations = exports.emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
19
|
+
var anchorName = "--node-anchor-paragraph-0";
|
|
20
|
+
var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
|
|
21
|
+
return _view.Decoration.node(0, 2, (0, _defineProperty2.default)({
|
|
22
|
+
style: style
|
|
23
|
+
}, 'data-drag-handler-anchor-name', anchorName), {
|
|
24
|
+
type: _decorationsCommon.TYPE_NODE_DEC
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var findHandleDec = exports.findHandleDec = function findHandleDec(decorations, from, to) {
|
|
28
|
+
return decorations.find(from, to, function (spec) {
|
|
29
|
+
return spec.type === _decorationsCommon.TYPE_HANDLE_DEC;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
|
|
33
|
+
(0, _decorationsCommon.unmountDecorations)('data-blocks-drag-handle-container');
|
|
34
|
+
var unbind;
|
|
35
|
+
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
36
|
+
var element = document.createElement('span');
|
|
37
|
+
// Need to set it to inline to avoid text being split when merging two paragraphs
|
|
38
|
+
// platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
|
|
39
|
+
element.style.display = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
|
|
40
|
+
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
41
|
+
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
42
|
+
var isTopLevelNode = true;
|
|
43
|
+
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
44
|
+
var newPos = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
|
|
45
|
+
if (typeof newPos === 'number') {
|
|
46
|
+
var $pos = view.state.doc.resolve(newPos);
|
|
47
|
+
isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
|
|
48
|
+
}
|
|
49
|
+
/*
|
|
50
|
+
* We disable mouseover event to fix flickering issue on hover
|
|
51
|
+
* However, the tooltip for nested drag handle is no long working.
|
|
52
|
+
*/
|
|
53
|
+
if (newPos === undefined || !isTopLevelNode) {
|
|
54
|
+
// This will also hide the tooltip.
|
|
55
|
+
unbind = (0, _bindEventListener.bind)(element, {
|
|
56
|
+
type: 'mouseover',
|
|
57
|
+
listener: function listener(e) {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
65
|
+
// due to margins applied to other nodes eg. Headings
|
|
66
|
+
element.style.clear = 'unset';
|
|
67
|
+
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
|
|
68
|
+
view: view,
|
|
69
|
+
api: api,
|
|
70
|
+
formatMessage: formatMessage,
|
|
71
|
+
getPos: getPos,
|
|
72
|
+
anchorName: anchorName,
|
|
73
|
+
nodeType: nodeType,
|
|
74
|
+
handleOptions: handleOptions,
|
|
75
|
+
isTopLevelNode: isTopLevelNode
|
|
76
|
+
}), element);
|
|
77
|
+
return element;
|
|
78
|
+
}, {
|
|
79
|
+
side: -1,
|
|
80
|
+
type: _decorationsCommon.TYPE_HANDLE_DEC,
|
|
81
|
+
testid: "".concat(_decorationsCommon.TYPE_HANDLE_DEC, "-").concat((0, _uuid.default)()),
|
|
82
|
+
destroy: function destroy() {
|
|
83
|
+
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
84
|
+
unbind && unbind();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
};
|
|
@@ -4,39 +4,30 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
8
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
7
|
+
exports.findDropTargetDecs = exports.dropTargetDecorations = exports.createDropTargetDecoration = void 0;
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
9
|
var _react = require("react");
|
|
12
|
-
var _bindEventListener = require("bind-event-listener");
|
|
13
10
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
14
|
-
var _uuid = _interopRequireDefault(require("uuid"));
|
|
15
11
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
12
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
17
13
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
14
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
19
15
|
var _consts = require("../ui/consts");
|
|
20
|
-
var _dragHandle = require("../ui/drag-handle");
|
|
21
16
|
var _dropTarget = require("../ui/drop-target");
|
|
22
17
|
var _dropTargetV = require("../ui/drop-target-v2");
|
|
23
18
|
var _dragTargetDebug = require("../utils/drag-target-debug");
|
|
24
19
|
var _validation = require("../utils/validation");
|
|
20
|
+
var _decorationsCommon = require("./decorations-common");
|
|
25
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
26
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
27
23
|
var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
|
|
28
|
-
var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
|
|
29
24
|
var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
|
|
30
25
|
var DISABLE_CHILD_DROP_TARGET = ['orderedList', 'bulletList'];
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
};
|
|
37
|
-
var getNodeAnchor = exports.getNodeAnchor = function getNodeAnchor(node) {
|
|
38
|
-
var handleId = ObjHash.getForNode(node);
|
|
39
|
-
return "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
26
|
+
var shouldDescend = function shouldDescend(node) {
|
|
27
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
|
|
28
|
+
return !['mediaSingle', 'paragraph', 'heading'].includes(node.type.name);
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
40
31
|
};
|
|
41
32
|
var getNodeMargins = function getNodeMargins(node) {
|
|
42
33
|
if (!node) {
|
|
@@ -81,12 +72,6 @@ var getGapAndOffset = function getGapAndOffset(prevNode, nextNode, parentNode) {
|
|
|
81
72
|
offset: offset
|
|
82
73
|
};
|
|
83
74
|
};
|
|
84
|
-
var shouldDescend = function shouldDescend(node) {
|
|
85
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_drag_and_drop_target_v2')) {
|
|
86
|
-
return !['mediaSingle', 'paragraph', 'heading'].includes(node.type.name);
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
75
|
|
|
91
76
|
/**
|
|
92
77
|
* Find drop target decorations in the pos range between from and to
|
|
@@ -97,42 +82,7 @@ var shouldDescend = function shouldDescend(node) {
|
|
|
97
82
|
*/
|
|
98
83
|
var findDropTargetDecs = exports.findDropTargetDecs = function findDropTargetDecs(decorations, from, to) {
|
|
99
84
|
return decorations.find(from, to, function (spec) {
|
|
100
|
-
return spec.type === TYPE_DROP_TARGET_DEC;
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
var findHandleDec = exports.findHandleDec = function findHandleDec(decorations, from, to) {
|
|
104
|
-
return decorations.find(from, to, function (spec) {
|
|
105
|
-
return spec.type === TYPE_HANDLE_DEC;
|
|
106
|
-
});
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Find node decorations in the pos range between from and to (non-inclusive)
|
|
111
|
-
* @param decorations
|
|
112
|
-
* @param from
|
|
113
|
-
* @param to
|
|
114
|
-
* @returns
|
|
115
|
-
*/
|
|
116
|
-
var findNodeDecs = exports.findNodeDecs = function findNodeDecs(decorations, from, to) {
|
|
117
|
-
var newfrom = from;
|
|
118
|
-
var newTo = to;
|
|
119
|
-
|
|
120
|
-
// make it non-inclusive
|
|
121
|
-
if (newfrom !== undefined) {
|
|
122
|
-
newfrom++;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// make it non-inclusive
|
|
126
|
-
if (newTo !== undefined) {
|
|
127
|
-
newTo--;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// return empty array if range reversed
|
|
131
|
-
if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
|
|
132
|
-
return new Array();
|
|
133
|
-
}
|
|
134
|
-
return decorations.find(newfrom, newTo, function (spec) {
|
|
135
|
-
return spec.type === TYPE_NODE_DEC;
|
|
85
|
+
return spec.type === _decorationsCommon.TYPE_DROP_TARGET_DEC;
|
|
136
86
|
});
|
|
137
87
|
};
|
|
138
88
|
var createDropTargetDecoration = exports.createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
|
|
@@ -158,12 +108,12 @@ var createDropTargetDecoration = exports.createDropTargetDecoration = function c
|
|
|
158
108
|
}
|
|
159
109
|
return element;
|
|
160
110
|
}, {
|
|
161
|
-
type: TYPE_DROP_TARGET_DEC,
|
|
111
|
+
type: _decorationsCommon.TYPE_DROP_TARGET_DEC,
|
|
162
112
|
side: side
|
|
163
113
|
});
|
|
164
114
|
};
|
|
165
115
|
var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
|
|
166
|
-
unmountDecorations('data-blocks-drop-target-container');
|
|
116
|
+
(0, _decorationsCommon.unmountDecorations)('data-blocks-drop-target-container');
|
|
167
117
|
var decs = [];
|
|
168
118
|
var POS_END_OF_DOC = newState.doc.nodeSize - 2;
|
|
169
119
|
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
@@ -249,7 +199,7 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
249
199
|
} else {
|
|
250
200
|
prevNode = node;
|
|
251
201
|
}
|
|
252
|
-
return depth < getNestedDepth() && shouldDescend(node);
|
|
202
|
+
return depth < (0, _decorationsCommon.getNestedDepth)() && shouldDescend(node);
|
|
253
203
|
});
|
|
254
204
|
if (docTo === POS_END_OF_DOC) {
|
|
255
205
|
decs.push(createDropTargetDecoration(POS_END_OF_DOC, {
|
|
@@ -260,152 +210,4 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
260
210
|
}, undefined, anchorRectCache));
|
|
261
211
|
}
|
|
262
212
|
return decs;
|
|
263
|
-
};
|
|
264
|
-
var emptyParagraphNodeDecorations = exports.emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
265
|
-
var anchorName = "--node-anchor-paragraph-0";
|
|
266
|
-
var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
|
|
267
|
-
return _view.Decoration.node(0, 2, (0, _defineProperty2.default)({
|
|
268
|
-
style: style
|
|
269
|
-
}, 'data-drag-handler-anchor-name', anchorName), {
|
|
270
|
-
type: TYPE_NODE_DEC
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
var ObjHash = /*#__PURE__*/function () {
|
|
274
|
-
function ObjHash() {
|
|
275
|
-
(0, _classCallCheck2.default)(this, ObjHash);
|
|
276
|
-
}
|
|
277
|
-
(0, _createClass2.default)(ObjHash, null, [{
|
|
278
|
-
key: "getForNode",
|
|
279
|
-
value: function getForNode(node) {
|
|
280
|
-
if (this.caching.has(node)) {
|
|
281
|
-
return this.caching.get(node);
|
|
282
|
-
}
|
|
283
|
-
var uniqueId = (0, _uuid.default)();
|
|
284
|
-
this.caching.set(node, uniqueId);
|
|
285
|
-
return uniqueId;
|
|
286
|
-
}
|
|
287
|
-
}]);
|
|
288
|
-
return ObjHash;
|
|
289
|
-
}();
|
|
290
|
-
(0, _defineProperty2.default)(ObjHash, "caching", new WeakMap());
|
|
291
|
-
var shouldIgnoreNode = function shouldIgnoreNode(node) {
|
|
292
|
-
// TODO use isWrappedMedia when clean up the featue flag
|
|
293
|
-
if ('mediaSingle' === node.type.name && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_1')) {
|
|
294
|
-
if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return IGNORE_NODES.includes(node.type.name);
|
|
299
|
-
};
|
|
300
|
-
var shouldDescendIntoNode = exports.shouldDescendIntoNode = function shouldDescendIntoNode(node) {
|
|
301
|
-
// Optimisation to avoid drawing node decorations for empty table cells
|
|
302
|
-
if (['tableCell', 'tableHeader'].includes(node.type.name) && !(0, _experiments.editorExperiment)('table-nested-dnd', true) && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3')) {
|
|
303
|
-
var _node$firstChild;
|
|
304
|
-
if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
|
|
309
|
-
};
|
|
310
|
-
var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState, from, to) {
|
|
311
|
-
var decs = [];
|
|
312
|
-
var docFrom = from === undefined || from < 0 ? 0 : from;
|
|
313
|
-
var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
|
|
314
|
-
newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
|
|
315
|
-
var _Decoration$node2;
|
|
316
|
-
var depth = 0;
|
|
317
|
-
var anchorName;
|
|
318
|
-
var shouldDescend = shouldDescendIntoNode(node);
|
|
319
|
-
var handleId = ObjHash.getForNode(node);
|
|
320
|
-
anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
|
|
321
|
-
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
322
|
-
var _anchorName;
|
|
323
|
-
// Doesn't descend into a node
|
|
324
|
-
if (node.isInline) {
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
if (shouldIgnoreNode(node)) {
|
|
328
|
-
return shouldDescend; //skip over, don't consider it a valid depth
|
|
329
|
-
}
|
|
330
|
-
depth = newState.doc.resolve(pos).depth;
|
|
331
|
-
anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
|
|
332
|
-
} else {
|
|
333
|
-
var _anchorName2;
|
|
334
|
-
anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
335
|
-
}
|
|
336
|
-
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
337
|
-
style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;")
|
|
338
|
-
}, (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node2), {
|
|
339
|
-
type: TYPE_NODE_DEC,
|
|
340
|
-
anchorName: anchorName,
|
|
341
|
-
nodeType: node.type.name
|
|
342
|
-
}));
|
|
343
|
-
return shouldDescend && depth < getNestedDepth();
|
|
344
|
-
});
|
|
345
|
-
return decs;
|
|
346
|
-
};
|
|
347
|
-
var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
|
|
348
|
-
unmountDecorations('data-blocks-drag-handle-container');
|
|
349
|
-
var unbind;
|
|
350
|
-
return _view.Decoration.widget(pos, function (view, getPos) {
|
|
351
|
-
var element = document.createElement('span');
|
|
352
|
-
// Need to set it to inline to avoid text being split when merging two paragraphs
|
|
353
|
-
// platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
|
|
354
|
-
element.style.display = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
|
|
355
|
-
element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
|
|
356
|
-
element.setAttribute('data-blocks-drag-handle-container', 'true');
|
|
357
|
-
var isTopLevelNode = true;
|
|
358
|
-
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
359
|
-
var newPos = (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
|
|
360
|
-
if (typeof newPos === 'number') {
|
|
361
|
-
var $pos = view.state.doc.resolve(newPos);
|
|
362
|
-
isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
|
|
363
|
-
}
|
|
364
|
-
/*
|
|
365
|
-
* We disable mouseover event to fix flickering issue on hover
|
|
366
|
-
* However, the tooltip for nested drag handle is no long working.
|
|
367
|
-
*/
|
|
368
|
-
if (newPos === undefined || !isTopLevelNode) {
|
|
369
|
-
// This will also hide the tooltip.
|
|
370
|
-
unbind = (0, _bindEventListener.bind)(element, {
|
|
371
|
-
type: 'mouseover',
|
|
372
|
-
listener: function listener(e) {
|
|
373
|
-
e.stopPropagation();
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// There are times when global clear: "both" styles are applied to this decoration causing jumpiness
|
|
380
|
-
// due to margins applied to other nodes eg. Headings
|
|
381
|
-
element.style.clear = 'unset';
|
|
382
|
-
_reactDom.default.render( /*#__PURE__*/(0, _react.createElement)(_dragHandle.DragHandle, {
|
|
383
|
-
view: view,
|
|
384
|
-
api: api,
|
|
385
|
-
formatMessage: formatMessage,
|
|
386
|
-
getPos: getPos,
|
|
387
|
-
anchorName: anchorName,
|
|
388
|
-
nodeType: nodeType,
|
|
389
|
-
handleOptions: handleOptions,
|
|
390
|
-
isTopLevelNode: isTopLevelNode
|
|
391
|
-
}), element);
|
|
392
|
-
return element;
|
|
393
|
-
}, {
|
|
394
|
-
side: -1,
|
|
395
|
-
type: TYPE_HANDLE_DEC,
|
|
396
|
-
testid: "".concat(TYPE_HANDLE_DEC, "-").concat((0, _uuid.default)()),
|
|
397
|
-
destroy: function destroy() {
|
|
398
|
-
if ((0, _experiments.editorExperiment)('nested-dnd', true)) {
|
|
399
|
-
unbind && unbind();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
});
|
|
403
|
-
};
|
|
404
|
-
var unmountDecorations = function unmountDecorations(selector) {
|
|
405
|
-
// Removing decorations manually instead of using native destroy function in prosemirror API
|
|
406
|
-
// as it was more responsive and causes less re-rendering
|
|
407
|
-
var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
|
|
408
|
-
decorationsToRemove.forEach(function (el) {
|
|
409
|
-
_reactDom.default.unmountComponentAtNode(el);
|
|
410
|
-
});
|
|
411
213
|
};
|