@atlaskit/editor-common 130.0.0 → 130.2.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/collab-agent-edit-chrome-ranges/package.json +10 -0
  3. package/dist/cjs/collab/agent-edit-changed-ranges.js +5 -288
  4. package/dist/cjs/collab/agent-edit-chrome-ranges.js +15 -0
  5. package/dist/cjs/collab/agent-edit-range-mapping.js +553 -0
  6. package/dist/cjs/messages/snippets.js +1 -1
  7. package/dist/cjs/monitoring/error.js +1 -1
  8. package/dist/cjs/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
  9. package/dist/cjs/quick-insert/CompactQuickInsertMenuItem.js +17 -2
  10. package/dist/cjs/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
  11. package/dist/cjs/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
  12. package/dist/cjs/quick-insert/get-matching-quick-insert-components.js +20 -10
  13. package/dist/cjs/quick-insert/messages.js +1 -1
  14. package/dist/cjs/ui/DropList/index.js +1 -1
  15. package/dist/es2019/collab/agent-edit-changed-ranges.js +5 -244
  16. package/dist/es2019/collab/agent-edit-chrome-ranges.js +10 -0
  17. package/dist/es2019/collab/agent-edit-range-mapping.js +463 -0
  18. package/dist/es2019/messages/snippets.js +1 -1
  19. package/dist/es2019/monitoring/error.js +1 -1
  20. package/dist/es2019/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
  21. package/dist/es2019/quick-insert/CompactQuickInsertMenuItem.js +17 -2
  22. package/dist/es2019/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
  23. package/dist/es2019/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
  24. package/dist/es2019/quick-insert/get-matching-quick-insert-components.js +16 -6
  25. package/dist/es2019/quick-insert/messages.js +1 -1
  26. package/dist/es2019/ui/DropList/index.js +1 -1
  27. package/dist/esm/collab/agent-edit-changed-ranges.js +5 -286
  28. package/dist/esm/collab/agent-edit-chrome-ranges.js +10 -0
  29. package/dist/esm/collab/agent-edit-range-mapping.js +546 -0
  30. package/dist/esm/messages/snippets.js +1 -1
  31. package/dist/esm/monitoring/error.js +1 -1
  32. package/dist/esm/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
  33. package/dist/esm/quick-insert/CompactQuickInsertMenuItem.js +17 -2
  34. package/dist/esm/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
  35. package/dist/esm/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
  36. package/dist/esm/quick-insert/get-matching-quick-insert-components.js +20 -10
  37. package/dist/esm/quick-insert/messages.js +1 -1
  38. package/dist/esm/ui/DropList/index.js +1 -1
  39. package/dist/types/card/cardOptions.d.ts +5 -0
  40. package/dist/types/collab/agent-edit-changed-ranges.d.ts +4 -1
  41. package/dist/types/collab/agent-edit-chrome-ranges.d.ts +8 -0
  42. package/dist/types/collab/agent-edit-range-mapping.d.ts +7 -0
  43. package/dist/types/quick-insert/CompactQuickInsertMenuItem.d.ts +4 -0
  44. package/package.json +4 -4
