@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.
- package/CHANGELOG.md +18 -0
- package/afm-cc/tsconfig.json +18 -0
- package/afm-products/tsconfig.json +18 -0
- package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +47 -26
- package/dist/cjs/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +61 -9
- package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +77 -20
- package/dist/cjs/pm-plugins/decorations/colorSchemes/factory.js +10 -0
- package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +2 -0
- package/dist/cjs/pm-plugins/decorations/createAnchorDecorationWidgets.js +52 -7
- package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +172 -0
- package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +37 -5
- package/dist/cjs/pm-plugins/decorations/createNodeChangedDecorationWidget.js +40 -7
- package/dist/cjs/pm-plugins/decorations/decorationKeys.js +31 -5
- package/dist/cjs/pm-plugins/decorations/extractContributorTags.js +128 -0
- package/dist/cjs/pm-plugins/main.js +57 -6
- package/dist/cjs/pm-plugins/resolveDiffContributors.js +143 -0
- package/dist/cjs/showDiffPlugin.js +21 -6
- package/dist/cjs/ui/ContributorTag/ContributorTag.compiled.css +29 -0
- package/dist/cjs/ui/ContributorTag/ContributorTag.js +383 -0
- package/dist/cjs/ui/ContributorTag/ContributorTagWidget.js +50 -0
- package/dist/cjs/ui/ContributorTag/messages.js +24 -0
- package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +48 -27
- package/dist/es2019/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +39 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +53 -11
- package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +9 -0
- package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +2 -0
- package/dist/es2019/pm-plugins/decorations/createAnchorDecorationWidgets.js +43 -1
- package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +163 -0
- package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +38 -5
- package/dist/es2019/pm-plugins/decorations/createNodeChangedDecorationWidget.js +38 -6
- package/dist/es2019/pm-plugins/decorations/decorationKeys.js +30 -2
- package/dist/es2019/pm-plugins/decorations/extractContributorTags.js +101 -0
- package/dist/es2019/pm-plugins/main.js +52 -3
- package/dist/es2019/pm-plugins/resolveDiffContributors.js +128 -0
- package/dist/es2019/showDiffPlugin.js +20 -5
- package/dist/es2019/ui/ContributorTag/ContributorTag.compiled.css +29 -0
- package/dist/es2019/ui/ContributorTag/ContributorTag.js +312 -0
- package/dist/es2019/ui/ContributorTag/ContributorTagWidget.js +43 -0
- package/dist/es2019/ui/ContributorTag/messages.js +18 -0
- package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +49 -28
- package/dist/esm/pm-plugins/calculateDiff/simplifyChangesWithAttribution.js +60 -8
- package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +77 -19
- package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +9 -0
- package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +2 -0
- package/dist/esm/pm-plugins/decorations/createAnchorDecorationWidgets.js +51 -6
- package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +166 -0
- package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +37 -5
- package/dist/esm/pm-plugins/decorations/createNodeChangedDecorationWidget.js +40 -7
- package/dist/esm/pm-plugins/decorations/decorationKeys.js +30 -5
- package/dist/esm/pm-plugins/decorations/extractContributorTags.js +122 -0
- package/dist/esm/pm-plugins/main.js +57 -6
- package/dist/esm/pm-plugins/resolveDiffContributors.js +137 -0
- package/dist/esm/showDiffPlugin.js +21 -6
- package/dist/esm/ui/ContributorTag/ContributorTag.compiled.css +29 -0
- package/dist/esm/ui/ContributorTag/ContributorTag.js +375 -0
- package/dist/esm/ui/ContributorTag/ContributorTagWidget.js +43 -0
- package/dist/esm/ui/ContributorTag/messages.js +18 -0
- package/dist/types/entry-points/show-diff-plugin-type.d.ts +1 -1
- package/dist/types/pm-plugins/calculateDiff/calculateDiffDecorations.d.ts +7 -1
- package/dist/types/pm-plugins/calculateDiff/simplifyChangesWithAttribution.d.ts +10 -0
- package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +24 -2
- package/dist/types/pm-plugins/decorations/colorSchemes/factory.d.ts +7 -1
- package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +1 -2
- package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +2 -1
- package/dist/types/pm-plugins/decorations/createAnchorDecorationWidgets.d.ts +14 -0
- package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +55 -0
- package/dist/types/pm-plugins/decorations/createInlineChangedDecoration.d.ts +5 -1
- package/dist/types/pm-plugins/decorations/createNodeChangedDecorationWidget.d.ts +5 -1
- package/dist/types/pm-plugins/decorations/decorationKeys.d.ts +28 -3
- package/dist/types/pm-plugins/decorations/extractContributorTags.d.ts +9 -0
- package/dist/types/pm-plugins/main.d.ts +8 -2
- package/dist/types/pm-plugins/resolveDiffContributors.d.ts +7 -0
- package/dist/types/showDiffPluginType.d.ts +65 -2
- package/dist/types/ui/ContributorTag/ContributorTag.d.ts +37 -0
- package/dist/types/ui/ContributorTag/ContributorTagWidget.d.ts +22 -0
- package/dist/types/ui/ContributorTag/messages.d.ts +6 -0
- package/package.json +16 -7
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
/* ContributorTag.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.ContributorTag = ContributorTag;
|
|
10
|
+
require("./ContributorTag.compiled.css");
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
var React = _react;
|
|
13
|
+
var _runtime = require("@compiled/react/runtime");
|
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
15
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
16
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
17
|
+
var _bindEventListener = require("bind-event-listener");
|
|
18
|
+
var _reactIntl = require("react-intl");
|
|
19
|
+
var _avatar = _interopRequireDefault(require("@atlaskit/avatar/avatar"));
|
|
20
|
+
var _avatarContent = require("@atlaskit/avatar/avatar-content");
|
|
21
|
+
var _aiBot = _interopRequireDefault(require("@atlaskit/icon-lab/core/ai-bot"));
|
|
22
|
+
var _icon = require("@atlaskit/logo/rovo-hex/icon");
|
|
23
|
+
var _Tooltip = _interopRequireDefault(require("@atlaskit/tooltip/Tooltip"));
|
|
24
|
+
var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden/visually-hidden"));
|
|
25
|
+
var _factory = require("../../pm-plugins/decorations/colorSchemes/factory");
|
|
26
|
+
var _schemes = require("../../pm-plugins/decorations/colorSchemes/schemes");
|
|
27
|
+
var _messages = require("./messages");
|
|
28
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
29
|
+
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; } } }; }
|
|
30
|
+
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; } }
|
|
31
|
+
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; }
|
|
32
|
+
// Floor for the tag width (~one 16px avatar plus padding), so the highlight-width clamp below
|
|
33
|
+
// cannot collapse the box on a very short highlight.
|
|
34
|
+
var MIN_TAG_WIDTH = '28px';
|
|
35
|
+
var styles = {
|
|
36
|
+
constraint: "_1e0c1ule _kqswstnw _94n51osq _1e02idpf _1ul9idpf _1pbykb7n _uiztglyw",
|
|
37
|
+
tag: "_zulp1b66 _1reo15vq _18m915vq _2rko12b0 _11c8wadc _18zr1b66 _1rjcv77o _1e0c116y _4cvr1h6o _p12f1osq _1ul9idpf _1il9nqa1 _1doc1dm9 _16qs130s _o5721q9c _vchhusvi",
|
|
38
|
+
hidden: "_tzy4idpf _lcxvglyw",
|
|
39
|
+
visible: "_tzy4kb7n _lcxv1wug",
|
|
40
|
+
avatars: "_1e0c116y _4cvr1h6o _1o9zidpf",
|
|
41
|
+
leadingAvatar: "_1e0c116y _12l2r5cr",
|
|
42
|
+
name: "_1reo15vq _18m915vq _1e0c1ule _1ul9idpf _1bto1l2s _o5721q9c"
|
|
43
|
+
};
|
|
44
|
+
var getContributorName = function getContributorName(contributor, formatMessage) {
|
|
45
|
+
var _contributor$name, _contributor$agentKin;
|
|
46
|
+
var name = (_contributor$name = contributor.name) === null || _contributor$name === void 0 ? void 0 : _contributor$name.trim();
|
|
47
|
+
if (name) {
|
|
48
|
+
return name;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// `agentKind` defaults to `'external'` per the plugin type contract; an unidentified external
|
|
52
|
+
// agent falls back to a generic label rather than rendering a nameless tag.
|
|
53
|
+
if (contributor.kind === 'agent' && ((_contributor$agentKin = contributor.agentKind) !== null && _contributor$agentKin !== void 0 ? _contributor$agentKin : 'external') === 'external') {
|
|
54
|
+
return formatMessage(_messages.contributorTagMessages.externalAgentName);
|
|
55
|
+
}
|
|
56
|
+
return '';
|
|
57
|
+
};
|
|
58
|
+
var ContributorAvatar = function ContributorAvatar(_ref) {
|
|
59
|
+
var contributor = _ref.contributor,
|
|
60
|
+
name = _ref.name,
|
|
61
|
+
ringColor = _ref.ringColor,
|
|
62
|
+
stackIndex = _ref.stackIndex;
|
|
63
|
+
if (contributor.kind === 'user') {
|
|
64
|
+
return /*#__PURE__*/React.createElement(_avatar.default, {
|
|
65
|
+
appearance: "circle",
|
|
66
|
+
size: "xxsmall",
|
|
67
|
+
src: contributor.avatarUrl,
|
|
68
|
+
name: name,
|
|
69
|
+
stackIndex: stackIndex,
|
|
70
|
+
borderColor: ringColor
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return /*#__PURE__*/React.createElement(_avatar.default, {
|
|
74
|
+
appearance: "hexagon",
|
|
75
|
+
size: "xxsmall",
|
|
76
|
+
src: contributor.avatarUrl,
|
|
77
|
+
name: name,
|
|
78
|
+
stackIndex: stackIndex,
|
|
79
|
+
borderColor: ringColor
|
|
80
|
+
}, contributor.avatarUrl ? undefined : /*#__PURE__*/React.createElement(_avatarContent.AvatarContent, null, contributor.agentKind === 'rovo' ? /*#__PURE__*/React.createElement(_icon.RovoHexIcon, {
|
|
81
|
+
size: "xxsmall",
|
|
82
|
+
label: ""
|
|
83
|
+
}) :
|
|
84
|
+
/*#__PURE__*/
|
|
85
|
+
// `small` (12px) fits inside the 16px hexagon.
|
|
86
|
+
React.createElement(_aiBot.default, {
|
|
87
|
+
label: "",
|
|
88
|
+
size: "small"
|
|
89
|
+
})));
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Resolves the tag's accent from the same scheme value and token maps the highlight used, so the two
|
|
93
|
+
* can never drift.
|
|
94
|
+
*/
|
|
95
|
+
var getTagAccent = function getTagAccent(_ref2) {
|
|
96
|
+
var colorScheme = _ref2.colorScheme,
|
|
97
|
+
isActive = _ref2.isActive,
|
|
98
|
+
isInserted = _ref2.isInserted;
|
|
99
|
+
var colors = _schemes.colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : 'standard'];
|
|
100
|
+
var accent = isInserted ? isActive ? colors.insertActiveColor : colors.insertColor : isActive ? colors.deleteActiveColor : colors.deleteColor;
|
|
101
|
+
return (0, _factory.getAccentTokens)(accent);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** The line the change starts on: topmost of its fragments, leftmost among those. */
|
|
105
|
+
var findChangeStartLine = function findChangeStartLine(highlights) {
|
|
106
|
+
var start;
|
|
107
|
+
var _iterator = _createForOfIteratorHelper(highlights),
|
|
108
|
+
_step;
|
|
109
|
+
try {
|
|
110
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
111
|
+
var highlight = _step.value;
|
|
112
|
+
var _iterator2 = _createForOfIteratorHelper(highlight.getClientRects()),
|
|
113
|
+
_step2;
|
|
114
|
+
try {
|
|
115
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
116
|
+
var rect = _step2.value;
|
|
117
|
+
if (!start || rect.top < start.top - 1 || Math.abs(rect.top - start.top) <= 1 && rect.left < start.left) {
|
|
118
|
+
start = rect;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
_iterator2.e(err);
|
|
123
|
+
} finally {
|
|
124
|
+
_iterator2.f();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
} catch (err) {
|
|
128
|
+
_iterator.e(err);
|
|
129
|
+
} finally {
|
|
130
|
+
_iterator.f();
|
|
131
|
+
}
|
|
132
|
+
return start;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Observes the highlight this tag describes, for what CSS here cannot see: its hover state (the
|
|
137
|
+
* highlight is a ProseMirror decoration in a different DOM subtree, so listeners are bound
|
|
138
|
+
* imperatively via `data-diff-id`) and the width the tag is clamped to.
|
|
139
|
+
*
|
|
140
|
+
* Deliberately not routed through plugin state: a transaction per pointer move would re-run the
|
|
141
|
+
* memoised decoration calculation.
|
|
142
|
+
*/
|
|
143
|
+
var useHighlightState = function useHighlightState(diffId, highlightSelector, getEditorRoot) {
|
|
144
|
+
var _useState = (0, _react.useState)(false),
|
|
145
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
146
|
+
isHovered = _useState2[0],
|
|
147
|
+
setIsHovered = _useState2[1];
|
|
148
|
+
var _useState3 = (0, _react.useState)(undefined),
|
|
149
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
150
|
+
maxWidthPx = _useState4[0],
|
|
151
|
+
setMaxWidthPx = _useState4[1];
|
|
152
|
+
(0, _react.useEffect)(function () {
|
|
153
|
+
// Both queries are scoped to this editor's content root, so a tag can only ever bind to the
|
|
154
|
+
// decorations its own plugin instance rendered — another editor on the page, or one nested
|
|
155
|
+
// inside this one, cannot supply the geometry.
|
|
156
|
+
var editorRoot = getEditorRoot();
|
|
157
|
+
var highlights = editorRoot === null || editorRoot === void 0 ? void 0 : editorRoot.querySelectorAll(highlightSelector);
|
|
158
|
+
if (!editorRoot || !(highlights !== null && highlights !== void 0 && highlights.length)) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
var elements = Array.from(highlights);
|
|
162
|
+
// The width comes from this tag's OWN decoration; sibling halves of the change are here for
|
|
163
|
+
// hover only.
|
|
164
|
+
var ownElements = Array.from(editorRoot.querySelectorAll("[data-diff-id=\"".concat(diffId, "\"]")));
|
|
165
|
+
var measure = function measure() {
|
|
166
|
+
var _findChangeStartLine;
|
|
167
|
+
// Counted by distinct line box, not by client rect: an inline node inside the change (a
|
|
168
|
+
// mention, emoji, date) splits the highlight into several rects on the same line, and
|
|
169
|
+
// treating that as a wrap would drop the width clamp on changes that never wrapped.
|
|
170
|
+
var lineTops = new Set();
|
|
171
|
+
for (var _i = 0, _ownElements = ownElements; _i < _ownElements.length; _i++) {
|
|
172
|
+
var highlight = _ownElements[_i];
|
|
173
|
+
var _iterator3 = _createForOfIteratorHelper(highlight.getClientRects()),
|
|
174
|
+
_step3;
|
|
175
|
+
try {
|
|
176
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
177
|
+
var rect = _step3.value;
|
|
178
|
+
lineTops.add(Math.round(rect.top));
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
_iterator3.e(err);
|
|
182
|
+
} finally {
|
|
183
|
+
_iterator3.f();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A wrapped change's first line says nothing useful about how wide the tag may be.
|
|
188
|
+
var width = lineTops.size > 1 ? undefined : (_findChangeStartLine = findChangeStartLine(ownElements)) === null || _findChangeStartLine === void 0 ? void 0 : _findChangeStartLine.width;
|
|
189
|
+
setMaxWidthPx(width);
|
|
190
|
+
};
|
|
191
|
+
measure();
|
|
192
|
+
|
|
193
|
+
// An inline element cannot be observed itself (ResizeObserver skips boxes with no principal
|
|
194
|
+
// box), so the block it sits in is observed instead.
|
|
195
|
+
var resizeObserver = new ResizeObserver(measure);
|
|
196
|
+
var _iterator4 = _createForOfIteratorHelper(new Set(ownElements.map(function (_ref3) {
|
|
197
|
+
var parentElement = _ref3.parentElement;
|
|
198
|
+
return parentElement;
|
|
199
|
+
}))),
|
|
200
|
+
_step4;
|
|
201
|
+
try {
|
|
202
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
203
|
+
var parent = _step4.value;
|
|
204
|
+
if (parent) {
|
|
205
|
+
resizeObserver.observe(parent);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// `bindAll` takes a single target, and a change can render more than one highlight.
|
|
210
|
+
} catch (err) {
|
|
211
|
+
_iterator4.e(err);
|
|
212
|
+
} finally {
|
|
213
|
+
_iterator4.f();
|
|
214
|
+
}
|
|
215
|
+
var unbinds = elements.map(function (highlight) {
|
|
216
|
+
return (0, _bindEventListener.bindAll)(highlight, [{
|
|
217
|
+
type: 'mouseenter',
|
|
218
|
+
listener: function listener() {
|
|
219
|
+
return setIsHovered(true);
|
|
220
|
+
}
|
|
221
|
+
}, {
|
|
222
|
+
type: 'mouseleave',
|
|
223
|
+
listener: function listener() {
|
|
224
|
+
return setIsHovered(false);
|
|
225
|
+
}
|
|
226
|
+
}]);
|
|
227
|
+
});
|
|
228
|
+
return function () {
|
|
229
|
+
resizeObserver.disconnect();
|
|
230
|
+
unbinds.forEach(function (unbind) {
|
|
231
|
+
return unbind();
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
}, [diffId, getEditorRoot, highlightSelector]);
|
|
235
|
+
return {
|
|
236
|
+
isHovered: isHovered,
|
|
237
|
+
maxWidthPx: maxWidthPx
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* A small tag naming who made one diff, rendered into the host widget its decoration places on the
|
|
243
|
+
* change's first character and positioned above it.
|
|
244
|
+
*/
|
|
245
|
+
function ContributorTag(_ref4) {
|
|
246
|
+
var colorScheme = _ref4.colorScheme,
|
|
247
|
+
connectedContributor = _ref4.connectedContributor,
|
|
248
|
+
contributor = _ref4.contributor,
|
|
249
|
+
diffId = _ref4.diffId,
|
|
250
|
+
getEditorRoot = _ref4.getEditorRoot,
|
|
251
|
+
isActive = _ref4.isActive,
|
|
252
|
+
_ref4$isInserted = _ref4.isInserted,
|
|
253
|
+
isInserted = _ref4$isInserted === void 0 ? true : _ref4$isInserted,
|
|
254
|
+
linkedDiffIds = _ref4.linkedDiffIds;
|
|
255
|
+
var _useIntl = (0, _reactIntl.useIntl)(),
|
|
256
|
+
formatMessage = _useIntl.formatMessage;
|
|
257
|
+
// A plain string, so the hook's effect is not re-run by a fresh array on every render.
|
|
258
|
+
var highlightSelector = [diffId].concat((0, _toConsumableArray2.default)(linkedDiffIds !== null && linkedDiffIds !== void 0 ? linkedDiffIds : [])).map(function (id) {
|
|
259
|
+
return "[data-diff-id=\"".concat(id, "\"]");
|
|
260
|
+
}).join(', ');
|
|
261
|
+
var _useHighlightState = useHighlightState(diffId, highlightSelector, getEditorRoot),
|
|
262
|
+
isHighlightHovered = _useHighlightState.isHovered,
|
|
263
|
+
maxWidthPx = _useHighlightState.maxWidthPx;
|
|
264
|
+
var accent = getTagAccent({
|
|
265
|
+
colorScheme: colorScheme,
|
|
266
|
+
isActive: Boolean(isActive),
|
|
267
|
+
isInserted: isInserted
|
|
268
|
+
});
|
|
269
|
+
var nameRef = (0, _react.useRef)(null);
|
|
270
|
+
var _useState5 = (0, _react.useState)(false),
|
|
271
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
272
|
+
isTruncated = _useState6[0],
|
|
273
|
+
setIsTruncated = _useState6[1];
|
|
274
|
+
var _useState7 = (0, _react.useState)(false),
|
|
275
|
+
_useState8 = (0, _slicedToArray2.default)(_useState7, 2),
|
|
276
|
+
isHoveredOrFocused = _useState8[0],
|
|
277
|
+
setIsHoveredOrFocused = _useState8[1];
|
|
278
|
+
var isConnectedPair = Boolean(connectedContributor);
|
|
279
|
+
var isPrimaryAgent = contributor.kind === 'agent';
|
|
280
|
+
var primaryName = getContributorName(contributor, formatMessage);
|
|
281
|
+
var secondaryName = connectedContributor ? getContributorName(connectedContributor, formatMessage) : '';
|
|
282
|
+
|
|
283
|
+
// Resolved by `kind` so a reverse `connectedTo` (an attributed user pointing at its agent)
|
|
284
|
+
// renders identically.
|
|
285
|
+
var agentName = isPrimaryAgent ? primaryName : secondaryName;
|
|
286
|
+
var userName = isPrimaryAgent ? secondaryName : primaryName;
|
|
287
|
+
var userContributor = isPrimaryAgent ? connectedContributor : contributor;
|
|
288
|
+
var agentContributor = isPrimaryAgent ? contributor : connectedContributor;
|
|
289
|
+
var displayName = isConnectedPair ? agentName || primaryName : primaryName;
|
|
290
|
+
var fullLabel = isConnectedPair ? formatMessage(_messages.contributorTagMessages.changedByConnected, {
|
|
291
|
+
agentName: agentName,
|
|
292
|
+
userName: userName
|
|
293
|
+
}) : formatMessage(_messages.contributorTagMessages.changedBy, {
|
|
294
|
+
name: primaryName
|
|
295
|
+
});
|
|
296
|
+
var measureTruncation = (0, _react.useCallback)(function () {
|
|
297
|
+
var element = nameRef.current;
|
|
298
|
+
if (element) {
|
|
299
|
+
setIsTruncated(element.scrollWidth > element.clientWidth);
|
|
300
|
+
}
|
|
301
|
+
}, []);
|
|
302
|
+
var isVisible = Boolean(isActive) || isHighlightHovered || isHoveredOrFocused;
|
|
303
|
+
|
|
304
|
+
// A connected pair only ever renders the agent name, so it always gets a tooltip; a single
|
|
305
|
+
// contributor only when its name is clipped.
|
|
306
|
+
var tooltipContent = isTruncated || isConnectedPair ? fullLabel : null;
|
|
307
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
308
|
+
style: {
|
|
309
|
+
// Clamped to the highlight's own width, floored at `MIN_TAG_WIDTH` so a one-character
|
|
310
|
+
// change still shows an avatar.
|
|
311
|
+
maxWidth: maxWidthPx === undefined ? undefined : "max(".concat(Math.round(maxWidthPx), "px, ").concat(MIN_TAG_WIDTH, ")")
|
|
312
|
+
},
|
|
313
|
+
className: (0, _runtime.ax)([styles.constraint])
|
|
314
|
+
}, /*#__PURE__*/React.createElement(_Tooltip.default, {
|
|
315
|
+
content: tooltipContent
|
|
316
|
+
// A tooltip below would cover the highlighted text the tag describes.
|
|
317
|
+
,
|
|
318
|
+
position: "top"
|
|
319
|
+
// The label is already exposed by the visually hidden text below.
|
|
320
|
+
,
|
|
321
|
+
isScreenReaderAnnouncementDisabled: true
|
|
322
|
+
}, function (tooltipProps) {
|
|
323
|
+
return /*#__PURE__*/React.createElement("span", (0, _extends2.default)({}, tooltipProps, {
|
|
324
|
+
"data-testid": "diff-contributor-tag"
|
|
325
|
+
// Deliberately no `aria-label`: it would be announced ahead of the element's
|
|
326
|
+
// contents, but design requires the contributor *after* the change — hence the
|
|
327
|
+
// visually hidden last child.
|
|
328
|
+
,
|
|
329
|
+
role: "note"
|
|
330
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex, @atlassian/a11y/no-noninteractive-tabindex
|
|
331
|
+
,
|
|
332
|
+
tabIndex: 0,
|
|
333
|
+
style: {
|
|
334
|
+
backgroundColor: accent.background,
|
|
335
|
+
borderBottomColor: accent.border
|
|
336
|
+
},
|
|
337
|
+
onMouseOver: function onMouseOver(event) {
|
|
338
|
+
tooltipProps.onMouseOver(event);
|
|
339
|
+
measureTruncation();
|
|
340
|
+
setIsHoveredOrFocused(true);
|
|
341
|
+
},
|
|
342
|
+
onMouseOut: function onMouseOut(event) {
|
|
343
|
+
tooltipProps.onMouseOut(event);
|
|
344
|
+
setIsHoveredOrFocused(false);
|
|
345
|
+
},
|
|
346
|
+
onFocus: function onFocus(event) {
|
|
347
|
+
tooltipProps.onFocus(event);
|
|
348
|
+
measureTruncation();
|
|
349
|
+
setIsHoveredOrFocused(true);
|
|
350
|
+
},
|
|
351
|
+
onBlur: function onBlur(event) {
|
|
352
|
+
tooltipProps.onBlur(event);
|
|
353
|
+
setIsHoveredOrFocused(false);
|
|
354
|
+
},
|
|
355
|
+
className: (0, _runtime.ax)([styles.tag, isVisible ? styles.visible : styles.hidden])
|
|
356
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
357
|
+
className: (0, _runtime.ax)([styles.avatars])
|
|
358
|
+
}, isConnectedPair && userContributor ? /*#__PURE__*/React.createElement("span", {
|
|
359
|
+
className: (0, _runtime.ax)([styles.leadingAvatar])
|
|
360
|
+
}, /*#__PURE__*/React.createElement(ContributorAvatar, {
|
|
361
|
+
contributor: userContributor,
|
|
362
|
+
name: userName,
|
|
363
|
+
ringColor: accent.background,
|
|
364
|
+
stackIndex: 1
|
|
365
|
+
})) : null, isConnectedPair && agentContributor ? /*#__PURE__*/React.createElement(ContributorAvatar, {
|
|
366
|
+
contributor: agentContributor,
|
|
367
|
+
name: agentName,
|
|
368
|
+
ringColor: accent.background,
|
|
369
|
+
stackIndex: 0
|
|
370
|
+
}) : null, !isConnectedPair ? /*#__PURE__*/React.createElement(ContributorAvatar, {
|
|
371
|
+
contributor: contributor,
|
|
372
|
+
name: primaryName,
|
|
373
|
+
ringColor: accent.background
|
|
374
|
+
}) : null), /*#__PURE__*/React.createElement("span", {
|
|
375
|
+
"data-testid": "diff-contributor-tag-name",
|
|
376
|
+
ref: nameRef,
|
|
377
|
+
style: {
|
|
378
|
+
color: accent.text
|
|
379
|
+
},
|
|
380
|
+
className: (0, _runtime.ax)([styles.name])
|
|
381
|
+
}, displayName), /*#__PURE__*/React.createElement(_visuallyHidden.default, null, fullLabel));
|
|
382
|
+
}));
|
|
383
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* ContributorTagWidget.tsx generated by @compiled/babel-plugin v2.0.0 */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ContributorTagWidget = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _runtime = require("@compiled/react/runtime");
|
|
11
|
+
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
12
|
+
var _ContributorTag = require("./ContributorTag");
|
|
13
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
14
|
+
/**
|
|
15
|
+
* One contributor tag, mounted by its diff decoration into the host element that decoration draws
|
|
16
|
+
* (see `mountContributorTag`).
|
|
17
|
+
*
|
|
18
|
+
* The model is read from plugin state here rather than passed in, because ProseMirror skips `toDOM`
|
|
19
|
+
* for a widget it reuses: stepping to the next change republishes the tags without redrawing their
|
|
20
|
+
* hosts, so anything the tag needs to react to — `isActive` above all — has to arrive through a
|
|
21
|
+
* subscription of its own. Renders nothing when this diff has no tag, which is the case for the
|
|
22
|
+
* deleted half of a replacement: that half is folded into the inline tag.
|
|
23
|
+
*/
|
|
24
|
+
var ContributorTagWidget = exports.ContributorTagWidget = function ContributorTagWidget(_ref) {
|
|
25
|
+
var api = _ref.api,
|
|
26
|
+
diffId = _ref.diffId,
|
|
27
|
+
getEditorRoot = _ref.getEditorRoot;
|
|
28
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['showDiff'], function (state) {
|
|
29
|
+
var _state$showDiffState;
|
|
30
|
+
return {
|
|
31
|
+
model: (_state$showDiffState = state.showDiffState) === null || _state$showDiffState === void 0 || (_state$showDiffState = _state$showDiffState.contributorTags) === null || _state$showDiffState === void 0 ? void 0 : _state$showDiffState.find(function (tag) {
|
|
32
|
+
return tag.diffId === diffId;
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
}),
|
|
36
|
+
model = _useSharedPluginState.model;
|
|
37
|
+
if (!model) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return /*#__PURE__*/React.createElement(_ContributorTag.ContributorTag, {
|
|
41
|
+
colorScheme: model.colorScheme,
|
|
42
|
+
connectedContributor: model.connectedContributor,
|
|
43
|
+
contributor: model.contributor,
|
|
44
|
+
diffId: model.diffId,
|
|
45
|
+
getEditorRoot: getEditorRoot,
|
|
46
|
+
isActive: model.isActive,
|
|
47
|
+
isInserted: model.isInserted,
|
|
48
|
+
linkedDiffIds: model.linkedDiffIds
|
|
49
|
+
});
|
|
50
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.contributorTagMessages = void 0;
|
|
7
|
+
var _reactIntl = require("react-intl");
|
|
8
|
+
var contributorTagMessages = exports.contributorTagMessages = (0, _reactIntl.defineMessages)({
|
|
9
|
+
changedBy: {
|
|
10
|
+
id: 'editor-plugin-show-diff.ContributorTag.changedBy',
|
|
11
|
+
defaultMessage: 'Changed by {name}',
|
|
12
|
+
description: 'Screen-reader label and tooltip for the tag pinned to a highlighted change in the version-history diff, naming the single person or agent that made the change. The name placeholder is the contributor display name.'
|
|
13
|
+
},
|
|
14
|
+
changedByConnected: {
|
|
15
|
+
id: 'editor-plugin-show-diff.ContributorTag.changedByConnected',
|
|
16
|
+
defaultMessage: 'Changed by {agentName} with {userName}',
|
|
17
|
+
description: 'Screen-reader label and tooltip for the tag pinned to a highlighted change in the version-history diff when an AI agent made the change on behalf of a user. The agentName placeholder is the agent display name. The userName placeholder is the display name of the user that invoked the agent.'
|
|
18
|
+
},
|
|
19
|
+
externalAgentName: {
|
|
20
|
+
id: 'editor-plugin-show-diff.ContributorTag.externalAgentName',
|
|
21
|
+
defaultMessage: 'External agent',
|
|
22
|
+
description: 'Fallback display name shown in the contributor tag of the version-history diff for an unidentified third-party agent (for example an MCP or CLI client) that has no name of its own.'
|
|
23
|
+
}
|
|
24
|
+
});
|