@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
@@ -47,7 +47,7 @@ var getSearchResults = function getSearchResults(matches) {
47
47
  * no empty-query path so browse behavior remains owned by buildQuickInsertMenuModel.
48
48
  */
49
49
  var getMatchingQuickInsertComponents = exports.getMatchingQuickInsertComponents = function getMatchingQuickInsertComponents(_ref4) {
50
- var _childrenMap$get2;
50
+ var _childrenMap$get;
51
51
  var components = _ref4.components,
52
52
  rootComponent = _ref4.rootComponent,
53
53
  query = _ref4.query,
@@ -139,7 +139,9 @@ var getMatchingQuickInsertComponents = exports.getMatchingQuickInsertComponents
139
139
  _iterator2.f();
140
140
  }
141
141
  var sections = Array.from(sectionsByKey.values());
142
- if (sections.length > 0 || query === '') {
142
+ // An empty query is browse mode: `buildQuickInsertMenuModel` supplies the footer there,
143
+ // so this search model must not add a second one.
144
+ if (query === '') {
143
145
  return {
144
146
  footer: undefined,
145
147
  root: root,
@@ -147,21 +149,29 @@ var getMatchingQuickInsertComponents = exports.getMatchingQuickInsertComponents
147
149
  sections: sections
148
150
  };
149
151
  }
152
+ var footerSection = topLevelChildren.find(function (section) {
153
+ return section.type === 'menu-section' && (0, _isMenuFooterSectionKey.isMenuFooterSectionKey)(section.key) && (0, _surfaceRenderer.willComponentRender)(section, childrenMap, surfaceContext);
154
+ });
155
+ var footer = footerSection ? ((_childrenMap$get = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(footerSection))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : []).find(function (child) {
156
+ return child.type === 'menu-item' && (0, _surfaceRenderer.willComponentRender)(child, childrenMap, surfaceContext);
157
+ }) : undefined;
158
+ if (sections.length > 0) {
159
+ return {
160
+ footer: footer,
161
+ root: root,
162
+ searchResults: searchResults,
163
+ sections: sections
164
+ };
165
+ }
150
166
  var fallbackItem = topLevelChildren.filter(function (section) {
151
167
  return section.type === 'menu-section' && !(0, _isMenuFooterSectionKey.isMenuFooterSectionKey)(section.key) && (0, _surfaceRenderer.willComponentRender)(section, childrenMap, surfaceContext);
152
168
  }).flatMap(function (section) {
153
- var _childrenMap$get;
154
- return (_childrenMap$get = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(section))) !== null && _childrenMap$get !== void 0 ? _childrenMap$get : [];
169
+ var _childrenMap$get2;
170
+ return (_childrenMap$get2 = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(section))) !== null && _childrenMap$get2 !== void 0 ? _childrenMap$get2 : [];
155
171
  }).find(function (component) {
156
172
  return component.type === _keys.ASK_ROVO_MENU_ITEM.type && component.key === _keys.ASK_ROVO_MENU_ITEM.key && (0, _surfaceRenderer.willComponentRender)(component, childrenMap, surfaceContext);
157
173
  });
158
174
  var fallbackItems = fallbackItem ? [fallbackItem] : [];
