@atlaskit/editor-plugin-selection 5.0.2 → 6.0.1

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,17 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 6.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 6.0.0
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 5.0.2
4
16
 
5
17
  ### Patch Changes
@@ -13,6 +13,25 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
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; } } }; }
14
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; } }
15
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
+
16
35
  /**
17
36
  * Get the slice of the document corresponding to the selection.
18
37
  * This is similar to the prosemirror `selection.content()` - but
@@ -43,7 +62,13 @@ var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFro
43
62
  // If we're in a text selection, and share the parent node across the anchor->head
44
63
  // make the depth the parent node
45
64
  selection instanceof _state.TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
46
- var finalDepth = (0, _platformFeatureFlags.fg)('platform_editor_expand_selection_context') ? 0 : 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
+ }
47
72
  var start = $from.start(finalDepth);
48
73
  var node = $from.node(finalDepth);
49
74
  var content = node.content.cut($from.pos - start, $to.pos - start);
@@ -2,6 +2,25 @@ 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
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
+
5
24
  /**
6
25
  * Get the slice of the document corresponding to the selection.
7
26
  * This is similar to the prosemirror `selection.content()` - but
@@ -30,7 +49,13 @@ export const getSliceFromSelection = selection => {
30
49
  // If we're in a text selection, and share the parent node across the anchor->head
31
50
  // make the depth the parent node
32
51
  selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(to) - 1) : $from.sharedDepth(to);
33
- const finalDepth = fg('platform_editor_expand_selection_context') ? 0 : 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
+ }
34
59
  const start = $from.start(finalDepth);
35
60
  const node = $from.node(finalDepth);
36
61
  const content = node.content.cut($from.pos - start, $to.pos - start);
@@ -6,6 +6,25 @@ 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
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
+
9
28
  /**
10
29
  * Get the slice of the document corresponding to the selection.
11
30
  * This is similar to the prosemirror `selection.content()` - but
@@ -36,7 +55,13 @@ export var getSliceFromSelection = function getSliceFromSelection(selection) {
36
55
  // If we're in a text selection, and share the parent node across the anchor->head
37
56
  // make the depth the parent node
38
57
  selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
39
- var finalDepth = fg('platform_editor_expand_selection_context') ? 0 : 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
+ }
40
65
  var start = $from.start(finalDepth);
41
66
  var node = $from.node(finalDepth);
42
67
  var content = node.content.cut($from.pos - start, $to.pos - start);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "5.0.2",
3
+ "version": "6.0.1",
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.27.0",
29
- "@atlaskit/tokens": "^6.3.0",
28
+ "@atlaskit/tmp-editor-statsig": "^13.0.0",
29
+ "@atlaskit/tokens": "^6.4.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@atlaskit/editor-common": "^109.11.0",
33
+ "@atlaskit/editor-common": "^110.4.0",
34
34
  "react": "^18.2.0"
35
35
  },
36
36
  "techstack": {