@atlaskit/editor-plugin-selection 5.0.1 → 6.0.0

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,19 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 6.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 5.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [`86e3af7e468bb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86e3af7e468bb) -
14
+ Add experiment to add additional context to selection fragment data.
15
+ - Updated dependencies
16
+
3
17
  ## 5.0.1
4
18
 
5
19
  ### Patch Changes
@@ -9,9 +9,29 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
9
9
  var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
10
10
  var _model = require("@atlaskit/editor-prosemirror/model");
11
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
13
14
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
15
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
17
+ // Block level lists
18
+ var listParents = ['bulletList', 'orderedList'];
19
+ if ($from.depth === 3 && $to.depth === 3) {
20
+ var _greatGrandparentFrom, _greatGrandparentFrom2;
21
+ // Get grandparents (from)
22
+ var grandparentFrom = $from.node($from.depth - 1);
23
+ var greatGrandparentFrom = $from.node($from.depth - 2);
24
+ // Get grandparents (to)
25
+ var grandparentTo = $to.node($from.depth - 1);
26
+ var greatGrandparentTo = $to.node($from.depth - 2);
27
+ if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
28
+ (_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
29
+ return true;
30
+ }
31
+ }
32
+ return false;
33
+ };
34
+
15
35
  /**
16
36
  * Get the slice of the document corresponding to the selection.
17
37
  * This is similar to the prosemirror `selection.content()` - but
@@ -42,8 +62,15 @@ var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFro
42
62
  // If we're in a text selection, and share the parent node across the anchor->head
43
63
  // make the depth the parent node
44
64
  selection instanceof _state.TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
45
- var start = $from.start(depth);
46
- var node = $from.node(depth);
65
+ var finalDepth = depth;
66
+ // For block-level lists (non-nested) specifically use the selection
67
+ if ((0, _platformFeatureFlags.fg)('platform_editor_expand_selection_context')) {
68
+ if (selectionCoversAllListItems($from, $to)) {
69
+ finalDepth = 0;
70
+ }
71
+ }
72
+ var start = $from.start(finalDepth);
73
+ var node = $from.node(finalDepth);
47
74
  var content = node.content.cut($from.pos - start, $to.pos - start);
48
75
  frag = frag.append(content);
49
76
  }
@@ -1,6 +1,26 @@
1
1
  import { nodeToJSON } from '@atlaskit/editor-json-transformer';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
5
+ const selectionCoversAllListItems = ($from, $to) => {
6
+ // Block level lists
7
+ const listParents = ['bulletList', 'orderedList'];
8
+ if ($from.depth === 3 && $to.depth === 3) {
9
+ var _greatGrandparentFrom, _greatGrandparentFrom2;
10
+ // Get grandparents (from)
11
+ const grandparentFrom = $from.node($from.depth - 1);
12
+ const greatGrandparentFrom = $from.node($from.depth - 2);
13
+ // Get grandparents (to)
14
+ const grandparentTo = $to.node($from.depth - 1);
15
+ const greatGrandparentTo = $to.node($from.depth - 2);
16
+ if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
17
+ (_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
18
+ return true;
19
+ }
20
+ }
21
+ return false;
22
+ };
23
+
4
24
  /**
5
25
  * Get the slice of the document corresponding to the selection.
6
26
  * This is similar to the prosemirror `selection.content()` - but
@@ -29,8 +49,15 @@ export const getSliceFromSelection = selection => {
29
49
  // If we're in a text selection, and share the parent node across the anchor->head
30
50
  // make the depth the parent node
31
51
  selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(to) - 1) : $from.sharedDepth(to);
32
- const start = $from.start(depth);
33
- const node = $from.node(depth);
52
+ let finalDepth = depth;
53
+ // For block-level lists (non-nested) specifically use the selection
54
+ if (fg('platform_editor_expand_selection_context')) {
55
+ if (selectionCoversAllListItems($from, $to)) {
56
+ finalDepth = 0;
57
+ }
58
+ }
59
+ const start = $from.start(finalDepth);
60
+ const node = $from.node(finalDepth);
34
61
  const content = node.content.cut($from.pos - start, $to.pos - start);
35
62
  frag = frag.append(content);
36
63
  }
@@ -5,6 +5,26 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
5
5
  import { nodeToJSON } from '@atlaskit/editor-json-transformer';
6
6
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
7
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
9
+ var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
10
+ // Block level lists
11
+ var listParents = ['bulletList', 'orderedList'];
12
+ if ($from.depth === 3 && $to.depth === 3) {
13
+ var _greatGrandparentFrom, _greatGrandparentFrom2;
14
+ // Get grandparents (from)
15
+ var grandparentFrom = $from.node($from.depth - 1);
16
+ var greatGrandparentFrom = $from.node($from.depth - 2);
17
+ // Get grandparents (to)
18
+ var grandparentTo = $to.node($from.depth - 1);
19
+ var greatGrandparentTo = $to.node($from.depth - 2);
20
+ if (greatGrandparentTo.eq(greatGrandparentFrom) && listParents.includes(greatGrandparentFrom.type.name) && // Selection covers entire list
21
+ (_greatGrandparentFrom = greatGrandparentFrom.firstChild) !== null && _greatGrandparentFrom !== void 0 && _greatGrandparentFrom.eq(grandparentFrom) && (_greatGrandparentFrom2 = greatGrandparentFrom.lastChild) !== null && _greatGrandparentFrom2 !== void 0 && _greatGrandparentFrom2.eq(grandparentTo)) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ };
27
+
8
28
  /**
9
29
  * Get the slice of the document corresponding to the selection.
10
30
  * This is similar to the prosemirror `selection.content()` - but
@@ -35,8 +55,15 @@ export var getSliceFromSelection = function getSliceFromSelection(selection) {
35
55
  // If we're in a text selection, and share the parent node across the anchor->head
36
56
  // make the depth the parent node
37
57
  selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
38
- var start = $from.start(depth);
39
- var node = $from.node(depth);
58
+ var finalDepth = depth;
59
+ // For block-level lists (non-nested) specifically use the selection
60
+ if (fg('platform_editor_expand_selection_context')) {
61
+ if (selectionCoversAllListItems($from, $to)) {
62
+ finalDepth = 0;
63
+ }
64
+ }
65
+ var start = $from.start(finalDepth);
66
+ var node = $from.node(finalDepth);
40
67
  var content = node.content.cut($from.pos - start, $to.pos - start);
41
68
  frag = frag.append(content);
42
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "5.0.1",
3
+ "version": "6.0.0",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -19,18 +19,18 @@
19
19
  "singleton": true
20
20
  },
21
21
  "dependencies": {
22
- "@atlaskit/editor-json-transformer": "^8.29.0",
23
- "@atlaskit/editor-plugin-interaction": "^7.0.0",
22
+ "@atlaskit/editor-json-transformer": "^8.30.0",
23
+ "@atlaskit/editor-plugin-interaction": "^8.0.0",
24
24
  "@atlaskit/editor-prosemirror": "7.0.0",
25
25
  "@atlaskit/editor-shared-styles": "^3.6.0",
26
26
  "@atlaskit/editor-tables": "^2.9.0",
27
27
  "@atlaskit/platform-feature-flags": "^1.1.0",
28
- "@atlaskit/tmp-editor-statsig": "^12.22.0",
28
+ "@atlaskit/tmp-editor-statsig": "^12.31.0",
29
29
  "@atlaskit/tokens": "^6.3.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@atlaskit/editor-common": "^109.7.0",
33
+ "@atlaskit/editor-common": "^110.0.0",
34
34
  "react": "^18.2.0"
35
35
  },
36
36
  "techstack": {
@@ -81,6 +81,9 @@
81
81
  "platform_editor_nested_tables_gap_cursor": {
82
82
  "type": "boolean"
83
83
  },
84
+ "platform_editor_expand_selection_context": {
85
+ "type": "boolean"
86
+ },
84
87
  "platform_editor_fix_right_arrow_bug_list_in_layout": {
85
88
  "type": "boolean"
86
89
  },