@atlaskit/editor-plugin-show-diff 14.3.2 → 14.4.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/afm-cc/tsconfig.json +18 -0
  3. package/afm-products/tsconfig.json +18 -0
  4. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +47 -26
  5. package/dist/cjs/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +61 -9
  6. package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +77 -20
  7. package/dist/cjs/pm-plugins/decorations/colorSchemes/factory.js +10 -0
  8. package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +2 -0
  9. package/dist/cjs/pm-plugins/decorations/createAnchorDecorationWidgets.js +52 -7
  10. package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +172 -0
  11. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +37 -5
  12. package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +40 -7
  13. package/dist/cjs/pm-plugins/decorations/decorationKeys.js +31 -5
  14. package/dist/cjs/pm-plugins/decorations/extractContributorTags.js +128 -0
  15. package/dist/cjs/pm-plugins/main.js +57 -6
  16. package/dist/cjs/pm-plugins/resolveDiffContributors.js +143 -0
  17. package/dist/cjs/showDiffPlugin.js +21 -6
  18. package/dist/cjs/ui/ContributorTag/ContributorTag.compiled.css +29 -0
  19. package/dist/cjs/ui/ContributorTag/ContributorTag.js +383 -0
  20. package/dist/cjs/ui/ContributorTag/ContributorTagWidget.js +50 -0
  21. package/dist/cjs/ui/ContributorTag/messages.js +24 -0
  22. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +48 -27
  23. package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +39 -0
  24. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +53 -11
  25. package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +9 -0
  26. package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +2 -0
  27. package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +43 -1
  28. package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +163 -0
  29. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +38 -5
  30. package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +38 -6
  31. package/dist/es2019/pm-plugins/decorations/decorationKeys.js +30 -2
  32. package/dist/es2019/pm-plugins/decorations/extractContributorTags.js +101 -0
  33. package/dist/es2019/pm-plugins/main.js +52 -3
  34. package/dist/es2019/pm-plugins/resolveDiffContributors.js +128 -0
  35. package/dist/es2019/showDiffPlugin.js +20 -5
  36. package/dist/es2019/ui/ContributorTag/ContributorTag.compiled.css +29 -0
  37. package/dist/es2019/ui/ContributorTag/ContributorTag.js +312 -0
  38. package/dist/es2019/ui/ContributorTag/ContributorTagWidget.js +43 -0
  39. package/dist/es2019/ui/ContributorTag/messages.js +18 -0
  40. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +49 -28
  41. package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +60 -8
  42. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +77 -19
  43. package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +9 -0
  44. package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +2 -0
  45. package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +51 -6
  46. package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +166 -0
  47. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +37 -5
  48. package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +40 -7
  49. package/dist/esm/pm-plugins/decorations/decorationKeys.js +30 -5
  50. package/dist/esm/pm-plugins/decorations/extractContributorTags.js +122 -0
  51. package/dist/esm/pm-plugins/main.js +57 -6
  52. package/dist/esm/pm-plugins/resolveDiffContributors.js +137 -0
  53. package/dist/esm/showDiffPlugin.js +21 -6
  54. package/dist/esm/ui/ContributorTag/ContributorTag.compiled.css +29 -0
  55. package/dist/esm/ui/ContributorTag/ContributorTag.js +375 -0
  56. package/dist/esm/ui/ContributorTag/ContributorTagWidget.js +43 -0
  57. package/dist/esm/ui/ContributorTag/messages.js +18 -0
  58. package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
  59. package/dist/types/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +7 -1
  60. package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +10 -0
  61. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +24 -2
  62. package/dist/types/pm-plugins/decorations/colorSchemes/factory.d.ts +7 -1
  63. package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +1 -2
  64. package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +2 -1
  65. package/dist/types/pm-plugins/decorations/createAnchorDecorationWidgets.d.ts +14 -0
  66. package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +55 -0
  67. package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +5 -1
  68. package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +5 -1
  69. package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +28 -3
  70. package/dist/types/pm-plugins/decorations/extractContributorTags.d.ts +9 -0
  71. package/dist/types/pm-plugins/main.d.ts +8 -2
  72. package/dist/types/pm-plugins/resolveDiffContributors.d.ts +7 -0
  73. package/dist/types/showDiffPluginType.d.ts +65 -2
  74. package/dist/types/ui/ContributorTag/ContributorTag.d.ts +37 -0
  75. package/dist/types/ui/ContributorTag/ContributorTagWidget.d.ts +22 -0
  76. package/dist/types/ui/ContributorTag/messages.d.ts +6 -0
  77. package/package.json +16 -7
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.extractContributorTags = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _decorationKeys = require("./decorationKeys");
12
+ var _excluded = ["connectedToKey"];
13
+ 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; }
14
+ 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; }
15
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
16
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
17
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
+ /**
19
+ * Diff kinds that expose an anchor a tag can be pinned to: `inline` is added/changed content,
20
+ * `widget` is deleted content. Block diffs carry no attribution.
21
+ */
22
+ var TAGGABLE_DECORATION_TYPES = new Set(['inline', 'widget']);
23
+
24
+ /** The connection is an internal key, so it is dropped on the way to the tag. */
25
+ var toTagContributor = function toTagContributor(_ref) {
26
+ var _connectedToKey = _ref.connectedToKey,
27
+ tagContributor = (0, _objectWithoutProperties2.default)(_ref, _excluded);
28
+ return tagContributor;
29
+ };
30
+ /**
31
+ * Whether a deleted-content widget belongs to the same change as an inline decoration. A replacement
32
+ * renders both — the inserted text inline, the deleted text as a widget anchored to one end of that
33
+ * inline range — and the two must not each claim a tag.
34
+ */
35
+ var isSameChange = function isSameChange(widget, inline) {
36
+ return widget.spec.attributionKey === inline.spec.attributionKey && widget.from >= inline.from && widget.from <= inline.to;
37
+ };
38
+
39
+ /**
40
+ * One model per diff decoration whose attribution resolves to a supplied contributor; anything
41
+ * unattributed, untaggable or unresolved is skipped. A replacement's two decorations are collapsed
42
+ * into the single inline tag — see `isSameChange`.
43
+ */
44
+ var extractContributorTags = exports.extractContributorTags = function extractContributorTags(decorations, contributors) {
45
+ if (!contributors) {
46
+ return [];
47
+ }
48
+ var targets = [];
49
+ var _iterator = _createForOfIteratorHelper(decorations.find(undefined, undefined, _decorationKeys.isDiffDecorationSpec)),
50
+ _step;
51
+ try {
52
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
53
+ var decoration = _step.value;
54
+ if (!(0, _decorationKeys.isDiffDecoration)(decoration)) {
55
+ continue;
56
+ }
57
+ var spec = decoration.spec;
58
+ if (!spec.attributionKey || !TAGGABLE_DECORATION_TYPES.has(spec.decorationType)) {
59
+ continue;
60
+ }
61
+ var contributor = contributors[spec.attributionKey];
62
+ if (!contributor) {
63
+ continue;
64
+ }
65
+ targets.push({
66
+ contributor: contributor,
67
+ decoration: decoration
68
+ });
69
+ }
70
+
71
+ // The inline decoration keeps the tag: it captions content still in the document.
72
+ } catch (err) {
73
+ _iterator.e(err);
74
+ } finally {
75
+ _iterator.f();
76
+ }
77
+ var inlineTargets = targets.filter(function (_ref2) {
78
+ var decoration = _ref2.decoration;
79
+ return decoration.spec.decorationType === 'inline';
80
+ });
81
+ var linkedDiffIds = new Map();
82
+ var folded = new Set();
83
+ var _loop = function _loop() {
84
+ var _linkedDiffIds$get;
85
+ var target = _targets[_i];
86
+ if (target.decoration.spec.decorationType !== 'widget') {
87
+ return 0; // continue
88
+ }
89
+ var host = inlineTargets.find(function (_ref3) {
90
+ var decoration = _ref3.decoration;
91
+ return isSameChange(target.decoration, decoration);
92
+ });
93
+ if (!host) {
94
+ return 0; // continue
95
+ }
96
+ folded.add(target);
97
+ var hostDiffId = host.decoration.spec.diffId;
98
+ linkedDiffIds.set(hostDiffId, [].concat((0, _toConsumableArray2.default)((_linkedDiffIds$get = linkedDiffIds.get(hostDiffId)) !== null && _linkedDiffIds$get !== void 0 ? _linkedDiffIds$get : []), [target.decoration.spec.diffId]));
99
+ },
100
+ _ret;
101
+ for (var _i = 0, _targets = targets; _i < _targets.length; _i++) {
102
+ _ret = _loop();
103
+ if (_ret === 0) continue;
104
+ }
105
+ return targets.filter(function (target) {
106
+ return !folded.has(target);
107
+ }).map(function (_ref4) {
108
+ var contributor = _ref4.contributor,
109
+ spec = _ref4.decoration.spec;
110
+ var connected = contributor.connectedToKey ? contributors[contributor.connectedToKey] : undefined;
111
+ var connectedContributor = connected ? toTagContributor(connected) : undefined;
112
+ var linked = linkedDiffIds.get(spec.diffId);
113
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
114
+ contributor: toTagContributor(contributor),
115
+ diffId: spec.diffId
116
+ }, connectedContributor ? {
117
+ connectedContributor: connectedContributor
118
+ } : {}), spec.colorScheme ? {
119
+ colorScheme: spec.colorScheme
120
+ } : {}), spec.isActive !== undefined ? {
121
+ isActive: spec.isActive
122
+ } : {}), spec.isInserted !== undefined ? {
123
+ isInserted: spec.isInserted
124
+ } : {}), linked ? {
125
+ linkedDiffIds: linked
126
+ } : {});
127
+ });
128
+ };
@@ -13,6 +13,7 @@ var _state2 = require("@atlaskit/editor-prosemirror/state");
13
13
  var _transformOverride = require("@atlaskit/editor-prosemirror/transform-override");
