@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.
- package/CHANGELOG.md +48 -0
- package/collab-agent-edit-chrome-ranges/package.json +10 -0
- package/dist/cjs/collab/agent-edit-changed-ranges.js +5 -288
- package/dist/cjs/collab/agent-edit-chrome-ranges.js +15 -0
- package/dist/cjs/collab/agent-edit-range-mapping.js +553 -0
- package/dist/cjs/messages/snippets.js +1 -1
- package/dist/cjs/monitoring/error.js +1 -1
- package/dist/cjs/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
- package/dist/cjs/quick-insert/CompactQuickInsertMenuItem.js +17 -2
- package/dist/cjs/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
- package/dist/cjs/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
- package/dist/cjs/quick-insert/get-matching-quick-insert-components.js +20 -10
- package/dist/cjs/quick-insert/messages.js +1 -1
- package/dist/cjs/ui/DropList/index.js +1 -1
- package/dist/es2019/collab/agent-edit-changed-ranges.js +5 -244
- package/dist/es2019/collab/agent-edit-chrome-ranges.js +10 -0
- package/dist/es2019/collab/agent-edit-range-mapping.js +463 -0
- package/dist/es2019/messages/snippets.js +1 -1
- package/dist/es2019/monitoring/error.js +1 -1
- package/dist/es2019/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
- package/dist/es2019/quick-insert/CompactQuickInsertMenuItem.js +17 -2
- package/dist/es2019/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
- package/dist/es2019/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
- package/dist/es2019/quick-insert/get-matching-quick-insert-components.js +16 -6
- package/dist/es2019/quick-insert/messages.js +1 -1
- package/dist/es2019/ui/DropList/index.js +1 -1
- package/dist/esm/collab/agent-edit-changed-ranges.js +5 -286
- package/dist/esm/collab/agent-edit-chrome-ranges.js +10 -0
- package/dist/esm/collab/agent-edit-range-mapping.js +546 -0
- package/dist/esm/messages/snippets.js +1 -1
- package/dist/esm/monitoring/error.js +1 -1
- package/dist/esm/quick-insert/CompactQuickInsertMenuItem.compiled.css +3 -0
- package/dist/esm/quick-insert/CompactQuickInsertMenuItem.js +17 -2
- package/dist/esm/quick-insert/ElementBrowserQuickInsertMenuItem.compiled.css +3 -1
- package/dist/esm/quick-insert/ElementBrowserQuickInsertMenuItem.js +17 -6
- package/dist/esm/quick-insert/get-matching-quick-insert-components.js +20 -10
- package/dist/esm/quick-insert/messages.js +1 -1
- package/dist/esm/ui/DropList/index.js +1 -1
- package/dist/types/card/cardOptions.d.ts +5 -0
- package/dist/types/collab/agent-edit-changed-ranges.d.ts +4 -1
- package/dist/types/collab/agent-edit-chrome-ranges.d.ts +8 -0
- package/dist/types/collab/agent-edit-range-mapping.d.ts +7 -0
- package/dist/types/quick-insert/CompactQuickInsertMenuItem.d.ts +4 -0
- package/package.json +4 -4
|
@@ -0,0 +1,463 @@
|
|
|
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 getSnapshotIndex = (doc, indexes) => {
|
|
34
|
+
const cached = indexes.get(doc);
|
|
35
|
+
if (cached) {
|
|
36
|
+
return cached;
|
|
37
|
+
}
|
|
38
|
+
const snapshot = {
|
|
39
|
+
byId: new Map(),
|
|
40
|
+
byPosition: new Map(),
|
|
41
|
+
nodes: [],
|
|
42
|
+
textblocks: []
|
|
43
|
+
};
|
|
44
|
+
const parents = [{
|
|
45
|
+
node: doc,
|
|
46
|
+
pos: -1,
|
|
47
|
+
index: 0
|
|
48
|
+
}];
|
|
49
|
+
doc.descendants((node, pos, _parent, index) => {
|
|
50
|
+
// Track ancestry by position because one immutable node can occupy several slots.
|
|
51
|
+
while (parents.length > 1 && pos >= parents[parents.length - 1].pos + parents[parents.length - 1].node.nodeSize - 1) {
|
|
52
|
+
parents.pop();
|
|
53
|
+
}
|
|
54
|
+
const positioned = {
|
|
55
|
+
node,
|
|
56
|
+
pos,
|
|
57
|
+
parent: parents[parents.length - 1],
|
|
58
|
+
index
|
|
59
|
+
};
|
|
60
|
+
snapshot.byPosition.set(pos, positioned);
|
|
61
|
+
snapshot.nodes.push(positioned);
|
|
62
|
+
if (node.isTextblock) {
|
|
63
|
+
snapshot.textblocks.push(positioned);
|
|
64
|
+
}
|
|
65
|
+
const id = node.attrs.localId;
|
|
66
|
+
if (typeof id === 'string' && id) {
|
|
67
|
+
snapshot.byId.set(id, snapshot.byId.has(id) ? null : positioned);
|
|
68
|
+
}
|
|
69
|
+
if (!node.isLeaf) {
|
|
70
|
+
parents.push(positioned);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
indexes.set(doc, snapshot);
|
|
74
|
+
return snapshot;
|
|
75
|
+
};
|
|
76
|
+
const indexedNodeAt = (doc, pos, indexes) => {
|
|
77
|
+
const snapshot = getSnapshotIndex(doc, indexes);
|
|
78
|
+
const exact = snapshot.byPosition.get(pos);
|
|
79
|
+
if (exact) {
|
|
80
|
+
return exact.node;
|
|
81
|
+
}
|
|
82
|
+
// nodeAt also returns a text node when the position is inside its text.
|
|
83
|
+
let low = 0;
|
|
84
|
+
let high = snapshot.nodes.length;
|
|
85
|
+
while (low < high) {
|
|
86
|
+
const middle = low + high >>> 1;
|
|
87
|
+
if (snapshot.nodes[middle].pos <= pos) {
|
|
88
|
+
low = middle + 1;
|
|
89
|
+
} else {
|
|
90
|
+
high = middle;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const previous = snapshot.nodes[low - 1];
|
|
94
|
+
return previous !== null && previous !== void 0 && previous.node.isText && pos < previous.pos + previous.node.nodeSize ? previous.node : undefined;
|
|
95
|
+
};
|
|
96
|
+
const collectChanges = (before, after, map, ranges) => {
|
|
97
|
+
const {
|
|
98
|
+
node,
|
|
99
|
+
pos
|
|
100
|
+
} = after;
|
|
101
|
+
if (before && sameNode(before.node, node)) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
// Text edits belong to their textblock. A node's own markup change instead
|
|
105
|
+
// owns its full content, so we stop here rather than adding child ranges too.
|
|
106
|
+
const markupChanged = !!before && node.isBlock && !sameMarkup(before.node, node);
|
|
107
|
+
if (node.isTextblock || markupChanged) {
|
|
108
|
+
if (node.content.size > 0) {
|
|
109
|
+
ranges.push({
|
|
110
|
+
from: pos,
|
|
111
|
+
to: pos + node.nodeSize,
|
|
112
|
+
markupChanged
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const byPosition = new Map();
|
|
118
|
+
const byId = new Map();
|
|
119
|
+
const oldChildren = [];
|
|
120
|
+
before === null || before === void 0 ? void 0 : before.node.forEach((child, offset) => {
|
|
121
|
+
// forEach offsets start inside the parent. Skip its opening boundary (+1)
|
|
122
|
+
// to convert this child offset into an absolute document position.
|
|
123
|
+
const previous = {
|
|
124
|
+
node: child,
|
|
125
|
+
pos: before.pos + 1 + offset
|
|
126
|
+
};
|
|
127
|
+
oldChildren.push(previous);
|
|
128
|
+
// This 1 is a mapping bias, not an added offset: follow the right side
|
|
129
|
+
// of an insertion at the child's start, keeping the original child after it.
|
|
130
|
+
const mapped = map.mapResult(previous.pos, 1);
|
|
131
|
+
if (!mapped.deleted) {
|
|
132
|
+
byPosition.set(mapped.pos, previous);
|
|
133
|
+
}
|
|
134
|
+
const id = child.attrs.localId;
|
|
135
|
+
if (typeof id === 'string' && id) {
|
|
136
|
+
// Duplicate IDs cannot identify a unique old child.
|
|
137
|
+
byId.set(id, byId.has(id) ? null : previous);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const nextChildren = [];
|
|
141
|
+
node.forEach((child, offset) => nextChildren.push({
|
|
142
|
+
node: child,
|
|
143
|
+
pos: pos + 1 + offset
|
|
144
|
+
}));
|
|
145
|
+
// Narrow edits usually preserve mapped positions. Whole-container replacements
|
|
146
|
+
// may erase those positions, so stable child IDs provide a second way to match.
|
|
147
|
+
const preferred = nextChildren.map(next => {
|
|
148
|
+
var _ref, _byPosition$get;
|
|
149
|
+
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;
|
|
150
|
+
});
|
|
151
|
+
const claims = new Map();
|
|
152
|
+
for (const match of preferred) {
|
|
153
|
+
if (match) {
|
|
154
|
+
var _claims$get;
|
|
155
|
+
claims.set(match, ((_claims$get = claims.get(match)) !== null && _claims$get !== void 0 ? _claims$get : 0) + 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
nextChildren.forEach((next, index) => {
|
|
159
|
+
const match = preferred[index];
|
|
160
|
+
// Same-index fallback supports replacements that regenerate IDs but keep
|
|
161
|
+
// the child structure. Different child counts make that correspondence unsafe.
|
|
162
|
+
const aligned = oldChildren.length === node.childCount ? oldChildren[index] : undefined;
|
|
163
|
+
// Reserve every position/ID match before fallback, including later siblings.
|
|
164
|
+
// Reusing one old sibling can otherwise disguise an equal-text insertion.
|
|
165
|
+
const previous = match && claims.get(match) === 1 ? match : aligned && !claims.has(aligned) ? aligned : undefined;
|
|
166
|
+
collectChanges(previous, next, map, ranges);
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
const findPreservedNode = (before, doc, previous, markupChanged, indexes) => {
|
|
170
|
+
const id = previous.attrs.localId;
|
|
171
|
+
if (typeof id !== 'string' || !id) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// When source uniqueness is required, removing a duplicate must not transfer
|
|
175
|
+
// its activity to the remaining equal-content sibling.
|
|
176
|
+
if (before && !getSnapshotIndex(before, indexes).byId.get(id)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const match = getSnapshotIndex(doc, indexes).byId.get(id);
|
|
180
|
+
// Attribute/mark activity belongs to the node even when its children are edited.
|
|
181
|
+
// Content-only activity still requires the entire candidate to survive unchanged.
|
|
182
|
+
const isPreserved = markupChanged ? sameMarkup : sameNode;
|
|
183
|
+
return match && isPreserved(previous, match.node) ? match : undefined;
|
|
184
|
+
};
|
|
185
|
+
const findAlignedTextblock = (before, after, pos, offsets, indexes) => {
|
|
186
|
+
let original = getSnapshotIndex(before, indexes).byPosition.get(pos);
|
|
187
|
+
const path = [];
|
|
188
|
+
while ((_original = original) !== null && _original !== void 0 && _original.parent) {
|
|
189
|
+
var _original;
|
|
190
|
+
path.push(original);
|
|
191
|
+
original = original.parent;
|
|
192
|
+
}
|
|
193
|
+
let parent = after;
|
|
194
|
+
let parentPos = -1;
|
|
195
|
+
for (const child of path.reverse()) {
|
|
196
|
+
var _child$parent;
|
|
197
|
+
const originalParent = (_child$parent = child.parent) === null || _child$parent === void 0 ? void 0 : _child$parent.node;
|
|
198
|
+
if (!originalParent) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (parent.type !== originalParent.type || parent.childCount !== originalParent.childCount) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const index = child.index;
|
|
205
|
+
if (index >= parent.childCount) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
let childOffsets = offsets.get(parent);
|
|
209
|
+
if (!childOffsets) {
|
|
210
|
+
const computedOffsets = [];
|
|
211
|
+
parent.forEach((_child, offset) => computedOffsets.push(offset));
|
|
212
|
+
childOffsets = computedOffsets;
|
|
213
|
+
offsets.set(parent, childOffsets);
|
|
214
|
+
}
|
|
215
|
+
parentPos += 1 + childOffsets[index];
|
|
216
|
+
parent = parent.child(index);
|
|
217
|
+
}
|
|
218
|
+
return parent.isTextblock ? {
|
|
219
|
+
node: parent,
|
|
220
|
+
pos: parentPos
|
|
221
|
+
} : undefined;
|
|
222
|
+
};
|
|
223
|
+
const mapToFinalBlocks = (tr, index, range, indexes, options) => {
|
|
224
|
+
var _tr$docs;
|
|
225
|
+
const {
|
|
226
|
+
alignedOffsets,
|
|
227
|
+
requireUniqueSourceIds
|
|
228
|
+
} = options;
|
|
229
|
+
// Carried ranges can cover every block in a document. Repeated nodeAt calls
|
|
230
|
+
// scan preceding siblings, so reuse one positioned index per snapshot instead.
|
|
231
|
+
const nodeAt = (doc, pos) => alignedOffsets ? indexedNodeAt(doc, pos, indexes) : doc.nodeAt(pos);
|
|
232
|
+
let {
|
|
233
|
+
from,
|
|
234
|
+
to
|
|
235
|
+
} = range;
|
|
236
|
+
// Track inner content separately from outer node bounds: +1 skips the opening
|
|
237
|
+
// boundary and -1 excludes the closing boundary (see paragraph example above).
|
|
238
|
+
let contentFrom = from + 1;
|
|
239
|
+
let contentTo = to - 1;
|
|
240
|
+
// docs[i] is the document BEFORE step i, so docs[i + 1] is its result.
|
|
241
|
+
// The last step has no next snapshot; tr.doc is its result instead.
|
|
242
|
+
let node = nodeAt((_tr$docs = tr.docs[index + 1]) !== null && _tr$docs !== void 0 ? _tr$docs : tr.doc, from);
|
|
243
|
+
if (!node) {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
// Later non-AI steps also shift/delete existing activity, even though they
|
|
247
|
+
// cannot create new activity themselves. Process every intermediate document.
|
|
248
|
+
for (let next = index + 1; next < tr.steps.length; next++) {
|
|
249
|
+
var _tr$docs2;
|
|
250
|
+
const map = tr.mapping.maps[next];
|
|
251
|
+
const after = (_tr$docs2 = tr.docs[next + 1]) !== null && _tr$docs2 !== void 0 ? _tr$docs2 : tr.doc;
|
|
252
|
+
// Mapping biases +1 (right) and -1 (left) keep boundary insertions outside
|
|
253
|
+
// the tracked content. These arguments do not add/subtract document positions.
|
|
254
|
+
const start = map.mapResult(contentFrom, 1);
|
|
255
|
+
const end = map.mapResult(contentTo, -1);
|
|
256
|
+
if (start.deleted && end.deleted || end.pos <= start.pos) {
|
|
257
|
+
var _indexes$get, _indexes$get2;
|
|
258
|
+
// A cumulative replacement can preserve the candidate content or owned markup.
|
|
259
|
+
// Check every intermediate doc so deletion then reinsertion never resurrects it.
|
|
260
|
+
let preserved = findPreservedNode(requireUniqueSourceIds ? tr.docs[next] : undefined, after, node, range.markupChanged, indexes);
|
|
261
|
+
const id = node.attrs.localId;
|
|
262
|
+
const 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;
|
|
263
|
+
const idMatch = typeof id === 'string' && id ? (_indexes$get2 = indexes.get(after)) === null || _indexes$get2 === void 0 ? void 0 : _indexes$get2.byId.get(id) : undefined;
|
|
264
|
+
if (!preserved && alignedOffsets && sourceMatch !== null && idMatch === undefined) {
|
|
265
|
+
// Inline replacements can keep a block's opening boundary while
|
|
266
|
+
// recreating its content and adding later blocks to the same chunk.
|
|
267
|
+
const mapped = map.mapResult(from, 1);
|
|
268
|
+
const mappedNode = !mapped.deleted ? nodeAt(after, mapped.pos) : undefined;
|
|
269
|
+
if (mappedNode !== null && mappedNode !== void 0 && mappedNode.isTextblock && sameNode(node, mappedNode)) {
|
|
270
|
+
preserved = {
|
|
271
|
+
node: mappedNode,
|
|
272
|
+
pos: mapped.pos
|
|
273
|
+
};
|
|
274
|
+
} else {
|
|
275
|
+
// Whole-block replacements may recreate unchanged blocks without IDs.
|
|
276
|
+
// Match their slot only while every parent keeps its shape.
|
|
277
|
+
const aligned = findAlignedTextblock(tr.docs[next], after, from, alignedOffsets, indexes);
|
|
278
|
+
if (aligned && sameNode(node, aligned.node)) {
|
|
279
|
+
preserved = aligned;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (!preserved) {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
from = preserved.pos;
|
|
287
|
+
to = from + preserved.node.nodeSize;
|
|
288
|
+
contentFrom = from + 1;
|
|
289
|
+
contentTo = to - 1;
|
|
290
|
+
node = preserved.node;
|
|
291
|
+
} else {
|
|
292
|
+
// Apply the same inward biases to the outer node bounds.
|
|
293
|
+
from = map.map(from, 1);
|
|
294
|
+
to = map.map(to, -1);
|
|
295
|
+
contentFrom = start.pos;
|
|
296
|
+
contentTo = end.pos;
|
|
297
|
+
const current = nodeAt(after, from);
|
|
298
|
+
if (current && current.nodeSize === to - from) {
|
|
299
|
+
node = current;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (from < 0 || to > tr.doc.content.size || contentTo <= contentFrom) {
|
|
304
|
+
return [];
|
|
305
|
+
}
|
|
306
|
+
const finalNode = nodeAt(tr.doc, from);
|
|
307
|
+
if (finalNode !== null && finalNode !== void 0 && finalNode.isBlock && finalNode.nodeSize === to - from) {
|
|
308
|
+
return [{
|
|
309
|
+
from,
|
|
310
|
+
to
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
// Joins/splits can leave mapped boundaries inside the final textblock.
|
|
314
|
+
const blocks = [];
|
|
315
|
+
if (alignedOffsets) {
|
|
316
|
+
const textblocks = getSnapshotIndex(tr.doc, indexes).textblocks;
|
|
317
|
+
let low = 0;
|
|
318
|
+
let high = textblocks.length;
|
|
319
|
+
while (low < high) {
|
|
320
|
+
const middle = low + high >>> 1;
|
|
321
|
+
const candidate = textblocks[middle];
|
|
322
|
+
if (candidate.pos + candidate.node.nodeSize <= contentFrom) {
|
|
323
|
+
low = middle + 1;
|
|
324
|
+
} else {
|
|
325
|
+
high = middle;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
for (let index = low; index < textblocks.length && textblocks[index].pos < contentTo; index++) {
|
|
329
|
+
const {
|
|
330
|
+
node,
|
|
331
|
+
pos
|
|
332
|
+
} = textblocks[index];
|
|
333
|
+
blocks.push({
|
|
334
|
+
from: pos,
|
|
335
|
+
to: pos + node.nodeSize
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
return blocks;
|
|
339
|
+
}
|
|
340
|
+
tr.doc.nodesBetween(contentFrom, contentTo, (child, pos) => {
|
|
341
|
+
if (child.isTextblock) {
|
|
342
|
+
blocks.push({
|
|
343
|
+
from: pos,
|
|
344
|
+
to: pos + child.nodeSize
|
|
345
|
+
});
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return blocks;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Maps existing textblock activity through each applied step into tr.doc coordinates.
|
|
354
|
+
* Replaced content is dropped unless an unchanged block survives with a unique ID
|
|
355
|
+
* or in the same structural slot. Newly changed blocks belong to the producer.
|
|
356
|
+
*/
|
|
357
|
+
function mapAgentEditChromeRanges(tr, ranges) {
|
|
358
|
+
const indexes = new WeakMap();
|
|
359
|
+
const alignedOffsets = new WeakMap();
|
|
360
|
+
const options = {
|
|
361
|
+
alignedOffsets,
|
|
362
|
+
requireUniqueSourceIds: true
|
|
363
|
+
};
|
|
364
|
+
const validRanges = [];
|
|
365
|
+
for (const {
|
|
366
|
+
from,
|
|
367
|
+
to
|
|
368
|
+
} of ranges) {
|
|
369
|
+
if (!Number.isFinite(from) || !Number.isFinite(to) || to <= from) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
const start = Math.max(0, Math.min(from, tr.before.content.size));
|
|
373
|
+
const end = Math.max(start, Math.min(to, tr.before.content.size));
|
|
374
|
+
if (start === end) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
validRanges.push({
|
|
378
|
+
from: start,
|
|
379
|
+
to: end
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (!validRanges.length) {
|
|
383
|
+
return [];
|
|
384
|
+
}
|
|
385
|
+
validRanges.sort((left, right) => left.from - right.from);
|
|
386
|
+
const blocks = [];
|
|
387
|
+
let rangeIndex = 0;
|
|
388
|
+
for (const {
|
|
389
|
+
node,
|
|
390
|
+
pos
|
|
391
|
+
} of getSnapshotIndex(tr.before, indexes).textblocks) {
|
|
392
|
+
while (rangeIndex < validRanges.length && validRanges[rangeIndex].to <= pos) {
|
|
393
|
+
rangeIndex++;
|
|
394
|
+
}
|
|
395
|
+
if (rangeIndex === validRanges.length) {
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
if (node.content.size && validRanges[rangeIndex].from < pos + node.nodeSize) {
|
|
399
|
+
blocks.push({
|
|
400
|
+
from: pos,
|
|
401
|
+
to: pos + node.nodeSize,
|
|
402
|
+
markupChanged: false
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
// Index -1 starts from docs[0], before the first step, instead of a step result.
|
|
407
|
+
return blocks.flatMap(range => mapToFinalBlocks(tr, -1, range, indexes, options));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Returns whole content-block ranges for selected applied steps, in tr.doc coordinates.
|
|
412
|
+
* Callers select actual AI writes (excluding restores, acknowledgments and preparation)
|
|
413
|
+
* and own experiment/lifecycle decisions. This helper does not dispatch or render.
|
|
414
|
+
*
|
|
415
|
+
* Comparing each step's snapshots also handles attribute/mark steps with empty maps.
|
|
416
|
+
* Shared unchanged subtrees are skipped by reference. Only localId changes are ignored;
|
|
417
|
+
* meaningful attributes and marks retain the affected node's full content scope.
|
|
418
|
+
*/
|
|
419
|
+
function getAgentEditChangedRanges(tr, includedStepIndexes, requireUniqueSourceIds) {
|
|
420
|
+
// Positions belong to each intermediate document, not just tr.doc. Keep the
|
|
421
|
+
// lazy indexes local to this call so deletion/reinsertion checks stay intact
|
|
422
|
+
// and no cache is retained between transactions or streaming chunks.
|
|
423
|
+
const indexes = new WeakMap();
|
|
424
|
+
const options = {
|
|
425
|
+
requireUniqueSourceIds
|
|
426
|
+
};
|
|
427
|
+
const ranges = [];
|
|
428
|
+
for (const index of new Set(includedStepIndexes)) {
|
|
429
|
+
var _tr$docs3;
|
|
430
|
+
if (!Number.isInteger(index) || index < 0 || index >= tr.steps.length) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const changed = [];
|
|
434
|
+
// The root document has no opening boundary. Using -1 makes the recursive
|
|
435
|
+
// parent.pos + 1 + offset formula place its first child at position 0.
|
|
436
|
+
collectChanges({
|
|
437
|
+
node: tr.docs[index],
|
|
438
|
+
pos: -1
|
|
439
|
+
}, {
|
|
440
|
+
node: (_tr$docs3 = tr.docs[index + 1]) !== null && _tr$docs3 !== void 0 ? _tr$docs3 : tr.doc,
|
|
441
|
+
pos: -1
|
|
442
|
+
}, tr.steps[index].getMap(), changed);
|
|
443
|
+
for (const range of changed) {
|
|
444
|
+
ranges.push(...mapToFinalBlocks(tr, index, range, indexes, options));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Return only the surviving final-document ranges, never intermediate step states.
|
|
449
|
+
// Sort outer ranges before their children, then discard duplicates/contained ranges.
|
|
450
|
+
// Separate ranges stay separate; this must not highlight the untouched gaps.
|
|
451
|
+
const unique = [];
|
|
452
|
+
for (const range of ranges.sort((left, right) => left.from - right.from || right.to - left.to)) {
|
|
453
|
+
const previous = unique[unique.length - 1];
|
|
454
|
+
if (!previous || range.to > previous.to) {
|
|
455
|
+
unique.push(range);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return unique;
|
|
459
|
+
}
|
|
460
|
+
export const agentEditRangeMapping = {
|
|
461
|
+
getChangedRanges: getAgentEditChangedRanges,
|
|
462
|
+
mapChromeRanges: mapAgentEditChromeRanges
|
|
463
|
+
};
|
|
@@ -22,7 +22,7 @@ export const templateGalleryMessages = defineMessages({
|
|
|
22
22
|
},
|
|
23
23
|
templateGalleryTitle: {
|
|
24
24
|
id: 'editor-plugin-snippets.snippetsPlugin.templateGalleryTitle',
|
|
25
|
-
defaultMessage: 'Block
|
|
25
|
+
defaultMessage: 'Block template gallery',
|
|
26
26
|
description: 'Title for the block template gallery quick insert item'
|
|
27
27
|
}
|
|
28
28
|
});
|
|
@@ -13,7 +13,7 @@ const NETWORK_FAILURE_REGEX = /^network failure/i;
|
|
|
13
13
|
const RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
|
|
14
14
|
const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
|
|
15
15
|
const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
|
|
16
|
-
const packageVersion = "
|
|
16
|
+
const packageVersion = "130.2.0";
|
|
17
17
|
const sanitiseSentryEvents = (data, _hint) => {
|
|
18
18
|
// Remove URL as it has UGC
|
|
19
19
|
// Ignored via go/ees007
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
._1e0c1txw{display:flex}
|
|
14
14
|
._1o9zidpf{flex-shrink:0}
|
|
15
15
|
._1o9zkb7n{flex-shrink:1}
|
|
16
|
+
._1pgcjdj5 [style*="--ds-icon-subtle"]{color:inherit!important}
|
|
16
17
|
._1reo15vq{overflow-x:hidden}
|
|
17
18
|
._1tke1tcg{min-height:24px}
|
|
18
19
|
._1ul91tcg{min-width:24px}
|
|
@@ -22,4 +23,6 @@
|
|
|
22
23
|
._bfhk1bhr{background-color:var(--ds-surface-overlay,#fff)}
|
|
23
24
|
._bfhki8nm{background-color:var(--ds-background-neutral,#0515240f)}
|
|
24
25
|
._i0dlidpf{flex-basis:0}
|
|
26
|
+
._rpzpjdj5 [style*="--ds-icon-accent-gray"]{color:inherit!important}
|
|
27
|
+
._syaz1q3r{color:var(--ds-icon,#292a2e)}
|
|
25
28
|
._syazazsu{color:var(--ds-text-subtle,#505258)}
|
|
@@ -14,6 +14,17 @@ const styles = {
|
|
|
14
14
|
iconLarge: "_2rko1mok _1reo15vq _18m915vq _1h6d1l7x _1dqonqa1 _189ee4h9 _4cvr1h6o _bfhk1bhr _1e0c1txw _4t3izwfg _1bah1h6o _1bsbzwfg",
|
|
15
15
|
shortcut: "_2rko12b0 _11c8wadc _1rjcv77o _18zr1b66 _bfhki8nm _syazazsu"
|
|
16
16
|
};
|
|
17
|
+
const iconColorStyles = null;
|
|
18
|
+
|
|
19
|
+
// Some icons pin a neutral colour inline (for example the Forge and Spotlight icons use
|
|
20
|
+
// color.icon.subtle or color.icon.accent.gray), which would ignore the colour set by the menu item.
|
|
21
|
+
// Reset only those so every icon follows the menu item (color.icon, or the disabled colour).
|
|
22
|
+
// Do NOT widen this to all icon colours: some icons are intentionally coloured (for example skill
|
|
23
|
+
// and brand icons that use other --ds-icon-accent-* tokens) and must keep their own colour.
|
|
24
|
+
/* eslint-disable @atlaskit/design-system/no-unsafe-design-token-usage, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-important-styles -- Icons pin their colour with an inline style, which only an !important rule on a descendant selector can override. */
|
|
25
|
+
const pinnedIconColorResetStyles = null;
|
|
26
|
+
/* eslint-enable @atlaskit/design-system/no-unsafe-design-token-usage, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-important-styles */
|
|
27
|
+
|
|
17
28
|
const itemStyles = xcss({
|
|
18
29
|
alignItems: 'center',
|
|
19
30
|
backgroundColor: 'elevation.surface.overlay',
|
|
@@ -123,11 +134,15 @@ export const CompactQuickInsertMenuItem = ({
|
|
|
123
134
|
xcss: isDisabled ? disabledItemStyles : isSelected ? selectedItemStyles : itemStyles
|
|
124
135
|
}, wrappedIcon && /*#__PURE__*/React.createElement(Box, {
|
|
125
136
|
xcss: styles.iconContainer
|
|
126
|
-
},
|
|
137
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
138
|
+
className: ax(["_rpzpjdj5 _1pgcjdj5", !isDisabled && "_syaz1q3r"])
|
|
139
|
+
}, wrappedIcon)), /*#__PURE__*/React.createElement(Inline, {
|
|
127
140
|
alignBlock: "center",
|
|
128
141
|
spread: "space-between",
|
|
129
142
|
xcss: styles.content
|
|
130
|
-
}, titleContent !== null && titleContent !== void 0 ? titleContent : /*#__PURE__*/React.createElement(Text,
|
|
143
|
+
}, titleContent !== null && titleContent !== void 0 ? titleContent : /*#__PURE__*/React.createElement(Text, {
|
|
144
|
+
color: isDisabled ? 'color.text.disabled' : 'color.text'
|
|
145
|
+
}, title), shortcut && /*#__PURE__*/React.createElement(Box, {
|
|
131
146
|
as: "span",
|
|
132
147
|
xcss: styles.shortcut
|
|
133
148
|
}, shortcut))), shouldRenderPreview && referenceElement && /*#__PURE__*/React.createElement(QuickInsertHoverPreview, {
|
|
@@ -92,6 +92,16 @@ const iconLargeStyles = xcss({
|
|
|
92
92
|
width: '40px'
|
|
93
93
|
});
|
|
94
94
|
const iconColorStyles = null;
|
|
95
|
+
|
|
96
|
+
// Some icons pin a neutral colour inline (for example the Forge and Spotlight icons use
|
|
97
|
+
// color.icon.subtle or color.icon.accent.gray), which would ignore the colour set by the menu item.
|
|
98
|
+
// Reset only those so every icon follows the menu item (color.icon, or the disabled colour).
|
|
99
|
+
// Do NOT widen this to all icon colours: some icons are intentionally coloured (for example skill
|
|
100
|
+
// and brand icons that use other --ds-icon-accent-* tokens) and must keep their own colour.
|
|
101
|
+
/* eslint-disable @atlaskit/design-system/no-unsafe-design-token-usage, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-important-styles -- Icons pin their colour with an inline style, which only an !important rule on a descendant selector can override. */
|
|
102
|
+
const pinnedIconColorResetStyles = null;
|
|
103
|
+
/* eslint-enable @atlaskit/design-system/no-unsafe-design-token-usage, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-important-styles */
|
|
104
|
+
|
|
95
105
|
const shortcutStyles = xcss({
|
|
96
106
|
backgroundColor: 'color.background.neutral',
|
|
97
107
|
borderRadius: 'radius.small',
|
|
@@ -124,6 +134,11 @@ export const ElementBrowserQuickInsertMenuItem = ({
|
|
|
124
134
|
const itemDescription = description !== null && description !== void 0 ? description : item === null || item === void 0 ? void 0 : item.description;
|
|
125
135
|
const handleClick = useQuickInsertMenuItemSelection(onSelect);
|
|
126
136
|
const itemStyles = useMemo(() => [isDisabled ? borderlessDisabledItemStyles : isSelected ? borderlessSelectedItemStyles : borderlessItemStyles, isExperimentEnabled('platform_editor_slash_command') && !isDisabled && !isSelected && hoveredItemStyles], [isDisabled, isSelected]);
|
|
137
|
+
|
|
138
|
+
// Disabled items keep the dimmed colour inherited from the item.
|
|
139
|
+
const icon = iconBefore ? /*#__PURE__*/React.createElement("span", {
|
|
140
|
+
className: ax(["_rpzpjdj5 _1pgcjdj5", !isDisabled && "_syaz1q3r"])
|
|
141
|
+
}, iconBefore) : iconBefore;
|
|
127
142
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
128
143
|
"aria-label": ariaLabel,
|
|
129
144
|
"aria-selected": isSelected,
|
|
@@ -137,11 +152,7 @@ export const ElementBrowserQuickInsertMenuItem = ({
|
|
|
137
152
|
xcss: itemStyles
|
|
138
153
|
}, iconBefore && shouldWrapIcon ? /*#__PURE__*/React.createElement(Box, {
|
|
139
154
|
xcss: isExperimentEnabled('platform_editor_slash_command') ? iconLargeStyles : iconStyles
|
|
140
|
-
}, /*#__PURE__*/React.createElement(
|
|
141
|
-
className: ax(["_syazdgkc"])
|
|
142
|
-
}, iconBefore)) : iconBefore ? /*#__PURE__*/React.createElement("span", {
|
|
143
|
-
className: ax(["_syazdgkc"])
|
|
144
|
-
}, iconBefore) : null, /*#__PURE__*/React.createElement(Stack, {
|
|
155
|
+
}, icon) : icon, /*#__PURE__*/React.createElement(Stack, {
|
|
145
156
|
space: "space.050",
|
|
146
157
|
grow: "fill"
|
|
147
158
|
}, /*#__PURE__*/React.createElement(Inline, {
|
|
@@ -149,7 +160,7 @@ export const ElementBrowserQuickInsertMenuItem = ({
|
|
|
149
160
|
spread: "space-between",
|
|
150
161
|
space: "space.100"
|
|
151
162
|
}, titleContent !== null && titleContent !== void 0 ? titleContent : /*#__PURE__*/React.createElement(Text, {
|
|
152
|
-
color:
|
|
163
|
+
color: isDisabled ? 'color.text.disabled' : 'color.text',
|
|
153
164
|
maxLines: 1,
|
|
154
165
|
size: "medium",
|
|
155
166
|
weight: "medium"
|
|
@@ -33,7 +33,7 @@ export const getMatchingQuickInsertComponents = ({
|
|
|
33
33
|
formatMessage,
|
|
34
34
|
surfaceContext
|
|
35
35
|
}) => {
|
|
36
|
-
var _childrenMap$
|
|
36
|
+
var _childrenMap$get2;
|
|
37
37
|
const {
|
|
38
38
|
childrenMap,
|
|
39
39
|
root,
|
|
@@ -91,7 +91,9 @@ export const getMatchingQuickInsertComponents = ({
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
const sections = Array.from(sectionsByKey.values());
|
|
94
|
-
|
|
94
|
+
// An empty query is browse mode: `buildQuickInsertMenuModel` supplies the footer there,
|
|
95
|
+
// so this search model must not add a second one.
|
|
96
|
+
if (query === '') {
|
|
95
97
|
return {
|
|
96
98
|
footer: undefined,
|
|
97
99
|
root,
|
|
@@ -99,13 +101,21 @@ export const getMatchingQuickInsertComponents = ({
|
|
|
99
101
|
sections
|
|
100
102
|
};
|
|
101
103
|
}
|
|
104
|
+
const footerSection = topLevelChildren.find(section => section.type === 'menu-section' && isMenuFooterSectionKey(section.key) && willComponentRender(section, childrenMap, surfaceContext));
|
|
105
|
+
const footer = footerSection ? ((_childrenMap$get2 = childrenMap.get(getComponentIdentity(footerSection))) !== null && _childrenMap$get2 !== void 0 ? _childrenMap$get2 : []).find(child => child.type === 'menu-item' && willComponentRender(child, childrenMap, surfaceContext)) : undefined;
|
|
106
|
+
if (sections.length > 0) {
|
|
107
|
+
return {
|
|
108
|
+
footer,
|
|
109
|
+
root,
|
|
110
|
+
searchResults,
|
|
111
|
+
sections
|
|
112
|
+
};
|
|
113
|
+
}
|
|
102
114
|
const fallbackItem = topLevelChildren.filter(section => section.type === 'menu-section' && !isMenuFooterSectionKey(section.key) && willComponentRender(section, childrenMap, surfaceContext)).flatMap(section => {
|
|
103
|
-
var _childrenMap$
|
|
104
|
-
return (_childrenMap$
|
|
115
|
+
var _childrenMap$get3;
|
|
116
|
+
return (_childrenMap$get3 = childrenMap.get(getComponentIdentity(section))) !== null && _childrenMap$get3 !== void 0 ? _childrenMap$get3 : [];
|
|
105
117
|
}).find(component => component.type === ASK_ROVO_MENU_ITEM.type && component.key === ASK_ROVO_MENU_ITEM.key && willComponentRender(component, childrenMap, surfaceContext));
|
|
106
118
|
const fallbackItems = fallbackItem ? [fallbackItem] : [];
|
|
107
|
-
const footerSection = topLevelChildren.find(section => section.type === 'menu-section' && isMenuFooterSectionKey(section.key) && willComponentRender(section, childrenMap, surfaceContext));
|
|
108
|
-
const footer = footerSection ? ((_childrenMap$get3 = childrenMap.get(getComponentIdentity(footerSection))) !== null && _childrenMap$get3 !== void 0 ? _childrenMap$get3 : []).find(child => child.type === 'menu-item' && willComponentRender(child, childrenMap, surfaceContext)) : undefined;
|
|
109
119
|
return {
|
|
110
120
|
fallbackItems,
|
|
111
121
|
footer,
|
|
@@ -132,7 +132,7 @@ export const messages = defineMessages({
|
|
|
132
132
|
},
|
|
133
133
|
categoryOther: {
|
|
134
134
|
id: 'editor-common.quick-insert.categoryOther',
|
|
135
|
-
defaultMessage: 'Other',
|
|
135
|
+
defaultMessage: 'Other elements',
|
|
136
136
|
description: 'Other items in the Quick Insert menu.'
|
|
137
137
|
},
|
|
138
138
|
previewAttributionBy: {
|
|
@@ -14,7 +14,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
|
|
|
14
14
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
15
15
|
import Layer from '../Layer';
|
|
16
16
|
const packageName = "@atlaskit/editor-common";
|
|
17
|
-
const packageVersion = "
|
|
17
|
+
const packageVersion = "130.2.0";
|
|
18
18
|
const halfFocusRing = 1;
|
|
19
19
|
const dropOffset = '0, 8';
|
|
20
20
|
const fadeIn = keyframes({
|