@atlaskit/editor-plugin-selection 2.1.0 → 2.1.2

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,20 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 2.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#124883](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/124883)
14
+ [`cdc857701ad32`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/cdc857701ad32) -
15
+ [ux] EDF-2571 Updated `selectNodeWithModA` function to account for nested tables.
16
+ - Updated dependencies
17
+
3
18
  ## 2.1.0
4
19
 
5
20
  ### Minor Changes
@@ -7,11 +7,12 @@ exports.setSelectionRelativeToNode = exports.setSelectionInsideAtNodeEnd = expor
7
7
  var _selection = require("@atlaskit/editor-common/selection");
8
8
  var _utils = require("@atlaskit/editor-common/utils");
9
9
  var _state = require("@atlaskit/editor-prosemirror/state");
10
- var _utils2 = require("@atlaskit/editor-tables/utils");
10
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
11
+ var _utils3 = require("@atlaskit/editor-tables/utils");
11
12
  var _types = require("../types");
12
13
  var _actions = require("./actions");
13
14
  var _pluginFactory = require("./plugin-factory");
14
- var _utils3 = require("./utils");
15
+ var _utils4 = require("./utils");
15
16
  /* eslint-disable import/no-extraneous-dependencies */
16
17
 
17
18
  var selectNearNode = exports.selectNearNode = function selectNearNode(selectionRelativeToNode, selection) {
@@ -65,12 +66,12 @@ var arrowRightFromGapCursor = function arrowRightFromGapCursor(selection) {
65
66
  $to = selection.$to,
66
67
  side = selection.side;
67
68
  if (side === _selection.Side.LEFT) {
68
- var selectableNode = (0, _utils3.findSelectableContainerAfter)($to, state.doc);
69
+ var selectableNode = (0, _utils4.findSelectableContainerAfter)($to, state.doc);
69
70
  if (selectableNode) {
70
71
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.Start, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
71
72
  }
72
- } else if (side === _selection.Side.RIGHT && (0, _utils3.isSelectionAtEndOfParentNode)($from, selection)) {
73
- var _selectableNode = (0, _utils3.findSelectableContainerParent)(selection);
73
+ } else if (side === _selection.Side.RIGHT && (0, _utils4.isSelectionAtEndOfParentNode)($from, selection)) {
74
+ var _selectableNode = (0, _utils4.findSelectableContainerParent)(selection);
74
75
  if (_selectableNode) {
75
76
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, _selectableNode.pos))(state, dispatch);
76
77
  }
@@ -85,15 +86,15 @@ var arrowLeftFromGapCursor = function arrowLeftFromGapCursor(selection) {
85
86
  var _getPluginState = (0, _pluginFactory.getPluginState)(state),
86
87
  selectionRelativeToNode = _getPluginState.selectionRelativeToNode;
87
88
  if (side === _selection.Side.RIGHT) {
88
- var selectableNode = (0, _utils3.findSelectableContainerBefore)($from, state.doc);
89
+ var selectableNode = (0, _utils4.findSelectableContainerBefore)($from, state.doc);
89
90
  if (selectableNode) {
90
91
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
91
92
  }
92
- } else if (side === _selection.Side.LEFT && (0, _utils3.isSelectionAtStartOfParentNode)($from, selection)) {
93
+ } else if (side === _selection.Side.LEFT && (0, _utils4.isSelectionAtStartOfParentNode)($from, selection)) {
93
94
  if (selectionRelativeToNode === _selection.RelativeSelectionPos.Before) {
94
95
  var $parent = state.doc.resolve(selection.$from.before(selection.$from.depth));
95
96
  if ($parent) {
96
- var _selectableNode2 = (0, _utils3.findSelectableContainerBefore)($parent, state.doc);
97
+ var _selectableNode2 = (0, _utils4.findSelectableContainerBefore)($parent, state.doc);
97
98
  if (_selectableNode2 && (0, _selection.isIgnored)(_selectableNode2.node)) {
98
99
  // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
99
100
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, _selectableNode2.pos))(state, dispatch);
@@ -103,7 +104,7 @@ var arrowLeftFromGapCursor = function arrowLeftFromGapCursor(selection) {
103
104
  // from responding to arrow left key
104
105
  setSelectionRelativeToNode()(state, dispatch);
105
106
  } else {
106
- var _selectableNode3 = (0, _utils3.findSelectableContainerParent)(selection);
107
+ var _selectableNode3 = (0, _utils4.findSelectableContainerParent)(selection);
107
108
  if (_selectableNode3) {
108
109
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.Start, _state.NodeSelection.create(state.doc, _selectableNode3.pos))(state, dispatch);
109
110
  }
@@ -120,7 +121,7 @@ var arrowRightFromNode = function arrowRightFromNode(selection) {
120
121
  var _getPluginState2 = (0, _pluginFactory.getPluginState)(state),
121
122
  selectionRelativeToNode = _getPluginState2.selectionRelativeToNode;
122
123
  if (node.isAtom) {
123
- if ((0, _utils3.isSelectionAtEndOfParentNode)($to, selection) && (node.isInline || (0, _selection.isIgnored)(node))) {
124
+ if ((0, _utils4.isSelectionAtEndOfParentNode)($to, selection) && (node.isInline || (0, _selection.isIgnored)(node))) {
124
125
  // selection is for inline node or atom node which is ignored by gap-cursor and that is the last child of its parent node - set text selection after it
125
126
  return findAndSetTextSelection(_selection.RelativeSelectionPos.End, state.doc.resolve(from + 1), _types.SelectionDirection.After)(state, dispatch);
126
127
  }
@@ -129,7 +130,7 @@ var arrowRightFromNode = function arrowRightFromNode(selection) {
129
130
  // selection is for container node - set selection inside it at the start
130
131
  return setSelectionInsideAtNodeStart(_selection.RelativeSelectionPos.Inside, node, from)(state, dispatch);
131
132
  } else if ((0, _selection.isIgnored)(node) && (!selectionRelativeToNode || selectionRelativeToNode === _selection.RelativeSelectionPos.End)) {
132
- var selectableNode = (0, _utils3.findSelectableContainerAfter)($to, state.doc);
133
+ var selectableNode = (0, _utils4.findSelectableContainerAfter)($to, state.doc);
133
134
  if (selectableNode && (0, _selection.isIgnored)(selectableNode.node)) {
134
135
  // selection is for node without gap cursor followed by another node without gap cursor - set node selection for next node
135
136
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.Start, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
@@ -147,7 +148,7 @@ var arrowLeftFromNode = function arrowLeftFromNode(selection) {
147
148
  var _getPluginState3 = (0, _pluginFactory.getPluginState)(state),
148
149
  selectionRelativeToNode = _getPluginState3.selectionRelativeToNode;
149
150
  if (node.isAtom) {
150
- if ((0, _utils3.isSelectionAtStartOfParentNode)($from, selection) && (node.isInline || (0, _selection.isIgnored)(node))) {
151
+ if ((0, _utils4.isSelectionAtStartOfParentNode)($from, selection) && (node.isInline || (0, _selection.isIgnored)(node))) {
151
152
  // selection is for inline node or atom node which is ignored by gap-cursor and that is the first child of its parent node - set text selection before it
152
153
  return findAndSetTextSelection(_selection.RelativeSelectionPos.Start, state.doc.resolve(from), _types.SelectionDirection.Before)(state, dispatch);
153
154
  }
@@ -161,7 +162,7 @@ var arrowLeftFromNode = function arrowLeftFromNode(selection) {
161
162
  return setSelectionInsideAtNodeStart(_selection.RelativeSelectionPos.Before, node, from)(state, dispatch);
162
163
  } else if ((0, _selection.isIgnored)(node) && selectionRelativeToNode === _selection.RelativeSelectionPos.Start) {
163
164
  // selection is for node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
164
- var selectableNode = (0, _utils3.findSelectableContainerBefore)($from, state.doc);
165
+ var selectableNode = (0, _utils4.findSelectableContainerBefore)($from, state.doc);
165
166
  if (selectableNode && (0, _selection.isIgnored)(selectableNode.node)) {
166
167
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
167
168
  }
@@ -171,8 +172,8 @@ var arrowLeftFromNode = function arrowLeftFromNode(selection) {
171
172
  };
172
173
  var arrowRightFromText = function arrowRightFromText(selection) {
173
174
  return function (state, dispatch) {
174
- if ((0, _utils3.isSelectionAtEndOfParentNode)(selection.$to, selection)) {
175
- var selectableNode = (0, _utils3.findSelectableContainerParent)(selection);
175
+ if ((0, _utils4.isSelectionAtEndOfParentNode)(selection.$to, selection)) {
176
+ var selectableNode = (0, _utils4.findSelectableContainerParent)(selection);
176
177
  if (selectableNode) {
177
178
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
178
179
  }
@@ -185,7 +186,7 @@ var arrowLeftFromText = function arrowLeftFromText(selection) {
185
186
  var _getPluginState4 = (0, _pluginFactory.getPluginState)(state),
186
187
  selectionRelativeToNode = _getPluginState4.selectionRelativeToNode;
187
188
  if (selectionRelativeToNode === _selection.RelativeSelectionPos.Before) {
188
- var selectableNode = (0, _utils3.findSelectableContainerBefore)(selection.$from, state.doc);
189
+ var selectableNode = (0, _utils4.findSelectableContainerBefore)(selection.$from, state.doc);
189
190
  if (selectableNode && (0, _selection.isIgnored)(selectableNode.node)) {
190
191
  // selection is inside node without gap cursor preceeded by another node without gap cursor - set node selection for previous node
191
192
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.End, _state.NodeSelection.create(state.doc, selectableNode.pos))(state, dispatch);
@@ -193,8 +194,8 @@ var arrowLeftFromText = function arrowLeftFromText(selection) {
193
194
  // we don't return this as we want to reset the relative pos, but not block other plugins
194
195
  // from responding to arrow left key
195
196
  setSelectionRelativeToNode(undefined)(state, dispatch);
196
- } else if ((0, _utils3.isSelectionAtStartOfParentNode)(selection.$from, selection)) {
197
- var _selectableNode4 = (0, _utils3.findSelectableContainerParent)(selection);
197
+ } else if ((0, _utils4.isSelectionAtStartOfParentNode)(selection.$from, selection)) {
198
+ var _selectableNode4 = (0, _utils4.findSelectableContainerParent)(selection);
198
199
  if (_selectableNode4) {
199
200
  return setSelectionRelativeToNode(_selection.RelativeSelectionPos.Start, _state.NodeSelection.create(state.doc, _selectableNode4.pos))(state, dispatch);
200
201
  }
@@ -216,7 +217,7 @@ var setSelectionInsideAtNodeStart = function setSelectionInsideAtNodeStart(selec
216
217
  if ((0, _utils.isNodeEmpty)(node)) {
217
218
  return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(pos), _types.SelectionDirection.After)(state, dispatch);
218
219
  }
219
- var selectableNode = (0, _utils3.findFirstChildNodeToSelect)(node);
220
+ var selectableNode = (0, _utils4.findFirstChildNodeToSelect)(node);
220
221
  if (selectableNode) {
221
222
  var childNode = selectableNode.node,
222
223
  childPos = selectableNode.pos;
@@ -228,7 +229,7 @@ var setSelectionInsideAtNodeStart = function setSelectionInsideAtNodeStart(selec
228
229
  return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos + 1), _types.SelectionDirection.Before)(state, dispatch);
229
230
  } else if (!(0, _selection.isIgnored)(node)) {
230
231
  return setSelectionRelativeToNode(selectionRelativeToNode, new _selection.GapCursorSelection(state.doc.resolve(selectionPos), _selection.Side.LEFT))(state, dispatch);
231
- } else if ((0, _utils3.isSelectableContainerNode)(node)) {
232
+ } else if ((0, _utils4.isSelectableContainerNode)(node)) {
232
233
  return setSelectionRelativeToNode(selectionRelativeToNode, _state.NodeSelection.create(state.doc, selectionPos))(state, dispatch);
233
234
  }
234
235
  }
@@ -240,7 +241,7 @@ var setSelectionInsideAtNodeEnd = exports.setSelectionInsideAtNodeEnd = function
240
241
  if ((0, _utils.isNodeEmpty)(node)) {
241
242
  return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(to), _types.SelectionDirection.Before)(state, dispatch);
242
243
  }
243
- var selectableNode = (0, _utils3.findLastChildNodeToSelect)(node);
244
+ var selectableNode = (0, _utils4.findLastChildNodeToSelect)(node);
244
245
  if (selectableNode) {
245
246
  var childNode = selectableNode.node,
246
247
  childPos = selectableNode.pos;
@@ -252,7 +253,7 @@ var setSelectionInsideAtNodeEnd = exports.setSelectionInsideAtNodeEnd = function
252
253
  return findAndSetTextSelection(selectionRelativeToNode, state.doc.resolve(selectionPos), _types.SelectionDirection.After)(state, dispatch);
253
254
  } else if (!(0, _selection.isIgnored)(node)) {
254
255
  return setSelectionRelativeToNode(selectionRelativeToNode, new _selection.GapCursorSelection(state.doc.resolve(selectionPos + 1), _selection.Side.RIGHT))(state, dispatch);
255
- } else if ((0, _utils3.isSelectableContainerNode)(node)) {
256
+ } else if ((0, _utils4.isSelectableContainerNode)(node)) {
256
257
  return setSelectionRelativeToNode(selectionRelativeToNode, _state.NodeSelection.create(state.doc, selectionPos))(state, dispatch);
257
258
  }
258
259
  }
@@ -271,12 +272,21 @@ var selectNodeWithModA = exports.selectNodeWithModA = function selectNodeWithMod
271
272
  var isInCodeBlock = $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
272
273
 
273
274
  // If the selection is at the top level and not in a code block, or if a table is selected, do nothing
274
- if (isTopLevelSelection && !isInCodeBlock || (0, _utils2.isTableSelected)(selection)) {
275
+ if (isTopLevelSelection && !isInCodeBlock) {
275
276
  return false;
276
277
  }
277
278
 
278
279
  // Get the depth of the first common ancestor node
279
280
  var commonAncestorDepth = $from.sharedDepth($to.pos);
281
+
282
+ // We need to adjust the common ancestor depth if a table is selected
283
+ // to skip the current table node and select the parent node instead
284
+ if ((0, _utils3.isTableSelected)(state.selection)) {
285
+ var table = (0, _utils2.findParentNodeOfType)(state.schema.nodes.table)(state.selection);
286
+ if (table) {
287
+ commonAncestorDepth = table.depth - 1;
288
+ }
289
+ }
280
290
  for (var depth = commonAncestorDepth; depth > 0; depth--) {
281
291
  var node = $from.node(depth);
282
292
  var isParentBlockQuote = node.type.name === 'blockquote';
@@ -18,7 +18,9 @@ function keymapPlugin() {
18
18
  // Ignored via go/ees005
19
19
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
20
20
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveLeft.common, _commands.arrowLeft, list);
21
- if ((0, _experiments.editorExperiment)('platform_editor_cmd_a_progressively_select_nodes', true)) {
21
+ if ((0, _experiments.editorExperiment)('platform_editor_cmd_a_progressively_select_nodes', true, {
22
+ exposure: true
23
+ })) {
22
24
  // Ignored via go/ees005
23
25
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
26
  (0, _keymaps.bindKeymapWithCommand)(_keymaps.selectNode.common, (0, _commands.selectNodeWithModA)(), list);
@@ -2,6 +2,7 @@
2
2
  import { isIgnored as isIgnoredByGapCursor, RelativeSelectionPos, GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
3
3
  import { isEmptyParagraph, isNodeEmpty } from '@atlaskit/editor-common/utils';
4
4
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
6
  import { isTableSelected } from '@atlaskit/editor-tables/utils';
6
7
  import { SelectionDirection, selectionPluginKey } from '../types';
7
8
  import { SelectionActionTypes } from './actions';
@@ -266,12 +267,21 @@ export const selectNodeWithModA = () => (state, dispatch) => {
266
267
  const isInCodeBlock = $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
267
268
 
268
269
  // If the selection is at the top level and not in a code block, or if a table is selected, do nothing
269
- if (isTopLevelSelection && !isInCodeBlock || isTableSelected(selection)) {
270
+ if (isTopLevelSelection && !isInCodeBlock) {
270
271
  return false;
271
272
  }
272
273
 
273
274
  // Get the depth of the first common ancestor node
274
- const commonAncestorDepth = $from.sharedDepth($to.pos);
275
+ let commonAncestorDepth = $from.sharedDepth($to.pos);
276
+
277
+ // We need to adjust the common ancestor depth if a table is selected
278
+ // to skip the current table node and select the parent node instead
279
+ if (isTableSelected(state.selection)) {
280
+ const table = findParentNodeOfType(state.schema.nodes.table)(state.selection);
281
+ if (table) {
282
+ commonAncestorDepth = table.depth - 1;
283
+ }
284
+ }
275
285
  for (let depth = commonAncestorDepth; depth > 0; depth--) {
276
286
  const node = $from.node(depth);
277
287
  const isParentBlockQuote = node.type.name === 'blockquote';
@@ -12,7 +12,9 @@ function keymapPlugin() {
12
12
  // Ignored via go/ees005
13
13
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
14
  bindKeymapWithCommand(moveLeft.common, arrowLeft, list);
15
- if (editorExperiment('platform_editor_cmd_a_progressively_select_nodes', true)) {
15
+ if (editorExperiment('platform_editor_cmd_a_progressively_select_nodes', true, {
16
+ exposure: true
17
+ })) {
16
18
  // Ignored via go/ees005
17
19
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18
20
  bindKeymapWithCommand(selectNode.common, selectNodeWithModA(), list);
@@ -2,6 +2,7 @@
2
2
  import { isIgnored as isIgnoredByGapCursor, RelativeSelectionPos, GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
3
3
  import { isEmptyParagraph, isNodeEmpty } from '@atlaskit/editor-common/utils';
4
4
  import { NodeSelection, Selection, TextSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { findParentNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
6
  import { isTableSelected } from '@atlaskit/editor-tables/utils';
6
7
  import { SelectionDirection, selectionPluginKey } from '../types';
7
8
  import { SelectionActionTypes } from './actions';
@@ -264,12 +265,21 @@ export var selectNodeWithModA = function selectNodeWithModA() {
264
265
  var isInCodeBlock = $from.sameParent($to) && $from.parent.type === state.schema.nodes.codeBlock;
265
266
 
266
267
  // If the selection is at the top level and not in a code block, or if a table is selected, do nothing
267
- if (isTopLevelSelection && !isInCodeBlock || isTableSelected(selection)) {
268
+ if (isTopLevelSelection && !isInCodeBlock) {
268
269
  return false;
269
270
  }
270
271
 
271
272
  // Get the depth of the first common ancestor node
272
273
  var commonAncestorDepth = $from.sharedDepth($to.pos);
274
+
275
+ // We need to adjust the common ancestor depth if a table is selected
276
+ // to skip the current table node and select the parent node instead
277
+ if (isTableSelected(state.selection)) {
278
+ var table = findParentNodeOfType(state.schema.nodes.table)(state.selection);
279
+ if (table) {
280
+ commonAncestorDepth = table.depth - 1;
281
+ }
282
+ }
273
283
  for (var depth = commonAncestorDepth; depth > 0; depth--) {
274
284
  var node = $from.node(depth);
275
285
  var isParentBlockQuote = node.type.name === 'blockquote';
@@ -12,7 +12,9 @@ function keymapPlugin() {
12
12
  // Ignored via go/ees005
13
13
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
14
14
  bindKeymapWithCommand(moveLeft.common, arrowLeft, list);
15
- if (editorExperiment('platform_editor_cmd_a_progressively_select_nodes', true)) {
15
+ if (editorExperiment('platform_editor_cmd_a_progressively_select_nodes', true, {
16
+ exposure: true
17
+ })) {
16
18
  // Ignored via go/ees005
17
19
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
18
20
  bindKeymapWithCommand(selectNode.common, selectNodeWithModA(), list);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
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.3.0",
23
+ "@atlaskit/editor-common": "^102.8.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": "^3.5.0",
29
- "@atlaskit/tokens": "^4.3.0",
28
+ "@atlaskit/tmp-editor-statsig": "^4.0.0",
29
+ "@atlaskit/tokens": "^4.5.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
32
32
  "peerDependencies": {