14
14
  var _view = require("@atlaskit/editor-prosemirror/view");
15
15
  var _calculateDiffDecorations = require("./calculateDiff/calculateDiffDecorations");
16
+ var _decorationKeys = require("./decorations/decorationKeys");
16
17
  var _enforceCustomStepRegisters = require("./enforceCustomStepRegisters");
17
18
  var _getScrollableDecorations = require("./getScrollableDecorations");
18
19
  var _isExtendedEnabled = require("./isExtendedEnabled");
@@ -21,7 +22,26 @@ var _scrollToDiff = require("./scrollToDiff");
21
22
  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; }
22
23
  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; }
23
24
  var showDiffPluginKey = exports.showDiffPluginKey = new _state2.PluginKey('showDiffPlugin');
24
- var createPlugin = exports.createPlugin = function createPlugin(config, getIntl, api, onEditorView) {
25
+ /**
26
+ * Tags whose diff decoration survived the transaction. A document change can map a decoration away
27
+ * without any `showDiff`/`hideDiff` following it, and a tag left behind has no host to render into.
28
+ * Returns the given array when every tag is still live.
29
+ */
30
+ var dropOrphanedContributorTags = function dropOrphanedContributorTags(contributorTags, decorations) {
31
+ if (!(contributorTags !== null && contributorTags !== void 0 && contributorTags.length)) {
32
+ return contributorTags;
33
+ }
34
+ var liveDiffIds = new Set(decorations.find(undefined, undefined, _decorationKeys.isDiffDecorationSpec).filter(_decorationKeys.isDiffDecoration).map(function (_ref) {
35
+ var spec = _ref.spec;
36
+ return spec.diffId;
37
+ }));
38
+ var liveTags = contributorTags.filter(function (_ref2) {
39
+ var diffId = _ref2.diffId;
40
+ return liveDiffIds.has(diffId);
41
+ });
42
+ return liveTags.length === contributorTags.length ? contributorTags : liveTags;
43
+ };
44
+ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl, api, portalProviderAPI, onEditorView) {
25
45
  (0, _enforceCustomStepRegisters.enforceCustomStepRegisters)();
26
46
  var nodeViewSerializer = new _NodeViewSerializer.NodeViewSerializer({});
27
47
  var setNodeViewSerializer = function setNodeViewSerializer(editorView) {
@@ -29,6 +49,23 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
29
49
  editorView: editorView
30
50
  });
