@atlaskit/editor-plugin-show-diff 26.0.0 → 26.0.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.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +36 -3
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +14 -2
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
- package/dist/cjs/pm-plugins/decorations/createReplacedCellDecorations.js +350 -0
- package/dist/cjs/pm-plugins/decorations/utils/cellAttrs.js +30 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +37 -4
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +12 -2
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
- package/dist/es2019/pm-plugins/decorations/createReplacedCellDecorations.js +338 -0
- package/dist/es2019/pm-plugins/decorations/utils/cellAttrs.js +19 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +36 -3
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +14 -2
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +14 -0
- package/dist/esm/pm-plugins/decorations/createReplacedCellDecorations.js +343 -0
- package/dist/esm/pm-plugins/decorations/utils/cellAttrs.js +25 -0
- package/dist/types/pm-plugins/decorations/createReplacedCellDecorations.d.ts +67 -0
- package/dist/types/pm-plugins/decorations/utils/cellAttrs.d.ts +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
import { getDarkModeLCHColor } from '@atlaskit/adf-schema/get-dark-mode-lch-color';
|
|
6
|
+
import { isRgb } from '@atlaskit/adf-schema/is-rgb';
|
|
7
|
+
import { rgbToHex } from '@atlaskit/adf-schema/rgb-to-hex';
|
|
8
|
+
import { getCellDomAttrs } from '@atlaskit/adf-schema/tableNodes';
|
|
9
|
+
import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
|
|
10
|
+
import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
|
|
11
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
12
|
+
import { createBlockChangedDecoration } from './createBlockChangedDecoration';
|
|
13
|
+
import { createInlineChangedDecoration } from './createInlineChangedDecoration';
|
|
14
|
+
import { buildDiffDecorationSpec } from './decorationKeys';
|
|
15
|
+
import { isCellAttrChanged, isCellBackgroundChanged, normalizeCellBackground } from './utils/cellAttrs';
|
|
16
|
+
import { injectInnerWrapper, wrapBlockNodeView } from './utils/wrapBlockNodeView';
|
|
17
|
+
var CELL_TYPE_NAMES = ['tableCell', 'tableHeader'];
|
|
18
|
+
/**
|
|
19
|
+
* Pairs each cell of a whole-cell replacement with the live cell it replaces, or `[]` when the slice
|
|
20
|
+
* is not a run of whole cells matching the live ones. Whole-cell replacement preserves cell count and
|
|
21
|
+
* order, so the nth live cell in the range matches the nth cell in the slice.
|
|
22
|
+
*/
|
|
23
|
+
export var getReplacedCells = function getReplacedCells(_ref) {
|
|
24
|
+
var slice = _ref.slice,
|
|
25
|
+
doc = _ref.doc,
|
|
26
|
+
fromB = _ref.fromB,
|
|
27
|
+
toB = _ref.toB;
|
|
28
|
+
var otherCells = slice.content.content;
|
|
29
|
+
if (slice.openStart !== 0 || slice.openEnd !== 0 || otherCells.length === 0 || !otherCells.every(function (node) {
|
|
30
|
+
return CELL_TYPE_NAMES.includes(node.type.name);
|
|
31
|
+
})) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
var liveCells = [];
|
|
35
|
+
doc.nodesBetween(fromB, toB, function (node, pos) {
|
|
36
|
+
if (CELL_TYPE_NAMES.includes(node.type.name)) {
|
|
37
|
+
liveCells.push({
|
|
38
|
+
node: node,
|
|
39
|
+
pos: pos
|
|
40
|
+
});
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
if (liveCells.length !== otherCells.length) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
return otherCells.map(function (otherCell, index) {
|
|
49
|
+
return {
|
|
50
|
+
otherCell: otherCell,
|
|
51
|
+
liveCell: liveCells[index].node,
|
|
52
|
+
liveCellPos: liveCells[index].pos
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Whether two cells hold the same content, ignoring the cells' own attributes and `localId`s, which
|
|
59
|
+
* a suggestion can regenerate. Such a replacement only changed the cell (e.g. its background), so
|
|
60
|
+
* there is no content to diff.
|
|
61
|
+
*/
|
|
62
|
+
var isCellContentEqual = function isCellContentEqual(left, right) {
|
|
63
|
+
if (left.childCount !== right.childCount) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
for (var index = 0; index < left.childCount; index++) {
|
|
67
|
+
if (!areNodesEqualIgnoreAttrs(left.child(index), right.child(index), ['localId'])) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Whether the cell itself changed — its type, or an attribute that represents a change such as its
|
|
76
|
+
* background or span — as opposed to only its content.
|
|
77
|
+
*/
|
|
78
|
+
var isCellChanged = function isCellChanged(left, right) {
|
|
79
|
+
return left.type !== right.type || isCellAttrChanged(left, right);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A custom (non-palette) cell colour as the schema renders it: inverted in dark mode so text stays
|
|
84
|
+
* readable, except for design tokens, which are already themed.
|
|
85
|
+
*/
|
|
86
|
+
var getCustomCellColor = function getCustomCellColor(background) {
|
|
87
|
+
var color = isRgb(background) && rgbToHex(background) || background;
|
|
88
|
+
if (color.startsWith('var(') || document.documentElement.getAttribute('data-color-mode') !== 'dark') {
|
|
89
|
+
return background;
|
|
90
|
+
}
|
|
91
|
+
return getDarkModeLCHColor(color);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The colour `cell` renders with. A palette colour is the editor's own themed variable for its colour
|
|
96
|
+
* name (e.g. for dark mode), the one `td[colorname]` cells use; a custom colour is the schema's own
|
|
97
|
+
* treatment of it; no colour is the editor's default.
|
|
98
|
+
*/
|
|
99
|
+
var getCellBackgroundColor = function getCellBackgroundColor(cell) {
|
|
100
|
+
var background = normalizeCellBackground(cell.attrs.background);
|
|
101
|
+
if (!background) {
|
|
102
|
+
return cell.type.name === 'tableHeader' ? "var(--ds-background-accent-gray-subtlest, #F0F1F2)" : "var(--ds-surface, #FFFFFF)";
|
|
103
|
+
}
|
|
104
|
+
var _getCellDomAttrs = getCellDomAttrs(cell),
|
|
105
|
+
colorname = _getCellDomAttrs.colorname;
|
|
106
|
+
return colorname ? "var(--ak-editor-table-cell-background-".concat(colorname.toLowerCase().split(' ').join('-'), ")") : getCustomCellColor(background);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* A layer painting `color` over the cell's own background and under its content, so the cell reads
|
|
111
|
+
* as having the new background without any of the cell's own attributes being overridden: removing
|
|
112
|
+
* a decoration removes the attributes it set rather than restoring the ones they replaced.
|
|
113
|
+
*/
|
|
114
|
+
var createCellBackgroundLayer = function createCellBackgroundLayer(color) {
|
|
115
|
+
var layer = document.createElement('div');
|
|
116
|
+
layer.setAttribute('aria-hidden', 'true');
|
|
117
|
+
layer.contentEditable = 'false';
|
|
118
|
+
layer.dataset.testid = 'show-diff-new-cell-background';
|
|
119
|
+
layer.setAttribute('style', convertToInlineCss({
|
|
120
|
+
position: 'absolute',
|
|
121
|
+
inset: 0,
|
|
122
|
+
zIndex: -1,
|
|
123
|
+
borderRadius: 'inherit',
|
|
124
|
+
pointerEvents: 'none',
|
|
125
|
+
backgroundColor: color
|
|
126
|
+
}));
|
|
127
|
+
return layer;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** The other side's cell content, as blocks, for the top of the live cell. */
|
|
131
|
+
var createCellContentWidget = function createCellContentWidget(_ref2) {
|
|
132
|
+
var cell = _ref2.cell,
|
|
133
|
+
pos = _ref2.pos,
|
|
134
|
+
nodeViewSerializer = _ref2.nodeViewSerializer,
|
|
135
|
+
colorScheme = _ref2.colorScheme,
|
|
136
|
+
intl = _ref2.intl,
|
|
137
|
+
isActive = _ref2.isActive,
|
|
138
|
+
isInserted = _ref2.isInserted,
|
|
139
|
+
leftAnchorId = _ref2.leftAnchorId;
|
|
140
|
+
var dom = document.createElement('div');
|
|
141
|
+
cell.content.forEach(function (block) {
|
|
142
|
+
var nodeView = nodeViewSerializer.tryCreateNodeView(block, 0, undefined, isInserted, colorScheme);
|
|
143
|
+
if (nodeView) {
|
|
144
|
+
wrapBlockNodeView({
|
|
145
|
+
dom: dom,
|
|
146
|
+
nodeView: nodeView,
|
|
147
|
+
targetNode: block,
|
|
148
|
+
colorScheme: colorScheme,
|
|
149
|
+
intl: intl,
|
|
150
|
+
isActive: isActive,
|
|
151
|
+
isInserted: isInserted
|
|
152
|
+
});
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
var serialized = nodeViewSerializer.serializeNode(block);
|
|
156
|
+
if (serialized instanceof HTMLElement) {
|
|
157
|
+
dom.append(injectInnerWrapper({
|
|
158
|
+
node: serialized,
|
|
159
|
+
colorScheme: colorScheme,
|
|
160
|
+
isActive: isActive,
|
|
161
|
+
isInserted: isInserted
|
|
162
|
+
}));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
if (dom.childNodes.length === 0) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
dom.setAttribute('data-testid', isInserted ? 'show-diff-changed-decoration' : 'show-diff-deleted-decoration');
|
|
169
|
+
|
|
170
|
+
// Before the cell's own blocks, as a block of its own, so it never lands inside a paragraph the
|
|
171
|
+
// displayed side may hide.
|
|
172
|
+
return Decoration.widget(pos + 1, dom, _objectSpread(_objectSpread({}, buildDiffDecorationSpec({
|
|
173
|
+
colorScheme: colorScheme,
|
|
174
|
+
decorationType: 'widget',
|
|
175
|
+
diffId: crypto.randomUUID(),
|
|
176
|
+
leftAnchorId: leftAnchorId,
|
|
177
|
+
isActive: isActive,
|
|
178
|
+
isInserted: isInserted,
|
|
179
|
+
side: -1
|
|
180
|
+
})), {}, {
|
|
181
|
+
marks: []
|
|
182
|
+
}));
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The other side of a whole-cell replacement, drawn inside the live cells so the table keeps its
|
|
187
|
+
* shape: each live cell takes the other cell's background when it differs, and its content when that
|
|
188
|
+
* differs. A cell whose content did not change has nothing to diff.
|
|
189
|
+
*/
|
|
190
|
+
export var createReplacedCellWidgets = function createReplacedCellWidgets(_ref3) {
|
|
191
|
+
var slice = _ref3.slice,
|
|
192
|
+
newDoc = _ref3.newDoc,
|
|
193
|
+
change = _ref3.change,
|
|
194
|
+
nodeViewSerializer = _ref3.nodeViewSerializer,
|
|
195
|
+
colorScheme = _ref3.colorScheme,
|
|
196
|
+
intl = _ref3.intl,
|
|
197
|
+
isActive = _ref3.isActive,
|
|
198
|
+
isInserted = _ref3.isInserted,
|
|
199
|
+
leftAnchorId = _ref3.leftAnchorId;
|
|
200
|
+
return getReplacedCells({
|
|
201
|
+
slice: slice,
|
|
202
|
+
doc: newDoc,
|
|
203
|
+
fromB: change.fromB,
|
|
204
|
+
toB: change.toB
|
|
205
|
+
}).flatMap(function (_ref4) {
|
|
206
|
+
var otherCell = _ref4.otherCell,
|
|
207
|
+
liveCell = _ref4.liveCell,
|
|
208
|
+
liveCellPos = _ref4.liveCellPos;
|
|
209
|
+
var decorations = [];
|
|
210
|
+
if (isInserted && isCellBackgroundChanged(otherCell, liveCell)) {
|
|
211
|
+
var cellEnd = liveCellPos + liveCell.nodeSize;
|
|
212
|
+
decorations.push(
|
|
213
|
+
// The cell becomes the layer's stacking context, so the layer sits above the cell's own
|
|
214
|
+
// background rather than behind it. Through `z-index` at the cell overlay's own level, not
|
|
215
|
+
// `isolation`: an isolated cell would trap its overlay below later cells, which then cover
|
|
216
|
+
// the overlay's outline where it overlaps their border. Properties the cell never sets, so
|
|
217
|
+
// removing them takes nothing of its own.
|
|
218
|
+
Decoration.node(liveCellPos, cellEnd, {
|
|
219
|
+
style: convertToInlineCss({
|
|
220
|
+
position: 'relative',
|
|
221
|
+
// The highest z-index a cell diff overlay takes (the rounded-corner variant).
|
|
222
|
+
zIndex: 2
|
|
223
|
+
})
|
|
224
|
+
}, {
|
|
225
|
+
key: "show-diff-new-cell-background-host-".concat(liveCellPos)
|
|
226
|
+
}),
|
|
227
|
+
// At the cell's end, beside its diff overlay, so the cell's first block stays its first child.
|
|
228
|
+
Decoration.widget(cellEnd - 1, createCellBackgroundLayer(getCellBackgroundColor(otherCell)), {
|
|
229
|
+
key: "show-diff-new-cell-background-".concat(liveCellPos),
|
|
230
|
+
side: -1,
|
|
231
|
+
marks: [],
|
|
232
|
+
ignoreSelection: true
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
if (!isCellContentEqual(otherCell, liveCell)) {
|
|
236
|
+
var contentWidget = createCellContentWidget({
|
|
237
|
+
cell: otherCell,
|
|
238
|
+
pos: liveCellPos,
|
|
239
|
+
nodeViewSerializer: nodeViewSerializer,
|
|
240
|
+
colorScheme: colorScheme,
|
|
241
|
+
intl: intl,
|
|
242
|
+
isActive: isActive,
|
|
243
|
+
isInserted: isInserted,
|
|
244
|
+
leftAnchorId: leftAnchorId
|
|
245
|
+
});
|
|
246
|
+
if (contentWidget) {
|
|
247
|
+
decorations.push(contentWidget);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return decorations;
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The displayed side of a whole-cell replacement. A table cell is never removed on its own, only
|
|
256
|
+
* replaced in place, so a live cell is never hidden — hiding it would leave the row a cell short. It
|
|
257
|
+
* takes the changed-cell treatment only when the cell itself changed; its content is diffed, and
|
|
258
|
+
* hidden in the clean view, only when that changed. A cell whose content stayed the same keeps
|
|
259
|
+
* showing it.
|
|
260
|
+
*/
|
|
261
|
+
export var createReplacedCellDecorations = function createReplacedCellDecorations(_ref5) {
|
|
262
|
+
var replacedCells = _ref5.replacedCells,
|
|
263
|
+
change = _ref5.change,
|
|
264
|
+
doc = _ref5.doc,
|
|
265
|
+
attributionKey = _ref5.attributionKey,
|
|
266
|
+
colorScheme = _ref5.colorScheme,
|
|
267
|
+
hasDeletedWidget = _ref5.hasDeletedWidget,
|
|
268
|
+
hideAddedDiffsUnderline = _ref5.hideAddedDiffsUnderline,
|
|
269
|
+
isActive = _ref5.isActive,
|
|
270
|
+
isDeletedWidgetBelow = _ref5.isDeletedWidgetBelow,
|
|
271
|
+
isInserted = _ref5.isInserted,
|
|
272
|
+
leftAnchorId = _ref5.leftAnchorId,
|
|
273
|
+
reveal = _ref5.reveal,
|
|
274
|
+
shouldHideDeleted = _ref5.shouldHideDeleted,
|
|
275
|
+
showContributorTags = _ref5.showContributorTags,
|
|
276
|
+
showIndicators = _ref5.showIndicators,
|
|
277
|
+
tagMountContext = _ref5.tagMountContext;
|
|
278
|
+
return replacedCells.flatMap(function (_ref6) {
|
|
279
|
+
var otherCell = _ref6.otherCell,
|
|
280
|
+
liveCell = _ref6.liveCell,
|
|
281
|
+
liveCellPos = _ref6.liveCellPos;
|
|
282
|
+
var cellEnd = liveCellPos + liveCell.nodeSize;
|
|
283
|
+
var decorations = isCellChanged(otherCell, liveCell) ? createBlockChangedDecoration({
|
|
284
|
+
attributionKey: attributionKey,
|
|
285
|
+
change: {
|
|
286
|
+
from: liveCellPos,
|
|
287
|
+
to: cellEnd,
|
|
288
|
+
name: liveCell.type.name
|
|
289
|
+
},
|
|
290
|
+
colorScheme: colorScheme,
|
|
291
|
+
doc: doc,
|
|
292
|
+
isActive: isActive,
|
|
293
|
+
// The cell stays either way, so it reads as changed, not removed.
|
|
294
|
+
isInserted: true,
|
|
295
|
+
leftAnchorId: leftAnchorId,
|
|
296
|
+
showContributorTags: showContributorTags,
|
|
297
|
+
showIndicators: showIndicators,
|
|
298
|
+
tagMountContext: tagMountContext
|
|
299
|
+
}) : [];
|
|
300
|
+
if (isCellContentEqual(otherCell, liveCell)) {
|
|
301
|
+
return decorations;
|
|
302
|
+
}
|
|
303
|
+
decorations.push.apply(decorations, _toConsumableArray(createInlineChangedDecoration({
|
|
304
|
+
attributionKey: attributionKey,
|
|
305
|
+
change: _objectSpread(_objectSpread({}, change), {}, {
|
|
306
|
+
fromB: liveCellPos,
|
|
307
|
+
toB: cellEnd
|
|
308
|
+
}),
|
|
309
|
+
colorScheme: colorScheme,
|
|
310
|
+
doc: doc,
|
|
311
|
+
hasDeletedWidget: hasDeletedWidget,
|
|
312
|
+
hideAddedDiffsUnderline: hideAddedDiffsUnderline,
|
|
313
|
+
isActive: isActive,
|
|
314
|
+
isDeletedWidgetBelow: isDeletedWidgetBelow,
|
|
315
|
+
isInserted: isInserted,
|
|
316
|
+
leftAnchorId: leftAnchorId,
|
|
317
|
+
reveal: reveal,
|
|
318
|
+
shouldHideDeleted: shouldHideDeleted,
|
|
319
|
+
showContributorTags: showContributorTags,
|
|
320
|
+
showIndicators: showIndicators,
|
|
321
|
+
tagMountContext: tagMountContext
|
|
322
|
+
})));
|
|
323
|
+
if (shouldHideDeleted) {
|
|
324
|
+
liveCell.forEach(function (block, offset) {
|
|
325
|
+
var blockPos = liveCellPos + 1 + offset;
|
|
326
|
+
decorations.push.apply(decorations, _toConsumableArray(createBlockChangedDecoration({
|
|
327
|
+
change: {
|
|
328
|
+
from: blockPos,
|
|
329
|
+
to: blockPos + block.nodeSize,
|
|
330
|
+
name: block.type.name
|
|
331
|
+
},
|
|
332
|
+
colorScheme: colorScheme,
|
|
333
|
+
doc: doc,
|
|
334
|
+
isActive: isActive,
|
|
335
|
+
isInserted: isInserted,
|
|
336
|
+
leftAnchorId: leftAnchorId,
|
|
337
|
+
shouldHideDeleted: shouldHideDeleted
|
|
338
|
+
})));
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return decorations;
|
|
342
|
+
});
|
|
343
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getDiffableAttrNames } from './diffableAttrs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A cell background as it renders: absent, empty and `"null"` — the string agent payloads send for
|
|
5
|
+
* no background — all mean the cell has none.
|
|
6
|
+
*/
|
|
7
|
+
export var normalizeCellBackground = function normalizeCellBackground(background) {
|
|
8
|
+
return typeof background === 'string' && background !== '' && background !== 'null' ? background : null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Whether two cells render different backgrounds. */
|
|
12
|
+
export var isCellBackgroundChanged = function isCellBackgroundChanged(left, right) {
|
|
13
|
+
return normalizeCellBackground(left.attrs.background) !== normalizeCellBackground(right.attrs.background);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Whether two cells differ by an attribute that represents a change, such as their background or
|
|
18
|
+
* span, as opposed to only their content.
|
|
19
|
+
*/
|
|
20
|
+
export var isCellAttrChanged = function isCellAttrChanged(left, right) {
|
|
21
|
+
var _getDiffableAttrNames;
|
|
22
|
+
return ((_getDiffableAttrNames = getDiffableAttrNames(left.type.name, left.attrs)) !== null && _getDiffableAttrNames !== void 0 ? _getDiffableAttrNames : []).some(function (name) {
|
|
23
|
+
return name === 'background' ? isCellBackgroundChanged(left, right) : left.attrs[name] !== right.attrs[name];
|
|
24
|
+
});
|
|
25
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Change } from 'prosemirror-changeset';
|
|
2
|
+
import type { IntlShape } from 'react-intl';
|
|
3
|
+
import type { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import type { RevealOptions } from '../../showDiffPluginType';
|
|
6
|
+
import type { NodeViewSerializer } from '../NodeViewSerializer';
|
|
7
|
+
import type { ColorScheme } from './colorSchemes/types';
|
|
8
|
+
import type { ContributorTagMountContext } from './createContributorTagWidget';
|
|
9
|
+
export type ReplacedCell = {
|
|
10
|
+
/** The live cell in the displayed document. */
|
|
11
|
+
liveCell: PMNode;
|
|
12
|
+
liveCellPos: number;
|
|
13
|
+
/** The other side's cell, from the replaced slice. */
|
|
14
|
+
otherCell: PMNode;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Pairs each cell of a whole-cell replacement with the live cell it replaces, or `[]` when the slice
|
|
18
|
+
* is not a run of whole cells matching the live ones. Whole-cell replacement preserves cell count and
|
|
19
|
+
* order, so the nth live cell in the range matches the nth cell in the slice.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getReplacedCells: ({ slice, doc, fromB, toB, }: {
|
|
22
|
+
doc: PMNode;
|
|
23
|
+
fromB: number;
|
|
24
|
+
slice: Slice;
|
|
25
|
+
toB: number;
|
|
26
|
+
}) => ReplacedCell[];
|
|
27
|
+
/**
|
|
28
|
+
* The other side of a whole-cell replacement, drawn inside the live cells so the table keeps its
|
|
29
|
+
* shape: each live cell takes the other cell's background when it differs, and its content when that
|
|
30
|
+
* differs. A cell whose content did not change has nothing to diff.
|
|
31
|
+
*/
|
|
32
|
+
export declare const createReplacedCellWidgets: ({ slice, newDoc, change, nodeViewSerializer, colorScheme, intl, isActive, isInserted, leftAnchorId, }: {
|
|
33
|
+
change: Pick<Change, 'fromB' | 'toB'>;
|
|
34
|
+
colorScheme?: ColorScheme;
|
|
35
|
+
intl: IntlShape;
|
|
36
|
+
isActive?: boolean;
|
|
37
|
+
isInserted: boolean;
|
|
38
|
+
leftAnchorId?: string;
|
|
39
|
+
newDoc: PMNode;
|
|
40
|
+
nodeViewSerializer: NodeViewSerializer;
|
|
41
|
+
slice: Slice;
|
|
42
|
+
}) => Decoration[];
|
|
43
|
+
/**
|
|
44
|
+
* The displayed side of a whole-cell replacement. A table cell is never removed on its own, only
|
|
45
|
+
* replaced in place, so a live cell is never hidden — hiding it would leave the row a cell short. It
|
|
46
|
+
* takes the changed-cell treatment only when the cell itself changed; its content is diffed, and
|
|
47
|
+
* hidden in the clean view, only when that changed. A cell whose content stayed the same keeps
|
|
48
|
+
* showing it.
|
|
49
|
+
*/
|
|
50
|
+
export declare const createReplacedCellDecorations: ({ replacedCells, change, doc, attributionKey, colorScheme, hasDeletedWidget, hideAddedDiffsUnderline, isActive, isDeletedWidgetBelow, isInserted, leftAnchorId, reveal, shouldHideDeleted, showContributorTags, showIndicators, tagMountContext, }: {
|
|
51
|
+
attributionKey?: string;
|
|
52
|
+
change: Pick<Change, 'fromA' | 'toA' | 'fromB' | 'toB'>;
|
|
53
|
+
colorScheme?: ColorScheme;
|
|
54
|
+
doc: PMNode;
|
|
55
|
+
hasDeletedWidget?: boolean;
|
|
56
|
+
hideAddedDiffsUnderline?: boolean;
|
|
57
|
+
isActive?: boolean;
|
|
58
|
+
isDeletedWidgetBelow?: boolean;
|
|
59
|
+
isInserted: boolean;
|
|
60
|
+
leftAnchorId?: string;
|
|
61
|
+
replacedCells: ReplacedCell[];
|
|
62
|
+
reveal?: RevealOptions;
|
|
63
|
+
shouldHideDeleted?: boolean;
|
|
64
|
+
showContributorTags?: boolean;
|
|
65
|
+
showIndicators?: boolean;
|
|
66
|
+
tagMountContext?: ContributorTagMountContext;
|
|
67
|
+
}) => Decoration[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* A cell background as it renders: absent, empty and `"null"` — the string agent payloads send for
|
|
4
|
+
* no background — all mean the cell has none.
|
|
5
|
+
*/
|
|
6
|
+
export declare const normalizeCellBackground: (background: unknown) => string | null;
|
|
7
|
+
/** Whether two cells render different backgrounds. */
|
|
8
|
+
export declare const isCellBackgroundChanged: (left: PMNode, right: PMNode) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Whether two cells differ by an attribute that represents a change, such as their background or
|
|
11
|
+
* span, as opposed to only their content.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isCellAttrChanged: (left: PMNode, right: PMNode) => boolean;
|