@atlaskit/editor-plugin-show-diff 14.5.2 → 15.0.1

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 (76) hide show
  1. package/CHANGELOG.md +34 -6
  2. package/afm-cc/tsconfig.json +0 -12
  3. package/afm-products/tsconfig.json +0 -12
  4. package/dist/cjs/pm-plugins/calculateDiff/calculateDiffDecorations.js +3 -9
  5. package/dist/cjs/pm-plugins/calculateDiff/smart/classifySmartChanges.js +1 -2
  6. package/dist/cjs/pm-plugins/decorations/colorSchemes/attributions.js +21 -4
  7. package/dist/cjs/pm-plugins/decorations/colorSchemes/factory.js +6 -56
  8. package/dist/cjs/pm-plugins/decorations/colorSchemes/schemes.js +6 -20
  9. package/dist/cjs/pm-plugins/decorations/colorSchemes/types.js +4 -6
  10. package/dist/cjs/pm-plugins/decorations/createChangedRowDecorationWidgets.js +1 -2
  11. package/dist/cjs/pm-plugins/decorations/createContributorTagWidget.js +14 -29
  12. package/dist/cjs/pm-plugins/decorations/createInlineChangedDecoration.js +1 -2
  13. package/dist/cjs/pm-plugins/decorations/utils/getAttrChangeRanges.js +2 -25
  14. package/dist/cjs/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +1 -2
  15. package/dist/cjs/pm-plugins/main.js +4 -4
  16. package/dist/cjs/showDiffPlugin.js +4 -5
  17. package/dist/cjs/ui/ContributorTag/buildContributorTagDom.js +122 -0
  18. package/dist/cjs/ui/ContributorTag/contributorAvatarRenderer.js +140 -0
  19. package/dist/cjs/ui/ContributorTag/contributorTagController.js +500 -0
  20. package/dist/cjs/ui/ContributorTag/contributorTagIcons.js +46 -0
  21. package/dist/es2019/pm-plugins/calculateDiff/calculateDiffDecorations.js +3 -5
  22. package/dist/es2019/pm-plugins/calculateDiff/smart/classifySmartChanges.js +1 -2
  23. package/dist/es2019/pm-plugins/decorations/colorSchemes/attributions.js +20 -3
  24. package/dist/es2019/pm-plugins/decorations/colorSchemes/factory.js +6 -55
  25. package/dist/es2019/pm-plugins/decorations/colorSchemes/schemes.js +14 -26
  26. package/dist/es2019/pm-plugins/decorations/colorSchemes/types.js +4 -6
  27. package/dist/es2019/pm-plugins/decorations/createChangedRowDecorationWidgets.js +1 -2
  28. package/dist/es2019/pm-plugins/decorations/createContributorTagWidget.js +16 -30
  29. package/dist/es2019/pm-plugins/decorations/createInlineChangedDecoration.js +1 -2
  30. package/dist/es2019/pm-plugins/decorations/utils/getAttrChangeRanges.js +2 -17
  31. package/dist/es2019/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +1 -2
  32. package/dist/es2019/pm-plugins/main.js +4 -4
  33. package/dist/es2019/showDiffPlugin.js +4 -5
  34. package/dist/es2019/ui/ContributorTag/buildContributorTagDom.js +110 -0
  35. package/dist/es2019/ui/ContributorTag/contributorAvatarRenderer.js +136 -0
  36. package/dist/es2019/ui/ContributorTag/contributorTagController.js +403 -0
  37. package/dist/es2019/ui/ContributorTag/contributorTagIcons.js +40 -0
  38. package/dist/esm/pm-plugins/calculateDiff/calculateDiffDecorations.js +3 -9
  39. package/dist/esm/pm-plugins/calculateDiff/smart/classifySmartChanges.js +1 -2
  40. package/dist/esm/pm-plugins/decorations/colorSchemes/attributions.js +21 -4
  41. package/dist/esm/pm-plugins/decorations/colorSchemes/factory.js +6 -57
  42. package/dist/esm/pm-plugins/decorations/colorSchemes/schemes.js +7 -20
  43. package/dist/esm/pm-plugins/decorations/colorSchemes/types.js +4 -6
  44. package/dist/esm/pm-plugins/decorations/createChangedRowDecorationWidgets.js +1 -2
  45. package/dist/esm/pm-plugins/decorations/createContributorTagWidget.js +15 -30
  46. package/dist/esm/pm-plugins/decorations/createInlineChangedDecoration.js +1 -2
  47. package/dist/esm/pm-plugins/decorations/utils/getAttrChangeRanges.js +2 -25
  48. package/dist/esm/pm-plugins/decorations/utils/wrapBlockNodeViewStyles.js +1 -2
  49. package/dist/esm/pm-plugins/main.js +4 -4
  50. package/dist/esm/showDiffPlugin.js +4 -5
  51. package/dist/esm/ui/ContributorTag/buildContributorTagDom.js +115 -0
  52. package/dist/esm/ui/ContributorTag/contributorAvatarRenderer.js +135 -0
  53. package/dist/esm/ui/ContributorTag/contributorTagController.js +493 -0
  54. package/dist/esm/ui/ContributorTag/contributorTagIcons.js +40 -0
  55. package/dist/types/pm-plugins/decorations/colorSchemes/attributions.d.ts +3 -3
  56. package/dist/types/pm-plugins/decorations/colorSchemes/factory.d.ts +2 -2
  57. package/dist/types/pm-plugins/decorations/colorSchemes/schemes.d.ts +1 -1
  58. package/dist/types/pm-plugins/decorations/colorSchemes/types.d.ts +13 -16
  59. package/dist/types/pm-plugins/decorations/createContributorTagWidget.d.ts +11 -9
  60. package/dist/types/pm-plugins/main.d.ts +1 -2
  61. package/dist/types/ui/ContributorTag/buildContributorTagDom.d.ts +25 -0
  62. package/dist/types/ui/ContributorTag/contributorAvatarRenderer.d.ts +22 -0
  63. package/dist/types/ui/ContributorTag/contributorTagController.d.ts +85 -0
  64. package/dist/types/ui/ContributorTag/contributorTagIcons.d.ts +12 -0
  65. package/package.json +9 -13
  66. package/dist/cjs/ui/ContributorTag/ContributorTag.compiled.css +0 -29
  67. package/dist/cjs/ui/ContributorTag/ContributorTag.js +0 -383
  68. package/dist/cjs/ui/ContributorTag/ContributorTagWidget.js +0 -50
  69. package/dist/es2019/ui/ContributorTag/ContributorTag.compiled.css +0 -29
  70. package/dist/es2019/ui/ContributorTag/ContributorTag.js +0 -312
  71. package/dist/es2019/ui/ContributorTag/ContributorTagWidget.js +0 -43
  72. package/dist/esm/ui/ContributorTag/ContributorTag.compiled.css +0 -29
  73. package/dist/esm/ui/ContributorTag/ContributorTag.js +0 -375
  74. package/dist/esm/ui/ContributorTag/ContributorTagWidget.js +0 -43
  75. package/dist/types/ui/ContributorTag/ContributorTag.d.ts +0 -37
  76. package/dist/types/ui/ContributorTag/ContributorTagWidget.d.ts +0 -22
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.buildContributorTagDom = exports.MIN_TAG_WIDTH = exports.CONTRIBUTOR_TAG_TESTID = exports.CONTRIBUTOR_TAG_NAME_TESTID = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
10
+ var CONTRIBUTOR_TAG_TESTID = exports.CONTRIBUTOR_TAG_TESTID = 'diff-contributor-tag';
11
+ var CONTRIBUTOR_TAG_NAME_TESTID = exports.CONTRIBUTOR_TAG_NAME_TESTID = 'diff-contributor-tag-name';
12
+
13
+ /**
14
+ * Floor for the tag width (~one 16px avatar plus padding), so the highlight-width clamp cannot
15
+ * collapse the box on a very short highlight.
16
+ */
17
+ var MIN_TAG_WIDTH = exports.MIN_TAG_WIDTH = '28px';
18
+
19
+ // Positioned against the host widget its decoration renders on the change's first character:
20
+ // `bottom: 100%` lifts the tag onto the line above, `inset-inline-start` starts it on that
21
+ // character.
22
+ var constraintStyle = (0, _lazyNodeView.convertToInlineCss)({
23
+ display: 'block',
24
+ position: 'absolute',
25
+ bottom: '100%',
26
+ insetInlineStart: 0,
27
+ minWidth: 0,
28
+ // The tag may cover surrounding text, so it has to paint over it. Matches `akEditorUnitZIndex`.
29
+ zIndex: 1,
30
+ // It renders inside the document and it is not content: dragging a selection across the change
31
+ // must not select it.
32
+ userSelect: 'none'
33
+ });
34
+
35
+ // `backgroundColor`, `borderBottomColor` and the visibility come from the model, and are set by the
36
+ // controller.
37
+ var tagStyle = (0, _lazyNodeView.convertToInlineCss)({
38
+ display: 'inline-flex',
39
+ alignItems: 'center',
40
+ gap: "var(--ds-space-050, 4px)",
41
+ // Never wider than the highlight; overflow is ellipsised on the name below.
42
+ maxWidth: '100%',
43
+ minWidth: 0,
44
+ overflow: 'hidden',
45
+ paddingInline: "var(--ds-space-050, 4px)",
46
+ paddingBlock: "var(--ds-space-025, 2px)",
47
+ borderRadius: "var(--ds-radius-small, 4px)",
48
+ borderBottomStyle: 'solid',
49
+ borderBottomWidth: "var(--ds-border-width-selected, 2px)",
50
+ boxShadow: "var(--ds-shadow-overlay, 0px 8px 12px #1E1F2126, 0px 0px 1px #1E1F214f)",
51
+ font: "var(--ds-font-body-small, normal 400 12px/16px \"Atlassian Sans\", ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
52
+ whiteSpace: 'nowrap',
53
+ boxSizing: 'border-box'
54
+ });
55
+ var avatarsStyle = (0, _lazyNodeView.convertToInlineCss)({
56
+ display: 'inline-flex',
57
+ alignItems: 'center',
58
+ flexShrink: 0
59
+ });
60
+ var nameStyle = (0, _lazyNodeView.convertToInlineCss)({
61
+ display: 'block',
62
+ minWidth: 0,
63
+ overflow: 'hidden',
64
+ textOverflow: 'ellipsis',
65
+ whiteSpace: 'nowrap'
66
+ });
67
+
68
+ /** `@atlaskit/visually-hidden`, inlined. */
69
+ var srLabelStyle = (0, _lazyNodeView.convertToInlineCss)({
70
+ width: '1px',
71
+ height: '1px',
72
+ padding: 0,
73
+ position: 'absolute',
74
+ border: 0,
75
+ clip: 'rect(1px, 1px, 1px, 1px)',
76
+ overflow: 'hidden',
77
+ userSelect: 'none',
78
+ whiteSpace: 'nowrap'
79
+ });
80
+ var createSpan = function createSpan(doc, style) {
81
+ var attributes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
82
+ var span = doc.createElement('span');
83
+ span.setAttribute('style', style);
84
+ for (var _i = 0, _Object$entries = Object.entries(attributes); _i < _Object$entries.length; _i++) {
85
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
86
+ name = _Object$entries$_i[0],
87
+ value = _Object$entries$_i[1];
88
+ span.setAttribute(name, value);
89
+ }
90
+ return span;
91
+ };
92
+ /**
93
+ * The tag's markup, with no model applied — see `ContributorTagController`.
94
+ *
95
+ * Built element by element rather than through `DOMSerializer.renderSpec`, which returns `Node` and
96
+ * would need a cast per reference below.
97
+ */
98
+ var buildContributorTagDom = exports.buildContributorTagDom = function buildContributorTagDom(doc) {
99
+ var root = createSpan(doc, constraintStyle);
100
+ var tag = createSpan(doc, tagStyle, {
101
+ 'data-testid': CONTRIBUTOR_TAG_TESTID,
102
+ // Deliberately no `aria-label`: it would be announced ahead of the element's contents, but
103
+ // design requires the contributor *after* the change — hence the visually hidden label.
104
+ role: 'note',
105
+ // Focusable so keyboard and screen-reader users can reach the tag and its tooltip.
106
+ tabindex: '0'
107
+ });
108
+ var avatars = createSpan(doc, avatarsStyle);
109
+ var name = createSpan(doc, nameStyle, {
110
+ 'data-testid': CONTRIBUTOR_TAG_NAME_TESTID
111
+ });
112
+ var srLabel = createSpan(doc, srLabelStyle);
113
+ tag.append(avatars, name, srLabel);
114
+ root.appendChild(tag);
115
+ return {
116
+ avatars: avatars,
117
+ name: name,
118
+ root: root,
119
+ srLabel: srLabel,
120
+ tag: tag
121
+ };
122
+ };
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.contributorAvatarRenderer = void 0;
7
+ var _bindEventListener = require("bind-event-listener");
8
+ var _avatarSizes = require("@atlaskit/avatar/avatar-sizes");
9
+ var _default = require("@atlaskit/avatar/constants/default");
10
+ var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view");
11
+ var _contributorTagIcons = require("./contributorTagIcons");
12
+ /** The size `@atlaskit/avatar`'s `xxsmall` rendered at. */
13
+ var AVATAR_SIZE = _avatarSizes.AVATAR_SIZES.xxsmall;
14
+ /** `xxsmall` also carried a `space.025` margin — the same 2px — which is where the ring is painted. */
15
+ var AVATAR_RING_WIDTH = _default.BORDER_WIDTH;
16
+ var AVATAR_BOX_SIZE = AVATAR_SIZE + AVATAR_RING_WIDTH * 2;
17
+
18
+ /** Reused from `@atlaskit/avatar`'s `avatar-content`, so the two shapes cannot drift. */
19
+ var HEXAGON_CLIP_PATH = 'polygon(45% 1.33975%, 46.5798% 0.60307%, 48.26352% 0.15192%, 50% 0%, 51.73648% 0.15192%, 53.4202% 0.60307%, 55% 1.33975%, 89.64102% 21.33975%, 91.06889% 22.33956%, 92.30146% 23.57212%, 93.30127% 25%, 94.03794% 26.5798%, 94.48909% 28.26352%, 94.64102% 30%, 94.64102% 70%, 94.48909% 71.73648%, 94.03794% 73.4202%, 93.30127% 75%, 92.30146% 76.42788%, 91.06889% 77.66044%, 89.64102% 78.66025%, 55% 98.66025%, 53.4202% 99.39693%, 51.73648% 99.84808%, 50% 100%, 48.26352% 99.84808%, 46.5798% 99.39693%, 45% 98.66025%, 10.35898% 78.66025%, 8.93111% 77.66044%, 7.69854% 76.42788%, 6.69873% 75%, 5.96206% 73.4202%, 5.51091% 71.73648%, 5.35898% 70%, 5.35898% 30%, 5.51091% 28.26352%, 5.96206% 26.5798%, 6.69873% 25%, 7.69854% 23.57212%, 8.93111% 22.33956%, 10.35898% 21.33975%)';
20
+ var boxStyle = (0, _lazyNodeView.convertToInlineCss)({
21
+ display: 'inline-flex',
22
+ alignItems: 'center',
23
+ justifyContent: 'center',
24
+ flexShrink: 0,
25
+ boxSizing: 'border-box',
26
+ width: "".concat(AVATAR_BOX_SIZE, "px"),
27
+ height: "".concat(AVATAR_BOX_SIZE, "px")
28
+ });
29
+ var shapeStyle = (0, _lazyNodeView.convertToInlineCss)({
30
+ display: 'inline-flex',
31
+ alignItems: 'center',
32
+ justifyContent: 'center',
33
+ boxSizing: 'border-box',
34
+ width: "".concat(AVATAR_SIZE, "px"),
35
+ height: "".concat(AVATAR_SIZE, "px"),
36
+ overflow: 'hidden'
37
+ });
38
+ var imageStyle = (0, _lazyNodeView.convertToInlineCss)({
39
+ display: 'block',
40
+ width: '100%',
41
+ height: '100%',
42
+ objectFit: 'cover'
43
+ });
44
+
45
+ /** The `@atlaskit/avatar` image fallback: a subtle glyph on a tinted box. */
46
+ var personFallbackStyle = (0, _lazyNodeView.convertToInlineCss)({
47
+ width: '100%',
48
+ height: '100%',
49
+ display: 'flex',
50
+ alignItems: 'center',
51
+ justifyContent: 'center',
52
+ backgroundColor: "var(--ds-background-accent-gray-subtler, #DDDEE1)",
53
+ color: "var(--ds-icon-subtle, #505258)"
54
+ });
55
+ /**
56
+ * One 16px avatar for a contributor: a circle for a person, a hexagon for an agent.
57
+ *
58
+ * Mirrors `mentionAvatarRenderer` — a bare `<img>` with a glyph fallback bound to `error`, and the
59
+ * hexagon cut with `clip-path`. The ring `@atlaskit/avatar` drew from `borderColor` is a
60
+ * `box-shadow` on the circle and a second clipped hexagon behind the agent, since `box-shadow` is
61
+ * cut away by `clip-path`.
62
+ */
63
+ var contributorAvatarRenderer = exports.contributorAvatarRenderer = function contributorAvatarRenderer(_ref) {
64
+ var contributor = _ref.contributor,
65
+ doc = _ref.doc,
66
+ ringColor = _ref.ringColor,
67
+ stackIndex = _ref.stackIndex;
68
+ var isAgent = contributor.kind === 'agent';
69
+ var element = doc.createElement('span');
70
+ element.setAttribute('style', boxStyle);
71
+ // Decorative: the tag names its contributors in the visually hidden label its screen-reader
72
+ // announcement comes from.
73
+ element.setAttribute('aria-hidden', 'true');
74
+ if (stackIndex !== undefined) {
75
+ element.style.setProperty('z-index', String(stackIndex));
76
+ }
77
+ var shape = doc.createElement('span');
78
+ shape.setAttribute('style', shapeStyle);
79
+ element.appendChild(shape);
80
+ if (isAgent) {
81
+ element.style.setProperty('clip-path', HEXAGON_CLIP_PATH);
82
+ shape.style.setProperty('clip-path', HEXAGON_CLIP_PATH);
83
+ } else {
84
+ shape.style.setProperty('border-radius', "var(--ds-radius-full, 9999px)");
85
+ }
86
+ var image;
87
+ var unbindImageError;
88
+ var showFallback = function showFallback() {
89
+ var _unbindImageError, _image;
90
+ (_unbindImageError = unbindImageError) === null || _unbindImageError === void 0 || _unbindImageError();
91
+ unbindImageError = undefined;
92
+ (_image = image) === null || _image === void 0 || _image.remove();
93
+ image = undefined;
94
+ if (!isAgent) {
95
+ var fallback = doc.createElement('span');
96
+ fallback.setAttribute('style', personFallbackStyle);
97
+ fallback.appendChild((0, _contributorTagIcons.getContributorTagIcon)('person', doc));
98
+ shape.appendChild(fallback);
99
+ return;
100
+ }
101
+ shape.appendChild((0, _contributorTagIcons.getContributorTagIcon)(contributor.agentKind === 'rovo' ? 'rovoHex' : 'aiBot', doc));
102
+ };
103
+ if (contributor.avatarUrl) {
104
+ image = doc.createElement('img');
105
+ image.alt = '';
106
+ image.decoding = 'async';
107
+ image.draggable = false;
108
+ image.loading = 'lazy';
109
+ image.setAttribute('style', imageStyle);
110
+ unbindImageError = (0, _bindEventListener.bind)(image, {
111
+ type: 'error',
112
+ listener: showFallback
113
+ });
114
+ shape.appendChild(image);
115
+ image.src = contributor.avatarUrl;
116
+ } else {
117
+ showFallback();
118
+ }
119
+ var setRingColor = function setRingColor(nextRingColor) {
120
+ if (isAgent) {
121
+ element.style.setProperty('background', nextRingColor);
122
+ // Shows through wherever the artwork is transparent, as the avatar background did.
123
+ shape.style.setProperty('background', nextRingColor);
124
+ return;
125
+ }
126
+ shape.style.setProperty('box-shadow', "0 0 0 ".concat(AVATAR_RING_WIDTH, "px ").concat(nextRingColor));
127
+ shape.style.setProperty('background', nextRingColor);
128
+ };
129
+ setRingColor(ringColor);
130
+ return {
131
+ destroy: function destroy() {
132
+ var _unbindImageError2;
133
+ (_unbindImageError2 = unbindImageError) === null || _unbindImageError2 === void 0 || _unbindImageError2();
134
+ unbindImageError = undefined;
135
+ element.remove();
136
+ },
137
+ element: element,
138
+ setRingColor: setRingColor
139
+ };
140
+ };