@@ -1,231 +1,4 @@
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 _collectChanges = function collectChanges(before, after, map, ranges) {
48
- var node = after.node,
49
- pos = after.pos;
50
- if (before && _sameNode(before.node, node)) {
51
- return;
52
- }
53
- // Text edits belong to their textblock. A node's own markup change instead
54
- // owns its full content, so we stop here rather than adding child ranges too.
55
- var markupChanged = !!before && node.isBlock && !sameMarkup(before.node, node);
56
- if (node.isTextblock || markupChanged) {
57
- if (node.content.size > 0) {
58
- ranges.push({
59
- from: pos,
60
- to: pos + node.nodeSize,
61
- markupChanged: markupChanged
62
- });
63
- }
64
- return;
65
- }
66
- var byPosition = new Map();
67
- var byId = new Map();
68
- var oldChildren = [];
69
- before === null || before === void 0 || before.node.forEach(function (child, offset) {
70
- // forEach offsets start inside the parent. Skip its opening boundary (+1)
71
- // to convert this child offset into an absolute document position.
72
- var previous = {
73
- node: child,
74
- pos: before.pos + 1 + offset
75
- };
76
- oldChildren.push(previous);
77
- // This 1 is a mapping bias, not an added offset: follow the right side
78
- // of an insertion at the child's start, keeping the original child after it.
79
- var mapped = map.mapResult(previous.pos, 1);
80
- if (!mapped.deleted) {
81
- byPosition.set(mapped.pos, previous);
82
- }
83
- var id = child.attrs.localId;
84
- if (typeof id === 'string' && id) {
85
- // Duplicate IDs cannot identify a unique old child.
86
- byId.set(id, byId.has(id) ? null : previous);
87
- }
88
- });
89
- var nextChildren = [];
90
- node.forEach(function (child, offset) {
91
- return nextChildren.push({
92
- node: child,
93
- pos: pos + 1 + offset
94
- });
95
- });
96
- // Narrow edits usually preserve mapped positions. Whole-container replacements
97
- // may erase those positions, so stable child IDs provide a second way to match.
98
- var preferred = nextChildren.map(function (next) {
99
- var _ref, _byPosition$get;
100
- 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;
101
- });
102
- var claims = new Map();
103
- var _iterator = _createForOfIteratorHelper(preferred),
104
- _step;
105
- try {
106
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
107
- var match = _step.value;
108
- if (match) {
109
- var _claims$get;
110
- claims.set(match, ((_claims$get = claims.get(match)) !== null && _claims$get !== void 0 ? _claims$get : 0) + 1);
111
- }
112
- }
113
- } catch (err) {
114
- _iterator.e(err);
115
- } finally {
116
- _iterator.f();
117
- }
118
- nextChildren.forEach(function (next, index) {
119
- var match = preferred[index];
120
- // Same-index fallback supports replacements that regenerate IDs but keep
121
- // the child structure. Different child counts make that correspondence unsafe.
122
- var aligned = oldChildren.length === node.childCount ? oldChildren[index] : undefined;
123
- // Reserve every position/ID match before fallback, including later siblings.
124
- // Reusing one old sibling can otherwise disguise an equal-text insertion.
125
- var previous = match && claims.get(match) === 1 ? match : aligned && !claims.has(aligned) ? aligned : undefined;
126
- _collectChanges(previous, next, map, ranges);
127
- });
128
- };
129
- var findPreservedNode = function findPreservedNode(doc, previous, markupChanged, indexes) {
130
- var id = previous.attrs.localId;
131
- if (typeof id !== 'string' || !id) {
132
- return;
133
- }
134
- var byId = indexes.get(doc);
135
- if (!byId) {
136
- // Build only when mapping loses a candidate, then reuse for every range
137
- // visiting this immutable snapshot. Ordinary mapped edits need no scan.
138
- var nodeIndex = new Map();
139
- doc.descendants(function (node, pos) {
140
- var localId = node.attrs.localId;
141
- if (typeof localId === 'string' && localId) {
142
- // Keep duplicates ambiguous, including IDs outside the changed subtree.
143
- nodeIndex.set(localId, nodeIndex.has(localId) ? null : {
144
- node: node,
145
- pos: pos
146
- });
147
- }
148
- });
149
- indexes.set(doc, nodeIndex);
150
- byId = nodeIndex;
151
- }
152
- var match = byId.get(id);
153
- // Attribute/mark activity belongs to the node even when its children are edited.
154
- // Content-only activity still requires the entire candidate to survive unchanged.
155
- var isPreserved = markupChanged ? sameMarkup : _sameNode;
156
- return match && isPreserved(previous, match.node) ? match : undefined;
157
- };
158
- var mapToFinalBlocks = function mapToFinalBlocks(tr, index, range, indexes) {
159
- var _tr$docs;
160
- var from = range.from,
161
- to = range.to;
162
- // Track inner content separately from outer node bounds: +1 skips the opening
163
- // boundary and -1 excludes the closing boundary (see paragraph example above).
164
- var contentFrom = from + 1;
165
- var contentTo = to - 1;
166
- // docs[i] is the document BEFORE step i, so docs[i + 1] is its result.
167
- // The last step has no next snapshot; tr.doc is its result instead.
168
- var node = ((_tr$docs = tr.docs[index + 1]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc).nodeAt(from);
169
- if (!node) {
170
- return [];
171
- }
172
- // Later non-AI steps also shift/delete existing activity, even though they
173
- // cannot create new activity themselves. Process every intermediate document.
174
- for (var next = index + 1; next < tr.steps.length; next++) {
175
- var _tr$docs2;
176
- var map = tr.mapping.maps[next];
177
- var after = (_tr$docs2 = tr.docs[next + 1]) !== null && _tr$docs2 !== void 0 ? _tr$docs2 : tr.doc;
178
- // Mapping biases +1 (right) and -1 (left) keep boundary insertions outside
179
- // the tracked content. These arguments do not add/subtract document positions.
180
- var start = map.mapResult(contentFrom, 1);
181
- var end = map.mapResult(contentTo, -1);
182
- if (start.deleted && end.deleted || end.pos <= start.pos) {
183
- // A cumulative replacement can preserve the candidate content or owned markup.
184
- // Check every intermediate doc so deletion then reinsertion never resurrects it.
185
- var preserved = findPreservedNode(after, node, range.markupChanged, indexes);
186
- if (!preserved) {
187
- return [];
188
- }
189
- from = preserved.pos;
190
- to = from + preserved.node.nodeSize;
191
- contentFrom = from + 1;
192
- contentTo = to - 1;
193
- node = preserved.node;
194
- } else {
195
- // Apply the same inward biases to the outer node bounds.
196
- from = map.map(from, 1);
197
- to = map.map(to, -1);
198
- contentFrom = start.pos;
199
- contentTo = end.pos;
200
- var current = after.nodeAt(from);
201
- if (current && current.nodeSize === to - from) {
202
- node = current;
203
- }
204
- }
205
- }
206
- if (from < 0 || to > tr.doc.content.size || contentTo <= contentFrom) {
207
- return [];
208
- }
209
- var finalNode = tr.doc.nodeAt(from);
210
- if (finalNode !== null && finalNode !== void 0 && finalNode.isBlock && finalNode.nodeSize === to - from) {
211
- return [{
212
- from: from,
213
- to: to
214
- }];
215
- }
216
- // Joins/splits can leave mapped boundaries inside the final textblock.
217
- var blocks = [];
218
- tr.doc.nodesBetween(contentFrom, contentTo, function (child, pos) {
219
- if (child.isTextblock) {
220
- blocks.push({
221
- from: pos,
222
- to: pos + child.nodeSize
223
- });
224
- return false;
225
- }
226
- });
227
- return blocks;
228
- };
1
+ import { agentEditRangeMapping } from './agent-edit-range-mapping';
229
2
 
230
3
  /**
231
4
  * Returns whole content-block ranges for selected applied steps, in tr.doc coordinates.
@@ -235,63 +8,9 @@ var mapToFinalBlocks = function mapToFinalBlocks(tr, index, range, indexes) {
235
8
  * Comparing each step's snapshots also handles attribute/mark steps with empty maps.
236
9
  * Shared unchanged subtrees are skipped by reference. Only localId changes are ignored;
237
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.
238
12
  */
239
- export function getAgentEditChangedRanges(tr, includedStepIndexes) {
240
- // Positions belong to each intermediate document, not just tr.doc. Keep the
241
- // lazy indexes local to this call so deletion/reinsertion checks stay intact
242
- // and no cache is retained between transactions or streaming chunks.
243
- var indexes = new WeakMap();
244
- var ranges = [];
245
- var _iterator2 = _createForOfIteratorHelper(new Set(includedStepIndexes)),
246
- _step2;
247
- try {
248
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
249
- var _tr$docs3;
250
- var index = _step2.value;
251
- if (!Number.isInteger(index) || index < 0 || index >= tr.steps.length) {
252
- continue;
253
- }
254
- var changed = [];
255
- // The root document has no opening boundary. Using -1 makes the recursive
256
- // parent.pos + 1 + offset formula place its first child at position 0.
257
- _collectChanges({
258
- node: tr.docs[index],
259
- pos: -1
260
- }, {
261
- node: (_tr$docs3 = tr.docs[index + 1]) !== null && _tr$docs3 !== void 0 ? _tr$docs3 : tr.doc,
262
- pos: -1
263
- }, tr.steps[index].getMap(), changed);
264
- for (var _i = 0, _changed = changed; _i < _changed.length; _i++) {
265
- var range = _changed[_i];
266
- ranges.push.apply(ranges, _toConsumableArray(mapToFinalBlocks(tr, index, range, indexes)));
267
- }
268
- }
269
-
270
- // Return only the surviving final-document ranges, never intermediate step states.
271
- // Sort outer ranges before their children, then discard duplicates/contained ranges.
272
- // Separate ranges stay separate; this must not highlight the untouched gaps.
273
- } catch (err) {
274
- _iterator2.e(err);
275
- } finally {
276
- _iterator2.f();
277
- }
278
- var unique = [];
279
- var _iterator3 = _createForOfIteratorHelper(ranges.sort(function (left, right) {
280
- return left.from - right.from || right.to - left.to;
281
- })),
282
- _step3;
283
- try {
284
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
285
- var _range = _step3.value;
286
- var previous = unique[unique.length - 1];
287
- if (!previous || _range.to > previous.to) {
288
- unique.push(_range);
289
- }
290
- }
291
- } catch (err) {
292
- _iterator3.e(err);
293
- } finally {
294
- _iterator3.f();
295
- }
296
- return unique;
13
+ export function getAgentEditChangedRanges(tr, includedStepIndexes, options) {
14
+ var _options$requireUniqu;
15
+ return agentEditRangeMapping.getChangedRanges(tr, includedStepIndexes, (_options$requireUniqu = options === null || options === void 0 ? void 0 : options.requireUniqueSourceIds) !== null && _options$requireUniqu !== void 0 ? _options$requireUniqu : false);
297
16
  }
@@ -0,0 +1,10 @@
1
+ import { agentEditRangeMapping } from './agent-edit-range-mapping';
2
+
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 function mapAgentEditChromeRanges(tr, ranges) {
9
+ return agentEditRangeMapping.mapChromeRanges(tr, ranges);
10
+ }