@atlaskit/editor-plugin-block-controls 1.4.34 → 1.4.35
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 +11 -0
- package/dist/cjs/pm-plugins/decorations.js +15 -4
- package/dist/cjs/pm-plugins/main.js +8 -1
- package/dist/cjs/ui/global-styles.js +9 -2
- package/dist/es2019/pm-plugins/decorations.js +12 -0
- package/dist/es2019/pm-plugins/main.js +8 -2
- package/dist/es2019/ui/global-styles.js +9 -0
- package/dist/esm/pm-plugins/decorations.js +14 -3
- package/dist/esm/pm-plugins/main.js +9 -2
- package/dist/esm/ui/global-styles.js +8 -2
- package/dist/types/pm-plugins/decorations.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.4.35
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#115170](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115170)
|
|
8
|
+
[`d3d39a486f0d9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d3d39a486f0d9) -
|
|
9
|
+
Fix drag handle position when deleting a paragraph
|
|
10
|
+
- [#115170](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115170)
|
|
11
|
+
[`108a85e557e41`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/108a85e557e41) -
|
|
12
|
+
Hide drag handle on empty paragraph
|
|
13
|
+
|
|
3
14
|
## 1.4.34
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -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.nodeDecorations = exports.mouseMoveWrapperDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
7
|
+
exports.nodeDecorations = exports.mouseMoveWrapperDecorations = exports.emptyParagraphNodeDecorations = exports.dropTargetDecorations = exports.dragHandleDecoration = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
@@ -69,10 +69,19 @@ var dropTargetDecorations = exports.dropTargetDecorations = function dropTargetD
|
|
|
69
69
|
decorationState: decorationState
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
+
var emptyParagraphNodeDecorations = exports.emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
73
|
+
var anchorName = "--node-anchor-paragraph-0";
|
|
74
|
+
var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
|
|
75
|
+
return _view.Decoration.node(0, 2, (0, _defineProperty2.default)({
|
|
76
|
+
style: style
|
|
77
|
+
}, 'data-drag-handler-anchor-name', anchorName), {
|
|
78
|
+
type: 'node-decoration'
|
|
79
|
+
});
|
|
80
|
+
};
|
|
72
81
|
var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState) {
|
|
73
82
|
var decs = [];
|
|
74
83
|
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
75
|
-
var _Decoration$
|
|
84
|
+
var _Decoration$node2;
|
|
76
85
|
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
77
86
|
var style;
|
|
78
87
|
if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
@@ -80,9 +89,11 @@ var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newStat
|
|
|
80
89
|
} else {
|
|
81
90
|
style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '');
|
|
82
91
|
}
|
|
83
|
-
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$
|
|
92
|
+
decs.push(_view.Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
84
93
|
style: style
|
|
85
|
-
}, (0, _defineProperty2.default)(_Decoration$
|
|
94
|
+
}, (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), (0, _defineProperty2.default)(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _Decoration$node2), {
|
|
95
|
+
type: 'node-decoration'
|
|
96
|
+
}));
|
|
86
97
|
return false;
|
|
87
98
|
});
|
|
88
99
|
return decs;
|
|
@@ -236,6 +236,14 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
236
236
|
if (tr.docChanged && !redrawDecorations) {
|
|
237
237
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
238
238
|
}
|
|
239
|
+
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
240
|
+
var hasNodeDecoration = decorations.find().some(function (_ref11) {
|
|
241
|
+
var spec = _ref11.spec;
|
|
242
|
+
return spec.type === 'node-decoration';
|
|
243
|
+
});
|
|
244
|
+
if (!hasNodeDecoration && isEmptyDoc) {
|
|
245
|
+
decorations = decorations.add(newState.doc, [(0, _decorations.emptyParagraphNodeDecorations)()]);
|
|
246
|
+
}
|
|
239
247
|
|
|
240
248
|
// Map active node position when the document changes
|
|
241
249
|
var mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
@@ -243,7 +251,6 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
|
243
251
|
anchorName: activeNode.anchorName,
|
|
244
252
|
nodeType: activeNode.nodeType
|
|
245
253
|
} : activeNode;
|
|
246
|
-
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
247
254
|
return {
|
|
248
255
|
decorations: decorations,
|
|
249
256
|
decorationState: decorationState,
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.GlobalStylesWrapper = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _react = require("@emotion/react");
|
|
8
10
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
9
11
|
/** @jsx jsx */
|
|
@@ -32,13 +34,18 @@ var extendedHoverZone = (0, _react.css)({
|
|
|
32
34
|
display: 'none'
|
|
33
35
|
}
|
|
34
36
|
});
|
|
35
|
-
var
|
|
37
|
+
var paragraphWithTrailingBreak = '+ p > .ProseMirror-trailingBreak';
|
|
38
|
+
var paragraphWithCursorTarget = '+ p > .cursor-target';
|
|
39
|
+
var globalStyles = (0, _react.css)((0, _defineProperty2.default)({
|
|
36
40
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
37
41
|
'.ProseMirror-widget:first-child + *': {
|
|
38
42
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
|
|
39
43
|
marginTop: '0 !important'
|
|
40
44
|
}
|
|
41
|
-
})
|
|
45
|
+
}, ".ProseMirror-widget[data-blocks-drag-handle-container=\"true\"]:has(".concat(paragraphWithTrailingBreak, "):not(:has(").concat(paragraphWithCursorTarget, "))"), {
|
|
46
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
47
|
+
display: 'none !important'
|
|
48
|
+
}));
|
|
42
49
|
var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
43
50
|
return (0, _react.jsx)(_react.Global, {
|
|
44
51
|
styles: [globalStyles, (0, _platformFeatureFlags.getBooleanFF)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') && extendedHoverZone]
|
|
@@ -61,6 +61,16 @@ export const dropTargetDecorations = (oldState, newState, api) => {
|
|
|
61
61
|
decorationState
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
+
export const emptyParagraphNodeDecorations = () => {
|
|
65
|
+
const anchorName = `--node-anchor-paragraph-0`;
|
|
66
|
+
const style = `anchor-name: ${anchorName}; margin-top: 0px;`;
|
|
67
|
+
return Decoration.node(0, 2, {
|
|
68
|
+
style,
|
|
69
|
+
['data-drag-handler-anchor-name']: anchorName
|
|
70
|
+
}, {
|
|
71
|
+
type: 'node-decoration'
|
|
72
|
+
});
|
|
73
|
+
};
|
|
64
74
|
export const nodeDecorations = newState => {
|
|
65
75
|
const decs = [];
|
|
66
76
|
newState.doc.descendants((node, pos, _parent, index) => {
|
|
@@ -75,6 +85,8 @@ export const nodeDecorations = newState => {
|
|
|
75
85
|
style,
|
|
76
86
|
['data-drag-handler-anchor-name']: anchorName,
|
|
77
87
|
['data-drag-handler-node-type']: node.type.name
|
|
88
|
+
}, {
|
|
89
|
+
type: 'node-decoration'
|
|
78
90
|
}));
|
|
79
91
|
return false;
|
|
80
92
|
});
|
|
@@ -9,7 +9,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
9
9
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
10
10
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
11
11
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
12
|
-
import { dragHandleDecoration, dropTargetDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
|
|
12
|
+
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
|
|
13
13
|
import { handleMouseOver } from './handle-mouse-over';
|
|
14
14
|
export const key = new PluginKey('blockControls');
|
|
15
15
|
const destroyFn = api => {
|
|
@@ -227,6 +227,13 @@ export const createPlugin = api => {
|
|
|
227
227
|
if (tr.docChanged && !redrawDecorations) {
|
|
228
228
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
229
229
|
}
|
|
230
|
+
const isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
231
|
+
const hasNodeDecoration = decorations.find().some(({
|
|
232
|
+
spec
|
|
233
|
+
}) => spec.type === 'node-decoration');
|
|
234
|
+
if (!hasNodeDecoration && isEmptyDoc) {
|
|
235
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
236
|
+
}
|
|
230
237
|
|
|
231
238
|
// Map active node position when the document changes
|
|
232
239
|
const mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
@@ -234,7 +241,6 @@ export const createPlugin = api => {
|
|
|
234
241
|
anchorName: activeNode.anchorName,
|
|
235
242
|
nodeType: activeNode.nodeType
|
|
236
243
|
} : activeNode;
|
|
237
|
-
const isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
238
244
|
return {
|
|
239
245
|
decorations,
|
|
240
246
|
decorationState,
|
|
@@ -25,11 +25,20 @@ const extendedHoverZone = css({
|
|
|
25
25
|
display: 'none'
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
+
const paragraphWithTrailingBreak = '+ p > .ProseMirror-trailingBreak';
|
|
29
|
+
const paragraphWithCursorTarget = '+ p > .cursor-target';
|
|
28
30
|
const globalStyles = css({
|
|
29
31
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
30
32
|
'.ProseMirror-widget:first-child + *': {
|
|
31
33
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
|
|
32
34
|
marginTop: '0 !important'
|
|
35
|
+
},
|
|
36
|
+
// Currently, we are hiding the drag handle container by checking if the paragraph has a trailing break and no cursor target
|
|
37
|
+
// TODO ED-23827 add a classname to empty paragraphs for easier targeting
|
|
38
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-values
|
|
39
|
+
[`.ProseMirror-widget[data-blocks-drag-handle-container="true"]:has(${paragraphWithTrailingBreak}):not(:has(${paragraphWithCursorTarget}))`]: {
|
|
40
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
41
|
+
display: 'none !important'
|
|
33
42
|
}
|
|
34
43
|
});
|
|
35
44
|
export const GlobalStylesWrapper = () => {
|
|
@@ -62,10 +62,19 @@ export var dropTargetDecorations = function dropTargetDecorations(oldState, newS
|
|
|
62
62
|
decorationState: decorationState
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
|
+
export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
|
|
66
|
+
var anchorName = "--node-anchor-paragraph-0";
|
|
67
|
+
var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
|
|
68
|
+
return Decoration.node(0, 2, _defineProperty({
|
|
69
|
+
style: style
|
|
70
|
+
}, 'data-drag-handler-anchor-name', anchorName), {
|
|
71
|
+
type: 'node-decoration'
|
|
72
|
+
});
|
|
73
|
+
};
|
|
65
74
|
export var nodeDecorations = function nodeDecorations(newState) {
|
|
66
75
|
var decs = [];
|
|
67
76
|
newState.doc.descendants(function (node, pos, _parent, index) {
|
|
68
|
-
var _Decoration$
|
|
77
|
+
var _Decoration$node2;
|
|
69
78
|
var anchorName = "--node-anchor-".concat(node.type.name, "-").concat(index);
|
|
70
79
|
var style;
|
|
71
80
|
if (getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
@@ -73,9 +82,11 @@ export var nodeDecorations = function nodeDecorations(newState) {
|
|
|
73
82
|
} else {
|
|
74
83
|
style = "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '');
|
|
75
84
|
}
|
|
76
|
-
decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$
|
|
85
|
+
decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
|
|
77
86
|
style: style
|
|
78
|
-
}, _defineProperty(_Decoration$
|
|
87
|
+
}, _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), _defineProperty(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _Decoration$node2), {
|
|
88
|
+
type: 'node-decoration'
|
|
89
|
+
}));
|
|
79
90
|
return false;
|
|
80
91
|
});
|
|
81
92
|
return decs;
|
|
@@ -10,7 +10,7 @@ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
|
10
10
|
import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-scroll/element';
|
|
11
11
|
import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
|
|
12
12
|
import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
13
|
-
import { dragHandleDecoration, dropTargetDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
|
|
13
|
+
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, mouseMoveWrapperDecorations, nodeDecorations } from './decorations';
|
|
14
14
|
import { handleMouseOver } from './handle-mouse-over';
|
|
15
15
|
export var key = new PluginKey('blockControls');
|
|
16
16
|
var destroyFn = function destroyFn(api) {
|
|
@@ -229,6 +229,14 @@ export var createPlugin = function createPlugin(api) {
|
|
|
229
229
|
if (tr.docChanged && !redrawDecorations) {
|
|
230
230
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
231
231
|
}
|
|
232
|
+
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
233
|
+
var hasNodeDecoration = decorations.find().some(function (_ref11) {
|
|
234
|
+
var spec = _ref11.spec;
|
|
235
|
+
return spec.type === 'node-decoration';
|
|
236
|
+
});
|
|
237
|
+
if (!hasNodeDecoration && isEmptyDoc) {
|
|
238
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
239
|
+
}
|
|
232
240
|
|
|
233
241
|
// Map active node position when the document changes
|
|
234
242
|
var mappedActiveNodePos = tr.docChanged && activeNode ? {
|
|
@@ -236,7 +244,6 @@ export var createPlugin = function createPlugin(api) {
|
|
|
236
244
|
anchorName: activeNode.anchorName,
|
|
237
245
|
nodeType: activeNode.nodeType
|
|
238
246
|
} : activeNode;
|
|
239
|
-
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
240
247
|
return {
|
|
241
248
|
decorations: decorations,
|
|
242
249
|
decorationState: decorationState,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
/** @jsx jsx */
|
|
2
3
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles, @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
3
4
|
import { css, Global, jsx } from '@emotion/react';
|
|
@@ -25,13 +26,18 @@ var extendedHoverZone = css({
|
|
|
25
26
|
display: 'none'
|
|
26
27
|
}
|
|
27
28
|
});
|
|
28
|
-
var
|
|
29
|
+
var paragraphWithTrailingBreak = '+ p > .ProseMirror-trailingBreak';
|
|
30
|
+
var paragraphWithCursorTarget = '+ p > .cursor-target';
|
|
31
|
+
var globalStyles = css(_defineProperty({
|
|
29
32
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
|
|
30
33
|
'.ProseMirror-widget:first-child + *': {
|
|
31
34
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
|
|
32
35
|
marginTop: '0 !important'
|
|
33
36
|
}
|
|
34
|
-
})
|
|
37
|
+
}, ".ProseMirror-widget[data-blocks-drag-handle-container=\"true\"]:has(".concat(paragraphWithTrailingBreak, "):not(:has(").concat(paragraphWithCursorTarget, "))"), {
|
|
38
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles
|
|
39
|
+
display: 'none !important'
|
|
40
|
+
}));
|
|
35
41
|
export var GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
36
42
|
return jsx(Global, {
|
|
37
43
|
styles: [globalStyles, getBooleanFF('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') && extendedHoverZone]
|
|
@@ -9,6 +9,7 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
9
9
|
pos: number;
|
|
10
10
|
}[];
|
|
11
11
|
};
|
|
12
|
+
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
12
13
|
export declare const nodeDecorations: (newState: EditorState) => Decoration[];
|
|
13
14
|
/**
|
|
14
15
|
* Setting up decorations around each node to track mousemove events into each node
|
|
@@ -9,6 +9,7 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
9
9
|
pos: number;
|
|
10
10
|
}[];
|
|
11
11
|
};
|
|
12
|
+
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
12
13
|
export declare const nodeDecorations: (newState: EditorState) => Decoration[];
|
|
13
14
|
/**
|
|
14
15
|
* Setting up decorations around each node to track mousemove events into each node
|