159
- var footerSection = topLevelChildren.find(function (section) {
160
- return section.type === 'menu-section' && (0, _isMenuFooterSectionKey.isMenuFooterSectionKey)(section.key) && (0, _surfaceRenderer.willComponentRender)(section, childrenMap, surfaceContext);
161
- });
162
- var footer = footerSection ? ((_childrenMap$get2 = childrenMap.get((0, _surfaceRenderer.getComponentIdentity)(footerSection))) !== null && _childrenMap$get2 !== void 0 ? _childrenMap$get2 : []).find(function (child) {
163
- return child.type === 'menu-item' && (0, _surfaceRenderer.willComponentRender)(child, childrenMap, surfaceContext);
164
- }) : undefined;
165
175
  return {
166
176
  fallbackItems: fallbackItems,
167
177
  footer: footer,
@@ -138,7 +138,7 @@ var messages = exports.messages = (0, _reactIntl.defineMessages)({
138
138
  },
139
139
  categoryOther: {
140
140
  id: 'editor-common.quick-insert.categoryOther',
141
- defaultMessage: 'Other',
141
+ defaultMessage: 'Other elements',
142
142
  description: 'Other items in the Quick Insert menu.'
143
143
  },
144
144
  previewAttributionBy: {
@@ -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 = "129.1.2";
27
+ var packageVersion = "130.2.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var fadeIn = (0, _react2.keyframes)({
@@ -1,210 +1,4 @@
1
- import isEqual from 'lodash/isEqual';
2
- // localId is identity metadata: regenerating it alone should not create activity.
3
- const sameAttrs = (left, right) => {
4
- const keys = Object.keys(left).filter(key => key !== 'localId');
5
- return keys.length === Object.keys(right).filter(key => key !== 'localId').length && keys.every(key => isEqual(left[key], right[key]));
6
- };
7
-
8
- // Compare the node's own type, attributes and marks, without comparing its children.
9
- const sameMarkup = (left, right) => left.type === right.type && sameAttrs(left.attrs, right.attrs) && left.marks.length === right.marks.length && left.marks.every((mark, index) => mark.type === right.marks[index].type && sameAttrs(mark.attrs, right.marks[index].attrs));
10
- const sameNode = (left, right) => {
11
- if (left === right) {
12
- return true;
13
- }
14
- if (!sameMarkup(left, right) || left.text !== right.text || left.childCount !== right.childCount) {
15
- return false;
16
- }
17
- for (let index = 0; index < left.childCount; index++) {
18
- if (!sameNode(left.child(index), right.child(index))) {
19
- return false;
20
- }
21
- }
22
- return true;
23
- };
24
-
25
- // Positions include document structure, not just character offsets. A non-leaf node
26
- // uses one position for each opening/closing boundary, plus the size of its content.
27
- // Example: paragraph('Hi') at pos 0 has nodeSize 4, outer range [0, 4),
28
- // and text content [1, 3). All ranges here use an exclusive end position.
29
-
30
- // Keep the reason internally so a panel attribute change can survive child edits.
31
- // Only ordinary { from, to } ranges are returned to the chrome consumer.
32
-
33
- const collectChanges = (before, after, map, ranges) => {
34
- const {
35
- node,
36
- pos
37
- } = after;
38
- if (before && sameNode(before.node, node)) {
39
- return;
40
- }
41
- // Text edits belong to their textblock. A node's own markup change instead
42
- // owns its full content, so we stop here rather than adding child ranges too.
43
- const markupChanged = !!before && node.isBlock && !sameMarkup(before.node, node);
44
- if (node.isTextblock || markupChanged) {
45
- if (node.content.size > 0) {
46
- ranges.push({
47
- from: pos,
48
- to: pos + node.nodeSize,
49
- markupChanged
50
- });
51
- }
52
- return;
53
- }
54
- const byPosition = new Map();
55
- const byId = new Map();
56
- const oldChildren = [];
57
- before === null || before === void 0 ? void 0 : before.node.forEach((child, offset) => {
58
- // forEach offsets start inside the parent. Skip its opening boundary (+1)
59
- // to convert this child offset into an absolute document position.
60
- const previous = {
61
- node: child,
62
- pos: before.pos + 1 + offset
63
- };
64
- oldChildren.push(previous);
65
- // This 1 is a mapping bias, not an added offset: follow the right side
66
- // of an insertion at the child's start, keeping the original child after it.
67
- const mapped = map.mapResult(previous.pos, 1);
68
- if (!mapped.deleted) {
69
- byPosition.set(mapped.pos, previous);
70
- }
71
- const id = child.attrs.localId;
72
- if (typeof id === 'string' && id) {
73
- // Duplicate IDs cannot identify a unique old child.
74
- byId.set(id, byId.has(id) ? null : previous);
75
- }
76
- });
77
- const nextChildren = [];
78
- node.forEach((child, offset) => nextChildren.push({
79
- node: child,
80
- pos: pos + 1 + offset
81
- }));
82
- // Narrow edits usually preserve mapped positions. Whole-container replacements
83
- // may erase those positions, so stable child IDs provide a second way to match.
84
- const preferred = nextChildren.map(next => {
85
- var _ref, _byPosition$get;
86
- 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;
87
- });
88
- const claims = new Map();
89
- for (const match of preferred) {
90
- if (match) {
91
- var _claims$get;
92
- claims.set(match, ((_claims$get = claims.get(match)) !== null && _claims$get !== void 0 ? _claims$get : 0) + 1);
93
- }
94
- }
95
- nextChildren.forEach((next, index) => {
96
- const match = preferred[index];
97
- // Same-index fallback supports replacements that regenerate IDs but keep
98
- // the child structure. Different child counts make that correspondence unsafe.
99
- const aligned = oldChildren.length === node.childCount ? oldChildren[index] : undefined;
100
- // Reserve every position/ID match before fallback, including later siblings.
101
- // Reusing one old sibling can otherwise disguise an equal-text insertion.
102
- const previous = match && claims.get(match) === 1 ? match : aligned && !claims.has(aligned) ? aligned : undefined;
103
- collectChanges(previous, next, map, ranges);
104
- });
105
- };
106
- const findPreservedNode = (doc, previous, markupChanged, indexes) => {
107
- const id = previous.attrs.localId;
108
- if (typeof id !== 'string' || !id) {
109
- return;
110
- }
111
- let byId = indexes.get(doc);
112
- if (!byId) {
113
- // Build only when mapping loses a candidate, then reuse for every range
114
- // visiting this immutable snapshot. Ordinary mapped edits need no scan.
115
- const nodeIndex = new Map();
116
- doc.descendants((node, pos) => {
117
- const localId = node.attrs.localId;
118
- if (typeof localId === 'string' && localId) {
119
- // Keep duplicates ambiguous, including IDs outside the changed subtree.
120
- nodeIndex.set(localId, nodeIndex.has(localId) ? null : {
121
- node,
122
- pos
123
- });
124
- }
125
- });
126
- indexes.set(doc, nodeIndex);
127
- byId = nodeIndex;
128
- }
129
- const match = byId.get(id);
130
- // Attribute/mark activity belongs to the node even when its children are edited.
131
- // Content-only activity still requires the entire candidate to survive unchanged.
132
- const isPreserved = markupChanged ? sameMarkup : sameNode;
133
- return match && isPreserved(previous, match.node) ? match : undefined;
134
- };
135
- const mapToFinalBlocks = (tr, index, range, indexes) => {
136
- var _tr$docs;
137
- let {
138
- from,
139
- to
140
- } = range;
141
- // Track inner content separately from outer node bounds: +1 skips the opening
142
- // boundary and -1 excludes the closing boundary (see paragraph example above).
143
- let contentFrom = from + 1;
144
- let contentTo = to - 1;
145
- // docs[i] is the document BEFORE step i, so docs[i + 1] is its result.
146
- // The last step has no next snapshot; tr.doc is its result instead.
147
- let node = ((_tr$docs = tr.docs[index + 1]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc).nodeAt(from);
148
- if (!node) {
149
- return [];
150
- }
151
- // Later non-AI steps also shift/delete existing activity, even though they
152
- // cannot create new activity themselves. Process every intermediate document.
153
- for (let next = index + 1; next < tr.steps.length; next++) {
154
- var _tr$docs2;
155
- const map = tr.mapping.maps[next];
156
- const after = (_tr$docs2 = tr.docs[next + 1]) !== null && _tr$docs2 !== void 0 ? _tr$docs2 : tr.doc;
157
- // Mapping biases +1 (right) and -1 (left) keep boundary insertions outside
158
- // the tracked content. These arguments do not add/subtract document positions.
159
- const start = map.mapResult(contentFrom, 1);
160
- const end = map.mapResult(contentTo, -1);
161
- if (start.deleted && end.deleted || end.pos <= start.pos) {
162
- // A cumulative replacement can preserve the candidate content or owned markup.
163
- // Check every intermediate doc so deletion then reinsertion never resurrects it.
164
- const preserved = findPreservedNode(after, node, range.markupChanged, indexes);
165
- if (!preserved) {
166
- return [];
167
- }
168
- from = preserved.pos;
169
- to = from + preserved.node.nodeSize;
170
- contentFrom = from + 1;
171
- contentTo = to - 1;
172
- node = preserved.node;
173
- } else {
174
- // Apply the same inward biases to the outer node bounds.
175
- from = map.map(from, 1);
176
- to = map.map(to, -1);
177
- contentFrom = start.pos;
178
- contentTo = end.pos;
179
- const current = after.nodeAt(from);
180
- if (current && current.nodeSize === to - from) {
181
- node = current;
182
- }
183
- }
184
- }
185
- if (from < 0 || to > tr.doc.content.size || contentTo <= contentFrom) {
186
- return [];
187
- }
188
- const finalNode = tr.doc.nodeAt(from);
189
- if (finalNode !== null && finalNode !== void 0 && finalNode.isBlock && finalNode.nodeSize === to - from) {
190
- return [{
191
- from,
192
- to
193
- }];
194
- }
195
- // Joins/splits can leave mapped boundaries inside the final textblock.
196
- const blocks = [];
197
- tr.doc.nodesBetween(contentFrom, contentTo, (child, pos) => {
198
- if (child.isTextblock) {
199
- blocks.push({
200
- from: pos,
201
- to: pos + child.nodeSize
202
- });
203
- return false;
204
- }
205
- });
206
- return blocks;
207
- };
1
+ import { agentEditRangeMapping } from './agent-edit-range-mapping';
208
2
 
209
3
  /**
210
4
  * Returns whole content-block ranges for selected applied steps, in tr.doc coordinates.
@@ -214,42 +8,9 @@ const mapToFinalBlocks = (tr, index, range, indexes) => {
214
8
  * Comparing each step's snapshots also handles attribute/mark steps with empty maps.
215
9
  * Shared unchanged subtrees are skipped by reference. Only localId changes are ignored;
216
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.
217
12
  */
218
- export function getAgentEditChangedRanges(tr, includedStepIndexes) {
219
- // Positions belong to each intermediate document, not just tr.doc. Keep the
220
- // lazy indexes local to this call so deletion/reinsertion checks stay intact
221
- // and no cache is retained between transactions or streaming chunks.
222
- const indexes = new WeakMap();
223
- const ranges = [];
224
- for (const index of new Set(includedStepIndexes)) {
225
- var _tr$docs3;
226
- if (!Number.isInteger(index) || index < 0 || index >= tr.steps.length) {
227
- continue;
228
- }
229
- const changed = [];
230
- // The root document has no opening boundary. Using -1 makes the recursive
231
- // parent.pos + 1 + offset formula place its first child at position 0.
232
- collectChanges({
233
- node: tr.docs[index],
234
- pos: -1
235
- }, {
236
- node: (_tr$docs3 = tr.docs[index + 1]) !== null && _tr$docs3 !== void 0 ? _tr$docs3 : tr.doc,
237
- pos: -1
238
- }, tr.steps[index].getMap(), changed);
239
- for (const range of changed) {
240
- ranges.push(...mapToFinalBlocks(tr, index, range, indexes));
241
- }
242
- }
243
-
244
- // Return only the surviving final-document ranges, never intermediate step states.
245
- // Sort outer ranges before their children, then discard duplicates/contained ranges.
246
- // Separate ranges stay separate; this must not highlight the untouched gaps.
247
- const unique = [];
248
- for (const range of ranges.sort((left, right) => left.from - right.from || right.to - left.to)) {
249
- const previous = unique[unique.length - 1];
250
- if (!previous || range.to > previous.to) {
251
- unique.push(range);
252
- }
253
- }
254
- 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);
255
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
+ }