@atlaskit/editor-plugin-block-menu 6.0.14 → 6.0.15

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,13 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 6.0.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2a1bf10d70beb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a1bf10d70beb) -
8
+ EDITOR-4293 Fix block menu selection highlight issues
9
+ - Updated dependencies
10
+
3
11
  ## 6.0.14
4
12
 
5
13
  ### Patch Changes
@@ -10,8 +10,9 @@ var _analytics = require("@atlaskit/editor-common/analytics");
10
10
  var _performanceMeasures = require("@atlaskit/editor-common/performance-measures");
11
11
  var _selection = require("@atlaskit/editor-common/selection");
12
12
  var _state = require("@atlaskit/editor-prosemirror/state");
13
+ var _transform = require("@atlaskit/editor-prosemirror/transform");
13
14
  var _isNestedNode = require("../ui/utils/isNestedNode");
14
- var _transform = require("./transform-node-utils/transform");
15
+ var _transform2 = require("./transform-node-utils/transform");
15
16
  var _utils = require("./transforms/utils");
16
17
  var transformNode = exports.transformNode = function transformNode(api) {
17
18
  return function (targetType, metadata) {
@@ -41,7 +42,7 @@ var transformNode = exports.transformNode = function transformNode(api) {
41
42
  var typeName = node.type.name;
42
43
  sourceNodeTypes[typeName] = (sourceNodeTypes[typeName] || 0) + 1;
43
44
  });
44
- var resultNodes = (0, _transform.convertNodesToTargetType)({
45
+ var resultNodes = (0, _transform2.convertNodesToTargetType)({
45
46
  sourceNodes: sourceNodes,
46
47
  targetNodeType: targetType,
47
48
  schema: tr.doc.type.schema,
@@ -51,6 +52,7 @@ var transformNode = exports.transformNode = function transformNode(api) {
51
52
  });
52
53
  var content = resultNodes.length > 0 ? resultNodes : slice.content;
53
54
  if (preservedSelection instanceof _state.NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
55
+ var _api$blockControls2;
54
56
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
55
57
  var deleteFrom = $from.pos;
56
58
  var deleteTo = $to.pos;
@@ -59,6 +61,17 @@ var transformNode = exports.transformNode = function transformNode(api) {
59
61
  // especially when mediaSingle with caption is at the bottom of the document
60
62
  var insertPos = Math.min(deleteFrom, tr.doc.content.size);
61
63
  tr.insert(insertPos, content);
64
+
65
+ // when we replace and insert content, we need to manually map the preserved selection
66
+ // through the transaction, otherwise it will treat the selection as having been deleted
67
+ // and stop preserving it
68
+ var oldSize = slice.size;
69
+ var newSize = Array.isArray(content) ? content.reduce(function (sum, node) {
70
+ return sum + node.nodeSize;
71
+ }, 0) : content.size;
72
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.mapPreservedSelection(new _transform.Mapping([new _transform.StepMap([0, oldSize, newSize])]))({
73
+ tr: tr
74
+ });
62
75
  } else {
63
76
  tr.replaceWith(sliceStart, $to.pos, content);
64
77
  }
@@ -2,6 +2,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit
2
2
  import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
3
3
  import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
4
4
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
5
+ import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
5
6
  import { isNestedNode } from '../ui/utils/isNestedNode';
6
7
  import { convertNodesToTargetType } from './transform-node-utils/transform';
7
8
  import { isListNode } from './transforms/utils';
@@ -45,6 +46,7 @@ export const transformNode = api => (targetType, metadata) => ({
45
46
  });
46
47
  const content = resultNodes.length > 0 ? resultNodes : slice.content;
47
48
  if (preservedSelection instanceof NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
49
+ var _api$blockControls2;
48
50
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
49
51
  const deleteFrom = $from.pos;
50
52
  const deleteTo = $to.pos;
@@ -53,6 +55,15 @@ export const transformNode = api => (targetType, metadata) => ({
53
55
  // especially when mediaSingle with caption is at the bottom of the document
54
56
  const insertPos = Math.min(deleteFrom, tr.doc.content.size);
55
57
  tr.insert(insertPos, content);
58
+
59
+ // when we replace and insert content, we need to manually map the preserved selection
60
+ // through the transaction, otherwise it will treat the selection as having been deleted
61
+ // and stop preserving it
62
+ const oldSize = slice.size;
63
+ const newSize = Array.isArray(content) ? content.reduce((sum, node) => sum + node.nodeSize, 0) : content.size;
64
+ api === null || api === void 0 ? void 0 : (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.commands.mapPreservedSelection(new Mapping([new StepMap([0, oldSize, newSize])]))({
65
+ tr
66
+ });
56
67
  } else {
57
68
  tr.replaceWith(sliceStart, $to.pos, content);
58
69
  }
@@ -3,6 +3,7 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit
3
3
  import { startMeasure, stopMeasure } from '@atlaskit/editor-common/performance-measures';
4
4
  import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
5
5
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
6
+ import { Mapping, StepMap } from '@atlaskit/editor-prosemirror/transform';
6
7
  import { isNestedNode } from '../ui/utils/isNestedNode';
7
8
  import { convertNodesToTargetType } from './transform-node-utils/transform';
8
9
  import { isListNode } from './transforms/utils';
@@ -44,6 +45,7 @@ export var transformNode = function transformNode(api) {
44
45
  });
45
46
  var content = resultNodes.length > 0 ? resultNodes : slice.content;
46
47
  if (preservedSelection instanceof NodeSelection && preservedSelection.node.type === nodes.mediaSingle) {
48
+ var _api$blockControls2;
47
49
  // when node is media single, use tr.replaceWith freeze editor, if modify position, tr.replaceWith creates duplicats
48
50
  var deleteFrom = $from.pos;
49
51
  var deleteTo = $to.pos;
@@ -52,6 +54,17 @@ export var transformNode = function transformNode(api) {
52
54
  // especially when mediaSingle with caption is at the bottom of the document
53
55
  var insertPos = Math.min(deleteFrom, tr.doc.content.size);
54
56
  tr.insert(insertPos, content);
57
+
58
+ // when we replace and insert content, we need to manually map the preserved selection
59
+ // through the transaction, otherwise it will treat the selection as having been deleted
60
+ // and stop preserving it
61
+ var oldSize = slice.size;
62
+ var newSize = Array.isArray(content) ? content.reduce(function (sum, node) {
63
+ return sum + node.nodeSize;
64
+ }, 0) : content.size;
65
+ api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || _api$blockControls2.commands.mapPreservedSelection(new Mapping([new StepMap([0, oldSize, newSize])]))({
66
+ tr: tr
67
+ });
55
68
  } else {
56
69
  tr.replaceWith(sliceStart, $to.pos, content);
57
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "6.0.14",
3
+ "version": "6.0.15",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^17.0.0",
47
- "@atlaskit/tmp-editor-statsig": "^16.13.0",
47
+ "@atlaskit/tmp-editor-statsig": "^16.15.0",
48
48
  "@atlaskit/tokens": "^9.1.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },