@atlaskit/editor-common 130.1.0 → 130.2.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.
@@ -0,0 +1,546 @@
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 isEqual from 'lodash/isEqual';
6
+ // localId is identity metadata: regenerating it alone should not create activity.
7
+ var sameAttrs = function sameAttrs(left, right) {
8
+ var keys = Object.keys(left).filter(function (key) {
9
+ return key !== 'localId';
10
+ });
11
+ return keys.length === Object.keys(right).filter(function (key) {
12
+ return key !== 'localId';
13
+ }).length && keys.every(function (key) {
14
+ return isEqual(left[key], right[key]);
15
+ });
16
+ };
17
+
18
+ // Compare the node's own type, attributes and marks, without comparing its children.
19
+ var sameMarkup = function sameMarkup(left, right) {
20
+ return left.type === right.type && sameAttrs(left.attrs, right.attrs) && left.marks.length === right.marks.length && left.marks.every(function (mark, index) {
21
+ return mark.type === right.marks[index].type && sameAttrs(mark.attrs, right.marks[index].attrs);
22
+ });
23
+ };
24
+ var _sameNode = function sameNode(left, right) {
25
+ if (left === right) {
26
+ return true;
27
+ }
28
+ if (!sameMarkup(left, right) || left.text !== right.text || left.childCount !== right.childCount) {
29
+ return false;
30
+ }
31
+ for (var index = 0; index < left.childCount; index++) {
32
+ if (!_sameNode(left.child(index), right.child(index))) {
33
+ return false;
34
+ }
35
+ }
36
+ return true;
37
+ };
38
+
39
+ // Positions include document structure, not just character offsets. A non-leaf node
40
+ // uses one position for each opening/closing boundary, plus the size of its content.
41
+ // Example: paragraph('Hi') at pos 0 has nodeSize 4, outer range [0, 4),
42
+ // and text content [1, 3). All ranges here use an exclusive end position.
43
+
44
+ // Keep the reason internally so a panel attribute change can survive child edits.
45
+ // Only ordinary { from, to } ranges are returned to the chrome consumer.
46
+
47
+ var getSnapshotIndex = function getSnapshotIndex(doc, indexes) {
48
+ var cached = indexes.get(doc);
49
+ if (cached) {
50
+ return cached;
51
+ }
52
+ var snapshot = {
53
+ byId: new Map(),
54
+ byPosition: new Map(),
55
+ nodes: [],
56
+ textblocks: []
57
+ };
58
+ var parents = [{
59
+ node: doc,
60
+ pos: -1,
61
+ index: 0
62
+ }];
63
+ doc.descendants(function (node, pos, _parent, index) {
64
+ // Track ancestry by position because one immutable node can occupy several slots.
65
+ while (parents.length > 1 && pos >= parents[parents.length - 1].pos + parents[parents.length - 1].node.nodeSize - 1) {
66
+ parents.pop();
67
+ }
68
+ var positioned = {
69
+ node: node,
70
+ pos: pos,
71
+ parent: parents[parents.length - 1],
72
+ index: index
73
+ };
74
+ snapshot.byPosition.set(pos, positioned);
75
+ snapshot.nodes.push(positioned);
76
+ if (node.isTextblock) {
77
+ snapshot.textblocks.push(positioned);
78
+ }
79
+ var id = node.attrs.localId;
80
+ if (typeof id === 'string' && id) {
81
+ snapshot.byId.set(id, snapshot.byId.has(id) ? null : positioned);
82
+ }
83
+ if (!node.isLeaf) {
84
+ parents.push(positioned);
85
+ }
86
+ });
87
+ indexes.set(doc, snapshot);
88
+ return snapshot;
89
+ };
90
+ var indexedNodeAt = function indexedNodeAt(doc, pos, indexes) {
91
+ var snapshot = getSnapshotIndex(doc, indexes);
92
+ var exact = snapshot.byPosition.get(pos);
93
+ if (exact) {
94
+ return exact.node;
95
+ }
96
+ // nodeAt also returns a text node when the position is inside its text.
97
+ var low = 0;
98
+ var high = snapshot.nodes.length;
99
+ while (low < high) {
100
+ var middle = low + high >>> 1;
101
+ if (snapshot.nodes[middle].pos <= pos) {
102
+ low = middle + 1;
103
+ } else {
104
+ high = middle;
105
+ }
106
+ }
107
+ var previous = snapshot.nodes[low - 1];
108
+ return previous !== null && previous !== void 0 && previous.node.isText && pos < previous.pos + previous.node.nodeSize ? previous.node : undefined;
109
+ };
110
+ var _collectChanges = function collectChanges(before, after, map, ranges) {
111
+ var node = after.node,
112
+ pos = after.pos;
113
+ if (before && _sameNode(before.node, node)) {
114
+ return;
115
+ }
116
+ // Text edits belong to their textblock. A node's own markup change instead
117
+ // owns its full content, so we stop here rather than adding child ranges too.
118
+ var markupChanged = !!before && node.isBlock && !sameMarkup(before.node, node);
119
+ if (node.isTextblock || markupChanged) {
120
+ if (node.content.size > 0) {
121
+ ranges.push({
122
+ from: pos,
123
+ to: pos + node.nodeSize,
124
+ markupChanged: markupChanged
125
+ });
126
+ }
127
+ return;
128
+ }
129
+ var byPosition = new Map();
130
+ var byId = new Map();
131
+ var oldChildren = [];
132
+ before === null || before === void 0 || before.node.forEach(function (child, offset) {
133
+ // forEach offsets start inside the parent. Skip its opening boundary (+1)
134
+ // to convert this child offset into an absolute document position.
135
+ var previous = {
136
+ node: child,
137
+ pos: before.pos + 1 + offset
138
+ };
139
+ oldChildren.push(previous);
140
+ // This 1 is a mapping bias, not an added offset: follow the right side
141
+ // of an insertion at the child's start, keeping the original child after it.
142
+ var mapped = map.mapResult(previous.pos, 1);
143
+ if (!mapped.deleted) {
144
+ byPosition.set(mapped.pos, previous);
145
+ }
146
+ var id = child.attrs.localId;
147
+ if (typeof id === 'string' && id) {
148
+ // Duplicate IDs cannot identify a unique old child.
149
+ byId.set(id, byId.has(id) ? null : previous);
150
+ }
151
+ });
152
+ var nextChildren = [];
153
+ node.forEach(function (child, offset) {
154
+ return nextChildren.push({
155
+ node: child,
156
+ pos: pos + 1 + offset
157
+ });
158
+ });
159
+ // Narrow edits usually preserve mapped positions. Whole-container replacements
160
+ // may erase those positions, so stable child IDs provide a second way to match.
161
+ var preferred = nextChildren.map(function (next) {
162
+ var _ref, _byPosition$get;
163
+ return (_ref = (_byPosition$get = byPosition.get(next.pos)) !== null && _byPosition$get !== void 0 ? _byPosition$get : byId.get(next.node.attrs.localId)) !== null && _ref !== void 0 ? _ref : undefined;
164
+ });
165
+ var claims = new Map();
166
+ var _iterator = _createForOfIteratorHelper(preferred),
167
+ _step;
168
+ try {
169
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
170
+ var match = _step.value;
171
+ if (match) {
172
+ var _claims$get;
173
+ claims.set(match, ((_claims$get = claims.get(match)) !== null && _claims$get !== void 0 ? _claims$get : 0) + 1);
174
+ }
175
+ }
176
+ } catch (err) {
177
+ _iterator.e(err);
178
+ } finally {
179
+ _iterator.f();
180
+ }
181
+ nextChildren.forEach(function (next, index) {
182
+ var match = preferred[index];
183
+ // Same-index fallback supports replacements that regenerate IDs but keep
184
+ // the child structure. Different child counts make that correspondence unsafe.
185
+ var aligned = oldChildren.length === node.childCount ? oldChildren[index] : undefined;
186
+ // Reserve every position/ID match before fallback, including later siblings.
187
+ // Reusing one old sibling can otherwise disguise an equal-text insertion.
188
+ var previous = match && claims.get(match) === 1 ? match : aligned && !claims.has(aligned) ? aligned : undefined;
189
+ _collectChanges(previous, next, map, ranges);
190
+ });
191
+ };
192
+ var findPreservedNode = function findPreservedNode(before, doc, previous, markupChanged, indexes) {
193
+ var id = previous.attrs.localId;
194
+ if (typeof id !== 'string' || !id) {
195
+ return;
196
+ }
197
+ // When source uniqueness is required, removing a duplicate must not transfer
198
+ // its activity to the remaining equal-content sibling.
199
+ if (before && !getSnapshotIndex(before, indexes).byId.get(id)) {
200
+ return;
201
+ }
202
+ var match = getSnapshotIndex(doc, indexes).byId.get(id);
203
+ // Attribute/mark activity belongs to the node even when its children are edited.
204
+ // Content-only activity still requires the entire candidate to survive unchanged.
205
+ var isPreserved = markupChanged ? sameMarkup : _sameNode;
206
+ return match && isPreserved(previous, match.node) ? match : undefined;
207
+ };
208
+ var findAlignedTextblock = function findAlignedTextblock(before, after, pos, offsets, indexes) {
209
+ var original = getSnapshotIndex(before, indexes).byPosition.get(pos);
210
+ var path = [];
211
+ while ((_original = original) !== null && _original !== void 0 && _original.parent) {
212
+ var _original;
213
+ path.push(original);
214
+ original = original.parent;
215
+ }
216
+ var parent = after;
217
+ var parentPos = -1;
218
+ var _iterator2 = _createForOfIteratorHelper(path.reverse()),
219
+ _step2;
220
+ try {
221
+ var _loop = function _loop() {
222
+ var _child$parent;
223
+ var child = _step2.value;
224
+ var originalParent = (_child$parent = child.parent) === null || _child$parent === void 0 ? void 0 : _child$parent.node;
225
+ if (!originalParent) {
226
+ return {
227
+ v: void 0
228
+ };
229
+ }
230
+ if (parent.type !== originalParent.type || parent.childCount !== originalParent.childCount) {
231
+ return {
232
+ v: void 0
233
+ };
234
+ }
235
+ var index = child.index;
236
+ if (index >= parent.childCount) {
237
+ return {
238
+ v: void 0
239
+ };
240
+ }
241
+ var childOffsets = offsets.get(parent);
242
+ if (!childOffsets) {
243
+ var computedOffsets = [];
244
+ parent.forEach(function (_child, offset) {
245
+ return computedOffsets.push(offset);
246
+ });
247
+ childOffsets = computedOffsets;
248
+ offsets.set(parent, childOffsets);
249
+ }
250
+ parentPos += 1 + childOffsets[index];
251
+ parent = parent.child(index);
252
+ },
253
+ _ret;
254
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
255
+ _ret = _loop();
256
+ if (_ret) return _ret.v;
257
+ }
258
+ } catch (err) {
259
+ _iterator2.e(err);
260
+ } finally {
261
+ _iterator2.f();
262
+ }
263
+ return parent.isTextblock ? {
264
+ node: parent,
265
+ pos: parentPos
266
+ } : undefined;
267
+ };
268
+ var mapToFinalBlocks = function mapToFinalBlocks(tr, index, range, indexes, options) {
269
+ var _tr$docs;
270
+ var alignedOffsets = options.alignedOffsets,
271
+ requireUniqueSourceIds = options.requireUniqueSourceIds;
272
+ // Carried ranges can cover every block in a document. Repeated nodeAt calls
273
+ // scan preceding siblings, so reuse one positioned index per snapshot instead.
274
+ var nodeAt = function nodeAt(doc, pos) {
275
+ return alignedOffsets ? indexedNodeAt(doc, pos, indexes) : doc.nodeAt(pos);
276
+ };
277
+ var from = range.from,
278
+ to = range.to;
279
+ // Track inner content separately from outer node bounds: +1 skips the opening
280
+ // boundary and -1 excludes the closing boundary (see paragraph example above).
281
+ var contentFrom = from + 1;
282
+ var contentTo = to - 1;
283
+ // docs[i] is the document BEFORE step i, so docs[i + 1] is its result.
284
+ // The last step has no next snapshot; tr.doc is its result instead.
285
+ var node = nodeAt((_tr$docs = tr.docs[index + 1]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc, from);
286
+ if (!node) {
287
+ return [];
288
+ }
289
+ // Later non-AI steps also shift/delete existing activity, even though they
290
+ // cannot create new activity themselves. Process every intermediate document.
291
+ for (var next = index + 1; next < tr.steps.length; next++) {
292
+ var _tr$docs2;
293
+ var map = tr.mapping.maps[next];
294
+ var after = (_tr$docs2 = tr.docs[next + 1]) !== null && _tr$docs2 !== void 0 ? _tr$docs2 : tr.doc;
295
+ // Mapping biases +1 (right) and -1 (left) keep boundary insertions outside
296
+ // the tracked content. These arguments do not add/subtract document positions.
297
+ var start = map.mapResult(contentFrom, 1);
298
+ var end = map.mapResult(contentTo, -1);
299
+ if (start.deleted && end.deleted || end.pos <= start.pos) {
300
+ var _indexes$get, _indexes$get2;
301
+ // A cumulative replacement can preserve the candidate content or owned markup.
302
+ // Check every intermediate doc so deletion then reinsertion never resurrects it.
303
+ var preserved = findPreservedNode(requireUniqueSourceIds ? tr.docs[next] : undefined, after, node, range.markupChanged, indexes);
304
+ var id = node.attrs.localId;
305
+ var sourceMatch = typeof id === 'string' && id ? (_indexes$get = indexes.get(tr.docs[next])) === null || _indexes$get === void 0 ? void 0 : _indexes$get.byId.get(id) : undefined;
306
+ var idMatch = typeof id === 'string' && id ? (_indexes$get2 = indexes.get(after)) === null || _indexes$get2 === void 0 ? void 0 : _indexes$get2.byId.get(id) : undefined;
307
+ if (!preserved && alignedOffsets && sourceMatch !== null && idMatch === undefined) {
308
+ // Inline replacements can keep a block's opening boundary while
309
+ // recreating its content and adding later blocks to the same chunk.
310
+ var mapped = map.mapResult(from, 1);
311
+ var mappedNode = !mapped.deleted ? nodeAt(after, mapped.pos) : undefined;
312
+ if (mappedNode !== null && mappedNode !== void 0 && mappedNode.isTextblock && _sameNode(node, mappedNode)) {
313
+ preserved = {
314
+ node: mappedNode,
315
+ pos: mapped.pos
316
+ };
317
+ } else {
318
+ // Whole-block replacements may recreate unchanged blocks without IDs.
319
+ // Match their slot only while every parent keeps its shape.
320
+ var aligned = findAlignedTextblock(tr.docs[next], after, from, alignedOffsets, indexes);
321
+ if (aligned && _sameNode(node, aligned.node)) {
322
+ preserved = aligned;
323
+ }
324
+ }
325
+ }
326
+ if (!preserved) {
327
+ return [];
328
+ }
329
+ from = preserved.pos;
330
+ to = from + preserved.node.nodeSize;
331
+ contentFrom = from + 1;
332
+ contentTo = to - 1;
333
+ node = preserved.node;
334
+ } else {
335
+ // Apply the same inward biases to the outer node bounds.
336
+ from = map.map(from, 1);
337
+ to = map.map(to, -1);
338
+ contentFrom = start.pos;
339
+ contentTo = end.pos;
340
+ var current = nodeAt(after, from);
341
+ if (current && current.nodeSize === to - from) {
342
+ node = current;
343
+ }
344
+ }
345
+ }
346
+ if (from < 0 || to > tr.doc.content.size || contentTo <= contentFrom) {
347
+ return [];
348
+ }
349
+ var finalNode = nodeAt(tr.doc, from);
350
+ if (finalNode !== null && finalNode !== void 0 && finalNode.isBlock && finalNode.nodeSize === to - from) {
351
+ return [{
352
+ from: from,
353
+ to: to
354
+ }];
355
+ }
356
+ // Joins/splits can leave mapped boundaries inside the final textblock.
357
+ var blocks = [];
358
+ if (alignedOffsets) {
359
+ var textblocks = getSnapshotIndex(tr.doc, indexes).textblocks;
360
+ var low = 0;
361
+ var high = textblocks.length;
362
+ while (low < high) {
363
+ var middle = low + high >>> 1;
364
+ var candidate = textblocks[middle];
365
+ if (candidate.pos + candidate.node.nodeSize <= contentFrom) {
366
+ low = middle + 1;
367
+ } else {
368
+ high = middle;
369
+ }
370
+ }
371
+ for (var _index = low; _index < textblocks.length && textblocks[_index].pos < contentTo; _index++) {
372
+ var _textblocks$_index = textblocks[_index],
373
+ _node = _textblocks$_index.node,
374
+ pos = _textblocks$_index.pos;
375
+ blocks.push({
376
+ from: pos,
377
+ to: pos + _node.nodeSize
378
+ });
379
+ }
380
+ return blocks;
381
+ }
382
+ tr.doc.nodesBetween(contentFrom, contentTo, function (child, pos) {
383
+ if (child.isTextblock) {
384
+ blocks.push({
385
+ from: pos,
386
+ to: pos + child.nodeSize
387
+ });
388
+ return false;
389
+ }
390
+ });
391
+ return blocks;
392
+ };
393
+
394
+ /**
395
+ * Maps existing textblock activity through each applied step into tr.doc coordinates.
396
+ * Replaced content is dropped unless an unchanged block survives with a unique ID
397
+ * or in the same structural slot. Newly changed blocks belong to the producer.
398
+ */
399
+ function mapAgentEditChromeRanges(tr, ranges) {
400
+ var indexes = new WeakMap();
401
+ var alignedOffsets = new WeakMap();
402
+ var options = {
403
+ alignedOffsets: alignedOffsets,
404
+ requireUniqueSourceIds: true
405
+ };
406
+ var validRanges = [];
407
+ var _iterator3 = _createForOfIteratorHelper(ranges),
408
+ _step3;
409
+ try {
410
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
411
+ var _step3$value = _step3.value,
412
+ from = _step3$value.from,
413
+ to = _step3$value.to;
414
+ if (!Number.isFinite(from) || !Number.isFinite(to) || to <= from) {
415
+ continue;
416
+ }
417
+ var start = Math.max(0, Math.min(from, tr.before.content.size));
418
+ var end = Math.max(start, Math.min(to, tr.before.content.size));
419
+ if (start === end) {
420
+ continue;
421
+ }
422
+ validRanges.push({
423
+ from: start,
424
+ to: end
425
+ });
426
+ }
427
+ } catch (err) {
428
+ _iterator3.e(err);
429
+ } finally {
430
+ _iterator3.f();
431
+ }
432
+ if (!validRanges.length) {
433
+ return [];
434
+ }
435
+ validRanges.sort(function (left, right) {
436
+ return left.from - right.from;
437
+ });
438
+ var blocks = [];
439
+ var rangeIndex = 0;
440
+ var _iterator4 = _createForOfIteratorHelper(getSnapshotIndex(tr.before, indexes).textblocks),
441
+ _step4;
442
+ try {
443
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
444
+ var _step4$value = _step4.value,
445
+ node = _step4$value.node,
446
+ pos = _step4$value.pos;
447
+ while (rangeIndex < validRanges.length && validRanges[rangeIndex].to <= pos) {
448
+ rangeIndex++;
449
+ }
450
+ if (rangeIndex === validRanges.length) {
451
+ break;
452
+ }
453
+ if (node.content.size && validRanges[rangeIndex].from < pos + node.nodeSize) {
454
+ blocks.push({
455
+ from: pos,
456
+ to: pos + node.nodeSize,
457
+ markupChanged: false
458
+ });
459
+ }
460
+ }
461
+ // Index -1 starts from docs[0], before the first step, instead of a step result.
462
+ } catch (err) {
463
+ _iterator4.e(err);
464
+ } finally {
465
+ _iterator4.f();
466
+ }
467
+ return blocks.flatMap(function (range) {
468
+ return mapToFinalBlocks(tr, -1, range, indexes, options);
469
+ });
470
+ }
471
+
472
+ /**
473
+ * Returns whole content-block ranges for selected applied steps, in tr.doc coordinates.
474
+ * Callers select actual AI writes (excluding restores, acknowledgments and preparation)
475
+ * and own experiment/lifecycle decisions. This helper does not dispatch or render.
476
+ *
477
+ * Comparing each step's snapshots also handles attribute/mark steps with empty maps.
478
+ * Shared unchanged subtrees are skipped by reference. Only localId changes are ignored;
479
+ * meaningful attributes and marks retain the affected node's full content scope.
480
+ */
481
+ function getAgentEditChangedRanges(tr, includedStepIndexes, requireUniqueSourceIds) {
482
+ // Positions belong to each intermediate document, not just tr.doc. Keep the
483
+ // lazy indexes local to this call so deletion/reinsertion checks stay intact
484
+ // and no cache is retained between transactions or streaming chunks.
485
+ var indexes = new WeakMap();
486
+ var options = {
487
+ requireUniqueSourceIds: requireUniqueSourceIds
488
+ };
489
+ var ranges = [];
490
+ var _iterator5 = _createForOfIteratorHelper(new Set(includedStepIndexes)),
491
+ _step5;
492
+ try {
493
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
494
+ var _tr$docs3;
495
+ var index = _step5.value;
496
+ if (!Number.isInteger(index) || index < 0 || index >= tr.steps.length) {
497
+ continue;
498
+ }
499
+ var changed = [];
500
+ // The root document has no opening boundary. Using -1 makes the recursive
501
+ // parent.pos + 1 + offset formula place its first child at position 0.
502
+ _collectChanges({
503
+ node: tr.docs[index],
504
+ pos: -1
505
+ }, {
506
+ node: (_tr$docs3 = tr.docs[index + 1]) !== null && _tr$docs3 !== void 0 ? _tr$docs3 : tr.doc,
507
+ pos: -1
508
+ }, tr.steps[index].getMap(), changed);
509
+ for (var _i = 0, _changed = changed; _i < _changed.length; _i++) {
510
+ var range = _changed[_i];
511
+ ranges.push.apply(ranges, _toConsumableArray(mapToFinalBlocks(tr, index, range, indexes, options)));
512
+ }
513
+ }
514
+
515
+ // Return only the surviving final-document ranges, never intermediate step states.
516
+ // Sort outer ranges before their children, then discard duplicates/contained ranges.
517
+ // Separate ranges stay separate; this must not highlight the untouched gaps.
518
+ } catch (err) {
519
+ _iterator5.e(err);
520
+ } finally {
521
+ _iterator5.f();
522
+ }
523
+ var unique = [];
524
+ var _iterator6 = _createForOfIteratorHelper(ranges.sort(function (left, right) {
525
+ return left.from - right.from || right.to - left.to;
526
+ })),
527
+ _step6;
528
+ try {
529
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
530
+ var _range = _step6.value;
531
+ var previous = unique[unique.length - 1];
532
+ if (!previous || _range.to > previous.to) {
533
+ unique.push(_range);
534
+ }
535
+ }
536
+ } catch (err) {
537
+ _iterator6.e(err);
538
+ } finally {
539
+ _iterator6.f();
540
+ }
541
+ return unique;
542
+ }
543
+ export var agentEditRangeMapping = {
544
+ getChangedRanges: getAgentEditChangedRanges,
545
+ mapChromeRanges: mapAgentEditChromeRanges
546
+ };
@@ -19,7 +19,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
19
19
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
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 = "130.0.0";
22
+ var packageVersion = "130.2.0";
23
23
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
24
24
  // Remove URL as it has UGC