31
51
  };
52
+
53
+ /**
54
+ * This editor's own content root. The contributor tags scope every DOM lookup to it, so they take
55
+ * it from the view the plugin was mounted on rather than resolving `.ProseMirror` by class name
56
+ * from a decoration — a class this package does not own, and one whose nearest match is the wrong
57
+ * editor whenever editors are nested. A getter because the view arrives with the ProseMirror view
58
+ * lifecycle, which decorations are calculated independently of.
59
+ */
60
+ var currentEditorView;
61
+ var tagMountContext = portalProviderAPI ? {
62
+ api: api,
63
+ getEditorRoot: function getEditorRoot() {
64
+ var _currentEditorView$do, _currentEditorView;
65
+ return (_currentEditorView$do = (_currentEditorView = currentEditorView) === null || _currentEditorView === void 0 ? void 0 : _currentEditorView.dom) !== null && _currentEditorView$do !== void 0 ? _currentEditorView$do : null;
66
+ },
67
+ portalProviderAPI: portalProviderAPI
68
+ } : undefined;
32
69
  return new _safePlugin.SafePlugin({
33
70
  key: showDiffPluginKey,
34
71
  state: {
@@ -69,7 +106,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
69
106
  colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
70
107
  intl: getIntl(),
71
108
  activeIndexPos: newPluginState.activeIndexPos,
72
- api: api
109
+ api: api,
110
+ tagMountContext: tagMountContext
73
111
  }, (0, _isExtendedEnabled.isExtendedEnabled)((_newPluginState = newPluginState) === null || _newPluginState === void 0 ? void 0 : _newPluginState.diffType) ? {
74
112
  isInverted: (_newPluginState2 = newPluginState) === null || _newPluginState2 === void 0 ? void 0 : _newPluginState2.isInverted,
75
113
  diffType: (_newPluginState3 = newPluginState) === null || _newPluginState3 === void 0 ? void 0 : _newPluginState3.diffType,
@@ -80,10 +118,12 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
80
118
  deletedDiffPlacement: (_newPluginState8 = newPluginState) === null || _newPluginState8 === void 0 ? void 0 : _newPluginState8.deletedDiffPlacement,
81
119
  inlineDeletedDiffPlacement: (_newPluginState9 = newPluginState) === null || _newPluginState9 === void 0 ? void 0 : _newPluginState9.inlineDeletedDiffPlacement
82
120
  } : {})),
