@atlaskit/editor-plugin-selection 0.1.2 → 0.2.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 +16 -0
- package/dist/cjs/plugin.js +2 -1
- package/dist/cjs/pm-plugins/events/create-selection-between.js +42 -28
- package/dist/es2019/plugin.js +2 -1
- package/dist/es2019/pm-plugins/events/create-selection-between.js +42 -28
- package/dist/esm/plugin.js +2 -1
- package/dist/esm/pm-plugins/events/create-selection-between.js +42 -28
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#65084](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65084) [`609bca09a972`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/609bca09a972) - expose selection as part of the shared state
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 0.1.3
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#63289](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/63289) [`f75faa16e84d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f75faa16e84d) - [ux] ED-20209: Fixed selection behaviour for Atomic and empty+selectable nodes and updated related tests.
|
|
18
|
+
|
|
3
19
|
## 0.1.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -44,7 +44,8 @@ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref2)
|
|
|
44
44
|
}
|
|
45
45
|
var pluginState = _types.selectionPluginKey.getState(editorState);
|
|
46
46
|
return {
|
|
47
|
-
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode
|
|
47
|
+
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode,
|
|
48
|
+
selection: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selection
|
|
48
49
|
};
|
|
49
50
|
},
|
|
50
51
|
pmPlugins: function pmPlugins() {
|
|
@@ -5,43 +5,36 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.onCreateSelectionBetween = void 0;
|
|
7
7
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
8
|
+
var DOC_START_POS = 0;
|
|
8
9
|
function isNodeContentEmpty(maybeNode) {
|
|
9
10
|
return (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.content.size) === 0 || (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.textContent) === '';
|
|
10
11
|
}
|
|
11
|
-
function findEmptySelectableParentNodePosition($pos
|
|
12
|
+
function findEmptySelectableParentNodePosition($pos) {
|
|
12
13
|
var doc = $pos.doc;
|
|
13
|
-
if ($pos.pos
|
|
14
|
+
if ($pos.pos > doc.content.size) {
|
|
14
15
|
return null;
|
|
15
16
|
}
|
|
17
|
+
if (isCurrentNodeAtomOrEmptySelectable($pos)) {
|
|
18
|
+
return $pos;
|
|
19
|
+
}
|
|
16
20
|
if ($pos.nodeBefore !== null) {
|
|
17
|
-
if (isValidPosition($pos)) {
|
|
18
|
-
return $pos;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// We can not use `$pos.before()` because ProseMirror throws an error when depth is zero.
|
|
22
|
-
var currentPosIndex = $pos.index();
|
|
23
|
-
if (currentPosIndex === 0) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
var previousIndex = currentPosIndex - 1;
|
|
27
|
-
var $previousPos = $pos.doc.resolve($pos.posAtIndex(previousIndex));
|
|
28
|
-
if (isValidPosition($previousPos)) {
|
|
29
|
-
return $previousPos;
|
|
30
|
-
}
|
|
31
21
|
return null;
|
|
32
22
|
}
|
|
33
|
-
if (isValidPosition($pos)) {
|
|
34
|
-
return $pos;
|
|
35
|
-
}
|
|
36
23
|
if ($pos.depth === 0 && $pos.pos === 0) {
|
|
37
24
|
return $pos;
|
|
38
25
|
}
|
|
39
26
|
var positionLevelUp = $pos.before();
|
|
40
27
|
var resolvedPositionLevelUp = doc.resolve(positionLevelUp);
|
|
41
|
-
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp
|
|
28
|
+
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp);
|
|
42
29
|
}
|
|
43
|
-
var
|
|
44
|
-
|
|
30
|
+
var isCurrentNodeAtomOrEmptySelectable = function isCurrentNodeAtomOrEmptySelectable($pos) {
|
|
31
|
+
//ED-20209: Using $resolvedJustBeforeNodePos so that $resolvedJustBeforeNodePos.nodeAfter return the node at $pos.pos even if that is an atomic node
|
|
32
|
+
if ($pos.pos === DOC_START_POS) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var justBeforeNodePos = $pos.pos - 1;
|
|
36
|
+
var $resolvedjustBeforePos = $pos.doc.resolve(justBeforeNodePos);
|
|
37
|
+
var maybeNode = $resolvedjustBeforePos.nodeAfter;
|
|
45
38
|
if (!maybeNode || !maybeNode.isBlock) {
|
|
46
39
|
return false;
|
|
47
40
|
}
|
|
@@ -55,12 +48,33 @@ function findNextSelectionPosition(_ref) {
|
|
|
55
48
|
$anchor = _ref.$anchor,
|
|
56
49
|
doc = _ref.doc;
|
|
57
50
|
var direction = $anchor.pos < $targetHead.pos ? 'down' : 'up';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
51
|
+
|
|
52
|
+
//ED-20209: If the targetHead position is just before some node, Then return $targetHead and not select any node.
|
|
53
|
+
var maybeNode = null;
|
|
54
|
+
if ($targetHead.pos !== DOC_START_POS) {
|
|
55
|
+
var justBeforeHeadPos = $targetHead.pos - 1;
|
|
56
|
+
var $resolvedJustBeforeHeadPos = doc.resolve(justBeforeHeadPos);
|
|
57
|
+
maybeNode = $resolvedJustBeforeHeadPos.nodeAfter;
|
|
58
|
+
}
|
|
59
|
+
if (maybeNode === null) {
|
|
60
|
+
maybeNode = $targetHead.nodeAfter;
|
|
61
|
+
if (maybeNode !== null) {
|
|
62
|
+
$targetHead = doc.resolve($targetHead.pos + 1);
|
|
63
|
+
} else {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
var maybeNextPosition = findEmptySelectableParentNodePosition($targetHead);
|
|
68
|
+
if (maybeNextPosition) {
|
|
69
|
+
var justBeforeMaybeNextPos = maybeNextPosition.pos - 1;
|
|
70
|
+
if (direction === 'up') {
|
|
71
|
+
return doc.resolve(Math.max(justBeforeMaybeNextPos, 0));
|
|
72
|
+
} else {
|
|
73
|
+
var maybeNextNode = doc.resolve(justBeforeMaybeNextPos).nodeAfter;
|
|
74
|
+
if (maybeNextNode) {
|
|
75
|
+
return doc.resolve(Math.min(justBeforeMaybeNextPos + maybeNextNode.nodeSize, doc.content.size));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
64
78
|
}
|
|
65
79
|
return null;
|
|
66
80
|
}
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -35,7 +35,8 @@ export const selectionPlugin = ({
|
|
|
35
35
|
}
|
|
36
36
|
const pluginState = selectionPluginKey.getState(editorState);
|
|
37
37
|
return {
|
|
38
|
-
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode
|
|
38
|
+
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode,
|
|
39
|
+
selection: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selection
|
|
39
40
|
};
|
|
40
41
|
},
|
|
41
42
|
pmPlugins() {
|
|
@@ -1,43 +1,36 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
const DOC_START_POS = 0;
|
|
2
3
|
function isNodeContentEmpty(maybeNode) {
|
|
3
4
|
return (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.content.size) === 0 || (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.textContent) === '';
|
|
4
5
|
}
|
|
5
|
-
function findEmptySelectableParentNodePosition($pos
|
|
6
|
+
function findEmptySelectableParentNodePosition($pos) {
|
|
6
7
|
const {
|
|
7
8
|
doc
|
|
8
9
|
} = $pos;
|
|
9
|
-
if ($pos.pos
|
|
10
|
+
if ($pos.pos > doc.content.size) {
|
|
10
11
|
return null;
|
|
11
12
|
}
|
|
13
|
+
if (isCurrentNodeAtomOrEmptySelectable($pos)) {
|
|
14
|
+
return $pos;
|
|
15
|
+
}
|
|
12
16
|
if ($pos.nodeBefore !== null) {
|
|
13
|
-
if (isValidPosition($pos)) {
|
|
14
|
-
return $pos;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// We can not use `$pos.before()` because ProseMirror throws an error when depth is zero.
|
|
18
|
-
const currentPosIndex = $pos.index();
|
|
19
|
-
if (currentPosIndex === 0) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
const previousIndex = currentPosIndex - 1;
|
|
23
|
-
const $previousPos = $pos.doc.resolve($pos.posAtIndex(previousIndex));
|
|
24
|
-
if (isValidPosition($previousPos)) {
|
|
25
|
-
return $previousPos;
|
|
26
|
-
}
|
|
27
17
|
return null;
|
|
28
18
|
}
|
|
29
|
-
if (isValidPosition($pos)) {
|
|
30
|
-
return $pos;
|
|
31
|
-
}
|
|
32
19
|
if ($pos.depth === 0 && $pos.pos === 0) {
|
|
33
20
|
return $pos;
|
|
34
21
|
}
|
|
35
22
|
const positionLevelUp = $pos.before();
|
|
36
23
|
const resolvedPositionLevelUp = doc.resolve(positionLevelUp);
|
|
37
|
-
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp
|
|
24
|
+
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp);
|
|
38
25
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
26
|
+
const isCurrentNodeAtomOrEmptySelectable = $pos => {
|
|
27
|
+
//ED-20209: Using $resolvedJustBeforeNodePos so that $resolvedJustBeforeNodePos.nodeAfter return the node at $pos.pos even if that is an atomic node
|
|
28
|
+
if ($pos.pos === DOC_START_POS) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const justBeforeNodePos = $pos.pos - 1;
|
|
32
|
+
const $resolvedjustBeforePos = $pos.doc.resolve(justBeforeNodePos);
|
|
33
|
+
const maybeNode = $resolvedjustBeforePos.nodeAfter;
|
|
41
34
|
if (!maybeNode || !maybeNode.isBlock) {
|
|
42
35
|
return false;
|
|
43
36
|
}
|
|
@@ -52,12 +45,33 @@ function findNextSelectionPosition({
|
|
|
52
45
|
doc
|
|
53
46
|
}) {
|
|
54
47
|
const direction = $anchor.pos < $targetHead.pos ? 'down' : 'up';
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
48
|
+
|
|
49
|
+
//ED-20209: If the targetHead position is just before some node, Then return $targetHead and not select any node.
|
|
50
|
+
let maybeNode = null;
|
|
51
|
+
if ($targetHead.pos !== DOC_START_POS) {
|
|
52
|
+
const justBeforeHeadPos = $targetHead.pos - 1;
|
|
53
|
+
const $resolvedJustBeforeHeadPos = doc.resolve(justBeforeHeadPos);
|
|
54
|
+
maybeNode = $resolvedJustBeforeHeadPos.nodeAfter;
|
|
55
|
+
}
|
|
56
|
+
if (maybeNode === null) {
|
|
57
|
+
maybeNode = $targetHead.nodeAfter;
|
|
58
|
+
if (maybeNode !== null) {
|
|
59
|
+
$targetHead = doc.resolve($targetHead.pos + 1);
|
|
60
|
+
} else {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const maybeNextPosition = findEmptySelectableParentNodePosition($targetHead);
|
|
65
|
+
if (maybeNextPosition) {
|
|
66
|
+
const justBeforeMaybeNextPos = maybeNextPosition.pos - 1;
|
|
67
|
+
if (direction === 'up') {
|
|
68
|
+
return doc.resolve(Math.max(justBeforeMaybeNextPos, 0));
|
|
69
|
+
} else {
|
|
70
|
+
const maybeNextNode = doc.resolve(justBeforeMaybeNextPos).nodeAfter;
|
|
71
|
+
if (maybeNextNode) {
|
|
72
|
+
return doc.resolve(Math.min(justBeforeMaybeNextPos + maybeNextNode.nodeSize, doc.content.size));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
return null;
|
|
63
77
|
}
|
package/dist/esm/plugin.js
CHANGED
|
@@ -37,7 +37,8 @@ export var selectionPlugin = function selectionPlugin(_ref2) {
|
|
|
37
37
|
}
|
|
38
38
|
var pluginState = selectionPluginKey.getState(editorState);
|
|
39
39
|
return {
|
|
40
|
-
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode
|
|
40
|
+
selectionRelativeToNode: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selectionRelativeToNode,
|
|
41
|
+
selection: pluginState === null || pluginState === void 0 ? void 0 : pluginState.selection
|
|
41
42
|
};
|
|
42
43
|
},
|
|
43
44
|
pmPlugins: function pmPlugins() {
|
|
@@ -1,41 +1,34 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
var DOC_START_POS = 0;
|
|
2
3
|
function isNodeContentEmpty(maybeNode) {
|
|
3
4
|
return (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.content.size) === 0 || (maybeNode === null || maybeNode === void 0 ? void 0 : maybeNode.textContent) === '';
|
|
4
5
|
}
|
|
5
|
-
function findEmptySelectableParentNodePosition($pos
|
|
6
|
+
function findEmptySelectableParentNodePosition($pos) {
|
|
6
7
|
var doc = $pos.doc;
|
|
7
|
-
if ($pos.pos
|
|
8
|
+
if ($pos.pos > doc.content.size) {
|
|
8
9
|
return null;
|
|
9
10
|
}
|
|
11
|
+
if (isCurrentNodeAtomOrEmptySelectable($pos)) {
|
|
12
|
+
return $pos;
|
|
13
|
+
}
|
|
10
14
|
if ($pos.nodeBefore !== null) {
|
|
11
|
-
if (isValidPosition($pos)) {
|
|
12
|
-
return $pos;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// We can not use `$pos.before()` because ProseMirror throws an error when depth is zero.
|
|
16
|
-
var currentPosIndex = $pos.index();
|
|
17
|
-
if (currentPosIndex === 0) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
var previousIndex = currentPosIndex - 1;
|
|
21
|
-
var $previousPos = $pos.doc.resolve($pos.posAtIndex(previousIndex));
|
|
22
|
-
if (isValidPosition($previousPos)) {
|
|
23
|
-
return $previousPos;
|
|
24
|
-
}
|
|
25
15
|
return null;
|
|
26
16
|
}
|
|
27
|
-
if (isValidPosition($pos)) {
|
|
28
|
-
return $pos;
|
|
29
|
-
}
|
|
30
17
|
if ($pos.depth === 0 && $pos.pos === 0) {
|
|
31
18
|
return $pos;
|
|
32
19
|
}
|
|
33
20
|
var positionLevelUp = $pos.before();
|
|
34
21
|
var resolvedPositionLevelUp = doc.resolve(positionLevelUp);
|
|
35
|
-
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp
|
|
22
|
+
return findEmptySelectableParentNodePosition(resolvedPositionLevelUp);
|
|
36
23
|
}
|
|
37
|
-
var
|
|
38
|
-
|
|
24
|
+
var isCurrentNodeAtomOrEmptySelectable = function isCurrentNodeAtomOrEmptySelectable($pos) {
|
|
25
|
+
//ED-20209: Using $resolvedJustBeforeNodePos so that $resolvedJustBeforeNodePos.nodeAfter return the node at $pos.pos even if that is an atomic node
|
|
26
|
+
if ($pos.pos === DOC_START_POS) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var justBeforeNodePos = $pos.pos - 1;
|
|
30
|
+
var $resolvedjustBeforePos = $pos.doc.resolve(justBeforeNodePos);
|
|
31
|
+
var maybeNode = $resolvedjustBeforePos.nodeAfter;
|
|
39
32
|
if (!maybeNode || !maybeNode.isBlock) {
|
|
40
33
|
return false;
|
|
41
34
|
}
|
|
@@ -49,12 +42,33 @@ function findNextSelectionPosition(_ref) {
|
|
|
49
42
|
$anchor = _ref.$anchor,
|
|
50
43
|
doc = _ref.doc;
|
|
51
44
|
var direction = $anchor.pos < $targetHead.pos ? 'down' : 'up';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var
|
|
57
|
-
|
|
45
|
+
|
|
46
|
+
//ED-20209: If the targetHead position is just before some node, Then return $targetHead and not select any node.
|
|
47
|
+
var maybeNode = null;
|
|
48
|
+
if ($targetHead.pos !== DOC_START_POS) {
|
|
49
|
+
var justBeforeHeadPos = $targetHead.pos - 1;
|
|
50
|
+
var $resolvedJustBeforeHeadPos = doc.resolve(justBeforeHeadPos);
|
|
51
|
+
maybeNode = $resolvedJustBeforeHeadPos.nodeAfter;
|
|
52
|
+
}
|
|
53
|
+
if (maybeNode === null) {
|
|
54
|
+
maybeNode = $targetHead.nodeAfter;
|
|
55
|
+
if (maybeNode !== null) {
|
|
56
|
+
$targetHead = doc.resolve($targetHead.pos + 1);
|
|
57
|
+
} else {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var maybeNextPosition = findEmptySelectableParentNodePosition($targetHead);
|
|
62
|
+
if (maybeNextPosition) {
|
|
63
|
+
var justBeforeMaybeNextPos = maybeNextPosition.pos - 1;
|
|
64
|
+
if (direction === 'up') {
|
|
65
|
+
return doc.resolve(Math.max(justBeforeMaybeNextPos, 0));
|
|
66
|
+
} else {
|
|
67
|
+
var maybeNextNode = doc.resolve(justBeforeMaybeNextPos).nodeAfter;
|
|
68
|
+
if (maybeNextNode) {
|
|
69
|
+
return doc.resolve(Math.min(justBeforeMaybeNextPos + maybeNextNode.nodeSize, doc.content.size));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
58
72
|
}
|
|
59
73
|
return null;
|
|
60
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Selection plugin for @atlaskit/editor-core",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"atlassian": {
|
|
18
18
|
"team": "Editor: Lego",
|
|
19
19
|
"releaseModel": "continuous",
|
|
20
|
-
"singleton": true
|
|
20
|
+
"singleton": true,
|
|
21
|
+
"runReact18": false
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@atlaskit/editor-common": "^76.
|
|
24
|
+
"@atlaskit/editor-common": "^76.39.0",
|
|
24
25
|
"@atlaskit/editor-prosemirror": "1.1.0",
|
|
25
|
-
"@atlaskit/editor-shared-styles": "^2.
|
|
26
|
+
"@atlaskit/editor-shared-styles": "^2.9.0",
|
|
26
27
|
"@atlaskit/editor-tables": "^2.3.10",
|
|
27
28
|
"@babel/runtime": "^7.0.0"
|
|
28
29
|
},
|
|
@@ -43,7 +44,6 @@
|
|
|
43
44
|
"@atlaskit/media-test-helpers": "^33.0.0",
|
|
44
45
|
"@atlaskit/ssr": "*",
|
|
45
46
|
"@atlaskit/visual-regression": "*",
|
|
46
|
-
"@atlaskit/webdriver-runner": "*",
|
|
47
47
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
|
|
48
48
|
"@testing-library/react": "^12.1.5",
|
|
49
49
|
"react-dom": "^16.8.0",
|