@atlaskit/editor-plugin-selection 2.1.2 → 2.1.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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 2.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#132086](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/132086)
8
+ [`0c61b5cc7a789`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0c61b5cc7a789) -
9
+ [ux] ED-27255 Fix bug which prevented the gap cursor from appearing sometimes when a table is
10
+ nested in another table, layout or expand
11
+
12
+ ## 2.1.3
13
+
14
+ ### Patch Changes
15
+
16
+ - [#129221](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/129221)
17
+ [`aad9678b8d08a`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/aad9678b8d08a) -
18
+ [ux] ED-25490 Fixes an issue where it was not possible to select block nodes at the top of the
19
+ document if they contain content.
20
+ - Updated dependencies
21
+
3
22
  ## 2.1.2
4
23
 
5
24
  ### 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
+ }
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.toDOM = void 0;
8
8
  var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
9
9
  var _selection = require("@atlaskit/editor-common/selection");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
11
  var _utils = require("../utils");
11
12
  /**
12
13
  * We have a couple of nodes that require us to compute style
@@ -90,7 +91,10 @@ var toDOM = exports.toDOM = function toDOM(view, getPos) {
90
91
  if (nodeStart !== 0 || layoutMode || (node === null || node === void 0 ? void 0 : node.type.name) === 'table') {
91
92
  gapCursor.style.marginTop = style.getPropertyValue('margin-top');
92
93
  }
93
- if (layoutMode) {
94
+
95
+ // Tables nested inside other elements such as layouts, expands and other tables do not have fixed width
96
+ var isNestedTable = (0, _platformFeatureFlags.fg)('platform_editor_nested_tables_gap_cursor') ? (node === null || node === void 0 ? void 0 : node.type.name) === 'table' && selection.$to.depth > 0 : false;
97
+ if (layoutMode && !isNestedTable) {
94
98
  gapCursor.setAttribute('layout', layoutMode);
95
99
  var breakoutModeStyle = (0, _utils.getComputedStyleForLayoutMode)(dom, node, style);
96
100
  gapCursor.style.width = "".concat(measureWidth(breakoutModeStyle), "px");
@@ -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
+ }
@@ -1,4 +1,5 @@
1
1
  import { Side } from '@atlaskit/editor-common/selection';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { getComputedStyleForLayoutMode, getLayoutModeFromTargetNode, isLeftCursor } from '../utils';
3
4
 
4
5
  /**
@@ -81,7 +82,10 @@ export const toDOM = (view, getPos) => {
81
82
  if (nodeStart !== 0 || layoutMode || (node === null || node === void 0 ? void 0 : node.type.name) === 'table') {
82
83
  gapCursor.style.marginTop = style.getPropertyValue('margin-top');
83
84
  }
84
- if (layoutMode) {
85
+
86
+ // Tables nested inside other elements such as layouts, expands and other tables do not have fixed width
87
+ const isNestedTable = fg('platform_editor_nested_tables_gap_cursor') ? (node === null || node === void 0 ? void 0 : node.type.name) === 'table' && selection.$to.depth > 0 : false;
88
+ if (layoutMode && !isNestedTable) {
85
89
  gapCursor.setAttribute('layout', layoutMode);
86
90
  const breakoutModeStyle = getComputedStyleForLayoutMode(dom, node, style);
87
91
  gapCursor.style.width = `${measureWidth(breakoutModeStyle)}px`;
@@ -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
+ }
@@ -1,5 +1,6 @@
1
1
  import _toArray from "@babel/runtime/helpers/toArray";
2
2
  import { Side } from '@atlaskit/editor-common/selection';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
3
4
  import { getComputedStyleForLayoutMode, getLayoutModeFromTargetNode, isLeftCursor } from '../utils';
4
5
 
5
6
  /**
@@ -84,7 +85,10 @@ export var toDOM = function toDOM(view, getPos) {
84
85
  if (nodeStart !== 0 || layoutMode || (node === null || node === void 0 ? void 0 : node.type.name) === 'table') {
85
86
  gapCursor.style.marginTop = style.getPropertyValue('margin-top');
86
87
  }
87
- if (layoutMode) {
88
+
89
+ // Tables nested inside other elements such as layouts, expands and other tables do not have fixed width
90
+ var isNestedTable = fg('platform_editor_nested_tables_gap_cursor') ? (node === null || node === void 0 ? void 0 : node.type.name) === 'table' && selection.$to.depth > 0 : false;
91
+ if (layoutMode && !isNestedTable) {
88
92
  gapCursor.setAttribute('layout', layoutMode);
89
93
  var breakoutModeStyle = getComputedStyleForLayoutMode(dom, node, style);
90
94
  gapCursor.style.width = "".concat(measureWidth(breakoutModeStyle), "px");
@@ -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.2",
3
+ "version": "2.1.4",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,12 +20,12 @@
20
20
  "runReact18": true
21
21
  },
22
22
  "dependencies": {
23
- "@atlaskit/editor-common": "^102.8.0",
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": "^4.0.0",
28
+ "@atlaskit/tmp-editor-statsig": "^4.4.0",
29
29
  "@atlaskit/tokens": "^4.5.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
@@ -92,6 +92,9 @@
92
92
  },
93
93
  "platform_editor_lcm_inline_node_selection_fix": {
94
94
  "type": "boolean"
95
+ },
96
+ "platform_editor_nested_tables_gap_cursor": {
97
+ "type": "boolean"
95
98
  }
96
99
  }
97
100
  }