@atlaskit/editor-plugin-block-controls 2.2.1 → 2.2.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,14 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 2.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#151024](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/151024)
8
+ [`73afcf51ef0da`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/73afcf51ef0da) -
9
+ ED-20516 Set selection at end of node after drop instead of selecting entire moved node
10
+ - Updated dependencies
11
+
3
12
  ## 2.2.1
4
13
 
5
14
  ### Patch Changes
@@ -18,6 +18,7 @@ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
18
18
  var _consts = require("../consts");
19
19
  var _main = require("../pm-plugins/main");
20
20
  var _utils4 = require("../utils");
21
+ var _getSelection = require("../utils/getSelection");
21
22
  var _validation = require("../utils/validation");
22
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
23
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -189,7 +190,7 @@ var moveNode = exports.moveNode = function moveNode(api) {
189
190
  mappedTo = tr.mapping.map(to);
190
191
  tr.insert(mappedTo, _nodeCopy); // insert the content at the new position
191
192
  }
192
- tr = (0, _utils4.selectNode)(tr, mappedTo, node.type.name);
193
+ tr = inputMethod === _analytics.INPUT_METHOD.DRAG_AND_DROP && (0, _platformFeatureFlags.fg)('platform_editor_element_dnd_nested_fix_patch_2') ? (0, _getSelection.setCursorPositionAtMovedNode)(tr, mappedTo) : (0, _utils4.selectNode)(tr, mappedTo, node.type.name);
193
194
  tr.setMeta(_main.key, {
194
195
  nodeMoved: true
195
196
  });
@@ -3,9 +3,32 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectNode = exports.getSelection = void 0;
6
+ exports.setCursorPositionAtMovedNode = exports.selectNode = exports.getSelection = exports.getInlineNodePos = void 0;
7
+ var _selection = require("@atlaskit/editor-common/selection");
7
8
  var _state = require("@atlaskit/editor-prosemirror/state");
8
9
  var _utils = require("@atlaskit/editor-tables/utils");
10
+ var getInlineNodePos = exports.getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
11
+ var $startPos = tr.doc.resolve(start);
12
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
13
+ // Find the first inline node in the node
14
+ var inlineNodePos = start;
15
+ var foundInlineNode = false;
16
+ var inlineNodeEndPos = 0;
17
+ tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
18
+ if (n.isInline) {
19
+ inlineNodeEndPos = pos + n.nodeSize;
20
+ }
21
+ if (n.isInline && !foundInlineNode) {
22
+ inlineNodePos = pos;
23
+ foundInlineNode = true;
24
+ }
25
+ return true;
26
+ });
27
+ return {
28
+ inlineNodePos: inlineNodePos,
29
+ inlineNodeEndPos: inlineNodeEndPos
30
+ };
31
+ };
9
32
  var getSelection = exports.getSelection = function getSelection(tr, start) {
10
33
  var node = tr.doc.nodeAt(start);
11
34
  var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
@@ -25,21 +48,9 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
25
48
  nodeName === 'mediaGroup') {
26
49
  return new _state.NodeSelection($startPos);
27
50
  } else {
28
- // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
29
- // Find the first inline node in the node
30
- var inlineNodePos = start;
31
- var foundInlineNode = false;
32
- var inlineNodeEndPos = 0;
33
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
34
- if (n.isInline) {
35
- inlineNodeEndPos = pos + n.nodeSize;
36
- }
37
- if (n.isInline && !foundInlineNode) {
38
- inlineNodePos = pos;
39
- foundInlineNode = true;
40
- }
41
- return true;
42
- });
51
+ var _getInlineNodePos = getInlineNodePos(tr, start, nodeSize),
52
+ inlineNodePos = _getInlineNodePos.inlineNodePos,
53
+ inlineNodeEndPos = _getInlineNodePos.inlineNodeEndPos;
43
54
  return new _state.TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
44
55
  }
45
56
  };
@@ -51,4 +62,20 @@ var selectNode = exports.selectNode = function selectNode(tr, start, nodeType) {
51
62
  tr.setSelection(getSelection(tr, start));
52
63
  }