25
25
  // Ignored via go/ees007
@@ -21,7 +21,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import { fg } from '@atlaskit/platform-feature-flags/fg';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "130.0.0";
24
+ var packageVersion = "130.2.0";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var fadeIn = keyframes({
@@ -8,5 +8,8 @@ import type { AgentEditChromeRange } from './agent-edit-chrome';
8
8
  * Comparing each step's snapshots also handles attribute/mark steps with empty maps.
9
9
  * Shared unchanged subtrees are skipped by reference. Only localId changes are ignored;
10
10
  * meaningful attributes and marks retain the affected node's full content scope.
11
+ * Callers can require unique source IDs when preserving ranges across replacements.
11
12
  */
12
- export declare function getAgentEditChangedRanges(tr: Transaction, includedStepIndexes: readonly number[]): AgentEditChromeRange[];
13
+ export declare function getAgentEditChangedRanges(tr: Transaction, includedStepIndexes: readonly number[], options?: {
14
+ requireUniqueSourceIds?: boolean;
15
+ }): AgentEditChromeRange[];
@@ -0,0 +1,8 @@
1
+ import type { AgentEditChromeRange } from './agent-edit-chrome';
2
+ import type { AgentEditRangeTransaction } from './agent-edit-range-mapping';
3
+ /**
4
+ * Maps existing textblock activity through each applied step into tr.doc coordinates.
5
+ * Replaced content is dropped unless an unchanged block survives with a unique ID
6
+ * or in the same structural slot. Newly changed blocks belong to the producer.
7
+ */
8
+ export declare function mapAgentEditChromeRanges(tr: AgentEditRangeTransaction, ranges: readonly AgentEditChromeRange[]): AgentEditChromeRange[];
@@ -0,0 +1,7 @@
1
+ import type { Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { AgentEditChromeRange } from './agent-edit-chrome';
3
+ export type AgentEditRangeTransaction = Pick<Transaction, 'before' | 'doc' | 'docs' | 'steps' | 'mapping'>;
4
+ export declare const agentEditRangeMapping: {
5
+ getChangedRanges: (tr: AgentEditRangeTransaction, includedStepIndexes: readonly number[], requireUniqueSourceIds: boolean) => AgentEditChromeRange[];
6
+ mapChromeRanges: (tr: AgentEditRangeTransaction, ranges: readonly AgentEditChromeRange[]) => AgentEditChromeRange[];
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "130.1.0",
3
+ "version": "130.2.1",
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/"
@@ -45,7 +45,7 @@
45
45
  "@atlaskit/editor-json-transformer": "^10.0.0",
46
46
  "@atlaskit/editor-palette": "^3.5.0",
47
47
  "@atlaskit/editor-prosemirror": "^9.0.0",
48
- "@atlaskit/editor-shared-styles": "^4.3.0",
48
+ "@atlaskit/editor-shared-styles": "^4.4.0",
49
49
  "@atlaskit/editor-tables": "^3.2.0",
50
50
  "@atlaskit/editor-toolbar": "^2.8.0",
51
51
  "@atlaskit/editor-toolbar-model": "^1.2.0",
@@ -80,7 +80,7 @@
80
80
  "@atlaskit/react-ufo": "^8.1.0",
81
81
  "@atlaskit/section-message": "^10.2.0",
82
82
  "@atlaskit/smart-card": "^46.5.0",
83
- "@atlaskit/smart-user-picker": "^12.3.0",
83
+ "@atlaskit/smart-user-picker": "^12.4.0",
84
84
  "@atlaskit/spinner": "^20.4.0",
85
85
  "@atlaskit/task-decision": "^21.12.0",
86
86
  "@atlaskit/teams-app-config": "^3.1.0",