@atlaskit/editor-plugin-show-diff 10.5.0 → 10.5.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.
Files changed (27) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +30 -3
  3. package/dist/cjs/pm-plugins/decorations/colorSchemes/standard.js +14 -1
  4. package/dist/cjs/pm-plugins/decorations/colorSchemes/traditional.js +15 -2
  5. package/dist/cjs/pm-plugins/decorations/createAnchorDecorationWidgets.js +52 -18
  6. package/dist/cjs/pm-plugins/decorations/createBlockChangedDecoration.js +6 -1
  7. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +23 -4
  8. package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +64 -4
  9. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +30 -3
  10. package/dist/es2019/pm-plugins/decorations/colorSchemes/standard.js +13 -0
  11. package/dist/es2019/pm-plugins/decorations/colorSchemes/traditional.js +14 -1
  12. package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +60 -28
  13. package/dist/es2019/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
  14. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +16 -1
  15. package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +53 -4
  16. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +30 -3
  17. package/dist/esm/pm-plugins/decorations/colorSchemes/standard.js +13 -0
  18. package/dist/esm/pm-plugins/decorations/colorSchemes/traditional.js +14 -1
  19. package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +51 -18
  20. package/dist/esm/pm-plugins/decorations/createBlockChangedDecoration.js +8 -3
  21. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +23 -4
  22. package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +63 -4
  23. package/dist/types/pm-plugins/decorations/colorSchemes/standard.d.ts +1 -0
  24. package/dist/types/pm-plugins/decorations/colorSchemes/traditional.d.ts +2 -1
  25. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +4 -1
  26. package/dist/types/pm-plugins/decorations/utils/getAttrChangeRanges.d.ts +11 -1
  27. package/package.json +7 -7
@@ -1,5 +1,9 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
2
5
  import { AttrStep } from '@atlaskit/editor-prosemirror/transform';
6
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
3
7
  var filterUndefined = function filterUndefined(x) {
4
8
  return !!x;
5
9
  };
@@ -13,6 +17,26 @@ var dateAttrs = ['timestamp'];
13
17
  // Attribute that indicates a task item state change
14
18
  var taskItemAttrs = ['state'];
15
19
 
20
+ // Attributes that indicate an emoji change
21
+ var emojiAttrs = ['shortName', 'id', 'text'];
22
+
23
+ // Attributes that indicate a mention change (who is mentioned)
24
+ var mentionAttrs = ['id', 'text'];
25
+
26
+ // Attributes that indicate a status change (label or colour)
27
+ var statusAttrs = ['text', 'color'];
28
+
29
+ // Map of node type name → the attrs that represent a meaningful content change for that node
30
+ var inlineNodeAttrMap = {
31
+ date: dateAttrs,
32
+ emoji: emojiAttrs,
33
+ mention: mentionAttrs,
34
+ status: statusAttrs
35
+ };
36
+ var isInlineAttrChangeNodeName = function isInlineAttrChangeNodeName(nodeName) {
37
+ return nodeName in inlineNodeAttrMap;
38
+ };
39
+
16
40
  // Attributes excluded from extension change detection (not meaningful content changes)
17
41
  var extensionExcludedAttrs = ['localId'];
18
42
 
@@ -27,7 +51,7 @@ var getStepAttrs = function getStepAttrs(step) {
27
51
  }
28
52
  return [];
29
53
  };
