@atlaskit/editor-plugin-selection 2.1.1 → 2.1.3
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/pm-plugins/events/keydown.js +9 -0
- package/dist/cjs/pm-plugins/events/mouseout.js +61 -0
- package/dist/cjs/pm-plugins/selection-main.js +5 -1
- package/dist/es2019/pm-plugins/events/keydown.js +9 -0
- package/dist/es2019/pm-plugins/events/mouseout.js +56 -0
- package/dist/es2019/pm-plugins/selection-main.js +5 -1
- package/dist/esm/pm-plugins/events/keydown.js +9 -0
- package/dist/esm/pm-plugins/events/mouseout.js +54 -0
- package/dist/esm/pm-plugins/selection-main.js +5 -1
- package/dist/types/pm-plugins/events/mouseout.d.ts +4 -0
- package/dist/types-ts4.5/pm-plugins/events/mouseout.d.ts +4 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-selection
|
|
2
2
|
|
|
3
|
+
## 2.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#129221](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/129221)
|
|
8
|
+
[`aad9678b8d08a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aad9678b8d08a) -
|
|
9
|
+
[ux] ED-25490 Fixes an issue where it was not possible to select block nodes at the top of the
|
|
10
|
+
document if they contain content.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 2.1.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 2.1.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -137,6 +137,15 @@ function createOnKeydown(_ref4) {
|
|
|
137
137
|
if (!(event instanceof KeyboardEvent)) {
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// Override the default behaviour to make sure that the selection always extends to
|
|
142
|
+
// the start of the document and not just the first inline position.
|
|
143
|
+
if (event.shiftKey && event.metaKey && event.key === 'ArrowUp') {
|
|
144
|
+
var selection = _state.TextSelection.create(view.state.doc, view.state.selection.$anchor.pos, 0);
|
|
145
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
140
149
|
if (isSelectionLineShortcutWhenCursorIsInsideInlineNode(view, event)) {
|
|
141
150
|
return true;
|
|
142
151
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isValidSelection = isValidSelection;
|
|
7
|
+
exports.onMouseOut = onMouseOut;
|
|
8
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
|
+
function isValidSelection(selection) {
|
|
10
|
+
if (selection.empty) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
var $anchor = selection.$anchor,
|
|
14
|
+
$head = selection.$head;
|
|
15
|
+
|
|
16
|
+
// Head must be at the start of its parent node's content
|
|
17
|
+
if ($head.parentOffset !== 0) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Head must be nested (e.g., in a panel > paragraph, not directly in doc)
|
|
22
|
+
if ($head.depth <= 1) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Head must be in the first top-level block (before depth 1 is 0)
|
|
27
|
+
if ($head.before(1) !== 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Selection must not span within a shared deeper structure
|
|
32
|
+
if ($head.sharedDepth($anchor.pos) !== 0) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Head must be in the first block at every level
|
|
37
|
+
var isFirstBlockInTree = true;
|
|
38
|
+
for (var i = $head.depth - 1; i >= 0; i--) {
|
|
39
|
+
if ($head.index(i) !== 0) {
|
|
40
|
+
isFirstBlockInTree = false;
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!isFirstBlockInTree) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
function onMouseOut(view, event) {
|
|
50
|
+
// Only trigger during a mouse drag
|
|
51
|
+
if (event.buttons === 0) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (view.state.selection instanceof _state.TextSelection && isValidSelection(view.state.selection)) {
|
|
55
|
+
// Set selection with head at document start (position 0)
|
|
56
|
+
var selection = new _state.TextSelection(view.state.doc.resolve(view.state.selection.$anchor.pos), view.state.doc.resolve(0));
|
|
57
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
@@ -11,6 +11,7 @@ var _types = require("../types");
|
|
|
11
11
|
var _actions = require("./actions");
|
|
12
12
|
var _createSelectionBetween = require("./events/create-selection-between");
|
|
13
13
|
var _keydown = require("./events/keydown");
|
|
14
|
+
var _mouseout = require("./events/mouseout");
|
|
14
15
|
var _pluginFactory = require("./plugin-factory");
|
|
15
16
|
var _utils = require("./utils");
|
|
16
17
|
var getInitialState = exports.getInitialState = function getInitialState(state) {
|
|
@@ -72,7 +73,10 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
|
|
|
72
73
|
handleDOMEvents: {
|
|
73
74
|
keydown: (0, _keydown.createOnKeydown)({
|
|
74
75
|
__livePage: options.__livePage
|
|
75
|
-
})
|
|
76
|
+
}),
|
|
77
|
+
// Without this event, it is not possible to click and drag to select the first node in the
|
|
78
|
+
// document if the node is a block with content (e.g. a panel with a paragraph inside).
|
|
79
|
+
mouseout: _mouseout.onMouseOut
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
});
|
|
@@ -135,6 +135,15 @@ export function createOnKeydown({
|
|
|
135
135
|
if (!(event instanceof KeyboardEvent)) {
|
|
136
136
|
return false;
|
|
137
137
|
}
|
|
138
|
+
|
|
139
|
+
// Override the default behaviour to make sure that the selection always extends to
|
|
140
|
+
// the start of the document and not just the first inline position.
|
|
141
|
+
if (event.shiftKey && event.metaKey && event.key === 'ArrowUp') {
|
|
142
|
+
const selection = TextSelection.create(view.state.doc, view.state.selection.$anchor.pos, 0);
|
|
143
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
138
147
|
if (isSelectionLineShortcutWhenCursorIsInsideInlineNode(view, event)) {
|
|
139
148
|
return true;
|
|
140
149
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export function isValidSelection(selection) {
|
|
3
|
+
if (selection.empty) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const {
|
|
7
|
+
$anchor,
|
|
8
|
+
$head
|
|
9
|
+
} = selection;
|
|
10
|
+
|
|
11
|
+
// Head must be at the start of its parent node's content
|
|
12
|
+
if ($head.parentOffset !== 0) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Head must be nested (e.g., in a panel > paragraph, not directly in doc)
|
|
17
|
+
if ($head.depth <= 1) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Head must be in the first top-level block (before depth 1 is 0)
|
|
22
|
+
if ($head.before(1) !== 0) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Selection must not span within a shared deeper structure
|
|
27
|
+
if ($head.sharedDepth($anchor.pos) !== 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Head must be in the first block at every level
|
|
32
|
+
let isFirstBlockInTree = true;
|
|
33
|
+
for (let i = $head.depth - 1; i >= 0; i--) {
|
|
34
|
+
if ($head.index(i) !== 0) {
|
|
35
|
+
isFirstBlockInTree = false;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!isFirstBlockInTree) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
export function onMouseOut(view, event) {
|
|
45
|
+
// Only trigger during a mouse drag
|
|
46
|
+
if (event.buttons === 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (view.state.selection instanceof TextSelection && isValidSelection(view.state.selection)) {
|
|
50
|
+
// Set selection with head at document start (position 0)
|
|
51
|
+
const selection = new TextSelection(view.state.doc.resolve(view.state.selection.$anchor.pos), view.state.doc.resolve(0));
|
|
52
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
@@ -5,6 +5,7 @@ import { selectionPluginKey } from '../types';
|
|
|
5
5
|
import { SelectionActionTypes } from './actions';
|
|
6
6
|
import { onCreateSelectionBetween } from './events/create-selection-between';
|
|
7
7
|
import { createOnKeydown } from './events/keydown';
|
|
8
|
+
import { onMouseOut } from './events/mouseout';
|
|
8
9
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
9
10
|
import { getDecorations, shouldRecalcDecorations } from './utils';
|
|
10
11
|
export const getInitialState = state => ({
|
|
@@ -65,7 +66,10 @@ export const createPlugin = (dispatch, dispatchAnalyticsEvent, options = {}) =>
|
|
|
65
66
|
handleDOMEvents: {
|
|
66
67
|
keydown: createOnKeydown({
|
|
67
68
|
__livePage: options.__livePage
|
|
68
|
-
})
|
|
69
|
+
}),
|
|
70
|
+
// Without this event, it is not possible to click and drag to select the first node in the
|
|
71
|
+
// document if the node is a block with content (e.g. a panel with a paragraph inside).
|
|
72
|
+
mouseout: onMouseOut
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
});
|
|
@@ -132,6 +132,15 @@ export function createOnKeydown(_ref4) {
|
|
|
132
132
|
if (!(event instanceof KeyboardEvent)) {
|
|
133
133
|
return false;
|
|
134
134
|
}
|
|
135
|
+
|
|
136
|
+
// Override the default behaviour to make sure that the selection always extends to
|
|
137
|
+
// the start of the document and not just the first inline position.
|
|
138
|
+
if (event.shiftKey && event.metaKey && event.key === 'ArrowUp') {
|
|
139
|
+
var selection = TextSelection.create(view.state.doc, view.state.selection.$anchor.pos, 0);
|
|
140
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
135
144
|
if (isSelectionLineShortcutWhenCursorIsInsideInlineNode(view, event)) {
|
|
136
145
|
return true;
|
|
137
146
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
export function isValidSelection(selection) {
|
|
3
|
+
if (selection.empty) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
var $anchor = selection.$anchor,
|
|
7
|
+
$head = selection.$head;
|
|
8
|
+
|
|
9
|
+
// Head must be at the start of its parent node's content
|
|
10
|
+
if ($head.parentOffset !== 0) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Head must be nested (e.g., in a panel > paragraph, not directly in doc)
|
|
15
|
+
if ($head.depth <= 1) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Head must be in the first top-level block (before depth 1 is 0)
|
|
20
|
+
if ($head.before(1) !== 0) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Selection must not span within a shared deeper structure
|
|
25
|
+
if ($head.sharedDepth($anchor.pos) !== 0) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Head must be in the first block at every level
|
|
30
|
+
var isFirstBlockInTree = true;
|
|
31
|
+
for (var i = $head.depth - 1; i >= 0; i--) {
|
|
32
|
+
if ($head.index(i) !== 0) {
|
|
33
|
+
isFirstBlockInTree = false;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!isFirstBlockInTree) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
export function onMouseOut(view, event) {
|
|
43
|
+
// Only trigger during a mouse drag
|
|
44
|
+
if (event.buttons === 0) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (view.state.selection instanceof TextSelection && isValidSelection(view.state.selection)) {
|
|
48
|
+
// Set selection with head at document start (position 0)
|
|
49
|
+
var selection = new TextSelection(view.state.doc.resolve(view.state.selection.$anchor.pos), view.state.doc.resolve(0));
|
|
50
|
+
view.dispatch(view.state.tr.setSelection(selection));
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
@@ -5,6 +5,7 @@ import { selectionPluginKey } from '../types';
|
|
|
5
5
|
import { SelectionActionTypes } from './actions';
|
|
6
6
|
import { onCreateSelectionBetween } from './events/create-selection-between';
|
|
7
7
|
import { createOnKeydown } from './events/keydown';
|
|
8
|
+
import { onMouseOut } from './events/mouseout';
|
|
8
9
|
import { createPluginState, getPluginState } from './plugin-factory';
|
|
9
10
|
import { getDecorations, shouldRecalcDecorations } from './utils';
|
|
10
11
|
export var getInitialState = function getInitialState(state) {
|
|
@@ -66,7 +67,10 @@ export var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent
|
|
|
66
67
|
handleDOMEvents: {
|
|
67
68
|
keydown: createOnKeydown({
|
|
68
69
|
__livePage: options.__livePage
|
|
69
|
-
})
|
|
70
|
+
}),
|
|
71
|
+
// Without this event, it is not possible to click and drag to select the first node in the
|
|
72
|
+
// document if the node is a block with content (e.g. a panel with a paragraph inside).
|
|
73
|
+
mouseout: onMouseOut
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export declare function isValidSelection(selection: Selection): boolean;
|
|
4
|
+
export declare function onMouseOut(view: EditorView, event: MouseEvent): boolean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export declare function isValidSelection(selection: Selection): boolean;
|
|
4
|
+
export declare function onMouseOut(view: EditorView, event: MouseEvent): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-selection",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Selection plugin for @atlaskit/editor-core",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"runReact18": true
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@atlaskit/editor-common": "^102.
|
|
23
|
+
"@atlaskit/editor-common": "^102.13.0",
|
|
24
24
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
25
25
|
"@atlaskit/editor-shared-styles": "^3.4.0",
|
|
26
26
|
"@atlaskit/editor-tables": "^2.9.0",
|
|
27
27
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
28
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
29
|
-
"@atlaskit/tokens": "^4.
|
|
28
|
+
"@atlaskit/tmp-editor-statsig": "^4.4.0",
|
|
29
|
+
"@atlaskit/tokens": "^4.5.0",
|
|
30
30
|
"@babel/runtime": "^7.0.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|