@atlaskit/editor-plugin-show-diff 17.0.0 → 17.0.2
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 +21 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +126 -49
- package/dist/cjs/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +265 -0
- package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
- package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +18 -13
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +82 -20
- package/dist/cjs/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +106 -0
- package/dist/cjs/pm-plugins/decorations/utils/tableDiffMode.js +36 -0
- package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeView.js +17 -6
- package/dist/cjs/pm-plugins/utils/emptyTextBlocks.js +66 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +61 -1
- package/dist/es2019/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +210 -0
- package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +79 -13
- package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +8 -2
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +85 -15
- package/dist/es2019/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
- package/dist/es2019/pm-plugins/decorations/utils/tableDiffMode.js +27 -0
- package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeView.js +15 -5
- package/dist/es2019/pm-plugins/utils/emptyTextBlocks.js +58 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +127 -50
- package/dist/esm/pm-plugins/calculateDiff/groupDeletedColumnChanges.js +258 -0
- package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +100 -34
- package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +18 -13
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +84 -22
- package/dist/esm/pm-plugins/decorations/utils/createDeletedLineBreakWidget.js +100 -0
- package/dist/esm/pm-plugins/decorations/utils/tableDiffMode.js +30 -0
- package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeView.js +16 -5
- package/dist/esm/pm-plugins/utils/emptyTextBlocks.js +60 -0
- package/dist/types/pm-plugins/calculateDiff/groupDeletedColumnChanges.d.ts +9 -0
- package/dist/types/pm-plugins/decorations/createChangedRowDecorationWidgets.d.ts +3 -1
- package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +5 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/utils/createDeletedLineBreakWidget.d.ts +50 -0
- package/dist/types/pm-plugins/decorations/utils/tableDiffMode.d.ts +26 -0
- package/dist/types/pm-plugins/decorations/utils/wrapBlockNodeView.d.ts +4 -0
- package/dist/types/pm-plugins/utils/emptyTextBlocks.d.ts +16 -0
- package/package.json +4 -4
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The textblock types whose empty form is a blank line the author put there deliberately, and so
|
|
3
|
+
* worth marking when a change removes it.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately not every textblock: an empty `codeBlock` is an empty code block, which renders as a
|
|
6
|
+
* visible box of its own and needs no stand-in.
|
|
7
|
+
*/
|
|
8
|
+
var BLANK_LINE_NODE_NAMES = new Set(['paragraph', 'heading']);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Structurally empty: no children at all, not merely no measurable content. The two coincide for a
|
|
12
|
+
* real node, and testing both keeps a node whose children report no size from passing as blank.
|
|
13
|
+
*/
|
|
14
|
+
var isEmptyTextBlock = function isEmptyTextBlock(node) {
|
|
15
|
+
return BLANK_LINE_NODE_NAMES.has(node.type.name) && node.content.childCount === 0 && node.content.size === 0;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How many empty textblocks a slice holds, or 0 unless that is *all* it holds.
|
|
20
|
+
*
|
|
21
|
+
* Counted rather than tested for one, because a run of adjacent blank lines is reported as a single
|
|
22
|
+
* change covering all of them — the case that made a single-block test miss.
|
|
23
|
+
*/
|
|
24
|
+
export var countEmptyTextBlockOnlySlice = function countEmptyTextBlockOnlySlice(slice) {
|
|
25
|
+
var _slice$content$childC;
|
|
26
|
+
var childCount = (_slice$content$childC = slice === null || slice === void 0 ? void 0 : slice.content.childCount) !== null && _slice$content$childC !== void 0 ? _slice$content$childC : 0;
|
|
27
|
+
if (!slice || childCount === 0) {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
for (var index = 0; index < childCount; index++) {
|
|
31
|
+
if (!isEmptyTextBlock(slice.content.child(index))) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return childCount;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The content position of every empty textblock lying wholly within `[from, to]`.
|
|
40
|
+
*
|
|
41
|
+
* Used to place a marker on each blank line a change removes. Partially covered blocks are skipped:
|
|
42
|
+
* the change only took part of one, so it still has text of its own, which the inline decoration
|
|
43
|
+
* already marks.
|
|
44
|
+
*/
|
|
45
|
+
export var emptyTextBlockContentPositions = function emptyTextBlockContentPositions(doc, from, to) {
|
|
46
|
+
var positions = [];
|
|
47
|
+
doc.nodesBetween(from, to, function (node, pos) {
|
|
48
|
+
if (node.isTextblock) {
|
|
49
|
+
if (isEmptyTextBlock(node) && pos >= from && pos + node.nodeSize <= to) {
|
|
50
|
+
// +1 steps over the block's own open token, into its (empty) content.
|
|
51
|
+
positions.push(pos + 1);
|
|
52
|
+
}
|
|
53
|
+
// A textblock holds inline content only, so there is nothing below it to visit.
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// Keep descending: blank lines nest inside cells, columns and panels.
|
|
57
|
+
return true;
|
|
58
|
+
});
|
|
59
|
+
return positions;
|
|
60
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Change } from 'prosemirror-changeset';
|
|
2
|
+
import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
export type ColumnAwareChange = Change & {
|
|
5
|
+
deletedColumns?: number[];
|
|
6
|
+
};
|
|
7
|
+
export declare const CELL_CONTENT_OFFSET = 2;
|
|
8
|
+
/** Groups a deleted column's cell changes into one whole-table change. */
|
|
9
|
+
export declare const groupDeletedColumnChanges: (changes: readonly Change[], originalDoc: PMNode, newDoc: PMNode, mapping: Mapping, isInverted: boolean) => ColumnAwareChange[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Change } from 'prosemirror-changeset';
|
|
2
|
+
import type { IntlShape } from 'react-intl';
|
|
2
3
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
import type { DiffType } from '../../showDiffPluginType';
|
|
@@ -9,11 +10,12 @@ type SimpleChange = Pick<Change, 'fromA' | 'toA' | 'fromB' | 'deleted'>;
|
|
|
9
10
|
/**
|
|
10
11
|
* Main function to handle deleted rows - computes diff and creates decorations
|
|
11
12
|
*/
|
|
12
|
-
export declare const createChangedRowDecorationWidgets: ({ attributionKey, changes, originalDoc, newDoc, nodeViewSerializer, colorScheme, isActive, isInserted, diffType, showIndicators, showContributorTags, tagMountContext, }: {
|
|
13
|
+
export declare const createChangedRowDecorationWidgets: ({ attributionKey, changes, originalDoc, newDoc, nodeViewSerializer, colorScheme, isActive, isInserted, diffType, intl, showIndicators, showContributorTags, tagMountContext, }: {
|
|
13
14
|
attributionKey?: string;
|
|
14
15
|
changes: SimpleChange[];
|
|
15
16
|
colorScheme?: ColorScheme;
|
|
16
17
|
diffType?: DiffType;
|
|
18
|
+
intl?: IntlShape;
|
|
17
19
|
isActive?: boolean;
|
|
18
20
|
isInserted?: boolean;
|
|
19
21
|
newDoc: PMNode;
|
|
@@ -39,7 +39,11 @@ export declare const unmountContributorTag: (mount: ContributorTagMount | undefi
|
|
|
39
39
|
* The host for a tag on deleted content, which renders inside its own widget decoration rather than
|
|
40
40
|
* needing one of its own. Unmount with `unmountContributorTag` from that widget's `destroy`.
|
|
41
41
|
*/
|
|
42
|
-
export declare const createContributorTagHost: (
|
|
42
|
+
export declare const createContributorTagHost: ({ anchorName, diffId, mountContext, }: {
|
|
43
|
+
anchorName?: string;
|
|
44
|
+
diffId: string;
|
|
45
|
+
mountContext?: ContributorTagMountContext;
|
|
46
|
+
}) => {
|
|
43
47
|
host: HTMLSpanElement;
|
|
44
48
|
mount: ContributorTagMount | undefined;
|
|
45
49
|
} | undefined;
|
|
@@ -10,7 +10,7 @@ import type { ColorScheme } from './colorSchemes/types';
|
|
|
10
10
|
* This function is used to create a decoration widget to show content
|
|
11
11
|
* that is not in the current document.
|
|
12
12
|
*/
|
|
13
|
-
export declare const createNodeChangedDecorationWidget: ({ attributionKey, change, doc, nodeViewSerializer, colorScheme, newDoc, intl, activeIndexPos, isInserted, showContributorTags, showIndicators, placeBelow, diffType, hideAddedDiffsUnderline, reveal, tagMountContext, }: {
|
|
13
|
+
export declare const createNodeChangedDecorationWidget: ({ attributionKey, change, doc, nodeViewSerializer, colorScheme, newDoc, intl, activeIndexPos, isInserted, showContributorTags, showIndicators, placeBelow, diffType, hideAddedDiffsUnderline, reveal, tagMountContext, deletedColumns, }: {
|
|
14
14
|
activeIndexPos?: {
|
|
15
15
|
from: number;
|
|
16
16
|
to: number;
|
|
@@ -18,6 +18,7 @@ export declare const createNodeChangedDecorationWidget: ({ attributionKey, chang
|
|
|
18
18
|
attributionKey?: string;
|
|
19
19
|
change: Pick<Change, 'fromA' | 'toA' | 'fromB' | 'deleted' | 'toB'>;
|
|
20
20
|
colorScheme?: ColorScheme;
|
|
21
|
+
deletedColumns?: readonly number[];
|
|
21
22
|
diffType?: DiffType;
|
|
22
23
|
doc: PMNode;
|
|
23
24
|
hideAddedDiffsUnderline?: boolean;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
2
|
+
import type { DiffType, RevealOptions } from '../../../showDiffPluginType';
|
|
3
|
+
import type { ColorScheme } from '../colorSchemes/types';
|
|
4
|
+
/**
|
|
5
|
+
* U+2936 ARROW POINTING DOWNWARDS THEN CURVING LEFTWARDS — the return-key glyph.
|
|
6
|
+
*
|
|
7
|
+
* Exported so tests assert against the glyph actually rendered rather than a copy of it.
|
|
8
|
+
*/
|
|
9
|
+
export declare const RETURN_GLYPH = "\u2936";
|
|
10
|
+
/**
|
|
11
|
+
* The DOM for a removed blank line: the return glyph, struck through in the deleted colours.
|
|
12
|
+
*
|
|
13
|
+
* An empty paragraph or heading is a line the author deliberately added, but it has no content for
|
|
14
|
+
* the deleted-content widget to serialize, so a deletion of one used to render nothing at all — the
|
|
15
|
+
* reviewer saw the surrounding text close up with no sign of what was removed. Standing the glyph
|
|
16
|
+
* in for the absent content keeps the deletion visible without inventing content that was not there.
|
|
17
|
+
*
|
|
18
|
+
* `createContentWrapper` supplies the highlight and the strikethrough line, so the glyph is styled
|
|
19
|
+
* exactly like any other run of deleted inline content, including the active and reveal states.
|
|
20
|
+
*
|
|
21
|
+
* Hidden from assistive technology: the glyph is a picture of a key, and read out it is announced as
|
|
22
|
+
* its Unicode name rather than as a removed line.
|
|
23
|
+
*/
|
|
24
|
+
export declare const createDeletedLineBreakWidget: ({ colorScheme, count, diffType, isActive, reveal, }: {
|
|
25
|
+
colorScheme?: ColorScheme;
|
|
26
|
+
/** One glyph per removed blank line, for a run of adjacent ones. */
|
|
27
|
+
count?: number;
|
|
28
|
+
diffType?: DiffType;
|
|
29
|
+
isActive?: boolean;
|
|
30
|
+
reveal?: RevealOptions;
|
|
31
|
+
}) => HTMLElement;
|
|
32
|
+
/**
|
|
33
|
+
* The glyph as a widget decoration anchored at `pos`.
|
|
34
|
+
*
|
|
35
|
+
* Shared by the two shapes a blank-line removal arrives in. On a forward diff the block is gone from
|
|
36
|
+
* the new document, so the change lands on the deleted side and the glyph is anchored where the
|
|
37
|
+
* block used to be. On an inverted diff — what AI suggested edits renders — the block is still in
|
|
38
|
+
* the displayed document and the change lands on the *inserted* side, so the glyph is anchored
|
|
39
|
+
* inside the surviving block, on the blank line itself.
|
|
40
|
+
*/
|
|
41
|
+
export declare const createDeletedLineBreakDecoration: ({ attributionKey, colorScheme, count, diffType, isActive, pos, reveal, side, }: {
|
|
42
|
+
attributionKey?: string;
|
|
43
|
+
colorScheme?: ColorScheme;
|
|
44
|
+
count?: number;
|
|
45
|
+
diffType?: DiffType;
|
|
46
|
+
isActive?: boolean;
|
|
47
|
+
pos: number;
|
|
48
|
+
reveal?: RevealOptions;
|
|
49
|
+
side?: number;
|
|
50
|
+
}) => Decoration;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
export type TableDiffMode =
|
|
3
|
+
/** Add table headers, or replace whole cells. Draws one content widget per cell. */
|
|
4
|
+
{
|
|
5
|
+
kind: 'cells';
|
|
6
|
+
}
|
|
7
|
+
/** Delete a row, or replace a whole row. Draws a row copy inside the table. */
|
|
8
|
+
| {
|
|
9
|
+
kind: 'rows';
|
|
10
|
+
}
|
|
11
|
+
/** Delete a column, or replace a whole table. Draws a table copy next to the live table. */
|
|
12
|
+
| {
|
|
13
|
+
kind: 'wholeTable';
|
|
14
|
+
}
|
|
15
|
+
/** Delete cells with no replacement. The new document has no cell to anchor to, so nothing draws. */
|
|
16
|
+
| {
|
|
17
|
+
kind: 'none';
|
|
18
|
+
}
|
|
19
|
+
/** Any change outside a table, such as a paragraph edit. Draws the generic block widget. */
|
|
20
|
+
| {
|
|
21
|
+
kind: 'generic';
|
|
22
|
+
};
|
|
23
|
+
export declare const getTableDiffMode: ({ slice, isInserted, }: {
|
|
24
|
+
isInserted: boolean;
|
|
25
|
+
slice: Slice;
|
|
26
|
+
}) => TableDiffMode;
|
|
@@ -2,6 +2,10 @@ import type { IntlShape } from 'react-intl';
|
|
|
2
2
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import type { DiffType, RevealOptions } from '../../../showDiffPluginType';
|
|
4
4
|
import type { ColorScheme } from '../colorSchemes/types';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a "Removed" lozenge to be displayed at the top right corner of deleted block nodes
|
|
7
|
+
*/
|
|
8
|
+
export declare const createRemovedLozenge: (intl: IntlShape, isActive?: boolean, colorScheme?: ColorScheme, inCell?: boolean) => HTMLElement;
|
|
5
9
|
/**
|
|
6
10
|
* Handles all block node rendering with appropriate deleted styling.
|
|
7
11
|
* For heading nodes, applies styles directly to preserve natural margins.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Node as PMNode, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* How many empty textblocks a slice holds, or 0 unless that is *all* it holds.
|
|
4
|
+
*
|
|
5
|
+
* Counted rather than tested for one, because a run of adjacent blank lines is reported as a single
|
|
6
|
+
* change covering all of them — the case that made a single-block test miss.
|
|
7
|
+
*/
|
|
8
|
+
export declare const countEmptyTextBlockOnlySlice: (slice: Slice | undefined) => number;
|
|
9
|
+
/**
|
|
10
|
+
* The content position of every empty textblock lying wholly within `[from, to]`.
|
|
11
|
+
*
|
|
12
|
+
* Used to place a marker on each blank line a change removes. Partially covered blocks are skipped:
|
|
13
|
+
* the change only took part of one, so it still has text of its own, which the inline decoration
|
|
14
|
+
* already marks.
|
|
15
|
+
*/
|
|
16
|
+
export declare const emptyTextBlockContentPositions: (doc: PMNode, from: number, to: number) => number[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-show-diff",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.2",
|
|
4
4
|
"description": "ShowDiff plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@atlaskit/platform-feature-experiments": "^0.3.0",
|
|
40
40
|
"@atlaskit/platform-feature-flags": "^2.2.0",
|
|
41
41
|
"@atlaskit/primitives": "^22.5.0",
|
|
42
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
42
|
+
"@atlaskit/tmp-editor-statsig": "^200.0.0",
|
|
43
43
|
"@atlaskit/tokens": "^18.2.0",
|
|
44
44
|
"@babel/runtime": "^7.0.0",
|
|
45
45
|
"@compiled/react": "^1.0.2",
|
|
@@ -64,14 +64,14 @@
|
|
|
64
64
|
"@atlassian/confluence-presets": "workspace:^",
|
|
65
65
|
"@atlassian/content-reconciliation": "^0.1.3506",
|
|
66
66
|
"@atlassian/editor-ai-injected-editors": "^33.0.0",
|
|
67
|
-
"@atlassian/editor-plugin-ai": "^73.
|
|
67
|
+
"@atlassian/editor-plugin-ai": "^73.2.0",
|
|
68
68
|
"@atlassian/structured-docs-types": "workspace:^",
|
|
69
69
|
"react": "^19.2.0",
|
|
70
70
|
"react-dom": "^19.2.0",
|
|
71
71
|
"react-intl": "^7.0.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@atlaskit/editor-common": "^123.
|
|
74
|
+
"@atlaskit/editor-common": "^123.1.0",
|
|
75
75
|
"react": "^18.2.0 || ^19.2.0",
|
|
76
76
|
"react-dom": "^18.2.0 || ^19.2.0",
|
|
77
77
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|