30
- export var getAttrChangeRanges = function getAttrChangeRanges(doc, steps) {
54
+ export var getAttrChangeRanges = function getAttrChangeRanges(doc, steps, originalDoc) {
31
55
  return steps.map(function (step) {
32
56
  if (!(step instanceof AttrStep) && !(step instanceof SetAttrsStep)) {
33
57
  return undefined;
@@ -39,14 +63,39 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, steps) {
39
63
  // date node: timestamp attribute change — highlight the date node itself (inline)
40
64
  if (stepAttrs.some(function (v) {
41
65
  return dateAttrs.includes(v);
42
- }) && (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type.name) === 'date') {
66
+ }) && (nodeAtPos === null || nodeAtPos === void 0 ? void 0 : nodeAtPos.type.name) === 'date' && !expValEquals('platform_editor_improve_inline_diffs', 'isEnabled', true)) {
43
67
  return {
44
68
  fromB: step.pos,
45
69
  toB: step.pos + nodeAtPos.nodeSize,
46
- isInline: true
70
+ isInline: true,
71
+ inlineNodeName: 'date'
47
72
  };
48
73
  }
49
74
 
75
+ // The following inline node attr changes are gated behind platform_editor_improve_inline_diffs.
76
+ // The changeset path (createDecorationsForChange) handles the deletion widget via
77
+ // prosemirror-changeset; we only need to add the inline insertion highlight here.
78
+ if (expValEquals('platform_editor_improve_inline_diffs', 'isEnabled', true) && nodeAtPos) {
79
+ var nodeName = nodeAtPos.type.name;
80
+ if (isInlineAttrChangeNodeName(nodeName)) {
81
+ var watchedAttrs = inlineNodeAttrMap[nodeName];
82
+ if (stepAttrs.some(function (v) {
83
+ return watchedAttrs.includes(v);
84
+ })) {
85
+ var originalNodeAtPos = originalDoc === null || originalDoc === void 0 ? void 0 : originalDoc.nodeAt(step.pos);
86
+ return _objectSpread({
87
+ fromB: step.pos,
88
+ toB: step.pos + nodeAtPos.nodeSize,
89
+ isInline: true,
90
+ inlineNodeName: nodeName
91
+ }, originalNodeAtPos && {
92
+ fromA: step.pos,
93
+ toA: step.pos + originalNodeAtPos.nodeSize
94
+ });
95
+ }
96
+ }
97
+ }
98
+
50
99
  // taskItem node: state attribute change — highlight the taskItem node
51
100
  if (stepAttrs.some(function (v) {
52
101
  return taskItemAttrs.includes(v);
@@ -80,7 +129,17 @@ export var getAttrChangeRanges = function getAttrChangeRanges(doc, steps) {
80
129
  };
81
130
  }
82
131
  return undefined;
83
- }).filter(filterUndefined);
132
+ }).filter(filterUndefined)
133
+ // Deduplicate by node position: multiple AttrSteps on the same node
134
+ // (e.g. setNodeAttribute(pos, 'text', ...) + setNodeAttribute(pos, 'color', ...))
135
+ // should produce only one decoration, not one per step.
136
+ // Gated behind the same experiment as the inline node attr changes that introduced
137
+ // the possibility of multiple ranges for the same node position.
138
+ .filter(function (range, i, arr) {
139
+ return !expValEquals('platform_editor_improve_inline_diffs', 'isEnabled', true) || arr.findIndex(function (r) {
140
+ return r.fromB === range.fromB;
141
+ }) === i;
142
+ });
84
143
  };
85
144
 
86
145
  /**
@@ -38,3 +38,4 @@ export declare const standardDecorationMarkerVariable: string;
38
38
  export declare const deletedDecorationMarkerVariable: string;
39
39
  export declare const addedCellOverlayStyle: string;
40
40
  export declare const deletedCellOverlayStyle: string;
41
+ export declare const deletedCellOverlayRoundedStyle: string;
@@ -11,7 +11,7 @@ export declare const deletedTraditionalBlockOutline: string;
11
11
  export declare const deletedTraditionalBlockOutlineActive: string;
12
12
  export declare const deletedTraditionalBlockOutlineRounded: string;
13
13
  export declare const deletedTraditionalBlockOutlineRoundedActive: string;
14
- /** Scroll-navigation “new” emphasis: 4px ring (see {@link traditionalStyleNodeNew}). */
14
+ /** Scroll-navigation “new” emphasis: 4px ring. */
15
15
  export declare const deletedTraditionalBlockOutlineNew: string;
16
16
  export declare const deletedTraditionalBlockOutlineRoundedNew: string;
17
17
  export declare const deletedTraditionalRowStyle: string;
@@ -37,3 +37,4 @@ export declare const traditionalDeletedDecorationMarkerVariableActive: string;
37
37
  export declare const traditionalAddedCellOverlayStyle: string;
38
38
  export declare const traditionalAddedCellOverlayStyleNew: string;
39
39
  export declare const deletedTraditionalCellOverlayStyle: string;
40
+ export declare const deletedTraditionalCellOverlayRoundedStyle: string;
@@ -1,13 +1,14 @@
1
1
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
3
  import type { ColorScheme, DiffType } from '../../showDiffPluginType';
4
+ import type { InlineAttrChangeNodeName } from './utils/getAttrChangeRanges';
4
5
  /**
5
6
  * Inline decoration used for insertions as the content already exists in the document
6
7
  *
7
8
  * @param change Changeset "change" containing information about the change content + range
8
9
  * @returns Prosemirror inline decoration
9
10
  */
