@atlaskit/editor-plugin-show-diff 3.1.4 → 3.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 +19 -0
- package/afm-cc/tsconfig.json +3 -0
- package/afm-jira/tsconfig.json +3 -0
- package/afm-post-office/tsconfig.json +3 -0
- package/afm-products/tsconfig.json +3 -0
- package/dist/cjs/pm-plugins/attributeDecorations.js +33 -0
- package/dist/cjs/pm-plugins/calculateDiffDecorations.js +13 -5
- package/dist/cjs/pm-plugins/decorations.js +225 -7
- package/dist/cjs/pm-plugins/main.js +6 -5
- package/dist/cjs/showDiffPlugin.js +4 -3
- package/dist/es2019/pm-plugins/attributeDecorations.js +21 -0
- package/dist/es2019/pm-plugins/calculateDiffDecorations.js +13 -5
- package/dist/es2019/pm-plugins/decorations.js +225 -7
- package/dist/es2019/pm-plugins/main.js +4 -3
- package/dist/es2019/showDiffPlugin.js +4 -2
- package/dist/esm/pm-plugins/attributeDecorations.js +26 -0
- package/dist/esm/pm-plugins/calculateDiffDecorations.js +13 -5
- package/dist/esm/pm-plugins/decorations.js +225 -7
- package/dist/esm/pm-plugins/main.js +4 -3
- package/dist/esm/showDiffPlugin.js +4 -3
- package/dist/types/pm-plugins/attributeDecorations.d.ts +8 -0
- package/dist/types/pm-plugins/calculateDiffDecorations.d.ts +3 -1
- package/dist/types/pm-plugins/decorations.d.ts +3 -1
- package/dist/types/pm-plugins/main.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/attributeDecorations.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/calculateDiffDecorations.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -1
- package/package.json +8 -2
- package/afm-dev-agents/tsconfig.json +0 -27
- package/afm-passionfruit/tsconfig.json +0 -27
- package/afm-rovo-extension/tsconfig.json +0 -27
- package/afm-townsquare/tsconfig.json +0 -27
- package/afm-volt/tsconfig.json +0 -27
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
2
|
+
import { trackChangesMessages } from '@atlaskit/editor-common/messages';
|
|
2
3
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
5
|
import { findSafeInsertPos } from './findSafeInsertPos';
|
|
4
6
|
const editingStyle = convertToInlineCss({
|
|
5
7
|
background: "var(--ds-background-accent-purple-subtlest, #F3F0FF)",
|
|
@@ -68,6 +70,59 @@ const getEditorStyleNode = (nodeName, colourScheme) => {
|
|
|
68
70
|
return colourScheme === 'traditional' ? traditionalStyleNode : editingStyleNode;
|
|
69
71
|
}
|
|
70
72
|
};
|
|
73
|
+
const getDeletedStyleNode = nodeName => {
|
|
74
|
+
switch (nodeName) {
|
|
75
|
+
case 'blockquote':
|
|
76
|
+
return deletedStyleQuoteNode;
|
|
77
|
+
case 'expand':
|
|
78
|
+
case 'decisionList':
|
|
79
|
+
return deletedBlockOutline;
|
|
80
|
+
case 'panel':
|
|
81
|
+
case 'codeBlock':
|
|
82
|
+
return deletedBlockOutlineRounded;
|
|
83
|
+
default:
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const shouldShowRemovedLozenge = nodeName => {
|
|
88
|
+
switch (nodeName) {
|
|
89
|
+
case 'expand':
|
|
90
|
+
case 'codeBlock':
|
|
91
|
+
case 'mediaSingle':
|
|
92
|
+
case 'panel':
|
|
93
|
+
case 'decisionList':
|
|
94
|
+
return true;
|
|
95
|
+
default:
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const shouldFitContentWidth = nodeName => {
|
|
100
|
+
switch (nodeName) {
|
|
101
|
+
case 'mediaSingle':
|
|
102
|
+
case 'embedCard':
|
|
103
|
+
case 'blockCard':
|
|
104
|
+
return true;
|
|
105
|
+
default:
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const shouldAddShowDiffDeletedNodeClass = nodeName => {
|
|
110
|
+
switch (nodeName) {
|
|
111
|
+
case 'mediaSingle':
|
|
112
|
+
case 'embedCard':
|
|
113
|
+
return true;
|
|
114
|
+
default:
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Checks if a node should apply deleted styles directly without wrapper
|
|
121
|
+
* to preserve natural block-level margins
|
|
122
|
+
*/
|
|
123
|
+
const shouldApplyDeletedStylesDirectly = nodeName => {
|
|
124
|
+
return nodeName === 'blockquote' || nodeName === 'heading';
|
|
125
|
+
};
|
|
71
126
|
const editingStyleQuoteNode = convertToInlineCss({
|
|
72
127
|
borderLeft: `2px solid ${"var(--ds-border-accent-purple, #8270DB)"}`
|
|
73
128
|
});
|
|
@@ -96,6 +151,18 @@ const traditionalStyleCardBlockNode = convertToInlineCss({
|
|
|
96
151
|
boxShadow: `0 0 0 1px ${"var(--ds-border-accent-green, #22A06B)"}`,
|
|
97
152
|
borderRadius: "var(--ds-radius-medium, 6px)"
|
|
98
153
|
});
|
|
154
|
+
const deletedStyleQuoteNode = convertToInlineCss({
|
|
155
|
+
borderLeft: `2px solid ${"var(--ds-border-accent-gray, #758195)"}`
|
|
156
|
+
});
|
|
157
|
+
const deletedBlockOutline = convertToInlineCss({
|
|
158
|
+
boxShadow: `0 0 0 1px ${"var(--ds-border-accent-gray, #758195)"}`,
|
|
159
|
+
borderRadius: "var(--ds-radius-small, 4px)"
|
|
160
|
+
});
|
|
161
|
+
const deletedBlockOutlineRounded = convertToInlineCss({
|
|
162
|
+
boxShadow: `0 0 0 1px ${"var(--ds-border-accent-gray, #758195)"}`,
|
|
163
|
+
borderRadius: `calc(${"var(--ds-radius-xsmall, 2px)"} + 1px)`
|
|
164
|
+
});
|
|
165
|
+
|
|
99
166
|
/**
|
|
100
167
|
* Inline decoration used for insertions as the content already exists in the document
|
|
101
168
|
*
|
|
@@ -136,14 +203,145 @@ const deletedTraditionalContentStyleUnbounded = convertToInlineCss({
|
|
|
136
203
|
pointerEvents: 'none',
|
|
137
204
|
zIndex: 1
|
|
138
205
|
});
|
|
206
|
+
const lozengeStyle = convertToInlineCss({
|
|
207
|
+
display: 'inline-flex',
|
|
208
|
+
boxSizing: 'border-box',
|
|
209
|
+
position: 'static',
|
|
210
|
+
blockSize: 'min-content',
|
|
211
|
+
borderRadius: "var(--ds-radius-small, 4px)",
|
|
212
|
+
overflow: 'hidden',
|
|
213
|
+
paddingInlineStart: "var(--ds-space-050, 4px)",
|
|
214
|
+
paddingInlineEnd: "var(--ds-space-050, 4px)",
|
|
215
|
+
backgroundColor: "var(--ds-background-accent-gray-subtler, #DCDFE4)",
|
|
216
|
+
font: "var(--ds-font-body-small, normal 400 11px/16px ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
|
|
217
|
+
fontWeight: "var(--ds-font-weight-bold, 700)",
|
|
218
|
+
textOverflow: 'ellipsis',
|
|
219
|
+
whiteSpace: 'nowrap',
|
|
220
|
+
color: "var(--ds-text-warning-inverse, #172B4D)"
|
|
221
|
+
});
|
|
139
222
|
const getDeletedContentStyleUnbounded = colourScheme => colourScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
|
|
140
223
|
const getDeletedContentStyle = colourScheme => colourScheme === 'traditional' ? deletedTraditionalContentStyle : deletedContentStyle;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Creates a "Removed" lozenge to be displayed at the top right corner of deleted block nodes
|
|
227
|
+
*/
|
|
228
|
+
const createRemovedLozenge = (intl, nodeName) => {
|
|
229
|
+
const container = document.createElement('span');
|
|
230
|
+
let borderTopRightRadius;
|
|
231
|
+
let borderTopLeftRadius;
|
|
232
|
+
if (['expand', 'decisionList'].includes(nodeName || '')) {
|
|
233
|
+
borderTopRightRadius = "var(--ds-radius-small, 4px)";
|
|
234
|
+
} else if (['panel', 'codeBlock'].includes(nodeName || '')) {
|
|
235
|
+
borderTopRightRadius = `calc(${"var(--ds-radius-xsmall, 2px)"} + 1px)`;
|
|
236
|
+
} else if (nodeName === 'mediaSingle') {
|
|
237
|
+
borderTopLeftRadius = "var(--ds-radius-small, 4px)";
|
|
238
|
+
}
|
|
239
|
+
const containerStyle = convertToInlineCss({
|
|
240
|
+
position: 'absolute',
|
|
241
|
+
top: nodeName === 'mediaSingle' ? "var(--ds-space-300, 24px)" : "var(--ds-space-0, 0px)",
|
|
242
|
+
right: nodeName === 'mediaSingle' ? undefined : "var(--ds-space-0, 0px)",
|
|
243
|
+
left: nodeName === 'mediaSingle' ? "var(--ds-space-0, 0px)" : undefined,
|
|
244
|
+
zIndex: 2,
|
|
245
|
+
pointerEvents: 'none',
|
|
246
|
+
display: 'flex',
|
|
247
|
+
overflow: 'hidden',
|
|
248
|
+
borderTopRightRadius,
|
|
249
|
+
borderTopLeftRadius
|
|
250
|
+
});
|
|
251
|
+
container.setAttribute('style', containerStyle);
|
|
252
|
+
container.setAttribute('data-testid', 'show-diff-removed-lozenge');
|
|
253
|
+
|
|
254
|
+
// Create vanilla HTML lozenge element with Atlaskit Lozenge styling (visual refresh)
|
|
255
|
+
const lozengeElement = document.createElement('span');
|
|
256
|
+
lozengeElement.setAttribute('style', lozengeStyle);
|
|
257
|
+
lozengeElement.textContent = intl.formatMessage(trackChangesMessages.removed).toUpperCase();
|
|
258
|
+
container.appendChild(lozengeElement);
|
|
259
|
+
return container;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Wraps a block node in a container with relative positioning to support absolute positioned lozenge
|
|
264
|
+
*/
|
|
265
|
+
const createBlockNodeWrapper = nodeName => {
|
|
266
|
+
const wrapper = document.createElement('div');
|
|
267
|
+
const fitContent = shouldFitContentWidth(nodeName);
|
|
268
|
+
const baseStyle = convertToInlineCss({
|
|
269
|
+
position: 'relative',
|
|
270
|
+
display: fitContent ? 'inline-block' : 'block',
|
|
271
|
+
width: fitContent ? 'fit-content' : undefined,
|
|
272
|
+
height: fitContent ? 'fit-content' : undefined,
|
|
273
|
+
opacity: 1
|
|
274
|
+
});
|
|
275
|
+
wrapper.setAttribute('style', baseStyle);
|
|
276
|
+
return wrapper;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Wraps content with deleted styling without opacity (for use when content is a direct child of dom)
|
|
281
|
+
*/
|
|
282
|
+
const createDeletedStyleWrapperWithoutOpacity = colourScheme => {
|
|
283
|
+
const wrapper = document.createElement('span');
|
|
284
|
+
wrapper.setAttribute('style', getDeletedContentStyle(colourScheme));
|
|
285
|
+
return wrapper;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Applies deleted styles directly to an HTML element by merging with existing styles
|
|
290
|
+
*/
|
|
291
|
+
const applyDeletedStylesToElement = (element, targetNode, colourScheme) => {
|
|
292
|
+
const currentStyle = element.getAttribute('style') || '';
|
|
293
|
+
const deletedContentStyle = getDeletedContentStyle(colourScheme);
|
|
294
|
+
const nodeSpecificStyle = getDeletedStyleNode(targetNode.type.name) || '';
|
|
295
|
+
element.setAttribute('style', `${currentStyle}${deletedContentStyle}${nodeSpecificStyle}`);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Appends a block node with wrapper, lozenge, and appropriate styling
|
|
300
|
+
*/
|
|
301
|
+
const appendBlockNodeWithWrapper = (dom, nodeView, targetNode, colourScheme, intl) => {
|
|
302
|
+
const blockWrapper = createBlockNodeWrapper(targetNode.type.name);
|
|
303
|
+
if (shouldShowRemovedLozenge(targetNode.type.name)) {
|
|
304
|
+
const lozenge = createRemovedLozenge(intl, targetNode.type.name);
|
|
305
|
+
blockWrapper.append(lozenge);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Wrap the nodeView in a content wrapper that has the opacity style AND the box-shadow
|
|
309
|
+
// This keeps the lozenge at full opacity while the content AND border are faded
|
|
310
|
+
const contentWrapper = document.createElement('div');
|
|
311
|
+
const nodeStyle = getDeletedStyleNode(targetNode.type.name);
|
|
312
|
+
contentWrapper.setAttribute('style', `${getDeletedContentStyle(colourScheme)}${nodeStyle || ''}`);
|
|
313
|
+
contentWrapper.append(nodeView);
|
|
314
|
+
blockWrapper.append(contentWrapper);
|
|
315
|
+
if (nodeView instanceof HTMLElement) {
|
|
316
|
+
if (shouldAddShowDiffDeletedNodeClass(targetNode.type.name)) {
|
|
317
|
+
nodeView.classList.add('show-diff-deleted-node');
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
dom.append(blockWrapper);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Handles all block node rendering with appropriate deleted styling.
|
|
325
|
+
* For blockquote and heading nodes, applies styles directly to preserve natural margins.
|
|
326
|
+
* For other block nodes, uses wrapper approach with optional lozenge.
|
|
327
|
+
*/
|
|
328
|
+
const handleBlockNodeView = (dom, nodeView, targetNode, colourScheme, intl) => {
|
|
329
|
+
if (shouldApplyDeletedStylesDirectly(targetNode.type.name) && nodeView instanceof HTMLElement) {
|
|
330
|
+
// Apply deleted styles directly to preserve natural block-level margins
|
|
331
|
+
applyDeletedStylesToElement(nodeView, targetNode, colourScheme);
|
|
332
|
+
dom.append(nodeView);
|
|
333
|
+
} else {
|
|
334
|
+
// Use wrapper approach for other block nodes
|
|
335
|
+
appendBlockNodeWithWrapper(dom, nodeView, targetNode, colourScheme, intl);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
141
338
|
export const createDeletedContentDecoration = ({
|
|
142
339
|
change,
|
|
143
340
|
doc,
|
|
144
341
|
nodeViewSerializer,
|
|
145
342
|
colourScheme,
|
|
146
|
-
newDoc
|
|
343
|
+
newDoc,
|
|
344
|
+
intl
|
|
147
345
|
}) => {
|
|
148
346
|
const slice = doc.slice(change.fromA, change.toA);
|
|
149
347
|
if (slice.content.content.length === 0) {
|
|
@@ -157,7 +355,9 @@ export const createDeletedContentDecoration = ({
|
|
|
157
355
|
|
|
158
356
|
// For non-table content, use the existing span wrapper approach
|
|
159
357
|
const dom = document.createElement('span');
|
|
160
|
-
|
|
358
|
+
if (!fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
359
|
+
dom.setAttribute('style', getDeletedContentStyle(colourScheme));
|
|
360
|
+
}
|
|
161
361
|
|
|
162
362
|
/*
|
|
163
363
|
* The thinking is we separate out the fragment we got from doc.slice
|
|
@@ -169,8 +369,11 @@ export const createDeletedContentDecoration = ({
|
|
|
169
369
|
// Create a wrapper for each node with strikethrough
|
|
170
370
|
const createWrapperWithStrikethrough = () => {
|
|
171
371
|
const wrapper = document.createElement('span');
|
|
172
|
-
|
|
173
|
-
|
|
372
|
+
const baseStyle = convertToInlineCss({
|
|
373
|
+
position: 'relative',
|
|
374
|
+
width: 'fit-content'
|
|
375
|
+
});
|
|
376
|
+
wrapper.setAttribute('style', `${baseStyle}${getDeletedContentStyle(colourScheme)}`);
|
|
174
377
|
const strikethrough = document.createElement('span');
|
|
175
378
|
strikethrough.setAttribute('style', getDeletedContentStyleUnbounded(colourScheme));
|
|
176
379
|
wrapper.append(strikethrough);
|
|
@@ -193,7 +396,13 @@ export const createDeletedContentDecoration = ({
|
|
|
193
396
|
// Fallback to serializing the individual child node
|
|
194
397
|
const serializedChild = serializer.serializeNode(childNode);
|
|
195
398
|
if (serializedChild) {
|
|
196
|
-
|
|
399
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
400
|
+
const wrapper = createWrapperWithStrikethrough();
|
|
401
|
+
wrapper.append(serializedChild);
|
|
402
|
+
dom.append(wrapper);
|
|
403
|
+
} else {
|
|
404
|
+
dom.append(serializedChild);
|
|
405
|
+
}
|
|
197
406
|
}
|
|
198
407
|
}
|
|
199
408
|
});
|
|
@@ -245,6 +454,9 @@ export const createDeletedContentDecoration = ({
|
|
|
245
454
|
const wrapper = createWrapperWithStrikethrough();
|
|
246
455
|
wrapper.append(nodeView);
|
|
247
456
|
dom.append(wrapper);
|
|
457
|
+
} else if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
458
|
+
// Handle all block nodes with unified function
|
|
459
|
+
handleBlockNodeView(dom, nodeView, targetNode, colourScheme, intl);
|
|
248
460
|
} else {
|
|
249
461
|
dom.append(nodeView);
|
|
250
462
|
}
|
|
@@ -254,7 +466,13 @@ export const createDeletedContentDecoration = ({
|
|
|
254
466
|
} else {
|
|
255
467
|
const fallbackNode = fallbackSerialization();
|
|
256
468
|
if (fallbackNode) {
|
|
257
|
-
|
|
469
|
+
if (fg('platform_editor_ai_aifc_patch_beta_2')) {
|
|
470
|
+
const wrapper = createDeletedStyleWrapperWithoutOpacity(colourScheme);
|
|
471
|
+
wrapper.append(fallbackNode);
|
|
472
|
+
dom.append(wrapper);
|
|
473
|
+
} else {
|
|
474
|
+
dom.append(fallbackNode);
|
|
475
|
+
}
|
|
258
476
|
}
|
|
259
477
|
}
|
|
260
478
|
});
|
|
@@ -263,5 +481,5 @@ export const createDeletedContentDecoration = ({
|
|
|
263
481
|
// Widget decoration used for deletions as the content is not in the document
|
|
264
482
|
// and we want to display the deleted content with a style.
|
|
265
483
|
const safeInsertPos = findSafeInsertPos(newDoc, change.fromB, slice);
|
|
266
|
-
return Decoration.widget(safeInsertPos, dom
|
|
484
|
+
return Decoration.widget(safeInsertPos, dom);
|
|
267
485
|
};
|
|
@@ -6,7 +6,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
|
6
6
|
import { calculateDiffDecorations } from './calculateDiffDecorations';
|
|
7
7
|
import { NodeViewSerializer } from './NodeViewSerializer';
|
|
8
8
|
export const showDiffPluginKey = new PluginKey('showDiffPlugin');
|
|
9
|
-
export const createPlugin = config => {
|
|
9
|
+
export const createPlugin = (config, getIntl) => {
|
|
10
10
|
const nodeViewSerializer = new NodeViewSerializer({});
|
|
11
11
|
const setNodeViewSerializer = editorView => {
|
|
12
12
|
nodeViewSerializer.init({
|
|
@@ -16,7 +16,7 @@ export const createPlugin = config => {
|
|
|
16
16
|
return new SafePlugin({
|
|
17
17
|
key: showDiffPluginKey,
|
|
18
18
|
state: {
|
|
19
|
-
init(_,
|
|
19
|
+
init(_, _state) {
|
|
20
20
|
// We do initial setup after we setup the editor view
|
|
21
21
|
return {
|
|
22
22
|
steps: [],
|
|
@@ -41,7 +41,8 @@ export const createPlugin = config => {
|
|
|
41
41
|
state: newState,
|
|
42
42
|
pluginState: newPluginState,
|
|
43
43
|
nodeViewSerializer,
|
|
44
|
-
colourScheme: config === null || config === void 0 ? void 0 : config.colourScheme
|
|
44
|
+
colourScheme: config === null || config === void 0 ? void 0 : config.colourScheme,
|
|
45
|
+
intl: getIntl()
|
|
45
46
|
});
|
|
46
47
|
// Update the decorations
|
|
47
48
|
newPluginState.decorations = decorations;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createPlugin, showDiffPluginKey } from './pm-plugins/main';
|
|
2
2
|
export const showDiffPlugin = ({
|
|
3
|
-
api,
|
|
3
|
+
api: _api,
|
|
4
4
|
config
|
|
5
5
|
}) => ({
|
|
6
6
|
name: 'showDiff',
|
|
@@ -25,7 +25,9 @@ export const showDiffPlugin = ({
|
|
|
25
25
|
pmPlugins() {
|
|
26
26
|
return [{
|
|
27
27
|
name: 'showDiffPlugin',
|
|
28
|
-
plugin: (
|
|
28
|
+
plugin: ({
|
|
29
|
+
getIntl
|
|
30
|
+
}) => createPlugin(config, getIntl)
|
|
29
31
|
}];
|
|
30
32
|
},
|
|
31
33
|
getSharedState: editorState => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
3
|
+
import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
var filterUndefined = function filterUndefined(x) {
|
|
5
|
+
return !!x;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// Currently allow attributes that indicats a change in media image
|
|
9
|
+
var allowedAttrs = ['id', 'collection', 'url'];
|
|
10
|
+
export var getAttrChangeRanges = function getAttrChangeRanges(doc, steps) {
|
|
11
|
+
return steps.map(function (step) {
|
|
12
|
+
if (step instanceof AttrStep && allowedAttrs.includes(step.attr) || step instanceof SetAttrsStep && _toConsumableArray(Object.keys(step.attrs)).some(function (v) {
|
|
13
|
+
return allowedAttrs.includes(v);
|
|
14
|
+
})) {
|
|
15
|
+
var $pos = doc.resolve(step.pos);
|
|
16
|
+
if ($pos.parent.type === doc.type.schema.nodes.mediaSingle) {
|
|
17
|
+
var startPos = $pos.pos + $pos.parentOffset;
|
|
18
|
+
return {
|
|
19
|
+
fromB: startPos,
|
|
20
|
+
toB: startPos + $pos.parent.nodeSize - 1
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}).filter(filterUndefined);
|
|
26
|
+
};
|
|
@@ -14,6 +14,7 @@ import { AnalyticsStep, SetAttrsStep } from '@atlaskit/adf-schema/steps';
|
|
|
14
14
|
import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
|
|
15
15
|
import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
|
|
16
16
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
17
|
+
import { getAttrChangeRanges } from './attributeDecorations';
|
|
17
18
|
import { createInlineChangedDecoration, createDeletedContentDecoration, createBlockChangedDecoration } from './decorations';
|
|
18
19
|
import { getMarkChangeRanges } from './markDecorations';
|
|
19
20
|
var calculateNodesForBlockDecoration = function calculateNodesForBlockDecoration(doc, from, to, colourScheme) {
|
|
@@ -88,7 +89,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
88
89
|
var state = _ref.state,
|
|
89
90
|
pluginState = _ref.pluginState,
|
|
90
91
|
nodeViewSerializer = _ref.nodeViewSerializer,
|
|
91
|
-
colourScheme = _ref.colourScheme
|
|
92
|
+
colourScheme = _ref.colourScheme,
|
|
93
|
+
intl = _ref.intl;
|
|
92
94
|
var originalDoc = pluginState.originalDoc,
|
|
93
95
|
rawSteps = pluginState.steps;
|
|
94
96
|
var steps = simplifySteps(rawSteps);
|
|
@@ -135,7 +137,8 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
135
137
|
doc: originalDoc,
|
|
136
138
|
nodeViewSerializer: nodeViewSerializer,
|
|
137
139
|
colourScheme: colourScheme,
|
|
138
|
-
newDoc: tr.doc
|
|
140
|
+
newDoc: tr.doc,
|
|
141
|
+
intl: intl
|
|
139
142
|
});
|
|
140
143
|
if (decoration) {
|
|
141
144
|
decorations.push(decoration);
|
|
@@ -145,6 +148,9 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref)
|
|
|
145
148
|
getMarkChangeRanges(steps).forEach(function (change) {
|
|
146
149
|
decorations.push(createInlineChangedDecoration(change, colourScheme));
|
|
147
150
|
});
|
|
151
|
+
getAttrChangeRanges(tr.doc, rawSteps).forEach(function (change) {
|
|
152
|
+
decorations.push.apply(decorations, _toConsumableArray(calculateNodesForBlockDecoration(tr.doc, change.fromB, change.toB, colourScheme)));
|
|
153
|
+
});
|
|
148
154
|
return DecorationSet.empty.add(tr.doc, decorations);
|
|
149
155
|
};
|
|
150
156
|
export var calculateDiffDecorations = memoizeOne(calculateDiffDecorationsInner,
|
|
@@ -155,12 +161,14 @@ function (_ref2, _ref3) {
|
|
|
155
161
|
_ref4$ = _ref4[0],
|
|
156
162
|
pluginState = _ref4$.pluginState,
|
|
157
163
|
state = _ref4$.state,
|
|
158
|
-
colourScheme = _ref4$.colourScheme
|
|
164
|
+
colourScheme = _ref4$.colourScheme,
|
|
165
|
+
intl = _ref4$.intl;
|
|
159
166
|
var _ref5 = _slicedToArray(_ref3, 1),
|
|
160
167
|
_ref5$ = _ref5[0],
|
|
161
168
|
lastPluginState = _ref5$.pluginState,
|
|
162
169
|
lastState = _ref5$.state,
|
|
163
|
-
lastColourScheme = _ref5$.colourScheme
|
|
170
|
+
lastColourScheme = _ref5$.colourScheme,
|
|
171
|
+
lastIntl = _ref5$.intl;
|
|
164
172
|
var originalDocIsSame = lastPluginState.originalDoc && pluginState.originalDoc && pluginState.originalDoc.eq(lastPluginState.originalDoc);
|
|
165
|
-
return (_ref6 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme) !== null && _ref6 !== void 0 ? _ref6 : false;
|
|
173
|
+
return (_ref6 = originalDocIsSame && isEqual(pluginState.steps, lastPluginState.steps) && state.doc.eq(lastState.doc) && colourScheme === lastColourScheme && intl.locale === lastIntl.locale) !== null && _ref6 !== void 0 ? _ref6 : false;
|
|
166
174
|
});
|