121
+ contributorTags = _calculateDiffDecorat.contributorTags,
83
122
  decorations = _calculateDiffDecorat.decorations,
84
123
  diffDescriptors = _calculateDiffDecorat.diffDescriptors;
85
124
  // Update the decorations and their ids
86
125
  newPluginState.decorations = decorations;
126
+ newPluginState.contributorTags = contributorTags;
87
127
  if ((0, _isExtendedEnabled.isExtendedEnabled)((_newPluginState0 = newPluginState) === null || _newPluginState0 === void 0 ? void 0 : _newPluginState0.diffType)) {
88
128
  newPluginState.diffDescriptors = diffDescriptors;
89
129
  }
@@ -91,7 +131,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
91
131
  newPluginState = _objectSpread(_objectSpread(_objectSpread({}, currentPluginState), meta), {}, {
92
132
  decorations: _view.DecorationSet.empty,
93
133
  isDisplayingChanges: false,
94
- activeIndex: undefined
134
+ activeIndex: undefined,
135
+ contributorTags: []
95
136
  }, (0, _isExtendedEnabled.isExtendedEnabled)(currentPluginState.diffType) ? {
96
137
  isInverted: false,
97
138
  diffType: (0, _isExtendedEnabled.getDefaultDiffType)(),
@@ -135,7 +176,8 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
135
176
  colorScheme: config === null || config === void 0 ? void 0 : config.colorScheme,
136
177
  intl: getIntl(),
137
178
  activeIndexPos: newPluginState.activeIndexPos,
138
- api: api
179
+ api: api,
180
+ tagMountContext: tagMountContext
139
181
  }, (0, _isExtendedEnabled.isExtendedEnabled)(newPluginState.diffType) ? {
140
182
  isInverted: newPluginState.isInverted,
141
183
  diffType: newPluginState.diffType,
@@ -146,9 +188,11 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
146
188
  deletedDiffPlacement: newPluginState.deletedDiffPlacement,
147
189
  inlineDeletedDiffPlacement: newPluginState.inlineDeletedDiffPlacement
148
190
  } : {})),
