@atlaskit/editor-common 111.28.0 → 111.28.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,18 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 111.28.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 111.28.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`10f36a235eedd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/10f36a235eedd) -
14
+ Extract selection helpers to editor-common
15
+
3
16
  ## 111.28.0
4
17
 
5
18
  ### Minor Changes
@@ -19,7 +19,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
19
19
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
20
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
21
21
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
22
- var packageVersion = "111.27.0";
22
+ var packageVersion = "111.28.1";
23
23
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
24
24
  // Remove URL as it has UGC
25
25
  // Ignored via go/ees007
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.selectionCoversAllListItems = exports.getSliceFromSelection = exports.getLocalIdsFromSelection = exports.getFragmentsFromSelection = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _editorJsonTransformer = require("@atlaskit/editor-json-transformer");
10
+ var _model = require("@atlaskit/editor-prosemirror/model");
11
+ var _state = require("@atlaskit/editor-prosemirror/state");
12
+ 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
+ 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
+ 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; }
15
+ var listDepth = 3;
16
+ var selectionCoversAllListItems = exports.selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
17
+ // Block level lists
18
+ var listParents = ['bulletList', 'orderedList'];
19
+ if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
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
+
35
+ /**
36
+ * Get the slice of the document corresponding to the selection.
37
+ * This is similar to the prosemirror `selection.content()` - but
38
+ * does not include the parents (unless the result is inline)
39
+ *
40
+ * @param selection The selection to get the slice for.
41
+ * @returns The slice of the document corresponding to the selection.
42
+ */
43
+ var getSliceFromSelection = exports.getSliceFromSelection = function getSliceFromSelection(selection) {
44
+ var from = selection.from,
45
+ to = selection.to;
46
+ if (from === to) {
47
+ return _model.Fragment.empty;
48
+ }
49
+ var frag = _model.Fragment.empty;
50
+ var sortedRanges = (0, _toConsumableArray2.default)(selection.ranges.slice()).sort(function (a, b) {
51
+ return a.$from.pos - b.$from.pos;
52
+ });
53
+ var _iterator = _createForOfIteratorHelper(sortedRanges),
54
+ _step;
55
+ try {
56
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
+ var range = _step.value;
58
+ var $from = range.$from,
59
+ $to = range.$to;
60
+ var _to = $to.pos;
61
+ var depth =
62
+ // If we're in a text selection, and share the parent node across the anchor->head
63
+ // make the depth the parent node
64
+ selection instanceof _state.TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
65
+ var finalDepth = depth;
66
+ // For block-level lists (non-nested) specifically use the selection
67
+ if (selectionCoversAllListItems($from, $to)) {
68
+ finalDepth = $from.depth - listDepth;
69
+ }
70
+ var start = $from.start(finalDepth);
71
+ var node = $from.node(finalDepth);
72
+ var content = node.content.cut($from.pos - start, $to.pos - start);
73
+ frag = frag.append(content);
74
+ }
75
+ } catch (err) {
76
+ _iterator.e(err);
77
+ } finally {
78
+ _iterator.f();
79
+ }
80
+ return frag;
81
+ };
82
+
83
+ /**
84
+ * Get the fragments from the selection.
85
+ * @param selection The selection to get the fragments from.
86
+ * @param schema The schema to use to convert the nodes to JSON.
87
+ * @returns The fragments as an array of JSON nodes.
88
+ */
89
+ var getFragmentsFromSelection = exports.getFragmentsFromSelection = function getFragmentsFromSelection(selection) {
90
+ if (!selection || selection.empty) {
91
+ return null;
92
+ }
93
+ var slice = getSliceFromSelection(selection);
94
+ var content = slice.content;
95
+ var fragment = [];
96
+ content.forEach(function (node) {
97
+ fragment.push((0, _editorJsonTransformer.nodeToJSON)(node));
98
+ });
99
+ return fragment;
100
+ };
101
+
102
+ /**
103
+ * Get the local IDs from the selection.
104
+ * @param selection The selection to get the local IDs from.
105
+ * @returns The local IDs as an array of strings.
106
+ */
107
+ var getLocalIdsFromSelection = exports.getLocalIdsFromSelection = function getLocalIdsFromSelection(selection) {
108
+ if (!selection) {
109
+ return null;
110
+ }
111
+ if (selection instanceof _state.NodeSelection) {
112
+ return [selection.node.attrs.localId];
113
+ } else if (selection.empty) {
114
+ return [selection.$from.parent.attrs.localId];
115
+ }
116
+ var slice = getSliceFromSelection(selection);
117
+ var content = slice.content;
118
+ var ids = [];
119
+ content.forEach(function (node) {
120
+ var _node$attrs;
121
+ var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
122
+ if (localId) {
123
+ ids.push(localId);
124
+ }
125
+ });
126
+ return ids;
127
+ };
@@ -96,8 +96,26 @@ Object.defineProperty(exports, "gapCursorStyles", {
96
96
  });
97
97
  exports.getAllSelectionAnalyticsPayload = getAllSelectionAnalyticsPayload;
98
98
  exports.getCellSelectionAnalyticsPayload = getCellSelectionAnalyticsPayload;
99
+ Object.defineProperty(exports, "getFragmentsFromSelection", {
100
+ enumerable: true,
101
+ get: function get() {
102
+ return _contextHelpers.getFragmentsFromSelection;
103
+ }
104
+ });
105
+ Object.defineProperty(exports, "getLocalIdsFromSelection", {
106
+ enumerable: true,
107
+ get: function get() {
108
+ return _contextHelpers.getLocalIdsFromSelection;
109
+ }
110
+ });
99
111
  exports.getNodeSelectionAnalyticsPayload = getNodeSelectionAnalyticsPayload;
100
112
  exports.getRangeSelectionAnalyticsPayload = getRangeSelectionAnalyticsPayload;
113
+ Object.defineProperty(exports, "getSliceFromSelection", {
114
+ enumerable: true,
115
+ get: function get() {
116
+ return _contextHelpers.getSliceFromSelection;
117
+ }
118
+ });
101
119
  Object.defineProperty(exports, "getSourceNodesFromSelectionRange", {
102
120
  enumerable: true,
103
121
  get: function get() {
@@ -189,6 +207,7 @@ var _isValidTargetNode = require("./gap-cursor/utils/is-valid-target-node");
189
207
  var _setGapCursorSelection = require("./gap-cursor/utils/setGapCursorSelection");
190
208
  var _styles = require("./gap-cursor/styles");
191
209
  var _utils2 = require("./utils");
210
+ var _contextHelpers = require("./context-helpers");
192
211
  // Disable no-re-export rule for entry point files
193
212
  /* eslint-disable @atlaskit/editor/no-re-export */
194
213
 
@@ -1 +1,5 @@
1
- "use strict";
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -24,7 +24,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
24
24
  * @jsx jsx
25
25
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "111.27.0";
27
+ var packageVersion = "111.28.1";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var fadeIn = (0, _react2.keyframes)({
@@ -4,7 +4,7 @@ import { isFedRamp } from './environment';
4
4
  import { normaliseSentryBreadcrumbs, SERIALIZABLE_ATTRIBUTES } from './normalise-sentry-breadcrumbs';
5
5
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
6
6
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
7
- const packageVersion = "111.27.0";
7
+ const packageVersion = "111.28.1";
8
8
  const sanitiseSentryEvents = (data, _hint) => {
9
9
  // Remove URL as it has UGC
10
10
  // Ignored via go/ees007
@@ -0,0 +1,109 @@
1
+ import { nodeToJSON } from '@atlaskit/editor-json-transformer';
2
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
+ import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
4
+ const listDepth = 3;
5
+ export const selectionCoversAllListItems = ($from, $to) => {
6
+ // Block level lists
7
+ const listParents = ['bulletList', 'orderedList'];
8
+ if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
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
+
24
+ /**
25
+ * Get the slice of the document corresponding to the selection.
26
+ * This is similar to the prosemirror `selection.content()` - but
27
+ * does not include the parents (unless the result is inline)
28
+ *
29
+ * @param selection The selection to get the slice for.
30
+ * @returns The slice of the document corresponding to the selection.
31
+ */
32
+ export const getSliceFromSelection = selection => {
33
+ const {
34
+ from,
35
+ to
36
+ } = selection;
37
+ if (from === to) {
38
+ return Fragment.empty;
39
+ }
40
+ let frag = Fragment.empty;
41
+ const sortedRanges = [...selection.ranges.slice()].sort((a, b) => a.$from.pos - b.$from.pos);
42
+ for (const range of sortedRanges) {
43
+ const {
44
+ $from,
45
+ $to
46
+ } = range;
47
+ const to = $to.pos;
48
+ const depth =
49
+ // If we're in a text selection, and share the parent node across the anchor->head
50
+ // make the depth the parent node
51
+ selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(to) - 1) : $from.sharedDepth(to);
52
+ let finalDepth = depth;
53
+ // For block-level lists (non-nested) specifically use the selection
54
+ if (selectionCoversAllListItems($from, $to)) {
55
+ finalDepth = $from.depth - listDepth;
56
+ }
57
+ const start = $from.start(finalDepth);
58
+ const node = $from.node(finalDepth);
59
+ const content = node.content.cut($from.pos - start, $to.pos - start);
60
+ frag = frag.append(content);
61
+ }
62
+ return frag;
63
+ };
64
+
65
+ /**
66
+ * Get the fragments from the selection.
67
+ * @param selection The selection to get the fragments from.
68
+ * @param schema The schema to use to convert the nodes to JSON.
69
+ * @returns The fragments as an array of JSON nodes.
70
+ */
71
+ export const getFragmentsFromSelection = selection => {
72
+ if (!selection || selection.empty) {
73
+ return null;
74
+ }
75
+ const slice = getSliceFromSelection(selection);
76
+ const content = slice.content;
77
+ const fragment = [];
78
+ content.forEach(node => {
79
+ fragment.push(nodeToJSON(node));
80
+ });
81
+ return fragment;
82
+ };
83
+
84
+ /**
85
+ * Get the local IDs from the selection.
86
+ * @param selection The selection to get the local IDs from.
87
+ * @returns The local IDs as an array of strings.
88
+ */
89
+ export const getLocalIdsFromSelection = selection => {
90
+ if (!selection) {
91
+ return null;
92
+ }
93
+ if (selection instanceof NodeSelection) {
94
+ return [selection.node.attrs.localId];
95
+ } else if (selection.empty) {
96
+ return [selection.$from.parent.attrs.localId];
97
+ }
98
+ const slice = getSliceFromSelection(selection);
99
+ const content = slice.content;
100
+ const ids = [];
101
+ content.forEach(node => {
102
+ var _node$attrs;
103
+ const localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
104
+ if (localId) {
105
+ ids.push(localId);
106
+ }
107
+ });
108
+ return ids;
109
+ };
@@ -13,6 +13,7 @@ export { isValidTargetNode } from './gap-cursor/utils/is-valid-target-node';
13
13
  export { setGapCursorSelection } from './gap-cursor/utils/setGapCursorSelection';
14
14
  export { hideCaretModifier, gapCursorStyles } from './gap-cursor/styles';
15
15
  export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, deleteSelectedRange, endPositionOfParent, expandSelectionBounds, expandSelectionToBlockRange, expandToBlockRange, getSourceNodesFromSelectionRange, isMultiBlockRange, isMultiBlockSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, selectionIsAtTheBeginningOfBlock, startPositionOfParent } from './utils';
16
+ export { getSliceFromSelection, getFragmentsFromSelection, getLocalIdsFromSelection } from './context-helpers';
16
17
  export function getNodeSelectionAnalyticsPayload(selection) {
17
18
  if (selection instanceof NodeSelection) {
18
19
  return {
@@ -0,0 +1 @@
1
+ export {};
@@ -14,7 +14,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
15
  import Layer from '../Layer';
16
16
  const packageName = "@atlaskit/editor-common";
17
- const packageVersion = "111.27.0";
17
+ const packageVersion = "111.28.1";
18
18
  const halfFocusRing = 1;
19
19
  const dropOffset = '0, 8';
20
20
  const fadeIn = keyframes({
@@ -10,7 +10,7 @@ import { isFedRamp } from './environment';
10
10
  import { normaliseSentryBreadcrumbs, SERIALIZABLE_ATTRIBUTES } from './normalise-sentry-breadcrumbs';
11
11
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
12
12
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
13
- var packageVersion = "111.27.0";
13
+ var packageVersion = "111.28.1";
14
14
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
15
15
  // Remove URL as it has UGC
16
16
  // Ignored via go/ees007
@@ -0,0 +1,120 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ 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; } } }; }
3
+ 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; } }
4
+ 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; }
5
+ import { nodeToJSON } from '@atlaskit/editor-json-transformer';
6
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
7
+ import { TextSelection, NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
+ var listDepth = 3;
9
+ export var selectionCoversAllListItems = function selectionCoversAllListItems($from, $to) {
10
+ // Block level lists
11
+ var listParents = ['bulletList', 'orderedList'];
12
+ if ($from.depth >= listDepth && $to.depth >= listDepth && $from.depth === $to.depth) {
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
+
28
+ /**
29
+ * Get the slice of the document corresponding to the selection.
30
+ * This is similar to the prosemirror `selection.content()` - but
31
+ * does not include the parents (unless the result is inline)
32
+ *
33
+ * @param selection The selection to get the slice for.
34
+ * @returns The slice of the document corresponding to the selection.
35
+ */
36
+ export var getSliceFromSelection = function getSliceFromSelection(selection) {
37
+ var from = selection.from,
38
+ to = selection.to;
39
+ if (from === to) {
40
+ return Fragment.empty;
41
+ }
42
+ var frag = Fragment.empty;
43
+ var sortedRanges = _toConsumableArray(selection.ranges.slice()).sort(function (a, b) {
44
+ return a.$from.pos - b.$from.pos;
45
+ });
46
+ var _iterator = _createForOfIteratorHelper(sortedRanges),
47
+ _step;
48
+ try {
49
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
50
+ var range = _step.value;
51
+ var $from = range.$from,
52
+ $to = range.$to;
53
+ var _to = $to.pos;
54
+ var depth =
55
+ // If we're in a text selection, and share the parent node across the anchor->head
56
+ // make the depth the parent node
57
+ selection instanceof TextSelection && $from.parent.eq($to.parent) ? Math.max(0, $from.sharedDepth(_to) - 1) : $from.sharedDepth(_to);
58
+ var finalDepth = depth;
59
+ // For block-level lists (non-nested) specifically use the selection
60
+ if (selectionCoversAllListItems($from, $to)) {
61
+ finalDepth = $from.depth - listDepth;
62
+ }
63
+ var start = $from.start(finalDepth);
64
+ var node = $from.node(finalDepth);
65
+ var content = node.content.cut($from.pos - start, $to.pos - start);
66
+ frag = frag.append(content);
67
+ }
68
+ } catch (err) {
69
+ _iterator.e(err);
70
+ } finally {
71
+ _iterator.f();
72
+ }
73
+ return frag;
74
+ };
75
+
76
+ /**
77
+ * Get the fragments from the selection.
78
+ * @param selection The selection to get the fragments from.
79
+ * @param schema The schema to use to convert the nodes to JSON.
80
+ * @returns The fragments as an array of JSON nodes.
81
+ */
82
+ export var getFragmentsFromSelection = function getFragmentsFromSelection(selection) {
83
+ if (!selection || selection.empty) {
84
+ return null;
85
+ }
86
+ var slice = getSliceFromSelection(selection);
87
+ var content = slice.content;
88
+ var fragment = [];
89
+ content.forEach(function (node) {
90
+ fragment.push(nodeToJSON(node));
91
+ });
92
+ return fragment;
93
+ };
94
+
95
+ /**
96
+ * Get the local IDs from the selection.
97
+ * @param selection The selection to get the local IDs from.
98
+ * @returns The local IDs as an array of strings.
99
+ */
100
+ export var getLocalIdsFromSelection = function getLocalIdsFromSelection(selection) {
101
+ if (!selection) {
102
+ return null;
103
+ }
104
+ if (selection instanceof NodeSelection) {
105
+ return [selection.node.attrs.localId];
106
+ } else if (selection.empty) {
107
+ return [selection.$from.parent.attrs.localId];
108
+ }
109
+ var slice = getSliceFromSelection(selection);
110
+ var content = slice.content;
111
+ var ids = [];
112
+ content.forEach(function (node) {
113
+ var _node$attrs;
114
+ var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
115
+ if (localId) {
116
+ ids.push(localId);
117
+ }
118
+ });
119
+ return ids;
120
+ };
@@ -13,6 +13,7 @@ export { isValidTargetNode } from './gap-cursor/utils/is-valid-target-node';
13
13
  export { setGapCursorSelection } from './gap-cursor/utils/setGapCursorSelection';
14
14
  export { hideCaretModifier, gapCursorStyles } from './gap-cursor/styles';
15
15
  export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, deleteSelectedRange, endPositionOfParent, expandSelectionBounds, expandSelectionToBlockRange, expandToBlockRange, getSourceNodesFromSelectionRange, isMultiBlockRange, isMultiBlockSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, selectionIsAtTheBeginningOfBlock, startPositionOfParent } from './utils';
16
+ export { getSliceFromSelection, getFragmentsFromSelection, getLocalIdsFromSelection } from './context-helpers';
16
17
  export function getNodeSelectionAnalyticsPayload(selection) {
17
18
  if (selection instanceof NodeSelection) {
18
19
  return {
@@ -0,0 +1 @@
1
+ export {};
@@ -21,7 +21,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import { fg } from '@atlaskit/platform-feature-flags';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "111.27.0";
24
+ var packageVersion = "111.28.1";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var fadeIn = keyframes({
@@ -0,0 +1,27 @@
1
+ import { type JSONNode } from '@atlaskit/editor-json-transformer';
2
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
4
+ import { type Selection } from '@atlaskit/editor-prosemirror/state';
5
+ export declare const selectionCoversAllListItems: ($from: ResolvedPos, $to: ResolvedPos) => boolean;
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;
15
+ /**
16
+ * Get the fragments from the selection.
17
+ * @param selection The selection to get the fragments from.
18
+ * @param schema The schema to use to convert the nodes to JSON.
19
+ * @returns The fragments as an array of JSON nodes.
20
+ */
21
+ export declare const getFragmentsFromSelection: (selection?: Selection) => JSONNode[] | null;
22
+ /**
23
+ * Get the local IDs from the selection.
24
+ * @param selection The selection to get the local IDs from.
25
+ * @returns The local IDs as an array of strings.
26
+ */
27
+ export declare const getLocalIdsFromSelection: (selection?: Selection) => string[] | null;
@@ -12,6 +12,7 @@ export { isValidTargetNode } from './gap-cursor/utils/is-valid-target-node';
12
12
  export { setGapCursorSelection } from './gap-cursor/utils/setGapCursorSelection';
13
13
  export { hideCaretModifier, gapCursorStyles } from './gap-cursor/styles';
14
14
  export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, deleteSelectedRange, endPositionOfParent, expandSelectionBounds, expandSelectionToBlockRange, expandToBlockRange, getSourceNodesFromSelectionRange, isMultiBlockRange, isMultiBlockSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, selectionIsAtTheBeginningOfBlock, startPositionOfParent, } from './utils';
15
+ export { getSliceFromSelection, getFragmentsFromSelection, getLocalIdsFromSelection, } from './context-helpers';
15
16
  export declare function getNodeSelectionAnalyticsPayload(selection: Selection): AnalyticsEventPayload | undefined;
16
17
  export declare function getAllSelectionAnalyticsPayload(selection: Selection): AnalyticsEventPayload | undefined;
17
18
  export declare function getCellSelectionAnalyticsPayload(state: EditorState): AnalyticsEventPayload | undefined;
@@ -42,7 +42,7 @@ export type { InputRuleHandler, OnHandlerApply, InputRuleWrapper } from './input
42
42
  export type { TOOLBAR_MENU_TYPE } from './insert-block';
43
43
  export type { TextFormattingOptions, TextFormattingState, InputMethodToolbar, InputMethodBasic, } from './text-formatting';
44
44
  export type { LayoutPluginOptions } from './layout';
45
- export type { LongPressSelectionPluginOptions } from './selection';
45
+ export type { LongPressSelectionPluginOptions, SelectionContext } from './selection';
46
46
  export type { QuickInsertPluginState, QuickInsertPluginStateKeys, QuickInsertOptions, QuickInsertPluginOptions, QuickInsertSearchOptions, QuickInsertSharedState, QuickInsertHandler, QuickInsertHandlerFn, } from './quick-insert';
47
47
  export type { Refs, RefsNode, DocBuilder } from './doc-builder';
48
48
  export type { SelectionToolbarGroup, SelectionToolbarHandler } from './selection-toolbar';
@@ -1,3 +1,29 @@
1
+ import type { JSONNode } from '@atlaskit/editor-json-transformer';
1
2
  export interface LongPressSelectionPluginOptions {
2
3
  useLongPressSelection?: boolean;
3
4
  }
5
+ export type SelectionContext = {
6
+ /**
7
+ * End index of the selection inside the last node of the selection
8
+ */
9
+ endIndex?: number | null;
10
+ /**
11
+ * Local IDs of the selected nodes
12
+ */
13
+ localIds: string[] | null;
14
+ /**
15
+ * Prosemirror fragment of the selection converted to JSONNode array
16
+ *
17
+ * Note that this is a direct Prosemirror Fragment and has some slight tweaks
18
+ * so it performs better with AI models (e.g. reduced depth to reduce token count).
19
+ */
20
+ selectionFragment: JSONNode[] | null;
21
+ /**
22
+ * Selection in markdown format
23
+ */
24
+ selectionMarkdown: string | null;
25
+ /**
26
+ * Start index of the selection inside the first node of the selection
27
+ */
28
+ startIndex?: number | null;
29
+ };
@@ -0,0 +1,27 @@
1
+ import { type JSONNode } from '@atlaskit/editor-json-transformer';
2
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
+ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
4
+ import { type Selection } from '@atlaskit/editor-prosemirror/state';
5
+ export declare const selectionCoversAllListItems: ($from: ResolvedPos, $to: ResolvedPos) => boolean;
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;
15
+ /**
16
+ * Get the fragments from the selection.
17
+ * @param selection The selection to get the fragments from.
18
+ * @param schema The schema to use to convert the nodes to JSON.
19
+ * @returns The fragments as an array of JSON nodes.
20
+ */
21
+ export declare const getFragmentsFromSelection: (selection?: Selection) => JSONNode[] | null;
22
+ /**
23
+ * Get the local IDs from the selection.
24
+ * @param selection The selection to get the local IDs from.
25
+ * @returns The local IDs as an array of strings.
26
+ */
27
+ export declare const getLocalIdsFromSelection: (selection?: Selection) => string[] | null;
@@ -12,6 +12,7 @@ export { isValidTargetNode } from './gap-cursor/utils/is-valid-target-node';
12
12
  export { setGapCursorSelection } from './gap-cursor/utils/setGapCursorSelection';
13
13
  export { hideCaretModifier, gapCursorStyles } from './gap-cursor/styles';
14
14
  export { atTheBeginningOfBlock, atTheBeginningOfDoc, atTheEndOfBlock, atTheEndOfDoc, deleteSelectedRange, endPositionOfParent, expandSelectionBounds, expandSelectionToBlockRange, expandToBlockRange, getSourceNodesFromSelectionRange, isMultiBlockRange, isMultiBlockSelection, isSelectionAtEndOfNode, isSelectionAtStartOfNode, selectionIsAtTheBeginningOfBlock, startPositionOfParent, } from './utils';
15
+ export { getSliceFromSelection, getFragmentsFromSelection, getLocalIdsFromSelection, } from './context-helpers';
15
16
  export declare function getNodeSelectionAnalyticsPayload(selection: Selection): AnalyticsEventPayload | undefined;
16
17
  export declare function getAllSelectionAnalyticsPayload(selection: Selection): AnalyticsEventPayload | undefined;
17
18
  export declare function getCellSelectionAnalyticsPayload(state: EditorState): AnalyticsEventPayload | undefined;
@@ -42,7 +42,7 @@ export type { InputRuleHandler, OnHandlerApply, InputRuleWrapper } from './input
42
42
  export type { TOOLBAR_MENU_TYPE } from './insert-block';
43
43
  export type { TextFormattingOptions, TextFormattingState, InputMethodToolbar, InputMethodBasic, } from './text-formatting';
44
44
  export type { LayoutPluginOptions } from './layout';
45
- export type { LongPressSelectionPluginOptions } from './selection';
45
+ export type { LongPressSelectionPluginOptions, SelectionContext } from './selection';
46
46
  export type { QuickInsertPluginState, QuickInsertPluginStateKeys, QuickInsertOptions, QuickInsertPluginOptions, QuickInsertSearchOptions, QuickInsertSharedState, QuickInsertHandler, QuickInsertHandlerFn, } from './quick-insert';
47
47
  export type { Refs, RefsNode, DocBuilder } from './doc-builder';
48
48
  export type { SelectionToolbarGroup, SelectionToolbarHandler } from './selection-toolbar';
@@ -1,3 +1,29 @@
1
+ import type { JSONNode } from '@atlaskit/editor-json-transformer';
1
2
  export interface LongPressSelectionPluginOptions {
2
3
  useLongPressSelection?: boolean;
3
4
  }
5
+ export type SelectionContext = {
6
+ /**
7
+ * End index of the selection inside the last node of the selection
8
+ */
9
+ endIndex?: number | null;
10
+ /**
11
+ * Local IDs of the selected nodes
12
+ */
13
+ localIds: string[] | null;
14
+ /**
15
+ * Prosemirror fragment of the selection converted to JSONNode array
16
+ *
17
+ * Note that this is a direct Prosemirror Fragment and has some slight tweaks
18
+ * so it performs better with AI models (e.g. reduced depth to reduce token count).
19
+ */
20
+ selectionFragment: JSONNode[] | null;
21
+ /**
22
+ * Selection in markdown format
23
+ */
24
+ selectionMarkdown: string | null;
25
+ /**
26
+ * Start index of the selection inside the first node of the selection
27
+ */
28
+ startIndex?: number | null;
29
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "111.28.0",
3
+ "version": "111.28.2",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -76,13 +76,13 @@
76
76
  "@atlaskit/react-ufo": "^5.4.0",
77
77
  "@atlaskit/section-message": "^8.12.0",
78
78
  "@atlaskit/smart-card": "^43.25.0",
79
- "@atlaskit/smart-user-picker": "^9.1.0",
79
+ "@atlaskit/smart-user-picker": "^9.2.0",
80
80
  "@atlaskit/spinner": "^19.0.0",
81
81
  "@atlaskit/status": "^3.1.0",
82
82
  "@atlaskit/task-decision": "^19.3.0",
83
83
  "@atlaskit/textfield": "^8.2.0",
84
84
  "@atlaskit/theme": "^22.0.0",
85
- "@atlaskit/tmp-editor-statsig": "^33.2.0",
85
+ "@atlaskit/tmp-editor-statsig": "^34.0.0",
86
86
  "@atlaskit/tokens": "^11.0.0",
87
87
  "@atlaskit/tooltip": "^20.14.0",
88
88
  "@atlaskit/width-detector": "^5.0.0",