@atlaskit/editor-plugin-mentions 21.1.1 → 21.1.3

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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 21.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`90cc9e3c7fc0c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/90cc9e3c7fc0c) -
8
+ Support gated dark-background styling for the configured Rovo Chat agent mention in editors and
9
+ the renderer.
10
+ - Updated dependencies
11
+
12
+ ## 21.1.2
13
+
14
+ ### Patch Changes
15
+
16
+ - [`e824823394e78`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e824823394e78) -
17
+ Use CSS-escaped zero-width-space helpers for mention node views to avoid mojibake in affected
18
+ editor bundles. The `platform_editor_mention_zero_width_space_escape` experiment controls the
19
+ rollout.
20
+ - Updated dependencies
21
+
3
22
  ## 21.1.1
4
23
 
5
24
  ### Patch Changes
@@ -10,6 +10,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
10
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _bindEventListener = require("bind-event-listener");
13
14
  var _browser = require("@atlaskit/editor-common/browser");
14
15
  var _coreUtils = require("@atlaskit/editor-common/core-utils");
15
16
  var _vanillaTooltip = require("@atlaskit/editor-common/vanilla-tooltip");
@@ -31,6 +32,7 @@ var primitiveClassName = 'editor-mention-primitive';
31
32
  var primitiveWithAvatarClassName = 'editor-mention-primitive-with-avatar';
32
33
  var avatarContainerClassName = 'editor-mention-avatar';
33
34
  var mentionTextClassName = 'editor-mention-text';
35
+ var mentionZeroWidthSpaceClassName = 'mentionNodeViewAddZeroWidthSpace';
34
36
  /** Classes applied to the disabled-reason tooltip: the shared default look, plus our own hook. */
35
37
  var disabledTooltipClassNames = "".concat(_vanillaTooltip.VANILLA_TOOLTIP_DEFAULT_CLASS, " mention-disabled-tooltip");
36
38
  var genericMentionIds = ['HipChat', 'all', 'here'];
@@ -104,17 +106,18 @@ var toDOM = function toDOM(node, hasAvatarSlot) {
104
106
  spellcheck: 'false',
105
107
  class: primitiveClassName
106
108
  }, mentionText];
109
+ var zeroWidthSpaceHelperClassName = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_mention_zero_width_space_escape') ? mentionZeroWidthSpaceClassName : 'inlineNodeViewAddZeroWidthSpace';
107
110
  return ['span', mentionAttrs, ['span', {
108
111
  class: 'zeroWidthSpaceContainer'
109
112
  }, ['span', {
110
- class: 'inlineNodeViewAddZeroWidthSpace'
113
+ class: zeroWidthSpaceHelperClassName
111
114
  }, _whitespace.ZERO_WIDTH_SPACE]], mentionContentSpec, browser.android ? ['span', {
112
115
  class: 'zeroWidthSpaceContainer',
113
116
  contenteditable: 'false'
114
117
  }, ['span', {
115
- class: 'inlineNodeViewAddZeroWidthSpace'
118
+ class: zeroWidthSpaceHelperClassName
116
119
  }, _whitespace.ZERO_WIDTH_SPACE]] : ['span', {
117
- class: 'inlineNodeViewAddZeroWidthSpace'
120
+ class: zeroWidthSpaceHelperClassName
118
121
  }, _whitespace.ZERO_WIDTH_SPACE]];
119
122
  };
120
123
  var processName = function processName(name) {
@@ -196,10 +199,16 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
196
199
  }
197
200
  var _ref2 = (_api$mention$sharedSt = api === null || api === void 0 ? void 0 : api.mention.sharedState.currentState()) !== null && _api$mention$sharedSt !== void 0 ? _api$mention$sharedSt : {},
198
201
  mentionProvider = _ref2.mentionProvider;
202
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_mention_rovo')) {
203
+ void this.resolveRovoChatIdentity(mentionProvider);
204
+ }
199
205
  this.updateState(mentionProvider);
200
206
  this.subscribeToProviderDisabledStateChanges(mentionProvider);
201
207
  this.cleanup = api === null || api === void 0 ? void 0 : api.mention.sharedState.onChange(function (_ref3) {
202
208
  var nextSharedState = _ref3.nextSharedState;
209
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_mention_rovo')) {
210
+ void _this.resolveRovoChatIdentity(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
211
+ }
203
212
  _this.updateState(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
204
213
  _this.subscribeToProviderDisabledStateChanges(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
205
214
  });
@@ -254,6 +263,116 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
254
263
  }
255
264
  }
256
265
  }
266
+ }, {
267
+ key: "resolveRovoChatIdentity",
268
+ value: function () {
269
+ var _resolveRovoChatIdentity = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(mentionProvider) {
270
+ var identityAccountId;
271
+ return _regenerator.default.wrap(function (_context2) {
272
+ while (1) switch (_context2.prev = _context2.next) {
273
+ case 0:
274
+ if (!(this.rovoChatIdentityProvider === mentionProvider)) {
275
+ _context2.next = 1;
276
+ break;
277
+ }
278
+ return _context2.abrupt("return");
279
+ case 1:
280
+ this.rovoChatIdentityProvider = mentionProvider;
281
+ if (!(!(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_mention_rovo') || !(mentionProvider !== null && mentionProvider !== void 0 && mentionProvider.getRovoChatAgentIdentityAccountId))) {
282
+ _context2.next = 2;
283
+ break;
284
+ }
285
+ this.setRovoChatStyles(false);
286
+ return _context2.abrupt("return");
287
+ case 2:
288
+ _context2.next = 3;
289
+ return mentionProvider.getRovoChatAgentIdentityAccountId();
290
+ case 3:
291
+ identityAccountId = _context2.sent;
292
+ if (!(this.rovoChatIdentityProvider !== mentionProvider)) {
293
+ _context2.next = 4;
294
+ break;
295
+ }
296
+ return _context2.abrupt("return");
297
+ case 4:
298
+ if (!(identityAccountId === undefined || identityAccountId !== this.node.attrs.id)) {
299
+ _context2.next = 5;
300
+ break;
301
+ }
302
+ this.setRovoChatStyles(false);
303
+ return _context2.abrupt("return");
304
+ case 5:
305
+ this.setRovoChatStyles(true);
306
+ case 6:
307
+ case "end":
308
+ return _context2.stop();
309
+ }
310
+ }, _callee2, this);
311
+ }));
312
+ function resolveRovoChatIdentity(_x4) {
313
+ return _resolveRovoChatIdentity.apply(this, arguments);
314
+ }
315
+ return resolveRovoChatIdentity;
316
+ }()
317
+ }, {
318
+ key: "setRovoChatStyles",
319
+ value: function setRovoChatStyles(isRovoChat) {
320
+ var _this$cleanupRovoChat, _this$mentionTextElem2;
321
+ (_this$cleanupRovoChat = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat === void 0 || _this$cleanupRovoChat.call(this);
322
+ this.cleanupRovoChatStyles = undefined;
323
+ var primitive = this.mentionPrimitiveElement;
324
+ if (!primitive) {
325
+ return;
326
+ }
327
+ primitive.classList.toggle('mention-rovo-chat', isRovoChat);
328
+ if (!isRovoChat) {
329
+ var _this$mentionTextElem;
330
+ primitive.style.removeProperty('background-color');
331
+ primitive.style.removeProperty('color');
332
+ (_this$mentionTextElem = this.mentionTextElement) === null || _this$mentionTextElem === void 0 || _this$mentionTextElem.style.removeProperty('color');
333
+ return;
334
+ }
335
+ var baseBackground = "var(--ds-background-neutral-bold, #292A2E)";
336
+ var hoveredBackground = "var(--ds-background-neutral-bold-hovered, #3B3D42)";
337
+ var pressedBackground = "var(--ds-background-neutral-bold-pressed, #505258)";
338
+ var inverseText = "var(--ds-text-inverse, #FFFFFF)";
339
+ var setBackground = function setBackground(background) {
340
+ primitive.style.setProperty('background-color', background);
341
+ };
342
+ setBackground(baseBackground);
343
+ primitive.style.setProperty('color', inverseText);
344
+ (_this$mentionTextElem2 = this.mentionTextElement) === null || _this$mentionTextElem2 === void 0 || _this$mentionTextElem2.style.setProperty('color', inverseText);
345
+ var onMouseEnter = function onMouseEnter() {
346
+ return setBackground(hoveredBackground);
347
+ };
348
+ var onMouseLeave = function onMouseLeave() {
349
+ return setBackground(baseBackground);
350
+ };
351
+ var onMouseDown = function onMouseDown() {
352
+ return setBackground(pressedBackground);
353
+ };
354
+ var onMouseUp = function onMouseUp() {
355
+ return setBackground(hoveredBackground);
356
+ };
357
+ var unbinders = [(0, _bindEventListener.bind)(primitive, {
358
+ type: 'mouseenter',
359
+ listener: onMouseEnter
360
+ }), (0, _bindEventListener.bind)(primitive, {
361
+ type: 'mouseleave',
362
+ listener: onMouseLeave
363
+ }), (0, _bindEventListener.bind)(primitive, {
364
+ type: 'mousedown',
365
+ listener: onMouseDown
366
+ }), (0, _bindEventListener.bind)(primitive, {
367
+ type: 'mouseup',
368
+ listener: onMouseUp
369
+ })];
370
+ this.cleanupRovoChatStyles = function () {
371
+ unbinders.forEach(function (unbind) {
372
+ return unbind();
373
+ });
374
+ };
375
+ }
257
376
  }, {
258
377
  key: "getDisabledState",
259
378
  value: function getDisabledState(mentionProvider) {
@@ -410,11 +529,11 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
410
529
  }, {
411
530
  key: "updateState",
412
531
  value: function () {
413
- var _updateState = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(mentionProvider) {
532
+ var _updateState = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(mentionProvider) {
414
533
  var _this$config$options2;
415
534
  var isAgentMentionsEnabled, isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name, text;
416
- return _regenerator.default.wrap(function (_context2) {
417
- while (1) switch (_context2.prev = _context2.next) {
535
+ return _regenerator.default.wrap(function (_context3) {
536
+ while (1) switch (_context3.prev = _context3.next) {
418
537
  case 0:
419
538
  isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
420
539
  isHighlighted = this.shouldHighlightMention(mentionProvider);
@@ -430,10 +549,10 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
430
549
  // the tooltip text stays in sync if the disabled reason changes while
431
550
  // the chip is already disabled.
432
551
  this.syncDisabledTooltip(disabledState);
433
- _context2.next = 1;
552
+ _context3.next = 1;
434
553
  return handleProviderName(mentionProvider, this.node, isAgentMentionsEnabled);
435
554
  case 1:
436
- name = _context2.sent;
555
+ name = _context3.sent;
437
556
  this.setTextContent(name, isAgentMentionsEnabled);
438
557
  // Only overwrite the disabled-state aria-label with the name-based one
439
558
  // when the chip is NOT disabled; otherwise the disabled reason set in
@@ -446,11 +565,11 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
446
565
  }
447
566
  case 2:
448
567
  case "end":
449
- return _context2.stop();
568
+ return _context3.stop();
450
569
  }
451
- }, _callee2, this);
570
+ }, _callee3, this);
452
571
  }));
453
- function updateState(_x4) {
572
+ function updateState(_x5) {
454
573
  return _updateState.apply(this, arguments);
455
574
  }
456
575
  return updateState;
@@ -484,7 +603,7 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
484
603
  }, {
485
604
  key: "destroy",
486
605
  value: function destroy() {
487
- var _this$cleanup, _this$destroyProfileC, _this$mentionAvatar, _this$disabledTooltip, _this$unsubscribeFrom2;
606
+ var _this$cleanup, _this$cleanupRovoChat2, _this$destroyProfileC, _this$mentionAvatar, _this$disabledTooltip, _this$unsubscribeFrom2;
488
607
  this.isDestroyed = true;
489
608
  // Surface the destruction to the provider before tearing down so the
490
609
  // chat layer can react (e.g. drop the agent id from `selectedAgentIds`).
@@ -500,6 +619,8 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
500
619
  // the NodeView from cleaning up its own resources below.
501
620
  }
502
621
  (_this$cleanup = this.cleanup) === null || _this$cleanup === void 0 || _this$cleanup.call(this);
622
+ (_this$cleanupRovoChat2 = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat2 === void 0 || _this$cleanupRovoChat2.call(this);
623
+ this.cleanupRovoChatStyles = undefined;
503
624
  (_this$destroyProfileC = this.destroyProfileCard) === null || _this$destroyProfileC === void 0 || _this$destroyProfileC.call(this);
504
625
  (_this$mentionAvatar = this.mentionAvatar) === null || _this$mentionAvatar === void 0 || _this$mentionAvatar.destroy();
505
626
  this.mentionAvatar = undefined;
@@ -44,7 +44,7 @@ var ACTIONS = exports.ACTIONS = {
44
44
  CLEAR_PENDING_PASTED_AGENT_MENTION: 'CLEAR_PENDING_PASTED_AGENT_MENTION'
45
45
  };
46
46
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
47
- var PACKAGE_VERSION = "21.1.0";
47
+ var PACKAGE_VERSION = "21.1.2";
48
48
  var setProvider = function setProvider(provider) {
49
49
  return function (state, dispatch) {
50
50
  if (dispatch) {
@@ -1,4 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { bind } from 'bind-event-listener';
2
3
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
3
4
  import { isSSR } from '@atlaskit/editor-common/core-utils';
4
5
  import { VANILLA_TOOLTIP_DEFAULT_CLASS, VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
@@ -20,6 +21,7 @@ const primitiveClassName = 'editor-mention-primitive';
20
21
  const primitiveWithAvatarClassName = 'editor-mention-primitive-with-avatar';
21
22
  const avatarContainerClassName = 'editor-mention-avatar';
22
23
  const mentionTextClassName = 'editor-mention-text';
24
+ const mentionZeroWidthSpaceClassName = 'mentionNodeViewAddZeroWidthSpace';
23
25
  /** Classes applied to the disabled-reason tooltip: the shared default look, plus our own hook. */
24
26
  const disabledTooltipClassNames = `${VANILLA_TOOLTIP_DEFAULT_CLASS} mention-disabled-tooltip`;
25
27
  const genericMentionIds = ['HipChat', 'all', 'here'];
@@ -87,17 +89,18 @@ const toDOM = (node, hasAvatarSlot) => {
87
89
  spellcheck: 'false',
88
90
  class: primitiveClassName
89
91
  }, mentionText];
92
+ const zeroWidthSpaceHelperClassName = isExperimentEnabled('platform_editor_mention_zero_width_space_escape') ? mentionZeroWidthSpaceClassName : 'inlineNodeViewAddZeroWidthSpace';
90
93
  return ['span', mentionAttrs, ['span', {
91
94
  class: 'zeroWidthSpaceContainer'
92
95
  }, ['span', {
93
- class: 'inlineNodeViewAddZeroWidthSpace'
96
+ class: zeroWidthSpaceHelperClassName
94
97
  }, ZERO_WIDTH_SPACE]], mentionContentSpec, browser.android ? ['span', {
95
98
  class: 'zeroWidthSpaceContainer',
96
99
  contenteditable: 'false'
97
100
  }, ['span', {
98
- class: 'inlineNodeViewAddZeroWidthSpace'
101
+ class: zeroWidthSpaceHelperClassName
99
102
  }, ZERO_WIDTH_SPACE]] : ['span', {
100
- class: 'inlineNodeViewAddZeroWidthSpace'
103
+ class: zeroWidthSpaceHelperClassName
101
104
  }, ZERO_WIDTH_SPACE]];
102
105
  };
103
106
  const processName = name => {
@@ -161,11 +164,17 @@ export class MentionNodeView {
161
164
  const {
162
165
  mentionProvider
163
166
  } = (_api$mention$sharedSt = api === null || api === void 0 ? void 0 : api.mention.sharedState.currentState()) !== null && _api$mention$sharedSt !== void 0 ? _api$mention$sharedSt : {};
167
+ if (isExperimentEnabled('platform_editor_mention_rovo')) {
168
+ void this.resolveRovoChatIdentity(mentionProvider);
169
+ }
164
170
  this.updateState(mentionProvider);
165
171
  this.subscribeToProviderDisabledStateChanges(mentionProvider);
166
172
  this.cleanup = api === null || api === void 0 ? void 0 : api.mention.sharedState.onChange(({
167
173
  nextSharedState
168
174
  }) => {
175
+ if (isExperimentEnabled('platform_editor_mention_rovo')) {
176
+ void this.resolveRovoChatIdentity(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
177
+ }
169
178
  this.updateState(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
170
179
  this.subscribeToProviderDisabledStateChanges(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
171
180
  });
@@ -219,6 +228,72 @@ export class MentionNodeView {
219
228
  }
220
229
  }
221
230
  }
231
+ async resolveRovoChatIdentity(mentionProvider) {
232
+ if (this.rovoChatIdentityProvider === mentionProvider) {
233
+ return;
234
+ }
235
+ this.rovoChatIdentityProvider = mentionProvider;
236
+ if (!isExperimentEnabled('platform_editor_mention_rovo') || !(mentionProvider !== null && mentionProvider !== void 0 && mentionProvider.getRovoChatAgentIdentityAccountId)) {
237
+ this.setRovoChatStyles(false);
238
+ return;
239
+ }
240
+ const identityAccountId = await mentionProvider.getRovoChatAgentIdentityAccountId();
241
+ if (this.rovoChatIdentityProvider !== mentionProvider) {
242
+ return;
243
+ }
244
+ if (identityAccountId === undefined || identityAccountId !== this.node.attrs.id) {
245
+ this.setRovoChatStyles(false);
246
+ return;
247
+ }
248
+ this.setRovoChatStyles(true);
249
+ }
250
+ setRovoChatStyles(isRovoChat) {
251
+ var _this$cleanupRovoChat, _this$mentionTextElem2;
252
+ (_this$cleanupRovoChat = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat === void 0 ? void 0 : _this$cleanupRovoChat.call(this);
253
+ this.cleanupRovoChatStyles = undefined;
254
+ const primitive = this.mentionPrimitiveElement;
255
+ if (!primitive) {
256
+ return;
257
+ }
258
+ primitive.classList.toggle('mention-rovo-chat', isRovoChat);
259
+ if (!isRovoChat) {
260
+ var _this$mentionTextElem;
261
+ primitive.style.removeProperty('background-color');
262
+ primitive.style.removeProperty('color');
263
+ (_this$mentionTextElem = this.mentionTextElement) === null || _this$mentionTextElem === void 0 ? void 0 : _this$mentionTextElem.style.removeProperty('color');
264
+ return;
265
+ }
266
+ const baseBackground = "var(--ds-background-neutral-bold, #292A2E)";
267
+ const hoveredBackground = "var(--ds-background-neutral-bold-hovered, #3B3D42)";
268
+ const pressedBackground = "var(--ds-background-neutral-bold-pressed, #505258)";
269
+ const inverseText = "var(--ds-text-inverse, #FFFFFF)";
270
+ const setBackground = background => {
271
+ primitive.style.setProperty('background-color', background);
272
+ };
273
+ setBackground(baseBackground);
274
+ primitive.style.setProperty('color', inverseText);
275
+ (_this$mentionTextElem2 = this.mentionTextElement) === null || _this$mentionTextElem2 === void 0 ? void 0 : _this$mentionTextElem2.style.setProperty('color', inverseText);
276
+ const onMouseEnter = () => setBackground(hoveredBackground);
277
+ const onMouseLeave = () => setBackground(baseBackground);
278
+ const onMouseDown = () => setBackground(pressedBackground);
279
+ const onMouseUp = () => setBackground(hoveredBackground);
280
+ const unbinders = [bind(primitive, {
281
+ type: 'mouseenter',
282
+ listener: onMouseEnter
283
+ }), bind(primitive, {
284
+ type: 'mouseleave',
285
+ listener: onMouseLeave
286
+ }), bind(primitive, {
287
+ type: 'mousedown',
288
+ listener: onMouseDown
289
+ }), bind(primitive, {
290
+ type: 'mouseup',
291
+ listener: onMouseUp
292
+ })];
293
+ this.cleanupRovoChatStyles = () => {
294
+ unbinders.forEach(unbind => unbind());
295
+ };
296
+ }
222
297
  getDisabledState(mentionProvider) {
223
298
  var _mentionProvider$getM;
224
299
  const input = {
@@ -410,7 +485,7 @@ export class MentionNodeView {
410
485
  return true;
411
486
  }
412
487
  destroy() {
413
- var _this$cleanup, _this$destroyProfileC, _this$mentionAvatar2, _this$disabledTooltip, _this$unsubscribeFrom2;
488
+ var _this$cleanup, _this$cleanupRovoChat2, _this$destroyProfileC, _this$mentionAvatar2, _this$disabledTooltip, _this$unsubscribeFrom2;
414
489
  this.isDestroyed = true;
415
490
  // Surface the destruction to the provider before tearing down so the
416
491
  // chat layer can react (e.g. drop the agent id from `selectedAgentIds`).
@@ -426,6 +501,8 @@ export class MentionNodeView {
426
501
  // the NodeView from cleaning up its own resources below.
427
502
  }
428
503
  (_this$cleanup = this.cleanup) === null || _this$cleanup === void 0 ? void 0 : _this$cleanup.call(this);
504
+ (_this$cleanupRovoChat2 = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat2 === void 0 ? void 0 : _this$cleanupRovoChat2.call(this);
505
+ this.cleanupRovoChatStyles = undefined;
429
506
  (_this$destroyProfileC = this.destroyProfileCard) === null || _this$destroyProfileC === void 0 ? void 0 : _this$destroyProfileC.call(this);
430
507
  (_this$mentionAvatar2 = this.mentionAvatar) === null || _this$mentionAvatar2 === void 0 ? void 0 : _this$mentionAvatar2.destroy();
431
508
  this.mentionAvatar = undefined;
@@ -33,7 +33,7 @@ export const ACTIONS = {
33
33
  CLEAR_PENDING_PASTED_AGENT_MENTION: 'CLEAR_PENDING_PASTED_AGENT_MENTION'
34
34
  };
35
35
  const PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
36
- const PACKAGE_VERSION = "21.1.0";
36
+ const PACKAGE_VERSION = "21.1.2";
37
37
  const setProvider = provider => (state, dispatch) => {
38
38
  if (dispatch) {
39
39
  dispatch(state.tr.setMeta(mentionPluginKey, {
@@ -5,6 +5,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
6
  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; }
7
7
  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; }
8
+ import { bind } from 'bind-event-listener';
8
9
  import { getBrowserInfo } from '@atlaskit/editor-common/browser';
9
10
  import { isSSR } from '@atlaskit/editor-common/core-utils';
10
11
  import { VANILLA_TOOLTIP_DEFAULT_CLASS, VanillaTooltip } from '@atlaskit/editor-common/vanilla-tooltip';
@@ -26,6 +27,7 @@ var primitiveClassName = 'editor-mention-primitive';
26
27
  var primitiveWithAvatarClassName = 'editor-mention-primitive-with-avatar';
27
28
  var avatarContainerClassName = 'editor-mention-avatar';
28
29
  var mentionTextClassName = 'editor-mention-text';
30
+ var mentionZeroWidthSpaceClassName = 'mentionNodeViewAddZeroWidthSpace';
29
31
  /** Classes applied to the disabled-reason tooltip: the shared default look, plus our own hook. */
30
32
  var disabledTooltipClassNames = "".concat(VANILLA_TOOLTIP_DEFAULT_CLASS, " mention-disabled-tooltip");
31
33
  var genericMentionIds = ['HipChat', 'all', 'here'];
@@ -99,17 +101,18 @@ var toDOM = function toDOM(node, hasAvatarSlot) {
99
101
  spellcheck: 'false',
100
102
  class: primitiveClassName
101
103
  }, mentionText];
104
+ var zeroWidthSpaceHelperClassName = isExperimentEnabled('platform_editor_mention_zero_width_space_escape') ? mentionZeroWidthSpaceClassName : 'inlineNodeViewAddZeroWidthSpace';
102
105
  return ['span', mentionAttrs, ['span', {
103
106
  class: 'zeroWidthSpaceContainer'
104
107
  }, ['span', {
105
- class: 'inlineNodeViewAddZeroWidthSpace'
108
+ class: zeroWidthSpaceHelperClassName
106
109
  }, ZERO_WIDTH_SPACE]], mentionContentSpec, browser.android ? ['span', {
107
110
  class: 'zeroWidthSpaceContainer',
108
111
  contenteditable: 'false'
109
112
  }, ['span', {
110
- class: 'inlineNodeViewAddZeroWidthSpace'
113
+ class: zeroWidthSpaceHelperClassName
111
114
  }, ZERO_WIDTH_SPACE]] : ['span', {
112
- class: 'inlineNodeViewAddZeroWidthSpace'
115
+ class: zeroWidthSpaceHelperClassName
113
116
  }, ZERO_WIDTH_SPACE]];
114
117
  };
115
118
  var processName = function processName(name) {
@@ -191,10 +194,16 @@ export var MentionNodeView = /*#__PURE__*/function () {
191
194
  }
192
195
  var _ref2 = (_api$mention$sharedSt = api === null || api === void 0 ? void 0 : api.mention.sharedState.currentState()) !== null && _api$mention$sharedSt !== void 0 ? _api$mention$sharedSt : {},
193
196
  mentionProvider = _ref2.mentionProvider;
197
+ if (isExperimentEnabled('platform_editor_mention_rovo')) {
198
+ void this.resolveRovoChatIdentity(mentionProvider);
199
+ }
194
200
  this.updateState(mentionProvider);
195
201
  this.subscribeToProviderDisabledStateChanges(mentionProvider);
196
202
  this.cleanup = api === null || api === void 0 ? void 0 : api.mention.sharedState.onChange(function (_ref3) {
197
203
  var nextSharedState = _ref3.nextSharedState;
204
+ if (isExperimentEnabled('platform_editor_mention_rovo')) {
205
+ void _this.resolveRovoChatIdentity(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
206
+ }
198
207
  _this.updateState(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
199
208
  _this.subscribeToProviderDisabledStateChanges(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.mentionProvider);
200
209
  });
@@ -249,6 +258,116 @@ export var MentionNodeView = /*#__PURE__*/function () {
249
258
  }
250
259
  }
251
260
  }
261
+ }, {
262
+ key: "resolveRovoChatIdentity",
263
+ value: function () {
264
+ var _resolveRovoChatIdentity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(mentionProvider) {
265
+ var identityAccountId;
266
+ return _regeneratorRuntime.wrap(function (_context2) {
267
+ while (1) switch (_context2.prev = _context2.next) {
268
+ case 0:
269
+ if (!(this.rovoChatIdentityProvider === mentionProvider)) {
270
+ _context2.next = 1;
271
+ break;
272
+ }
273
+ return _context2.abrupt("return");
274
+ case 1:
275
+ this.rovoChatIdentityProvider = mentionProvider;
276
+ if (!(!isExperimentEnabled('platform_editor_mention_rovo') || !(mentionProvider !== null && mentionProvider !== void 0 && mentionProvider.getRovoChatAgentIdentityAccountId))) {
277
+ _context2.next = 2;
278
+ break;
279
+ }
280
+ this.setRovoChatStyles(false);
281
+ return _context2.abrupt("return");
282
+ case 2:
283
+ _context2.next = 3;
284
+ return mentionProvider.getRovoChatAgentIdentityAccountId();
285
+ case 3:
286
+ identityAccountId = _context2.sent;
287
+ if (!(this.rovoChatIdentityProvider !== mentionProvider)) {
288
+ _context2.next = 4;
289
+ break;
290
+ }
291
+ return _context2.abrupt("return");
292
+ case 4:
293
+ if (!(identityAccountId === undefined || identityAccountId !== this.node.attrs.id)) {
294
+ _context2.next = 5;
295
+ break;
296
+ }
297
+ this.setRovoChatStyles(false);
298
+ return _context2.abrupt("return");
299
+ case 5:
300
+ this.setRovoChatStyles(true);
301
+ case 6:
302
+ case "end":
303
+ return _context2.stop();
304
+ }
305
+ }, _callee2, this);
306
+ }));
307
+ function resolveRovoChatIdentity(_x4) {
308
+ return _resolveRovoChatIdentity.apply(this, arguments);
309
+ }
310
+ return resolveRovoChatIdentity;
311
+ }()
312
+ }, {
313
+ key: "setRovoChatStyles",
314
+ value: function setRovoChatStyles(isRovoChat) {
315
+ var _this$cleanupRovoChat, _this$mentionTextElem2;
316
+ (_this$cleanupRovoChat = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat === void 0 || _this$cleanupRovoChat.call(this);
317
+ this.cleanupRovoChatStyles = undefined;
318
+ var primitive = this.mentionPrimitiveElement;
319
+ if (!primitive) {
320
+ return;
321
+ }
322
+ primitive.classList.toggle('mention-rovo-chat', isRovoChat);
323
+ if (!isRovoChat) {
324
+ var _this$mentionTextElem;
325
+ primitive.style.removeProperty('background-color');
326
+ primitive.style.removeProperty('color');
327
+ (_this$mentionTextElem = this.mentionTextElement) === null || _this$mentionTextElem === void 0 || _this$mentionTextElem.style.removeProperty('color');
328
+ return;
329
+ }
330
+ var baseBackground = "var(--ds-background-neutral-bold, #292A2E)";
331
+ var hoveredBackground = "var(--ds-background-neutral-bold-hovered, #3B3D42)";
332
+ var pressedBackground = "var(--ds-background-neutral-bold-pressed, #505258)";
333
+ var inverseText = "var(--ds-text-inverse, #FFFFFF)";
334
+ var setBackground = function setBackground(background) {
335
+ primitive.style.setProperty('background-color', background);
336
+ };
337
+ setBackground(baseBackground);
338
+ primitive.style.setProperty('color', inverseText);
339
+ (_this$mentionTextElem2 = this.mentionTextElement) === null || _this$mentionTextElem2 === void 0 || _this$mentionTextElem2.style.setProperty('color', inverseText);
340
+ var onMouseEnter = function onMouseEnter() {
341
+ return setBackground(hoveredBackground);
342
+ };
343
+ var onMouseLeave = function onMouseLeave() {
344
+ return setBackground(baseBackground);
345
+ };
346
+ var onMouseDown = function onMouseDown() {
347
+ return setBackground(pressedBackground);
348
+ };
349
+ var onMouseUp = function onMouseUp() {
350
+ return setBackground(hoveredBackground);
351
+ };
352
+ var unbinders = [bind(primitive, {
353
+ type: 'mouseenter',
354
+ listener: onMouseEnter
355
+ }), bind(primitive, {
356
+ type: 'mouseleave',
357
+ listener: onMouseLeave
358
+ }), bind(primitive, {
359
+ type: 'mousedown',
360
+ listener: onMouseDown
361
+ }), bind(primitive, {
362
+ type: 'mouseup',
363
+ listener: onMouseUp
364
+ })];
365
+ this.cleanupRovoChatStyles = function () {
366
+ unbinders.forEach(function (unbind) {
367
+ return unbind();
368
+ });
369
+ };
370
+ }
252
371
  }, {
253
372
  key: "getDisabledState",
254
373
  value: function getDisabledState(mentionProvider) {
@@ -405,11 +524,11 @@ export var MentionNodeView = /*#__PURE__*/function () {
405
524
  }, {
406
525
  key: "updateState",
407
526
  value: function () {
408
- var _updateState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(mentionProvider) {
527
+ var _updateState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(mentionProvider) {
409
528
  var _this$config$options2;
410
529
  var isAgentMentionsEnabled, isHighlighted, disabledState, isDisabled, newState, disabledTooltip, name, text;
411
- return _regeneratorRuntime.wrap(function (_context2) {
412
- while (1) switch (_context2.prev = _context2.next) {
530
+ return _regeneratorRuntime.wrap(function (_context3) {
531
+ while (1) switch (_context3.prev = _context3.next) {
413
532
  case 0:
414
533
  isAgentMentionsEnabled = isAgentMentionsExperimentEnabled();
415
534
  isHighlighted = this.shouldHighlightMention(mentionProvider);
@@ -425,10 +544,10 @@ export var MentionNodeView = /*#__PURE__*/function () {
425
544
  // the tooltip text stays in sync if the disabled reason changes while
426
545
  // the chip is already disabled.
427
546
  this.syncDisabledTooltip(disabledState);
428
- _context2.next = 1;
547
+ _context3.next = 1;
429
548
  return handleProviderName(mentionProvider, this.node, isAgentMentionsEnabled);
430
549
  case 1:
431
- name = _context2.sent;
550
+ name = _context3.sent;
432
551
  this.setTextContent(name, isAgentMentionsEnabled);
433
552
  // Only overwrite the disabled-state aria-label with the name-based one
434
553
  // when the chip is NOT disabled; otherwise the disabled reason set in
@@ -441,11 +560,11 @@ export var MentionNodeView = /*#__PURE__*/function () {
441
560
  }
442
561
  case 2:
443
562
  case "end":
444
- return _context2.stop();
563
+ return _context3.stop();
445
564
  }
446
- }, _callee2, this);
565
+ }, _callee3, this);
447
566
  }));
448
- function updateState(_x4) {
567
+ function updateState(_x5) {
449
568
  return _updateState.apply(this, arguments);
450
569
  }
451
570
  return updateState;
@@ -479,7 +598,7 @@ export var MentionNodeView = /*#__PURE__*/function () {
479
598
  }, {
480
599
  key: "destroy",
481
600
  value: function destroy() {
482
- var _this$cleanup, _this$destroyProfileC, _this$mentionAvatar, _this$disabledTooltip, _this$unsubscribeFrom2;
601
+ var _this$cleanup, _this$cleanupRovoChat2, _this$destroyProfileC, _this$mentionAvatar, _this$disabledTooltip, _this$unsubscribeFrom2;
483
602
  this.isDestroyed = true;
484
603
  // Surface the destruction to the provider before tearing down so the
485
604
  // chat layer can react (e.g. drop the agent id from `selectedAgentIds`).
@@ -495,6 +614,8 @@ export var MentionNodeView = /*#__PURE__*/function () {
495
614
  // the NodeView from cleaning up its own resources below.
496
615
  }
497
616
  (_this$cleanup = this.cleanup) === null || _this$cleanup === void 0 || _this$cleanup.call(this);
617
+ (_this$cleanupRovoChat2 = this.cleanupRovoChatStyles) === null || _this$cleanupRovoChat2 === void 0 || _this$cleanupRovoChat2.call(this);
618
+ this.cleanupRovoChatStyles = undefined;
498
619
  (_this$destroyProfileC = this.destroyProfileCard) === null || _this$destroyProfileC === void 0 || _this$destroyProfileC.call(this);
499
620
  (_this$mentionAvatar = this.mentionAvatar) === null || _this$mentionAvatar === void 0 || _this$mentionAvatar.destroy();
500
621
  this.mentionAvatar = undefined;
@@ -36,7 +36,7 @@ export var ACTIONS = {
36
36
  CLEAR_PENDING_PASTED_AGENT_MENTION: 'CLEAR_PENDING_PASTED_AGENT_MENTION'
37
37
  };
38
38
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
39
- var PACKAGE_VERSION = "21.1.0";
39
+ var PACKAGE_VERSION = "21.1.2";
40
40
  var setProvider = function setProvider(provider) {
41
41
  return function (state, dispatch) {
42
42
  if (dispatch) {
@@ -23,6 +23,8 @@ export declare class MentionNodeView implements NodeView {
23
23
  private mentionPrimitiveElement;
24
24
  private mentionTextElement;
25
25
  private mentionAvatar;
26
+ private cleanupRovoChatStyles;
27
+ private rovoChatIdentityProvider;
26
28
  private hasAvatarSlot;
27
29
  private isDestroyed;
28
30
  private disabledTooltip;
@@ -32,6 +34,8 @@ export declare class MentionNodeView implements NodeView {
32
34
  private subscribedProvider;
33
35
  constructor(node: PMNode, config: MentionNodeViewProps);
34
36
  private setClassList;
37
+ private resolveRovoChatIdentity;
38
+ private setRovoChatStyles;
35
39
  private getDisabledState;
36
40
  /**
37
41
  * Subscribes this NodeView to disabled-state-change notifications on the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "21.1.1",
3
+ "version": "21.1.3",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -60,7 +60,7 @@
60
60
  "uuid": "^11.1.1"
61
61
  },
62
62
  "peerDependencies": {
63
- "@atlaskit/editor-common": "^123.5.0",
63
+ "@atlaskit/editor-common": "^123.6.0",
64
64
  "react": "^18.2.0 || ^19.2.0",
65
65
  "react-dom": "^18.2.0 || ^19.2.0",
66
66
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"