191
+ updatedContributorTags = _calculateDiffDecorat2.contributorTags,
149
192
  updatedDecorations = _calculateDiffDecorat2.decorations,
150
193
  updatedDiffDescriptors = _calculateDiffDecorat2.diffDescriptors;
151
194
  newPluginState.decorations = updatedDecorations;
195
+ newPluginState.contributorTags = updatedContributorTags;
152
196
  if ((0, _isExtendedEnabled.isExtendedEnabled)(newPluginState.diffType)) {
153
197
  newPluginState.diffDescriptors = updatedDiffDescriptors;
154
198
  }
@@ -157,13 +201,19 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
157
201
  newPluginState = _objectSpread(_objectSpread({}, currentPluginState), meta);
158
202
  }
159
203
  }
160
- return _objectSpread(_objectSpread({}, newPluginState), {}, {
161
- decorations: newPluginState.decorations.map(tr.mapping, tr.doc)
204
+ var mappedDecorations = newPluginState.decorations.map(tr.mapping, tr.doc);
205
+ var nextState = _objectSpread(_objectSpread({}, newPluginState), {}, {
206
+ decorations: mappedDecorations
162
207
  });
208
+ if (tr.docChanged) {
209
+ nextState.contributorTags = dropOrphanedContributorTags(newPluginState.contributorTags, mappedDecorations);
210
+ }
211
+ return nextState;
163
212
  }
164
213
  },
165
214
  view: function view(editorView) {
166
215
  setNodeViewSerializer(editorView);
216
+ currentEditorView = editorView;
167
217
  onEditorView === null || onEditorView === void 0 || onEditorView(editorView);
168
218
  var isFirst = true;
169
219
  var previousActiveIndex;
@@ -217,6 +267,7 @@ var createPlugin = exports.createPlugin = function createPlugin(config, getIntl,
217
267
  var _cancelPendingScrollT3;
218
268
  (_cancelPendingScrollT3 = cancelPendingScrollToDecoration) === null || _cancelPendingScrollT3 === void 0 || _cancelPendingScrollT3();
219
269
  cancelPendingScrollToDecoration = null;
270
+ currentEditorView = undefined;
220
271
  onEditorView === null || onEditorView === void 0 || onEditorView(undefined);
221
272
  }
222
273
  };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.resolveDiffContributors = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _attributions = require("./decorations/colorSchemes/attributions");