53
64
  return tr;
65
+ };
66
+ var setCursorPositionAtMovedNode = exports.setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(tr, start) {
67
+ var node = tr.doc.nodeAt(start);
68
+ var isNodeSelection = node && _state.NodeSelection.isSelectable(node);
69
+ var nodeSize = node ? node.nodeSize : 1;
70
+ var selection;
71
+ // decisionList node is not selectable, but we want to select the whole node not just text
72
+ if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
73
+ selection = new _selection.GapCursorSelection(tr.doc.resolve(start + node.nodeSize), _selection.Side.RIGHT);
74
+ } else {
75
+ var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
76
+ inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
77
+ selection = new _state.TextSelection(tr.doc.resolve(inlineNodeEndPos));
78
+ }
79
+ tr.setSelection(selection);
80
+ return tr;
54
81
  };
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "getInlineNodePos", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _getSelection.getInlineNodePos;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "getNestedNodePosition", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -21,5 +27,11 @@ Object.defineProperty(exports, "selectNode", {
21
27
  return _getSelection.selectNode;
22
28
  }
23
29
  });
30
+ Object.defineProperty(exports, "setCursorPositionAtMovedNode", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _getSelection.setCursorPositionAtMovedNode;
34
+ }
35
+ });
24
36
  var _getSelection = require("./getSelection");
25
37
  var _getNestedNodePosition = require("./getNestedNodePosition");
@@ -10,6 +10,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
10
10
  import { DIRECTION } from '../consts';
11
11
  import { key } from '../pm-plugins/main';
12
12
  import { getNestedNodePosition, selectNode } from '../utils';
13
+ import { setCursorPositionAtMovedNode } from '../utils/getSelection';
13
14
  import { canMoveNodeToIndex, isInsideTable, transformSliceExpandToNestedExpand } from '../utils/validation';
14
15
 
