@atlaskit/editor-plugin-show-diff 12.1.3 → 13.0.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 +40 -0
- package/compass.yml +3 -3
- package/dist/cjs/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +76 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +6 -1
- package/dist/cjs/pm-plugins/calculateDiff/computeDiffChanges.js +8 -1
- package/dist/cjs/pm-plugins/calculateDiff/diffBySteps.js +2 -1
- package/dist/cjs/pm-plugins/calculateDiff/smart/classifySmartChanges.js +9 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/factory.js +678 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +39 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +1 -0
- package/dist/es2019/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +64 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +6 -1
- package/dist/es2019/pm-plugins/calculateDiff/computeDiffChanges.js +8 -1
- package/dist/es2019/pm-plugins/calculateDiff/diffBySteps.js +2 -1
- package/dist/es2019/pm-plugins/calculateDiff/smart/classifySmartChanges.js +9 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +625 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +33 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +0 -0
- package/dist/esm/pm-plugins/calculateDiff/attrAwareTokenEncoder.js +70 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +6 -1
- package/dist/esm/pm-plugins/calculateDiff/computeDiffChanges.js +8 -1
- package/dist/esm/pm-plugins/calculateDiff/diffBySteps.js +2 -1
- package/dist/esm/pm-plugins/calculateDiff/smart/classifySmartChanges.js +9 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +622 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +33 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +0 -0
- package/dist/types/pm-plugins/calculateDiff/attrAwareTokenEncoder.d.ts +7 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/factory.d.ts +101 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +5 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +38 -0
- package/package.json +6 -6
- package/editor-plugin-show-diff.docs.tsx +0 -43
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-show-diff
|
|
2
2
|
|
|
3
|
+
## 13.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 12.1.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`522f40dd846c1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/522f40dd846c1) -
|
|
14
|
+
Fix table-cell diffs in the Post Stream Review experience. Recolouring a table cell is now
|
|
15
|
+
surfaced in the review with a highlight and a navigable step-through segment, and stepping onto a
|
|
16
|
+
cell no longer renders a blank cell.
|
|
17
|
+
- The AI modal mount-point widget could be positioned directly inside a table row, where the
|
|
18
|
+
browser wrapped it in an anonymous table cell — a blank column that hid the real cell's content.
|
|
19
|
+
It is now kept out of table structure.
|
|
20
|
+
- `prosemirror-changeset`'s default token encoder ignores node attributes, so a cell recolour
|
|
21
|
+
produced no change at all. An attribute-aware encoder now folds an allow-list of table-cell
|
|
22
|
+
attributes into the diff.
|
|
23
|
+
- The smart classifier discarded attribute changes on table cells because they sit on the node
|
|
24
|
+
boundary rather than inside the cell's content. It now emits a whole-cell change when a rigid
|
|
25
|
+
wrapper's own attributes differ.
|
|
26
|
+
|
|
27
|
+
- [`3fd2c0404aff0`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3fd2c0404aff0) -
|
|
28
|
+
Introduce a data-driven colour-scheme pattern for show-diff decorations: a `DiffColorScheme` type
|
|
29
|
+
(`types.ts`), shared CSS-generating functions (`factory.ts`) and the two scheme definitions
|
|
30
|
+
(`schemes.ts`).
|
|
31
|
+
|
|
32
|
+
Most scheme fields are ADS accent colour names; seven encode structural differences that no colour
|
|
33
|
+
can express (`insertUnderlineStyle`, `deletedQuoteNodeShape`, `deletedCellBorderProminence`,
|
|
34
|
+
`deletedRowTreatment`, `deletedBlockOutlineActiveEmphasis`, `addedCellOverlayZIndex`,
|
|
35
|
+
`roundedAddedCellOverlayInheritsBorder`), so a new scheme has to decide each of those too.
|
|
36
|
+
|
|
37
|
+
Additive only — nothing consumes the factory yet. `standard.ts` and `traditional.ts` are unchanged
|
|
38
|
+
and remain the source of every rendered style, so there is no behaviour or visual change. Wiring
|
|
39
|
+
the decoration consumers up behind a feature gate follows separately.
|
|
40
|
+
|
|
41
|
+
- Updated dependencies
|
|
42
|
+
|
|
3
43
|
## 12.1.3
|
|
4
44
|
|
|
5
45
|
### Patch Changes
|
package/compass.yml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
configVersion: 1
|
|
2
2
|
id: ari:cloud:compass:a436116f-02ce-4520-8fbb-7301462a1674:component/c5751cc6-3513-4070-9deb-af31e86aed34/1617e71c-fdf1-40c0-b143-03bf8d5a1648
|
|
3
3
|
name: '@atlaskit/editor-plugin-show-diff'
|
|
4
|
-
ownerId: ari:cloud:identity::team/
|
|
4
|
+
ownerId: ari:cloud:identity::team/cf6a670b-5252-4c68-a769-9207de366beb # Editor Developers
|
|
5
5
|
labels:
|
|
6
6
|
- platform-code
|
|
7
7
|
- platform-afm
|
|
@@ -16,14 +16,14 @@ links:
|
|
|
16
16
|
url: https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master
|
|
17
17
|
- name: Slack Channel
|
|
18
18
|
type: CHAT_CHANNEL
|
|
19
|
-
url: https://atlassian.enterprise.slack.com/archives/
|
|
19
|
+
url: https://atlassian.enterprise.slack.com/archives/CFG3PSQ9E # #help-editor
|
|
20
20
|
- name: Editor Plugin Show Diff
|
|
21
21
|
type: REPOSITORY
|
|
22
22
|
url: https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/editor/editor-plugin-show-diff
|
|
23
23
|
customFields:
|
|
24
24
|
- name: Department
|
|
25
25
|
type: text
|
|
26
|
-
value:
|
|
26
|
+
value: Editor Developers
|
|
27
27
|
- name: Trusted Reviewer Teams
|
|
28
28
|
type: text
|
|
29
29
|
value: ari:cloud:identity::team/cf6a670b-5252-4c68-a769-9207de366beb
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attrAwareTokenEncoder = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Attribute-aware token encoder for `prosemirror-changeset`.
|
|
9
|
+
*
|
|
10
|
+
* The library's default encoder reduces a node's open token to `node.type.name`,
|
|
11
|
+
* ignoring attributes. An attribute-only change (e.g. recolouring a table cell's
|
|
12
|
+
* `background`) therefore tokenises identically on both sides and reports no
|
|
13
|
+
* change at all.
|
|
14
|
+
*
|
|
15
|
+
* This encoder folds an allow-listed set of attributes into the open token so
|
|
16
|
+
* such changes register. Everything else encodes exactly as the default. The
|
|
17
|
+
* allow-list is deliberately narrow — folding in ephemeral attrs like `localId`
|
|
18
|
+
* would produce phantom diffs.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var DIFFED_ATTRS_BY_NODE_TYPE = {
|
|
22
|
+
tableCell: ['background', 'colspan', 'rowspan'],
|
|
23
|
+
tableHeader: ['background', 'colspan', 'rowspan']
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Builds a stable composite token. Iterates the allow-list rather than
|
|
28
|
+
* `Object.keys` so ordering is deterministic for string comparison.
|
|
29
|
+
*/
|
|
30
|
+
var encodeNodeWithAttrs = function encodeNodeWithAttrs(node, attrNames) {
|
|
31
|
+
var _node$attrs;
|
|
32
|
+
var attrs = (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 ? _node$attrs : {};
|
|
33
|
+
// Deterministic order: iterate the allow-list, not `Object.keys(attrs)`.
|
|
34
|
+
var parts = attrNames.map(function (name) {
|
|
35
|
+
var _attrs$name;
|
|
36
|
+
return "".concat(name, "=").concat(JSON.stringify((_attrs$name = attrs[name]) !== null && _attrs$name !== void 0 ? _attrs$name : null));
|
|
37
|
+
});
|
|
38
|
+
return "".concat(node.type.name, "|").concat(parts.join('|'));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Identical to the library default except that allow-listed node types encode
|
|
43
|
+
* their allow-listed attributes into the open token. Characters and node-end
|
|
44
|
+
* tokens are left as-is, hence the `string | number` token type.
|
|
45
|
+
*/
|
|
46
|
+
var attrAwareTokenEncoder = exports.attrAwareTokenEncoder = {
|
|
47
|
+
encodeCharacter: function encodeCharacter(char, _marks) {
|
|
48
|
+
return char;
|
|
49
|
+
},
|
|
50
|
+
encodeNodeStart: function encodeNodeStart(node) {
|
|
51
|
+
var attrNames = DIFFED_ATTRS_BY_NODE_TYPE[node.type.name];
|
|
52
|
+
if (attrNames) {
|
|
53
|
+
return encodeNodeWithAttrs(node, attrNames);
|
|
54
|
+
}
|
|
55
|
+
return node.type.name;
|
|
56
|
+
},
|
|
57
|
+
encodeNodeEnd: function encodeNodeEnd(node) {
|
|
58
|
+
return -typeID(node.type);
|
|
59
|
+
},
|
|
60
|
+
compareTokens: function compareTokens(a, b) {
|
|
61
|
+
return a === b;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Mirrors the library's private `typeID` so node-end tokens match the default
|
|
67
|
+
* encoding exactly. Reimplemented here because it is not exported.
|
|
68
|
+
*/
|
|
69
|
+
function typeID(type) {
|
|
70
|
+
var cache = type.schema.cached.changeSetIDs || (type.schema.cached.changeSetIDs = Object.create(null));
|
|
71
|
+
var id = cache[type.name];
|
|
72
|
+
if (id == null) {
|
|
73
|
+
cache[type.name] = id = Object.keys(type.schema.nodes).indexOf(type.name) + 1;
|
|
74
|
+
}
|
|
75
|
+
return id;
|
|
76
|
+
}
|
|
@@ -25,6 +25,7 @@ var _decorationKeys = require("../decorations/decorationKeys");
|
|
|
25
25
|
var _getAttrChangeRanges = require("../decorations/utils/getAttrChangeRanges");
|
|
26
26
|
var _getMarkChangeRanges = require("../decorations/utils/getMarkChangeRanges");
|
|
27
27
|
var _isExtendedEnabled = require("../isExtendedEnabled");
|
|
28
|
+
var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
28
29
|
var _diffBySteps = require("./diffBySteps");
|
|
29
30
|
var _groupChangesByBlock = require("./groupChangesByBlock");
|
|
30
31
|
var _optimizeChanges = require("./optimizeChanges");
|
|
@@ -237,7 +238,11 @@ var calculateDiffDecorationsInner = function calculateDiffDecorationsInner(_ref4
|
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
|
-
|
|
241
|
+
// The attribute-aware encoder is only needed by the smart classifier and is
|
|
242
|
+
// gated with it; other diff types keep the library default so their output is
|
|
243
|
+
// unchanged.
|
|
244
|
+
var tokenEncoder = diffType === 'smart' && (0, _platformFeatureFlags.fg)('platform_editor_ai_smart_diff') ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
|
|
245
|
+
var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, tr.doc);
|
|
241
246
|
var changes = getChanges({
|
|
242
247
|
changeset: changeset,
|
|
243
248
|
originalDoc: originalDoc,
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.computeDiffChanges = void 0;
|
|
7
7
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
8
|
+
var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
8
9
|
var _diffBySteps = require("./diffBySteps");
|
|
9
10
|
var _groupChangesByBlock = require("./groupChangesByBlock");
|
|
10
11
|
var _optimizeChanges = require("./optimizeChanges");
|
|
@@ -80,7 +81,13 @@ var computeDiffChanges = exports.computeDiffChanges = function computeDiffChange
|
|
|
80
81
|
newDoc: originalDoc
|
|
81
82
|
};
|
|
82
83
|
}
|
|
83
|
-
|
|
84
|
+
|
|
85
|
+
// The attribute-aware encoder only affects the `smart` classification, so it is
|
|
86
|
+
// applied only for that type. (This utility intentionally applies no feature
|
|
87
|
+
// gate — see the file docstring — but a caller requesting `smart` is already
|
|
88
|
+
// behind the smart-diff gate.)
|
|
89
|
+
var tokenEncoder = diffType === 'smart' ? _attrAwareTokenEncoder.attrAwareTokenEncoder : undefined;
|
|
90
|
+
var changeset = _prosemirrorChangeset.ChangeSet.create(originalDoc, undefined, tokenEncoder).addSteps(steppedDoc, stepMaps, steppedDoc);
|
|
84
91
|
if (diffType === 'smart') {
|
|
85
92
|
return {
|
|
86
93
|
changes: (0, _classifySmartChanges.classifySmartChanges)({
|
|
@@ -10,6 +10,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
10
10
|
var _prosemirrorChangeset = require("prosemirror-changeset");
|
|
11
11
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
12
12
|
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
13
|
+
var _attrAwareTokenEncoder = require("./attrAwareTokenEncoder");
|
|
13
14
|
var _optimizeChanges = require("./optimizeChanges");
|
|
14
15
|
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; }
|
|
15
16
|
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) { (0, _defineProperty2.default)(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; }
|
|
@@ -328,7 +329,7 @@ var diffBySteps = exports.diffBySteps = function diffBySteps(originalDoc, steps)
|
|
|
328
329
|
var fromB = mapPosition(afterStepToFinal, fromAfterStep);
|
|
329
330
|
var toB = mapPosition(afterStepToFinal, toAfterStep);
|
|
330
331
|
if (shouldCheckGranularDiff(rangedStep.step, rangedStep.before, rangedStep.from, rangedStep.to)) {
|
|
331
|
-
var granularStepChanges = _prosemirrorChangeset.ChangeSet.create(rangedStep.before).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
332
|
+
var granularStepChanges = _prosemirrorChangeset.ChangeSet.create(rangedStep.before, undefined, _attrAwareTokenEncoder.attrAwareTokenEncoder).addSteps(rangedStep.doc, [rangedStep.stepMap], null);
|
|
332
333
|
|
|
333
334
|
// `simplifyChanges` reads text using `Change.fromB`/`toB`, which are
|
|
334
335
|
// positions in the post-step doc (the "B" doc). Passing the pre-step
|
|
@@ -772,6 +772,15 @@ var _classifyChild = function classifyChild(childA, childB, changes, originalDoc
|
|
|
772
772
|
var childrenB = childRefs(blockB);
|
|
773
773
|
var childrenA = wrapperA ? childRefs(wrapperA) : [];
|
|
774
774
|
var out = [];
|
|
775
|
+
|
|
776
|
+
// An attribute-only change on the wrapper itself (e.g. a table cell's
|
|
777
|
+
// `background`) sits on the node boundary, not inside any inner child, so the
|
|
778
|
+
// recursion below would emit nothing and the change would be dropped. Emit a
|
|
779
|
+
// whole-wrapper change instead, which also subsumes any inner content change.
|
|
780
|
+
if (wrapperA && !wrapperA.node.sameMarkup(blockB.node)) {
|
|
781
|
+
out.push((0, _helpers.makePromotedChange)(wrapperA.from, wrapperA.to, blockB.from, blockB.to, 'node'));
|
|
782
|
+
return out;
|
|
783
|
+
}
|
|
775
784
|
// LCS-align inner children (mirrors classifyContainer) so a paragraph inserted/deleted
|
|
776
785
|
// inside the cell/column does not mis-pair every subsequent inner child by index. We never
|
|
777
786
|
// promote the wrapper itself here — we only classify each inner child.
|