@atlaskit/editor-plugin-decorations 7.0.2 → 7.0.4
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/decorationsPlugin.js +1 -3
- package/dist/cjs/pm-plugins/commands.js +73 -77
- package/dist/es2019/decorationsPlugin.js +0 -2
- package/dist/es2019/pm-plugins/commands.js +73 -72
- package/dist/esm/decorationsPlugin.js +1 -3
- package/dist/esm/pm-plugins/commands.js +74 -77
- package/dist/types/decorationsPluginType.d.ts +1 -3
- package/dist/types-ts4.5/decorationsPluginType.d.ts +1 -3
- package/package.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-decorations
|
|
2
2
|
|
|
3
|
+
## 7.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 7.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`265980d7959cf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/265980d7959cf) -
|
|
14
|
+
[ux] recursive node decoration and 'selected danger' classname
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 7.0.2
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -38,11 +38,9 @@ var decorationsPlugin = exports.decorationsPlugin = function decorationsPlugin()
|
|
|
38
38
|
},
|
|
39
39
|
commands: {
|
|
40
40
|
hoverDecoration: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) ? function (_ref) {
|
|
41
|
-
var
|
|
42
|
-
add = _ref.add,
|
|
41
|
+
var add = _ref.add,
|
|
43
42
|
className = _ref.className;
|
|
44
43
|
return (0, _commands.hoverDecorationCommand)({
|
|
45
|
-
nodeType: nodeType,
|
|
46
44
|
add: add,
|
|
47
45
|
className: className
|
|
48
46
|
});
|
|
@@ -1,106 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.removeDecorationCommand = exports.hoverDecorationCommand = void 0;
|
|
8
|
-
var
|
|
7
|
+
var _selection = require("@atlaskit/editor-common/selection");
|
|
9
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
|
-
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
11
9
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
12
10
|
var _editorTables = require("@atlaskit/editor-tables");
|
|
13
|
-
var
|
|
11
|
+
var _utils = require("@atlaskit/editor-tables/utils");
|
|
14
12
|
var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
|
|
15
13
|
var _main = require("./main");
|
|
16
14
|
var hoverDecorationCommand = exports.hoverDecorationCommand = function hoverDecorationCommand(_ref) {
|
|
17
|
-
var
|
|
18
|
-
add = _ref.add,
|
|
15
|
+
var add = _ref.add,
|
|
19
16
|
_ref$className = _ref.className,
|
|
20
|
-
className = _ref$className === void 0 ? 'danger' : _ref$className;
|
|
17
|
+
className = _ref$className === void 0 ? 'danger selected' : _ref$className;
|
|
21
18
|
return function (_ref2) {
|
|
22
19
|
var tr = _ref2.tr;
|
|
23
|
-
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
30
|
-
// This adds danger styling if the selected node is the one that requires
|
|
31
|
-
// the decoration to be added, e.g. if a layout is selected and the user
|
|
32
|
-
// hovers over the layout's delete button.
|
|
33
|
-
if (isNodeTypeMatching) {
|
|
34
|
-
from = tr.selection.from;
|
|
35
|
-
parentNode = selectedNode;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// This adds danger styling if the selection is not a node selection, OR if
|
|
40
|
-
// the selected node is a child of the one that requires the decoration to
|
|
41
|
-
// be added, e.g. if a decision item is selected inside a layout and the
|
|
42
|
-
// user hovers over the layout's delete button.
|
|
43
|
-
var foundParentNode = (0, _utils.findParentNodeOfType)(nodeType)(tr.selection);
|
|
44
|
-
// Override from and parentNode values if foundParentNode is a mediaGroup
|
|
45
|
-
if (foundParentNode && (from === undefined || foundParentNode.node.type.name === 'mediaGroup')) {
|
|
46
|
-
from = foundParentNode.pos;
|
|
47
|
-
parentNode = foundParentNode.node;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
51
|
-
if (from === undefined || parentNode === undefined) {
|
|
52
|
-
return tr;
|
|
53
|
-
}
|
|
54
|
-
decoration = _view.Decoration.node(from, from + parentNode.nodeSize, {
|
|
55
|
-
class: className
|
|
56
|
-
}, {
|
|
57
|
-
key: 'decorationNode'
|
|
58
|
-
});
|
|
59
|
-
if (tr.selection instanceof _state.TextSelection) {
|
|
60
|
-
decoration = _view.Decoration.inline(from, tr.selection.to, {
|
|
61
|
-
class: className,
|
|
62
|
-
style: "background-color: ".concat("var(--ds-background-danger, #FFECEB)", ";")
|
|
63
|
-
}, {
|
|
64
|
-
key: 'decorationNode'
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (tr.selection instanceof _editorTables.CellSelection) {
|
|
68
|
-
var table = (0, _editorTables.findTable)(tr.selection);
|
|
20
|
+
// Use the provided selection (e.g., preservedSelection) or fall back to tr.selection
|
|
21
|
+
var selection = tr.selection;
|
|
22
|
+
var decorations = [];
|
|
23
|
+
var handleTableSelection = function handleTableSelection() {
|
|
24
|
+
var pos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : selection.$from;
|
|
25
|
+
var table = (0, _utils.findTableClosestToPos)(pos);
|
|
69
26
|
if (!table) {
|
|
70
27
|
return tr;
|
|
71
28
|
}
|
|
72
|
-
var
|
|
73
|
-
var
|
|
74
|
-
|
|
75
|
-
return tr;
|
|
76
|
-
}
|
|
77
|
-
var tableNodeDec = _view.Decoration.node(table.pos, table.pos + table.node.nodeSize, {
|
|
29
|
+
var tableNode = table.node;
|
|
30
|
+
var tablePos = table.pos;
|
|
31
|
+
decorations.push(_view.Decoration.node(tablePos, tablePos + tableNode.nodeSize, {
|
|
78
32
|
class: className
|
|
79
33
|
}, {
|
|
80
|
-
key:
|
|
81
|
-
});
|
|
82
|
-
var
|
|
83
|
-
|
|
34
|
+
key: "decorationNode-table-".concat(tablePos)
|
|
35
|
+
}));
|
|
36
|
+
var map = _editorTables.TableMap.get(tableNode);
|
|
37
|
+
var cellPositions = new Set(map.map);
|
|
38
|
+
cellPositions.forEach(function (cellPos) {
|
|
39
|
+
var docPos = tablePos + cellPos + 1;
|
|
40
|
+
var cell = tableNode.nodeAt(cellPos);
|
|
41
|
+
if (cell) {
|
|
42
|
+
decorations.push(_view.Decoration.node(docPos, docPos + cell.nodeSize, {
|
|
43
|
+
class: className
|
|
44
|
+
}, {
|
|
45
|
+
key: "decorationNode-cell-".concat(docPos)
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
84
48
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
};
|
|
50
|
+
var handleNodeSelection = function handleNodeSelection(node, pos) {
|
|
51
|
+
var from = pos;
|
|
52
|
+
var to = from + node.nodeSize;
|
|
53
|
+
decorations.push(_view.Decoration.node(from, to, {
|
|
54
|
+
class: className
|
|
55
|
+
}, {
|
|
56
|
+
key: 'decorationNode'
|
|
57
|
+
}));
|
|
58
|
+
if (node.type.name === 'layoutSection' || node.type.name === 'layoutColumn') {
|
|
59
|
+
var startOfInsideOfContainer = tr.doc.resolve(from + 1);
|
|
60
|
+
var endOfInsideOfContainer = tr.doc.resolve(to - 1);
|
|
61
|
+
handleNodesSelection(startOfInsideOfContainer, endOfInsideOfContainer);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var handleNodesSelection = function handleNodesSelection($from, $to) {
|
|
65
|
+
var currentPos = $from.pos;
|
|
66
|
+
var sourceNodes = (0, _selection.getSourceNodesFromSelectionRange)(tr, _state.TextSelection.create(tr.doc, currentPos, $to.pos));
|
|
67
|
+
sourceNodes.forEach(function (sourceNode) {
|
|
68
|
+
if (sourceNode.type.name === 'table') {
|
|
69
|
+
var startPosOfTable = tr.doc.resolve(currentPos + 3);
|
|
70
|
+
handleTableSelection(startPosOfTable);
|
|
71
|
+
} else {
|
|
72
|
+
handleNodeSelection(sourceNode, currentPos);
|
|
89
73
|
}
|
|
90
|
-
|
|
91
|
-
class: className
|
|
92
|
-
}, {
|
|
93
|
-
key: 'decorationNode'
|
|
94
|
-
});
|
|
95
|
-
}).filter(function (decoration) {
|
|
96
|
-
return !!decoration;
|
|
74
|
+
currentPos += sourceNode.nodeSize;
|
|
97
75
|
});
|
|
98
|
-
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Selecting a table directly: CellSelection
|
|
79
|
+
if (selection instanceof _editorTables.CellSelection) {
|
|
80
|
+
handleTableSelection();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// multiselect: TextSelection
|
|
84
|
+
if (selection instanceof _state.TextSelection) {
|
|
85
|
+
handleNodesSelection(selection.$from, selection.$to);
|
|
86
|
+
}
|
|
87
|
+
if (selection instanceof _state.NodeSelection) {
|
|
88
|
+
handleNodeSelection(selection.node, selection.from);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// If no decorations were created, return early
|
|
92
|
+
if (decorations.length === 0) {
|
|
93
|
+
return tr;
|
|
99
94
|
}
|
|
95
|
+
var hasDangerDecorations = className.split(' ').includes('danger');
|
|
100
96
|
tr.setMeta(_main.decorationStateKey, {
|
|
101
97
|
action: add ? _main.ACTIONS.DECORATION_ADD : _main.ACTIONS.DECORATION_REMOVE,
|
|
102
|
-
data:
|
|
103
|
-
hasDangerDecorations: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true)
|
|
98
|
+
data: _view.DecorationSet.create(tr.doc, decorations),
|
|
99
|
+
hasDangerDecorations: (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true) && hasDangerDecorations
|
|
104
100
|
}).setMeta('addToHistory', false);
|
|
105
101
|
return tr;
|
|
106
102
|
};
|
|
@@ -28,11 +28,9 @@ export const decorationsPlugin = () => ({
|
|
|
28
28
|
},
|
|
29
29
|
commands: {
|
|
30
30
|
hoverDecoration: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) ? ({
|
|
31
|
-
nodeType,
|
|
32
31
|
add,
|
|
33
32
|
className
|
|
34
33
|
}) => hoverDecorationCommand({
|
|
35
|
-
nodeType,
|
|
36
34
|
add,
|
|
37
35
|
className
|
|
38
36
|
}) : undefined,
|
|
@@ -1,94 +1,95 @@
|
|
|
1
|
+
import { getSourceNodesFromSelectionRange } from '@atlaskit/editor-common/selection';
|
|
1
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
-
import { CellSelection,
|
|
5
|
-
import {
|
|
4
|
+
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
5
|
+
import { findTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
6
6
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
7
7
|
import { ACTIONS, decorationStateKey } from './main';
|
|
8
8
|
export const hoverDecorationCommand = ({
|
|
9
|
-
nodeType,
|
|
10
9
|
add,
|
|
11
|
-
className = 'danger'
|
|
10
|
+
className = 'danger selected'
|
|
12
11
|
}) => ({
|
|
13
12
|
tr
|
|
14
13
|
}) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const nodeTypes = Array.isArray(nodeType) ? nodeType : [nodeType];
|
|
21
|
-
const isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
22
|
-
// This adds danger styling if the selected node is the one that requires
|
|
23
|
-
// the decoration to be added, e.g. if a layout is selected and the user
|
|
24
|
-
// hovers over the layout's delete button.
|
|
25
|
-
if (isNodeTypeMatching) {
|
|
26
|
-
from = tr.selection.from;
|
|
27
|
-
parentNode = selectedNode;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// This adds danger styling if the selection is not a node selection, OR if
|
|
32
|
-
// the selected node is a child of the one that requires the decoration to
|
|
33
|
-
// be added, e.g. if a decision item is selected inside a layout and the
|
|
34
|
-
// user hovers over the layout's delete button.
|
|
35
|
-
const foundParentNode = findParentNodeOfType(nodeType)(tr.selection);
|
|
36
|
-
// Override from and parentNode values if foundParentNode is a mediaGroup
|
|
37
|
-
if (foundParentNode && (from === undefined || foundParentNode.node.type.name === 'mediaGroup')) {
|
|
38
|
-
from = foundParentNode.pos;
|
|
39
|
-
parentNode = foundParentNode.node;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
43
|
-
if (from === undefined || parentNode === undefined) {
|
|
44
|
-
return tr;
|
|
45
|
-
}
|
|
46
|
-
decoration = Decoration.node(from, from + parentNode.nodeSize, {
|
|
47
|
-
class: className
|
|
48
|
-
}, {
|
|
49
|
-
key: 'decorationNode'
|
|
50
|
-
});
|
|
51
|
-
if (tr.selection instanceof TextSelection) {
|
|
52
|
-
decoration = Decoration.inline(from, tr.selection.to, {
|
|
53
|
-
class: className,
|
|
54
|
-
style: `background-color: ${"var(--ds-background-danger, #FFECEB)"};`
|
|
55
|
-
}, {
|
|
56
|
-
key: 'decorationNode'
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
if (tr.selection instanceof CellSelection) {
|
|
60
|
-
const table = findTable(tr.selection);
|
|
14
|
+
// Use the provided selection (e.g., preservedSelection) or fall back to tr.selection
|
|
15
|
+
const selection = tr.selection;
|
|
16
|
+
const decorations = [];
|
|
17
|
+
const handleTableSelection = (pos = selection.$from) => {
|
|
18
|
+
const table = findTableClosestToPos(pos);
|
|
61
19
|
if (!table) {
|
|
62
20
|
return tr;
|
|
63
21
|
}
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
return tr;
|
|
68
|
-
}
|
|
69
|
-
const tableNodeDec = Decoration.node(table.pos, table.pos + table.node.nodeSize, {
|
|
22
|
+
const tableNode = table.node;
|
|
23
|
+
const tablePos = table.pos;
|
|
24
|
+
decorations.push(Decoration.node(tablePos, tablePos + tableNode.nodeSize, {
|
|
70
25
|
class: className
|
|
71
26
|
}, {
|
|
72
|
-
key:
|
|
27
|
+
key: `decorationNode-table-${tablePos}`
|
|
28
|
+
}));
|
|
29
|
+
const map = TableMap.get(tableNode);
|
|
30
|
+
const cellPositions = new Set(map.map);
|
|
31
|
+
cellPositions.forEach(cellPos => {
|
|
32
|
+
const docPos = tablePos + cellPos + 1;
|
|
33
|
+
const cell = tableNode.nodeAt(cellPos);
|
|
34
|
+
if (cell) {
|
|
35
|
+
decorations.push(Decoration.node(docPos, docPos + cell.nodeSize, {
|
|
36
|
+
class: className
|
|
37
|
+
}, {
|
|
38
|
+
key: `decorationNode-cell-${docPos}`
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
73
41
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
};
|
|
43
|
+
const handleNodeSelection = (node, pos) => {
|
|
44
|
+
const from = pos;
|
|
45
|
+
const to = from + node.nodeSize;
|
|
46
|
+
decorations.push(Decoration.node(from, to, {
|
|
47
|
+
class: className
|
|
48
|
+
}, {
|
|
49
|
+
key: 'decorationNode'
|
|
50
|
+
}));
|
|
51
|
+
if (node.type.name === 'layoutSection' || node.type.name === 'layoutColumn') {
|
|
52
|
+
const startOfInsideOfContainer = tr.doc.resolve(from + 1);
|
|
53
|
+
const endOfInsideOfContainer = tr.doc.resolve(to - 1);
|
|
54
|
+
handleNodesSelection(startOfInsideOfContainer, endOfInsideOfContainer);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const handleNodesSelection = ($from, $to) => {
|
|
58
|
+
let currentPos = $from.pos;
|
|
59
|
+
const sourceNodes = getSourceNodesFromSelectionRange(tr, TextSelection.create(tr.doc, currentPos, $to.pos));
|
|
60
|
+
sourceNodes.forEach(sourceNode => {
|
|
61
|
+
if (sourceNode.type.name === 'table') {
|
|
62
|
+
const startPosOfTable = tr.doc.resolve(currentPos + 3);
|
|
63
|
+
handleTableSelection(startPosOfTable);
|
|
64
|
+
} else {
|
|
65
|
+
handleNodeSelection(sourceNode, currentPos);
|
|
79
66
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
67
|
+
currentPos += sourceNode.nodeSize;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// Selecting a table directly: CellSelection
|
|
72
|
+
if (selection instanceof CellSelection) {
|
|
73
|
+
handleTableSelection();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// multiselect: TextSelection
|
|
77
|
+
if (selection instanceof TextSelection) {
|
|
78
|
+
handleNodesSelection(selection.$from, selection.$to);
|
|
79
|
+
}
|
|
80
|
+
if (selection instanceof NodeSelection) {
|
|
81
|
+
handleNodeSelection(selection.node, selection.from);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// If no decorations were created, return early
|
|
85
|
+
if (decorations.length === 0) {
|
|
86
|
+
return tr;
|
|
87
87
|
}
|
|
88
|
+
const hasDangerDecorations = className.split(' ').includes('danger');
|
|
88
89
|
tr.setMeta(decorationStateKey, {
|
|
89
90
|
action: add ? ACTIONS.DECORATION_ADD : ACTIONS.DECORATION_REMOVE,
|
|
90
|
-
data:
|
|
91
|
-
hasDangerDecorations: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)
|
|
91
|
+
data: DecorationSet.create(tr.doc, decorations),
|
|
92
|
+
hasDangerDecorations: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) && hasDangerDecorations
|
|
92
93
|
}).setMeta('addToHistory', false);
|
|
93
94
|
return tr;
|
|
94
95
|
};
|
|
@@ -31,11 +31,9 @@ export var decorationsPlugin = function decorationsPlugin() {
|
|
|
31
31
|
},
|
|
32
32
|
commands: {
|
|
33
33
|
hoverDecoration: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) ? function (_ref) {
|
|
34
|
-
var
|
|
35
|
-
add = _ref.add,
|
|
34
|
+
var add = _ref.add,
|
|
36
35
|
className = _ref.className;
|
|
37
36
|
return hoverDecorationCommand({
|
|
38
|
-
nodeType: nodeType,
|
|
39
37
|
add: add,
|
|
40
38
|
className: className
|
|
41
39
|
});
|
|
@@ -1,99 +1,96 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getSourceNodesFromSelectionRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
-
import { CellSelection,
|
|
6
|
-
import {
|
|
4
|
+
import { CellSelection, TableMap } from '@atlaskit/editor-tables';
|
|
5
|
+
import { findTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
7
6
|
import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
|
|
8
7
|
import { ACTIONS, decorationStateKey } from './main';
|
|
9
8
|
export var hoverDecorationCommand = function hoverDecorationCommand(_ref) {
|
|
10
|
-
var
|
|
11
|
-
add = _ref.add,
|
|
9
|
+
var add = _ref.add,
|
|
12
10
|
_ref$className = _ref.className,
|
|
13
|
-
className = _ref$className === void 0 ? 'danger' : _ref$className;
|
|
11
|
+
className = _ref$className === void 0 ? 'danger selected' : _ref$className;
|
|
14
12
|
return function (_ref2) {
|
|
15
13
|
var tr = _ref2.tr;
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var isNodeTypeMatching = nodeTypes.indexOf(selectedNode.type) > -1;
|
|
23
|
-
// This adds danger styling if the selected node is the one that requires
|
|
24
|
-
// the decoration to be added, e.g. if a layout is selected and the user
|
|
25
|
-
// hovers over the layout's delete button.
|
|
26
|
-
if (isNodeTypeMatching) {
|
|
27
|
-
from = tr.selection.from;
|
|
28
|
-
parentNode = selectedNode;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// This adds danger styling if the selection is not a node selection, OR if
|
|
33
|
-
// the selected node is a child of the one that requires the decoration to
|
|
34
|
-
// be added, e.g. if a decision item is selected inside a layout and the
|
|
35
|
-
// user hovers over the layout's delete button.
|
|
36
|
-
var foundParentNode = findParentNodeOfType(nodeType)(tr.selection);
|
|
37
|
-
// Override from and parentNode values if foundParentNode is a mediaGroup
|
|
38
|
-
if (foundParentNode && (from === undefined || foundParentNode.node.type.name === 'mediaGroup')) {
|
|
39
|
-
from = foundParentNode.pos;
|
|
40
|
-
parentNode = foundParentNode.node;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Note: can't use !from as from could be 0, which is falsy but valid
|
|
44
|
-
if (from === undefined || parentNode === undefined) {
|
|
45
|
-
return tr;
|
|
46
|
-
}
|
|
47
|
-
decoration = Decoration.node(from, from + parentNode.nodeSize, {
|
|
48
|
-
class: className
|
|
49
|
-
}, {
|
|
50
|
-
key: 'decorationNode'
|
|
51
|
-
});
|
|
52
|
-
if (tr.selection instanceof TextSelection) {
|
|
53
|
-
decoration = Decoration.inline(from, tr.selection.to, {
|
|
54
|
-
class: className,
|
|
55
|
-
style: "background-color: ".concat("var(--ds-background-danger, #FFECEB)", ";")
|
|
56
|
-
}, {
|
|
57
|
-
key: 'decorationNode'
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (tr.selection instanceof CellSelection) {
|
|
61
|
-
var table = findTable(tr.selection);
|
|
14
|
+
// Use the provided selection (e.g., preservedSelection) or fall back to tr.selection
|
|
15
|
+
var selection = tr.selection;
|
|
16
|
+
var decorations = [];
|
|
17
|
+
var handleTableSelection = function handleTableSelection() {
|
|
18
|
+
var pos = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : selection.$from;
|
|
19
|
+
var table = findTableClosestToPos(pos);
|
|
62
20
|
if (!table) {
|
|
63
21
|
return tr;
|
|
64
22
|
}
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
return tr;
|
|
69
|
-
}
|
|
70
|
-
var tableNodeDec = Decoration.node(table.pos, table.pos + table.node.nodeSize, {
|
|
23
|
+
var tableNode = table.node;
|
|
24
|
+
var tablePos = table.pos;
|
|
25
|
+
decorations.push(Decoration.node(tablePos, tablePos + tableNode.nodeSize, {
|
|
71
26
|
class: className
|
|
72
27
|
}, {
|
|
73
|
-
key:
|
|
74
|
-
});
|
|
75
|
-
var
|
|
76
|
-
|
|
28
|
+
key: "decorationNode-table-".concat(tablePos)
|
|
29
|
+
}));
|
|
30
|
+
var map = TableMap.get(tableNode);
|
|
31
|
+
var cellPositions = new Set(map.map);
|
|
32
|
+
cellPositions.forEach(function (cellPos) {
|
|
33
|
+
var docPos = tablePos + cellPos + 1;
|
|
34
|
+
var cell = tableNode.nodeAt(cellPos);
|
|
35
|
+
if (cell) {
|
|
36
|
+
decorations.push(Decoration.node(docPos, docPos + cell.nodeSize, {
|
|
37
|
+
class: className
|
|
38
|
+
}, {
|
|
39
|
+
key: "decorationNode-cell-".concat(docPos)
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
77
42
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
43
|
+
};
|
|
44
|
+
var handleNodeSelection = function handleNodeSelection(node, pos) {
|
|
45
|
+
var from = pos;
|
|
46
|
+
var to = from + node.nodeSize;
|
|
47
|
+
decorations.push(Decoration.node(from, to, {
|
|
48
|
+
class: className
|
|
49
|
+
}, {
|
|
50
|
+
key: 'decorationNode'
|
|
51
|
+
}));
|
|
52
|
+
if (node.type.name === 'layoutSection' || node.type.name === 'layoutColumn') {
|
|
53
|
+
var startOfInsideOfContainer = tr.doc.resolve(from + 1);
|
|
54
|
+
var endOfInsideOfContainer = tr.doc.resolve(to - 1);
|
|
55
|
+
handleNodesSelection(startOfInsideOfContainer, endOfInsideOfContainer);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var handleNodesSelection = function handleNodesSelection($from, $to) {
|
|
59
|
+
var currentPos = $from.pos;
|
|
60
|
+
var sourceNodes = getSourceNodesFromSelectionRange(tr, TextSelection.create(tr.doc, currentPos, $to.pos));
|
|
61
|
+
sourceNodes.forEach(function (sourceNode) {
|
|
62
|
+
if (sourceNode.type.name === 'table') {
|
|
63
|
+
var startPosOfTable = tr.doc.resolve(currentPos + 3);
|
|
64
|
+
handleTableSelection(startPosOfTable);
|
|
65
|
+
} else {
|
|
66
|
+
handleNodeSelection(sourceNode, currentPos);
|
|
82
67
|
}
|
|
83
|
-
|
|
84
|
-
class: className
|
|
85
|
-
}, {
|
|
86
|
-
key: 'decorationNode'
|
|
87
|
-
});
|
|
88
|
-
}).filter(function (decoration) {
|
|
89
|
-
return !!decoration;
|
|
68
|
+
currentPos += sourceNode.nodeSize;
|
|
90
69
|
});
|
|
91
|
-
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Selecting a table directly: CellSelection
|
|
73
|
+
if (selection instanceof CellSelection) {
|
|
74
|
+
handleTableSelection();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// multiselect: TextSelection
|
|
78
|
+
if (selection instanceof TextSelection) {
|
|
79
|
+
handleNodesSelection(selection.$from, selection.$to);
|
|
80
|
+
}
|
|
81
|
+
if (selection instanceof NodeSelection) {
|
|
82
|
+
handleNodeSelection(selection.node, selection.from);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// If no decorations were created, return early
|
|
86
|
+
if (decorations.length === 0) {
|
|
87
|
+
return tr;
|
|
92
88
|
}
|
|
89
|
+
var hasDangerDecorations = className.split(' ').includes('danger');
|
|
93
90
|
tr.setMeta(decorationStateKey, {
|
|
94
91
|
action: add ? ACTIONS.DECORATION_ADD : ACTIONS.DECORATION_REMOVE,
|
|
95
|
-
data:
|
|
96
|
-
hasDangerDecorations: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)
|
|
92
|
+
data: DecorationSet.create(tr.doc, decorations),
|
|
93
|
+
hasDangerDecorations: expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true) && hasDangerDecorations
|
|
97
94
|
}).setMeta('addToHistory', false);
|
|
98
95
|
return tr;
|
|
99
96
|
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { NextEditorPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import type { DecorationState, HoverDecorationHandler, removeDecoration } from './pm-plugins/main';
|
|
4
3
|
export type HoverDecorationProps = {
|
|
5
4
|
add: boolean;
|
|
6
5
|
className?: string;
|
|
7
|
-
nodeType: NodeType | Array<NodeType>;
|
|
8
6
|
};
|
|
9
|
-
export type HoverDecorationCommand = ({
|
|
7
|
+
export type HoverDecorationCommand = ({ add, className }: HoverDecorationProps) => EditorCommand;
|
|
10
8
|
export type DecorationsPlugin = NextEditorPlugin<'decorations', {
|
|
11
9
|
actions: {
|
|
12
10
|
hoverDecoration: HoverDecorationHandler;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import type { NextEditorPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
3
2
|
import type { DecorationState, HoverDecorationHandler, removeDecoration } from './pm-plugins/main';
|
|
4
3
|
export type HoverDecorationProps = {
|
|
5
4
|
add: boolean;
|
|
6
5
|
className?: string;
|
|
7
|
-
nodeType: NodeType | Array<NodeType>;
|
|
8
6
|
};
|
|
9
|
-
export type HoverDecorationCommand = ({
|
|
7
|
+
export type HoverDecorationCommand = ({ add, className }: HoverDecorationProps) => EditorCommand;
|
|
10
8
|
export type DecorationsPlugin = NextEditorPlugin<'decorations', {
|
|
11
9
|
actions: {
|
|
12
10
|
hoverDecoration: HoverDecorationHandler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-decorations",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4",
|
|
4
4
|
"description": "Decorations plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -21,12 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@atlaskit/editor-prosemirror": "^7.2.0",
|
|
23
23
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
24
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
25
|
-
"@atlaskit/tokens": "^10.0.0",
|
|
24
|
+
"@atlaskit/tmp-editor-statsig": "^17.0.0",
|
|
26
25
|
"@babel/runtime": "^7.0.0"
|
|
27
26
|
},
|
|
28
27
|
"peerDependencies": {
|
|
29
|
-
"@atlaskit/editor-common": "^111.
|
|
28
|
+
"@atlaskit/editor-common": "^111.9.0",
|
|
30
29
|
"react": "^18.2.0",
|
|
31
30
|
"react-dom": "^18.2.0"
|
|
32
31
|
},
|