@atlaskit/editor-plugin-block-controls 1.4.3 → 1.4.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,13 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#104094](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/104094)
8
+ [`ae80ae898d90`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ae80ae898d90) -
9
+ Refactor getSelection and add tests
10
+
3
11
  ## 1.4.3
4
12
 
5
13
  ### Patch Changes
@@ -9,7 +9,7 @@ var _react = require("@emotion/react");
9
9
 
10
10
  var globalStyles = (0, _react.css)({
11
11
  '.ProseMirror-widget:first-child + *': {
12
- 'margin-top': '0 !important'
12
+ marginTop: '0 !important'
13
13
  }
14
14
  });
15
15
  var GlobalStylesWrapper = exports.GlobalStylesWrapper = function GlobalStylesWrapper() {
@@ -13,16 +13,22 @@ var getSelection = exports.getSelection = function getSelection(tr, start) {
13
13
  if (isNodeSelection) {
14
14
  return new _state.NodeSelection($startPos);
15
15
  } else {
16
- var textNodesPos = [];
16
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select on the text node
17
+ // Find the first text node in the node
18
+ var textNodesPos = start;
19
+ var foundTextNodes = false;
17
20
  tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
21
+ if (foundTextNodes) {
22
+ return false;
23
+ }
18
24
  if (n.isText) {
19
- textNodesPos.push(pos);
25
+ textNodesPos = pos;
26
+ foundTextNodes = true;
20
27
  return false;
21
28
  }
22
29
  return true;
23
30
  });
24
- var textNodeStart = textNodesPos[0] || start;
25
- var textNodeDepth = textNodeStart - start;
26
- return new _state.TextSelection(tr.doc.resolve(textNodeStart), tr.doc.resolve(start + nodeSize - textNodeDepth));
31
+ var textNodeDepth = textNodesPos - start;
32
+ return new _state.TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
27
33
  }
28
34
  };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "getSelection", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _getSelection.getSelection;
10
+ }
11
+ });
12
+ var _getSelection = require("./getSelection");
@@ -2,7 +2,7 @@
2
2
  import { css, Global, jsx } from '@emotion/react';
3
3
  const globalStyles = css({
4
4
  '.ProseMirror-widget:first-child + *': {
5
- 'margin-top': '0 !important'
5
+ marginTop: '0 !important'
6
6
  }
7
7
  });
8
8
  export const GlobalStylesWrapper = () => {
@@ -7,16 +7,22 @@ export const getSelection = (tr, start) => {
7
7
  if (isNodeSelection) {
8
8
  return new NodeSelection($startPos);
9
9
  } else {
10
- const textNodesPos = [];
10
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select on the text node
11
+ // Find the first text node in the node
12
+ let textNodesPos = start;
13
+ let foundTextNodes = false;
11
14
  tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, (n, pos) => {
15
+ if (foundTextNodes) {
16
+ return false;
17
+ }
12
18
  if (n.isText) {
13
- textNodesPos.push(pos);
19
+ textNodesPos = pos;
20
+ foundTextNodes = true;
14
21
  return false;
15
22
  }
16
23
  return true;
17
24
  });
18
- const textNodeStart = textNodesPos[0] || start;
19
- const textNodeDepth = textNodeStart - start;
20
- return new TextSelection(tr.doc.resolve(textNodeStart), tr.doc.resolve(start + nodeSize - textNodeDepth));
25
+ const textNodeDepth = textNodesPos - start;
26
+ return new TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
21
27
  }
22
28
  };
@@ -0,0 +1 @@
1
+ export { getSelection } from './getSelection';
@@ -2,7 +2,7 @@
2
2
  import { css, Global, jsx } from '@emotion/react';
3
3
  var globalStyles = css({
4
4
  '.ProseMirror-widget:first-child + *': {
5
- 'margin-top': '0 !important'
5
+ marginTop: '0 !important'
6
6
  }
7
7
  });
8
8
  export var GlobalStylesWrapper = function GlobalStylesWrapper() {
@@ -7,16 +7,22 @@ export var getSelection = function getSelection(tr, start) {
7
7
  if (isNodeSelection) {
8
8
  return new NodeSelection($startPos);
9
9
  } else {
10
- var textNodesPos = [];
10
+ // To trigger the annotation floating toolbar for non-selectable node, we need to select on the text node
11
+ // Find the first text node in the node
12
+ var textNodesPos = start;
13
+ var foundTextNodes = false;
11
14
  tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
15
+ if (foundTextNodes) {
16
+ return false;
17
+ }
12
18
  if (n.isText) {
13
- textNodesPos.push(pos);
19
+ textNodesPos = pos;
20
+ foundTextNodes = true;
14
21
  return false;
15
22
  }
16
23
  return true;
17
24
  });
18
- var textNodeStart = textNodesPos[0] || start;
19
- var textNodeDepth = textNodeStart - start;
20
- return new TextSelection(tr.doc.resolve(textNodeStart), tr.doc.resolve(start + nodeSize - textNodeDepth));
25
+ var textNodeDepth = textNodesPos - start;
26
+ return new TextSelection(tr.doc.resolve(textNodesPos), tr.doc.resolve(start + nodeSize - textNodeDepth));
21
27
  }
22
28
  };
@@ -0,0 +1 @@
1
+ export { getSelection } from './getSelection';
@@ -0,0 +1 @@
1
+ export { getSelection } from './getSelection';
@@ -0,0 +1 @@
1
+ export { getSelection } from './getSelection';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
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
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^81.0.0",
34
+ "@atlaskit/editor-common": "^81.1.0",
35
35
  "@atlaskit/editor-prosemirror": "4.0.1",
36
36
  "@atlaskit/icon": "^22.3.0",
37
37
  "@atlaskit/pragmatic-drag-and-drop": "^1.1.0",