10
+ 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; }
11
+ 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; }
12
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
13
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ /** A brand name, so a literal rather than a translated message. */
16
+ var ROVO_AGENT_NAME = 'Rovo';
17
+
18
+ /** `agentType` values that render as "Rovo" rather than as a generic external agent. */
19
+ var ROVO_AGENT_TYPES = new Set(['convo-ai', 'rovo_chat']);
20
+ var hasAgentIdentity = function hasAgentIdentity(attribution) {
21
+ var _attribution$agentId, _attribution$agentTyp;
22
+ return Boolean(((_attribution$agentId = attribution.agentId) === null || _attribution$agentId === void 0 ? void 0 : _attribution$agentId.trim()) || ((_attribution$agentTyp = attribution.agentType) === null || _attribution$agentTyp === void 0 ? void 0 : _attribution$agentTyp.trim()));
23
+ };
24
+ var toProfilesByAccountId = function toProfilesByAccountId(profiles) {
25
+ var profilesByAccountId = new Map();
26
+ profiles === null || profiles === void 0 || profiles.forEach(function (profile) {
27
+ // Trimmed to match how attribution ids are keyed, so the two sides compare like for like.
28
+ var accountId = profile.accountId.trim();
29
+ if (accountId && !profilesByAccountId.has(accountId)) {
30
+ profilesByAccountId.set(accountId, profile);
31
+ }
32
+ });
33
+ return profilesByAccountId;
34
+ };
35
+ var resolveUser = function resolveUser(userId, profilesByAccountId) {
36
+ var profile = profilesByAccountId.get(userId);
37
+ return profile ? {
38
+ avatarUrl: profile.avatarUrl,
39
+ kind: 'user',
40
+ name: profile.name
41
+ } : undefined;
42
+ };
43
+
44
+ /** An agent always resolves: its profile, else "Rovo" for a first-party type, else external. */
45
+ var resolveAgent = function resolveAgent(attribution, profilesByAccountId) {
46
+ var _attribution$agentId2, _attribution$agentTyp2;
47
+ var agentId = (_attribution$agentId2 = attribution.agentId) === null || _attribution$agentId2 === void 0 ? void 0 : _attribution$agentId2.trim();
48
+ var agentProfile = agentId ? profilesByAccountId.get(agentId) : undefined;
49
+ if (agentProfile) {
50
+ return {
51
+ agentKind: 'identified',
52
+ avatarUrl: agentProfile.avatarUrl,
53
+ kind: 'agent',
54
+ name: agentProfile.name
55
+ };
56
+ }
57
+ var agentType = (_attribution$agentTyp2 = attribution.agentType) === null || _attribution$agentTyp2 === void 0 ? void 0 : _attribution$agentTyp2.trim().toLowerCase();
58
+
59
+ // An empty name lets the tag fall back to its own localised "External agent" label.
60
+ return agentType && ROVO_AGENT_TYPES.has(agentType) ? {
61
+ agentKind: 'rovo',
62
+ kind: 'agent',
63
+ name: ROVO_AGENT_NAME
64
+ } : {
65
+ agentKind: 'external',
66
+ kind: 'agent',
67
+ name: ''
68
+ };
69
+ };
70
+
71
+ /**
72
+ * One contributor per distinct actor behind the attributed steps, resolved against the identities
73
+ * the consumer supplied. Returns `undefined` if any actor cannot be named: a half-credited diff
74
+ * reads as "nobody touched this", so the whole list is dropped and the plain diff renders instead.
75
+ */
76
+ var resolveDiffContributors = exports.resolveDiffContributors = function resolveDiffContributors(stepsWithAttribution, profiles) {
77
+ var profilesByAccountId = toProfilesByAccountId(profiles);
78
+ var contributors = [];
79
+ /** Keyed as the plugin keys changes, so no two entries can collapse onto one another. */
80
+ var creditedActors = new Set();
81
+ var _iterator = _createForOfIteratorHelper(stepsWithAttribution),
82
+ _step;
83
+ try {
84
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
85
+ var _stepAttribution$user;
86
+ var stepAttribution = _step.value.stepAttribution;
87
+ // An attribution naming nobody (e.g. one carrying only `wasOffline`) has nobody to credit.
88
+ var actor = stepAttribution ? (0, _attributions.getAttributionKey)(stepAttribution) : undefined;
89
+ if (!stepAttribution || !actor || creditedActors.has(actor)) {
90
+ continue;
91
+ }
92
+ var userId = (_stepAttribution$user = stepAttribution.userId) === null || _stepAttribution$user === void 0 ? void 0 : _stepAttribution$user.trim();
93
+ if (hasAgentIdentity(stepAttribution)) {
94
+ var agent = resolveAgent(stepAttribution, profilesByAccountId);
95
+ if (!userId) {
96
+ // Agent mode: the agent acted on its own, so it is credited on its own.
97
+ contributors.push(_objectSpread(_objectSpread({}, agent), {}, {
98
+ attribution: stepAttribution
99
+ }));
100
+ creditedActors.add(actor);
101
+ continue;
102
+ }
103
+
104
+ // User-invoked agent: credit both actors and link the agent back to the invoking user.
105
+ var invokingUser = {
106
+ userId: userId
107
+ };
108
+ var _user = resolveUser(userId, profilesByAccountId);
109
+ if (!_user) {
110
+ return undefined;
111
+ }
112
+
113
+ // Skipped if the invoking user's own step already credited them.
114
+ var invokingUserActor = (0, _attributions.getAttributionKey)(invokingUser);
115
+ if (invokingUserActor && !creditedActors.has(invokingUserActor)) {
116
+ contributors.push(_objectSpread(_objectSpread({}, _user), {}, {
117
+ attribution: invokingUser
118
+ }));
119
+ creditedActors.add(invokingUserActor);
120
+ }
121
+ contributors.push(_objectSpread(_objectSpread({}, agent), {}, {
122
+ attribution: stepAttribution,
123
+ connectedTo: invokingUser
124
+ }));
125
+ creditedActors.add(actor);
126
+ continue;
127
+ }
128
+ var user = userId ? resolveUser(userId, profilesByAccountId) : undefined;
129
+ if (!user) {
130
+ return undefined;
131
+ }
132
+ contributors.push(_objectSpread(_objectSpread({}, user), {}, {
133
+ attribution: stepAttribution
134
+ }));
135
+ creditedActors.add(actor);
136
+ }
137
+ } catch (err) {
138
+ _iterator.e(err);
139
+ } finally {
140
+ _iterator.f();
141
+ }
142
+ return contributors.length > 0 ? contributors : undefined;
143
+ };
@@ -9,22 +9,30 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/h
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
12
+ var _attributions = require("./pm-plugins/decorations/colorSchemes/attributions");
12
13
  var _getDeletedWidgets2 = require("./pm-plugins/getDeletedWidgets");
