@atlaskit/editor-plugin-selection 5.0.0 → 5.0.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,20 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 5.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`86e3af7e468bb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/86e3af7e468bb) -
8
+ Add experiment to add additional context to selection fragment data.
9
+ - Updated dependencies
10
+
11
+ ## 5.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [`c69b58dc48801`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c69b58dc48801) -
16
+ Expose getSliceFromSelection
17
+
3
18
  ## 5.0.0
4
19
 
5
20
  ### Patch Changes
@@ -4,11 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
7
+ exports.getSliceFromSelection = exports.getSelectionLocalIds = exports.getSelectionFragment = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
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; }
@@ -20,7 +21,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
20
21
  * @param selection The selection to get the slice for.
21
22
  * @returns The slice of the document corresponding to the selection.
22
23
  */
23
- var getSlice = function getSlice(selection) {
24
+ var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFromSelection(selection) {
24
25
  var from = selection.from,
25
26
  to = selection.to;
26
27
  if (from === to) {
@@ -42,8 +43,9 @@ var getSlice = function getSlice(selection) {
42
43
  // If we're in a text selection, and share the parent node across the anchor->head
43
44
  // make the depth the parent node
44
45
  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);
46
+ var finalDepth = (0, _platformFeatureFlags.fg)('platform_editor_expand_selection_context') ? 0 : depth;
47
+ var start = $from.start(finalDepth);
48
+ var node = $from.node(finalDepth);
47
49
  var content = node.content.cut($from.pos - start, $to.pos - start);
48
50
  frag = frag.append(content);
49
51
  }
@@ -62,7 +64,7 @@ var getSelectionFragment = exports.getSelectionFragment = function getSelectionF
62
64
  if (!selection || !schema || selection.empty) {
63
65
  return null;
64
66
  }
65
- var slice = getSlice(selection);
67
+ var slice = getSliceFromSelection(selection);
66
68
  var content = slice.content;
67
69
  var fragment = [];
68
70
  content.forEach(function (node) {
@@ -92,7 +94,7 @@ var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionL
92
94
  } else if (selection.empty) {
93
95
  return [selection.$from.parent.attrs.localId];
94
96
  }
95
- var content = getSlice(selection).content;
97
+ var content = getSliceFromSelection(selection).content;
96
98
  var ids = [];
97
99
  content.forEach(function (node) {
98
100
  var _node$attrs;
@@ -1,6 +1,7 @@
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';
4
5
  /**
5
6
  * Get the slice of the document corresponding to the selection.
6
7
  * This is similar to the prosemirror `selection.content()` - but
@@ -9,7 +10,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
9
10
  * @param selection The selection to get the slice for.
10
11
  * @returns The slice of the document corresponding to the selection.
11
12
  */
12
- const getSlice = selection => {
13
+ export const getSliceFromSelection = selection => {
13
14
  const {
14
15
  from,
15
16
  to
@@ -29,8 +30,9 @@ const getSlice = selection => {
29
30
  // If we're in a text selection, and share the parent node across the anchor->head
30
31
  // make the depth the parent node
31
32
  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);
33
+ const finalDepth = fg('platform_editor_expand_selection_context') ? 0 : depth;
34
+ const start = $from.start(finalDepth);
35
+ const node = $from.node(finalDepth);
34
36
  const content = node.content.cut($from.pos - start, $to.pos - start);
35
37
  frag = frag.append(content);
36
38
  }
@@ -43,7 +45,7 @@ export const getSelectionFragment = api => () => {
43
45
  if (!selection || !schema || selection.empty) {
44
46
  return null;
45
47
  }
46
- const slice = getSlice(selection);
48
+ const slice = getSliceFromSelection(selection);
47
49
  const content = slice.content;
48
50
  const fragment = [];
49
51
  content.forEach(node => {
@@ -72,7 +74,7 @@ export const getSelectionLocalIds = api => () => {
72
74
  } else if (selection.empty) {
73
75
  return [selection.$from.parent.attrs.localId];
74
76
  }
75
- const content = getSlice(selection).content;
77
+ const content = getSliceFromSelection(selection).content;
76
78
  const ids = [];
77
79
  content.forEach(node => {
78
80
  var _node$attrs;
@@ -5,6 +5,7 @@ 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';
8
9
  /**
9
10
  * Get the slice of the document corresponding to the selection.
10
11
  * This is similar to the prosemirror `selection.content()` - but
@@ -13,7 +14,7 @@ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state
13
14
  * @param selection The selection to get the slice for.
14
15
  * @returns The slice of the document corresponding to the selection.
15
16
  */
16
- var getSlice = function getSlice(selection) {
17
+ export var getSliceFromSelection = function getSliceFromSelection(selection) {
17
18
  var from = selection.from,
18
19
  to = selection.to;
19
20
  if (from === to) {
@@ -35,8 +36,9 @@ var getSlice = function getSlice(selection) {
35
36
  // If we're in a text selection, and share the parent node across the anchor->head
36
37
  // make the depth the parent node
37
38
  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);
39
+ var finalDepth = fg('platform_editor_expand_selection_context') ? 0 : depth;
40
+ var start = $from.start(finalDepth);
41
+ var node = $from.node(finalDepth);
40
42
  var content = node.content.cut($from.pos - start, $to.pos - start);
41
43
  frag = frag.append(content);
42
44
  }
@@ -55,7 +57,7 @@ export var getSelectionFragment = function getSelectionFragment(api) {
55
57
  if (!selection || !schema || selection.empty) {
56
58
  return null;
57
59
  }
58
- var slice = getSlice(selection);
60
+ var slice = getSliceFromSelection(selection);
59
61
  var content = slice.content;
60
62
  var fragment = [];
61
63
  content.forEach(function (node) {
@@ -85,7 +87,7 @@ export var getSelectionLocalIds = function getSelectionLocalIds(api) {
85
87
  } else if (selection.empty) {
86
88
  return [selection.$from.parent.attrs.localId];
87
89
  }
88
- var content = getSlice(selection).content;
90
+ var content = getSliceFromSelection(selection).content;
89
91
  var ids = [];
90
92
  content.forEach(function (node) {
91
93
  var _node$attrs;
@@ -1,5 +1,16 @@
1
1
  import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { type JSONNode } from '@atlaskit/editor-json-transformer';
3
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
4
+ import { type Selection } from '@atlaskit/editor-prosemirror/state';
3
5
  import type { SelectionPlugin } from '../selectionPluginType';
6
+ /**
7
+ * Get the slice of the document corresponding to the selection.
8
+ * This is similar to the prosemirror `selection.content()` - but
9
+ * does not include the parents (unless the result is inline)
10
+ *
11
+ * @param selection The selection to get the slice for.
12
+ * @returns The slice of the document corresponding to the selection.
13
+ */
14
+ export declare const getSliceFromSelection: (selection: Selection) => Fragment;
4
15
  export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
5
16
  export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
@@ -1,5 +1,16 @@
1
1
  import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
2
  import { type JSONNode } from '@atlaskit/editor-json-transformer';
3
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
4
+ import { type Selection } from '@atlaskit/editor-prosemirror/state';
3
5
  import type { SelectionPlugin } from '../selectionPluginType';
6
+ /**
7
+ * Get the slice of the document corresponding to the selection.
8
+ * This is similar to the prosemirror `selection.content()` - but
9
+ * does not include the parents (unless the result is inline)
10
+ *
11
+ * @param selection The selection to get the slice for.
12
+ * @returns The slice of the document corresponding to the selection.
13
+ */
14
+ export declare const getSliceFromSelection: (selection: Selection) => Fragment;
4
15
  export declare const getSelectionFragment: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => JSONNode[] | null;
5
16
  export declare const getSelectionLocalIds: (api: ExtractInjectionAPI<SelectionPlugin> | undefined) => () => any[] | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
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.27.0",
22
+ "@atlaskit/editor-json-transformer": "^8.29.0",
23
23
  "@atlaskit/editor-plugin-interaction": "^7.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.9.0",
28
+ "@atlaskit/tmp-editor-statsig": "^12.27.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.0.0",
33
+ "@atlaskit/editor-common": "^109.11.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
  },