10
- export declare const createInlineChangedDecoration: ({ change, colorScheme, isActive, isInserted, shouldHideDeleted, showIndicators, doc, diffType, hideAddedDiffsUnderline, }: {
11
+ export declare const createInlineChangedDecoration: ({ change, colorScheme, isActive, isInserted, isAtomicInlineNode, shouldHideDeleted, showIndicators, doc, diffType, hideAddedDiffsUnderline, inlineNodeName, }: {
11
12
  change: {
12
13
  fromB: number;
13
14
  toB: number;
@@ -16,7 +17,9 @@ export declare const createInlineChangedDecoration: ({ change, colorScheme, isAc
16
17
  diffType?: DiffType;
17
18
  doc?: PMNode;
18
19
  hideAddedDiffsUnderline?: boolean;
20
+ inlineNodeName?: InlineAttrChangeNodeName;
19
21
  isActive?: boolean;
22
+ isAtomicInlineNode?: boolean;
20
23
  isInserted?: boolean;
21
24
  shouldHideDeleted?: boolean;
22
25
  showIndicators?: boolean;
@@ -1,12 +1,22 @@
1
1
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  import { type Step as ProseMirrorStep } from '@atlaskit/editor-prosemirror/transform';
3
+ export type InlineAttrChangeNodeName = 'date' | 'emoji' | 'mention' | 'status';
3
4
  type StepRange = {
5
+ /**
6
+ * Position of the original (before) node in the original doc.
7
+ * Populated for inline attr changes (e.g. emoji, date) so the caller can
8
+ * render the old node as a "deleted" widget alongside the new highlighted node.
9
+ */
10
+ fromA?: number;
4
11
  fromB: number;
12
+ /** Inline node type, used by callers that need node-view-specific styling. */
13
+ inlineNodeName?: InlineAttrChangeNodeName;
5
14
  /** Whether the changed node is inline (true) or block (false/undefined) */
6
15
  isInline?: boolean;
16
+ toA?: number;
7
17
  toB: number;
8
18
  };
9
- export declare const getAttrChangeRanges: (doc: PMNode, steps: ProseMirrorStep[]) => StepRange[];
19
+ export declare const getAttrChangeRanges: (doc: PMNode, steps: ProseMirrorStep[], originalDoc: PMNode) => StepRange[];
10
20
  /**
11
21
  * Check if the step was a valid attr change and affected the doc
12
22
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-show-diff",
3
- "version": "10.5.0",
3
+ "version": "10.5.2",
4
4
  "description": "ShowDiff plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -28,10 +28,10 @@
28
28
  "@atlaskit/editor-prosemirror": "^8.0.0",
29
29
  "@atlaskit/editor-tables": "^3.0.0",
30
30
  "@atlaskit/platform-feature-flags": "^2.1.0",
31
- "@atlaskit/tmp-editor-statsig": "^130.2.0",
32
- "@atlaskit/tokens": "^16.1.0",
31
+ "@atlaskit/tmp-editor-statsig": "^132.0.0",
32
+ "@atlaskit/tokens": "^16.2.0",
33
33
  "@babel/runtime": "^7.0.0",
34
- "@compiled/react": "^0.22.2",
34
+ "@compiled/react": "^1.0.0",
35
35
  "lodash": "^4.17.21",
36
36
  "memoize-one": "^6.0.0",
37
37
  "prosemirror-changeset": "^2.3.1"
@@ -41,10 +41,10 @@
41
41
  "@atlaskit/button": "^24.3.0",
42
42
  "@atlaskit/css": "^1.0.0",
43
43
  "@atlaskit/dropdown-menu": "^17.1.0",
44
- "@atlaskit/editor-core": "^221.10.0",
44
+ "@atlaskit/editor-core": "^221.12.0",
45
45
  "@atlaskit/editor-json-transformer": "^9.0.0",
46
46
  "@atlaskit/form": "^16.1.0",
47
- "@atlaskit/primitives": "^22.0.0",
47
+ "@atlaskit/primitives": "^22.1.0",
48
48
  "@atlaskit/section-message": "^9.2.0",
49
49
  "@atlaskit/textarea": "^9.1.0",
50
50
  "@atlassian/confluence-presets": "workspace:^",
@@ -54,7 +54,7 @@
54
54
  "react-intl": "^7.0.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "@atlaskit/editor-common": "^116.34.0",
57
+ "@atlaskit/editor-common": "^116.35.0",
58
58
  "react": "^18.2.0"
59
59
  },
60
60
  "techstack": {