13
14
  var _getScrollableDecorations = require("./pm-plugins/getScrollableDecorations");
14
15
  var _main = require("./pm-plugins/main");
16
+ var _resolveDiffContributors = require("./pm-plugins/resolveDiffContributors");
15
17
  var _IndicatorBarContentComponent = require("./ui/IndicatorBar/IndicatorBarContentComponent");
16
- var _excluded = ["stepsWithAttribution"];
18
+ var _excluded = ["stepsWithAttribution", "contributorProfiles"];
17
19
  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; }
18
20
  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; }
19
21
  var normalizeShowDiffParams = function normalizeShowDiffParams(params) {
20
22
  if (!params || !('stepsWithAttribution' in params)) {
23
+ // Cleared so a previous attributed diff's contributors cannot leak onto an unattributed one.
21
24
  return params ? _objectSpread(_objectSpread({}, params), {}, {
22
- stepAttributions: []
25
+ stepAttributions: [],
26
+ contributors: undefined
23
27
  }) : params;
24
28
  }
25
29
  var stepsWithAttribution = params.stepsWithAttribution,
30
+ contributorProfiles = params.contributorProfiles,
26
31
  rest = (0, _objectWithoutProperties2.default)(params, _excluded);
27
32
  return _objectSpread(_objectSpread({}, rest), {}, {
33
+ // Resolved and keyed at the public boundary so both the contributor model and the attribution-key
34
+ // format stay internal.
35
+ contributors: (0, _attributions.areAttributionColorGatesEnabled)() ? (0, _attributions.resolveContributors)((0, _resolveDiffContributors.resolveDiffContributors)(stepsWithAttribution, contributorProfiles)) : undefined,
28
36
  steps: stepsWithAttribution.map(function (_ref) {
29
37
  var step = _ref.step;
30
38
  return step;
@@ -77,6 +85,7 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref3) {
77
85
  return tr.setMeta(_main.showDiffPluginKey, {
78
86
  steps: [],
79
87
  stepAttributions: [],
88
+ contributors: undefined,
80
89
  action: 'HIDE_DIFF'
81
90
  });
82
91
  },
@@ -96,9 +105,12 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref3) {
96
105
  pmPlugins: function pmPlugins() {
97
106
  return [{
98
107
  name: 'showDiffPlugin',
108
+ // Contributor tags mount into their own decoration widgets through the portal
109
+ // provider, the way the rest of the editor renders React into decorations.
99
110
  plugin: function plugin(_ref8) {
100
- var getIntl = _ref8.getIntl;
101
- return (0, _main.createPlugin)(config, getIntl, api, setEditorView);
111
+ var getIntl = _ref8.getIntl,
112
+ nodeViewPortalProviderAPI = _ref8.nodeViewPortalProviderAPI;
113
+ return (0, _main.createPlugin)(config, getIntl, api, nodeViewPortalProviderAPI, setEditorView);
102
114
  }
103
115
  }];
104
116
  },
@@ -106,9 +118,11 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref3) {
106
118
  if (!(0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true)) {
107
119
  return null;
108
120
  }
109
- return /*#__PURE__*/_react.default.createElement(_IndicatorBarContentComponent.IndicatorBarContentComponent, {
121
+ // Rendered here so it shares the DOM context of the decoration anchor spans. Contributor
122
+ // tags are not: each one mounts into the host element its own decoration draws.
123
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_IndicatorBarContentComponent.IndicatorBarContentComponent, {
110
124
  api: api
111
- });
125
+ }));
112
126
  },
113
127
  getSharedState: function getSharedState(editorState) {
114
128
  if (!editorState) {
@@ -126,6 +140,7 @@ var showDiffPlugin = exports.showDiffPlugin = function showDiffPlugin(_ref3) {
126
140
  activeIndex: pluginState === null || pluginState === void 0 ? void 0 : pluginState.activeIndex,
127
141
  numberOfChanges: decorationCount.length
128
142
  }, (0, _expValEquals.expValEquals)('platform_editor_diff_plugin_extended', 'isEnabled', true) ? {
143
+ contributorTags: pluginState === null || pluginState === void 0 ? void 0 : pluginState.contributorTags,
129
144
  diffDescriptors: pluginState === null || pluginState === void 0 ? void 0 : pluginState.diffDescriptors,
130
145
  showIndicators: pluginState === null || pluginState === void 0 ? void 0 : pluginState.showIndicators
131
146
  } : {});
@@ -0,0 +1,29 @@
1
+ ._11c8wadc{font:var(--ds-font-body-small,normal 400 9pt/1pc "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
+ ._2rko12b0{border-radius:var(--ds-radius-small,4px)}
3
+ ._zulp1b66{gap:var(--ds-space-050,4px)}
4
+ ._18zr1b66{padding-inline:var(--ds-space-050,4px)}
5
+ ._1rjcv77o{padding-block:var(--ds-space-025,2px)}
6
+ ._12l2r5cr{margin-inline-end:var(--ds-space-negative-050,-4px)}
7
+ ._16qs130s{box-shadow:var(--ds-shadow-overlay,0 8px 9pt #1e1f2126,0 0 1px #1e1f214f)}
8
+ ._18m915vq{overflow-y:hidden}
9
+ ._1bto1l2s{text-overflow:ellipsis}
10
+ ._1doc1dm9{border-bottom-width:var(--ds-border-width-selected,2px)}
11
+ ._1e02idpf{inset-inline-start:0}
12
+ ._1e0c116y{display:inline-flex}
13
+ ._1e0c1ule{display:block}
14
+ ._1il9nqa1{border-bottom-style:solid}
15
+ ._1o9zidpf{flex-shrink:0}
16
+ ._1pbykb7n{z-index:1}
17
+ ._1reo15vq{overflow-x:hidden}
18
+ ._1ul9idpf{min-width:0}
19
+ ._4cvr1h6o{align-items:center}
20
+ ._94n51osq{bottom:100%}
21
+ ._kqswstnw{position:absolute}
22
+ ._lcxv1wug{pointer-events:auto}
23
+ ._lcxvglyw{pointer-events:none}
24
+ ._o5721q9c{white-space:nowrap}
25
+ ._p12f1osq{max-width:100%}
26
+ ._tzy4idpf{opacity:0}
27
+ ._tzy4kb7n{opacity:1}
28
+ ._uiztglyw{-webkit-user-select:none;-ms-user-select:none;user-select:none}
29
+ ._vchhusvi{box-sizing:border-box}