15
16
  /**
@@ -183,7 +184,7 @@ export const moveNode = api => (start, to, inputMethod = INPUT_METHOD.DRAG_AND_D
183
184
  mappedTo = tr.mapping.map(to);
184
185
  tr.insert(mappedTo, nodeCopy); // insert the content at the new position
185
186
  }
186
- tr = selectNode(tr, mappedTo, node.type.name);
187
+ tr = inputMethod === INPUT_METHOD.DRAG_AND_DROP && fg('platform_editor_element_dnd_nested_fix_patch_2') ? setCursorPositionAtMovedNode(tr, mappedTo) : selectNode(tr, mappedTo, node.type.name);
187
188
  tr.setMeta(key, {
188
189
  nodeMoved: true
189
190
  });
@@ -1,5 +1,28 @@
1
+ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
1
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
4
+ export const getInlineNodePos = (tr, start, nodeSize) => {
5
+ const $startPos = tr.doc.resolve(start);
6
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
7
+ // Find the first inline node in the node
8
+ let inlineNodePos = start;
9
+ let foundInlineNode = false;
10
+ let inlineNodeEndPos = 0;
11
+ tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, (n, pos) => {
12
+ if (n.isInline) {
13
+ inlineNodeEndPos = pos + n.nodeSize;
14
+ }
15
+ if (n.isInline && !foundInlineNode) {
16
+ inlineNodePos = pos;
17
+ foundInlineNode = true;
18
+ }
19
+ return true;
20
+ });
21
+ return {
22
+ inlineNodePos,
23
+ inlineNodeEndPos
24
+ };
25
+ };
3
26
  export const getSelection = (tr, start) => {
4
27
  const node = tr.doc.nodeAt(start);
5
28
  const isNodeSelection = node && NodeSelection.isSelectable(node);
@@ -19,21 +42,10 @@ export const getSelection = (tr, start) => {
19
42
  nodeName === 'mediaGroup') {
20
43
  return new NodeSelection($startPos);
21
44
  } else {
22
- // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
23
- // Find the first inline node in the node
24
- let inlineNodePos = start;
25
- let foundInlineNode = false;
26
- let inlineNodeEndPos = 0;
27
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, (n, pos) => {
28
- if (n.isInline) {
29
- inlineNodeEndPos = pos + n.nodeSize;
30
- }
31
- if (n.isInline && !foundInlineNode) {
32
- inlineNodePos = pos;
33
- foundInlineNode = true;
34
- }
35
- return true;
36
- });
45
+ const {
46
+ inlineNodePos,
47
+ inlineNodeEndPos
48
+ } = getInlineNodePos(tr, start, nodeSize);
37
49
  return new TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
38
50
  }
39
51
  };
@@ -45,4 +57,21 @@ export const selectNode = (tr, start, nodeType) => {
45
57
  tr.setSelection(getSelection(tr, start));
46
58
  }
47
59
  return tr;
60
+ };
61
+ export const setCursorPositionAtMovedNode = (tr, start) => {
62
+ const node = tr.doc.nodeAt(start);
63
+ const isNodeSelection = node && NodeSelection.isSelectable(node);
64
+ const nodeSize = node ? node.nodeSize : 1;
65
+ let selection;
66
+ // decisionList node is not selectable, but we want to select the whole node not just text
67
+ if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
68
+ selection = new GapCursorSelection(tr.doc.resolve(start + node.nodeSize), Side.RIGHT);
69
+ } else {
70
+ const {
71
+ inlineNodeEndPos
72
+ } = getInlineNodePos(tr, start, nodeSize);
73
+ selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
74
+ }
75
+ tr.setSelection(selection);
76
+ return tr;
48
77
  };
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
@@ -13,6 +13,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
13
13
  import { DIRECTION } from '../consts';
14
14
  import { key } from '../pm-plugins/main';
15
15
  import { getNestedNodePosition, selectNode } from '../utils';
16
+ import { setCursorPositionAtMovedNode } from '../utils/getSelection';
16
17
  import { canMoveNodeToIndex, isInsideTable, transformSliceExpandToNestedExpand } from '../utils/validation';
17
18
 
18
19
  /**
@@ -183,7 +184,7 @@ export var moveNode = function moveNode(api) {
183
184
  mappedTo = tr.mapping.map(to);
184
185
  tr.insert(mappedTo, _nodeCopy); // insert the content at the new position
185
186
  }
186
- tr = selectNode(tr, mappedTo, node.type.name);
187
+ tr = inputMethod === INPUT_METHOD.DRAG_AND_DROP && fg('platform_editor_element_dnd_nested_fix_patch_2') ? setCursorPositionAtMovedNode(tr, mappedTo) : selectNode(tr, mappedTo, node.type.name);
187
188
  tr.setMeta(key, {
188
189
  nodeMoved: true
189
190
  });
@@ -1,5 +1,28 @@
1
+ import { GapCursorSelection, Side } from '@atlaskit/editor-common/selection';
1
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
3
  import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
4
+ export var getInlineNodePos = function getInlineNodePos(tr, start, nodeSize) {
5
+ var $startPos = tr.doc.resolve(start);
6
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
7
+ // Find the first inline node in the node
8
+ var inlineNodePos = start;
9
+ var foundInlineNode = false;
10
+ var inlineNodeEndPos = 0;
11
+ tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
12
+ if (n.isInline) {
13
+ inlineNodeEndPos = pos + n.nodeSize;
14
+ }
15
+ if (n.isInline && !foundInlineNode) {
16
+ inlineNodePos = pos;
17
+ foundInlineNode = true;
18
+ }
19
+ return true;
20
+ });
21
+ return {
22
+ inlineNodePos: inlineNodePos,
23
+ inlineNodeEndPos: inlineNodeEndPos
24
+ };
25
+ };
3
26
  export var getSelection = function getSelection(tr, start) {
4
27
  var node = tr.doc.nodeAt(start);
5
28
  var isNodeSelection = node && NodeSelection.isSelectable(node);
@@ -19,21 +42,9 @@ export var getSelection = function getSelection(tr, start) {
19
42
  nodeName === 'mediaGroup') {
20
43
  return new NodeSelection($startPos);
21
44
  } else {
22
- // To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
23
- // Find the first inline node in the node
24
- var inlineNodePos = start;
25
- var foundInlineNode = false;
26
- var inlineNodeEndPos = 0;
27
- tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
28
- if (n.isInline) {
29
- inlineNodeEndPos = pos + n.nodeSize;
30
- }
31
- if (n.isInline && !foundInlineNode) {
32
- inlineNodePos = pos;
33
- foundInlineNode = true;
34
- }
35
- return true;
36
- });
45
+ var _getInlineNodePos = getInlineNodePos(tr, start, nodeSize),
46
+ inlineNodePos = _getInlineNodePos.inlineNodePos,
47
+ inlineNodeEndPos = _getInlineNodePos.inlineNodeEndPos;
37
48
  return new TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
38
49
  }
39
50
  };
@@ -45,4 +56,20 @@ export var selectNode = function selectNode(tr, start, nodeType) {
45
56
  tr.setSelection(getSelection(tr, start));
46
57
  }
47
58
  return tr;
59
+ };
60
+ export var setCursorPositionAtMovedNode = function setCursorPositionAtMovedNode(tr, start) {
61
+ var node = tr.doc.nodeAt(start);
62
+ var isNodeSelection = node && NodeSelection.isSelectable(node);
63
+ var nodeSize = node ? node.nodeSize : 1;
64
+ var selection;
65
+ // decisionList node is not selectable, but we want to select the whole node not just text
66
+ if (isNodeSelection || (node === null || node === void 0 ? void 0 : node.type.name) === 'decisionList') {
67
+ selection = new GapCursorSelection(tr.doc.resolve(start + node.nodeSize), Side.RIGHT);
68
+ } else {
69
+ var _getInlineNodePos2 = getInlineNodePos(tr, start, nodeSize),
70
+ inlineNodeEndPos = _getInlineNodePos2.inlineNodeEndPos;
71
+ selection = new TextSelection(tr.doc.resolve(inlineNodeEndPos));
72
+ }
73
+ tr.setSelection(selection);
74
+ return tr;
48
75
  };
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
@@ -1,3 +1,8 @@
1
1
  import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
3
+ inlineNodePos: number;
4
+ inlineNodeEndPos: number;
5
+ };
2
6
  export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
3
7
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
8
+ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode, } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
@@ -1,3 +1,8 @@
1
1
  import { NodeSelection, TextSelection, type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const getInlineNodePos: (tr: Transaction, start: number, nodeSize: number) => {
3
+ inlineNodePos: number;
4
+ inlineNodeEndPos: number;
5
+ };
2
6
  export declare const getSelection: (tr: Transaction, start: number) => NodeSelection | TextSelection;
3
7
  export declare const selectNode: (tr: Transaction, start: number, nodeType: string) => Transaction;
8
+ export declare const setCursorPositionAtMovedNode: (tr: Transaction, start: number) => Transaction;
@@ -1,2 +1,2 @@
1
- export { getSelection, selectNode } from './getSelection';
1
+ export { getInlineNodePos, getSelection, selectNode, setCursorPositionAtMovedNode, } from './getSelection';
2
2
  export { getNestedNodePosition } from './getNestedNodePosition';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@atlaskit/adf-schema": "^40.9.0",
34
- "@atlaskit/editor-common": "^93.1.0",
34
+ "@atlaskit/editor-common": "^93.2.0",
35
35
  "@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.8.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
@@ -43,7 +43,7 @@
43
43
  "@atlaskit/editor-tables": "^2.8.0",
44
44
  "@atlaskit/icon": "^22.22.0",
45
45
  "@atlaskit/platform-feature-flags": "^0.3.0",
46
- "@atlaskit/pragmatic-drag-and-drop": "^1.3.0",
46
+ "@atlaskit/pragmatic-drag-and-drop": "^1.4.0",
47
47
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^1.4.0",
48
48
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
49
49
  "@atlaskit/primitives": "^12.2.0",