@atlaskit/editor-plugin-mentions 14.5.6 → 14.5.8

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,19 @@
1
1
  # @atlaskit/editor-plugin-mentions
2
2
 
3
+ ## 14.5.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [`14023b8bbf880`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/14023b8bbf880) -
8
+ [ux] Shows reduced profile card when user lacks permission to read/access agent mention on page
9
+ - Updated dependencies
10
+
11
+ ## 14.5.7
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 14.5.6
4
18
 
5
19
  ### Patch Changes
@@ -143,7 +143,8 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
143
143
  api: api
144
144
  }),
145
145
  destroyProfileCard = _profileCardRenderer.destroyProfileCard,
146
- removeProfileCard = _profileCardRenderer.removeProfileCard;
146
+ removeProfileCard = _profileCardRenderer.removeProfileCard,
147
+ updateNode = _profileCardRenderer.updateNode;
147
148
  // Accessibility attributes - based on `packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx`
148
149
  if (this.domElement && options !== null && options !== void 0 && options.profilecardProvider) {
149
150
  if (node.attrs.text) {
@@ -156,6 +157,7 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
156
157
  }
157
158
  this.destroyProfileCard = destroyProfileCard;
158
159
  this.removeProfileCard = removeProfileCard;
160
+ this.updateProfileCardNode = updateNode;
159
161
  }
160
162
  return (0, _createClass2.default)(MentionNodeView, [{
161
163
  key: "setClassList",
@@ -333,10 +335,14 @@ var MentionNodeView = exports.MentionNodeView = /*#__PURE__*/function () {
333
335
  }, {
334
336
  key: "update",
335
337
  value: function update(node) {
338
+ var _this$updateProfileCa;
336
339
  if (!this.nodeIsEqual(node)) {
337
340
  return false;
338
341
  }
339
342
  this.node = node;
343
+ // Keep the profile card renderer's node reference in sync so that the
344
+ // click handler always reads up-to-date attrs.
345
+ (_this$updateProfileCa = this.updateProfileCardNode) === null || _this$updateProfileCa === void 0 || _this$updateProfileCa.call(this, node);
340
346
  return true;
341
347
  }
342
348
  }, {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.profileCardRenderer = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _react = _interopRequireDefault(require("react"));
9
10
  var _bindEventListener = require("bind-event-listener");
10
11
  var _v = _interopRequireDefault(require("uuid/v4"));
@@ -13,14 +14,17 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
14
  var _navigation = require("@atlaskit/teams-app-config/navigation");
14
15
  var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
15
16
  var _ProfileCardComponent = require("../ui/ProfileCardComponent");
16
- // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
17
-
17
+ 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
+ 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; } // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
18
19
  var profileCardRenderer = exports.profileCardRenderer = function profileCardRenderer(_ref) {
19
20
  var dom = _ref.dom,
20
21
  options = _ref.options,
21
22
  portalProviderAPI = _ref.portalProviderAPI,
22
23
  node = _ref.node,
23
24
  api = _ref.api;
25
+ // Keep a mutable reference to the latest node so the click handler always
26
+ // reads up-to-date attrs
27
+ var currentNode = node;
24
28
  var renderingProfileCard = false;
25
29
  var navigatingToProfile = false;
26
30
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -49,16 +53,28 @@ var profileCardRenderer = exports.profileCardRenderer = function profileCardRend
49
53
  cleanupSelection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.sharedState.onChange(function (_ref2) {
50
54
  var nextSharedState = _ref2.nextSharedState;
51
55
  var selection = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.selection;
52
- if (selection instanceof _state.NodeSelection ? selection.node === node : false) {
56
+ if (selection instanceof _state.NodeSelection ? (0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? selection.node.sameMarkup(currentNode) : selection.node === node : false) {
53
57
  return;
54
58
  }
55
59
  removeProfileCard === null || removeProfileCard === void 0 || removeProfileCard();
56
60
  });
57
61
  };
58
62
  var renderEditorProfileCard = function renderEditorProfileCard() {
63
+ var activeMention = (0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? function (_dom$querySelector, _currentNode, _currentNode2) {
64
+ // Read the display name from the DOM element at click time — this is
65
+ // always up-to-date even when node.attrs.text is absent
66
+ var primitiveText = dom instanceof HTMLElement ? (_dom$querySelector = dom.querySelector('.editor-mention-primitive')) === null || _dom$querySelector === void 0 || (_dom$querySelector = _dom$querySelector.textContent) === null || _dom$querySelector === void 0 ? void 0 : _dom$querySelector.trim() : undefined;
67
+ return {
68
+ attrs: _objectSpread(_objectSpread({}, (_currentNode = currentNode) === null || _currentNode === void 0 ? void 0 : _currentNode.attrs), {}, {
69
+ text: ((_currentNode2 = currentNode) === null || _currentNode2 === void 0 || (_currentNode2 = _currentNode2.attrs) === null || _currentNode2 === void 0 ? void 0 : _currentNode2.text) || primitiveText || undefined
70
+ })
71
+ };
72
+ }() : {
73
+ attrs: node.attrs
74
+ };
59
75
  renderProfileCardPopup(function (referenceElement) {
60
76
  return /*#__PURE__*/_react.default.createElement(_ProfileCardComponent.ProfileCardComponent, {
61
- activeMention: node,
77
+ activeMention: activeMention,
62
78
  profilecardProvider: options === null || options === void 0 ? void 0 : options.profilecardProvider,
63
79
  dom: referenceElement,
64
80
  closeComponent: removeProfileCard
@@ -112,19 +128,19 @@ var profileCardRenderer = exports.profileCardRenderer = function profileCardRend
112
128
  type: 'click',
113
129
  listener: function listener() {
114
130
  if ((0, _platformFeatureFlags.fg)('people-teams_migrate-user-profile-card')) {
115
- var _node$attrs, _options$profilecardP;
116
- var userId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
131
+ var _currentNode$attrs, _node$attrs, _options$profilecardP;
132
+ var userId = (0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs = currentNode.attrs) === null || _currentNode$attrs === void 0 ? void 0 : _currentNode$attrs.id : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
117
133
  if (!userId) {
118
134
  return;
119
135
  }
120
136
  navigatingToProfile = false;
121
137
  options === null || options === void 0 || (_options$profilecardP = options.profilecardProvider) === null || _options$profilecardP === void 0 || _options$profilecardP.then(function (provider) {
122
- var _node$attrs2;
138
+ var _currentNode$attrs2, _node$attrs2;
123
139
  if (!(0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false)) {
124
140
  renderDefaultProfileCard(userId, provider);
125
141
  return;
126
142
  }
127
- if ((0, _ProfileCardComponent.isAgentMentionType)((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
143
+ if ((0, _ProfileCardComponent.isAgentMentionType)((0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs2 = currentNode.attrs) === null || _currentNode$attrs2 === void 0 ? void 0 : _currentNode$attrs2.userType : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
128
144
  renderEditorProfileCard();
129
145
  } else {
130
146
  renderDefaultProfileCard(userId, provider);
@@ -142,6 +158,9 @@ var profileCardRenderer = exports.profileCardRenderer = function profileCardRend
142
158
  listenerCleanup();
143
159
  removeProfileCard === null || removeProfileCard === void 0 || removeProfileCard();
144
160
  },
145
- removeProfileCard: removeProfileCard
161
+ removeProfileCard: removeProfileCard,
162
+ updateNode: function updateNode(nextNode) {
163
+ currentNode = nextNode;
164
+ }
146
165
  };
147
166
  };
@@ -50,7 +50,7 @@ var getAgentMentionName = function getAgentMentionName(text, fallbackName) {
50
50
  var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
51
51
  var AGENT_MENTION_INACTIVITY_MS = 3000;
52
52
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
53
- var PACKAGE_VERSION = "14.5.5";
53
+ var PACKAGE_VERSION = "14.5.7";
54
54
  var setProvider = function setProvider(provider) {
55
55
  return function (state, dispatch) {
56
56
  if (dispatch) {
@@ -17,6 +17,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
17
17
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
18
18
  var _bindEventListener = require("bind-event-listener");
19
19
  var _reactLoadable = _interopRequireDefault(require("react-loadable"));
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _user = require("@atlaskit/profilecard/user");
21
22
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
22
23
  var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
@@ -190,7 +191,8 @@ function ProfileCardComponent(_ref5) {
190
191
  referenceElement: dom
191
192
  }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
192
193
  accountId: id,
193
- provider: provider
194
+ provider: provider,
195
+ text: (0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? text : undefined
194
196
  }) : /*#__PURE__*/React.createElement(UserProfileCardContent, {
195
197
  accessLevel: accessLevel,
196
198
  id: id,
@@ -198,20 +200,11 @@ function ProfileCardComponent(_ref5) {
198
200
  text: text
199
201
  }));
200
202
  }
201
- var AgentProfileCardContent = function AgentProfileCardContent(_ref8) {
202
- var accountId = _ref8.accountId,
203
- provider = _ref8.provider;
204
- return /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
205
- accountId: accountId,
206
- cloudId: provider.cloudId,
207
- resourceClient: provider.resourceClient
208
- });
209
- };
210
- var UserProfileCardContent = function UserProfileCardContent(_ref9) {
211
- var accessLevel = _ref9.accessLevel,
212
- id = _ref9.id,
213
- provider = _ref9.provider,
214
- text = _ref9.text;
203
+ var UserProfileCardContent = function UserProfileCardContent(_ref8) {
204
+ var accessLevel = _ref8.accessLevel,
205
+ id = _ref8.id,
206
+ provider = _ref8.provider,
207
+ text = _ref8.text;
215
208
  var actions = (0, _react.useMemo)(function () {
216
209
  return provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
217
210
  }, [accessLevel, id, provider, text]);
@@ -251,4 +244,21 @@ var UserProfileCardContent = function UserProfileCardContent(_ref9) {
251
244
  teamCentralBaseUrl: teamCentralBaseUrl,
252
245
  isRenderedInPortal: (0, _expValEquals.expValEquals)('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
253
246
  }));
247
+ };
248
+ var AgentProfileCardContent = function AgentProfileCardContent(_ref9) {
249
+ var accountId = _ref9.accountId,
250
+ provider = _ref9.provider,
251
+ text = _ref9.text;
252
+ // eslint-disable-next-line require-unicode-regexp
253
+ var agentName = (text !== null && text !== void 0 ? text : '').replace(/^@/, '');
254
+ return (0, _platformFeatureFlags.fg)('platform_editor_reduced_agent_profile_card') ? /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
255
+ accountId: accountId,
256
+ cloudId: provider.cloudId,
257
+ resourceClient: provider.resourceClient,
258
+ agentName: agentName
259
+ }) : /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
260
+ accountId: accountId,
261
+ cloudId: provider.cloudId,
262
+ resourceClient: provider.resourceClient
263
+ });
254
264
  };
@@ -106,7 +106,8 @@ export class MentionNodeView {
106
106
  });
107
107
  const {
108
108
  destroyProfileCard,
109
- removeProfileCard
109
+ removeProfileCard,
110
+ updateNode
110
111
  } = profileCardRenderer({
111
112
  dom,
112
113
  options,
@@ -126,6 +127,7 @@ export class MentionNodeView {
126
127
  }
127
128
  this.destroyProfileCard = destroyProfileCard;
128
129
  this.removeProfileCard = removeProfileCard;
130
+ this.updateProfileCardNode = updateNode;
129
131
  }
130
132
  setClassList(state, disabledTooltip) {
131
133
  var _this$mentionPrimitiv, _this$mentionPrimitiv2, _this$mentionPrimitiv3;
@@ -271,10 +273,14 @@ export class MentionNodeView {
271
273
  return this.node.sameMarkup(nextNode);
272
274
  }
273
275
  update(node) {
276
+ var _this$updateProfileCa;
274
277
  if (!this.nodeIsEqual(node)) {
275
278
  return false;
276
279
  }
277
280
  this.node = node;
281
+ // Keep the profile card renderer's node reference in sync so that the
282
+ // click handler always reads up-to-date attrs.
283
+ (_this$updateProfileCa = this.updateProfileCardNode) === null || _this$updateProfileCa === void 0 ? void 0 : _this$updateProfileCa.call(this, node);
278
284
  return true;
279
285
  }
280
286
  destroy() {
@@ -14,6 +14,9 @@ export const profileCardRenderer = ({
14
14
  node,
15
15
  api
16
16
  }) => {
17
+ // Keep a mutable reference to the latest node so the click handler always
18
+ // reads up-to-date attrs
19
+ let currentNode = node;
17
20
  let renderingProfileCard = false;
18
21
  let navigatingToProfile = false;
19
22
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -41,15 +44,28 @@ export const profileCardRenderer = ({
41
44
  nextSharedState
42
45
  }) => {
43
46
  const selection = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.selection;
44
- if (selection instanceof NodeSelection ? selection.node === node : false) {
47
+ if (selection instanceof NodeSelection ? fg('platform_editor_reduced_agent_profile_card') ? selection.node.sameMarkup(currentNode) : selection.node === node : false) {
45
48
  return;
46
49
  }
47
50
  removeProfileCard === null || removeProfileCard === void 0 ? void 0 : removeProfileCard();
48
51
  });
49
52
  };
50
53
  const renderEditorProfileCard = () => {
54
+ const activeMention = fg('platform_editor_reduced_agent_profile_card') ? ((_dom$querySelector, _dom$querySelector$te, _currentNode, _currentNode2, _currentNode2$attrs) => {
55
+ // Read the display name from the DOM element at click time — this is
56
+ // always up-to-date even when node.attrs.text is absent
57
+ const primitiveText = dom instanceof HTMLElement ? (_dom$querySelector = dom.querySelector('.editor-mention-primitive')) === null || _dom$querySelector === void 0 ? void 0 : (_dom$querySelector$te = _dom$querySelector.textContent) === null || _dom$querySelector$te === void 0 ? void 0 : _dom$querySelector$te.trim() : undefined;
58
+ return {
59
+ attrs: {
60
+ ...((_currentNode = currentNode) === null || _currentNode === void 0 ? void 0 : _currentNode.attrs),
61
+ text: ((_currentNode2 = currentNode) === null || _currentNode2 === void 0 ? void 0 : (_currentNode2$attrs = _currentNode2.attrs) === null || _currentNode2$attrs === void 0 ? void 0 : _currentNode2$attrs.text) || primitiveText || undefined
62
+ }
63
+ };
64
+ })() : {
65
+ attrs: node.attrs
66
+ };
51
67
  renderProfileCardPopup(referenceElement => /*#__PURE__*/React.createElement(ProfileCardComponent, {
52
- activeMention: node,
68
+ activeMention: activeMention,
53
69
  profilecardProvider: options === null || options === void 0 ? void 0 : options.profilecardProvider,
54
70
  dom: referenceElement,
55
71
  closeComponent: removeProfileCard
@@ -102,19 +118,19 @@ export const profileCardRenderer = ({
102
118
  type: 'click',
103
119
  listener: () => {
104
120
  if (fg('people-teams_migrate-user-profile-card')) {
105
- var _node$attrs, _options$profilecardP;
106
- const userId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
121
+ var _currentNode$attrs, _node$attrs, _options$profilecardP;
122
+ const userId = fg('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs = currentNode.attrs) === null || _currentNode$attrs === void 0 ? void 0 : _currentNode$attrs.id : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
107
123
  if (!userId) {
108
124
  return;
109
125
  }
110
126
  navigatingToProfile = false;
111
127
  options === null || options === void 0 ? void 0 : (_options$profilecardP = options.profilecardProvider) === null || _options$profilecardP === void 0 ? void 0 : _options$profilecardP.then(provider => {
112
- var _node$attrs2;
128
+ var _currentNode$attrs2, _node$attrs2;
113
129
  if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
114
130
  renderDefaultProfileCard(userId, provider);
115
131
  return;
116
132
  }
117
- if (isAgentMentionType((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
133
+ if (isAgentMentionType(fg('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs2 = currentNode.attrs) === null || _currentNode$attrs2 === void 0 ? void 0 : _currentNode$attrs2.userType : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
118
134
  renderEditorProfileCard();
119
135
  } else {
120
136
  renderDefaultProfileCard(userId, provider);
@@ -132,6 +148,9 @@ export const profileCardRenderer = ({
132
148
  listenerCleanup();
133
149
  removeProfileCard === null || removeProfileCard === void 0 ? void 0 : removeProfileCard();
134
150
  },
135
- removeProfileCard
151
+ removeProfileCard,
152
+ updateNode: nextNode => {
153
+ currentNode = nextNode;
154
+ }
136
155
  };
137
156
  };
@@ -35,7 +35,7 @@ const getAgentMentionName = (text, fallbackName) => {
35
35
  const AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
36
36
  const AGENT_MENTION_INACTIVITY_MS = 3000;
37
37
  const PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
38
- const PACKAGE_VERSION = "14.5.5";
38
+ const PACKAGE_VERSION = "14.5.7";
39
39
  const setProvider = provider => (state, dispatch) => {
40
40
  if (dispatch) {
41
41
  dispatch(state.tr.setMeta(mentionPluginKey, {
@@ -5,6 +5,7 @@ import { ax, ix } from "@compiled/react/runtime";
5
5
  import { useEffect, useMemo, useState } from 'react';
6
6
  import { bind } from 'bind-event-listener';
7
7
  import Loadable from 'react-loadable';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
8
9
  import { ProfileCardLazy } from '@atlaskit/profilecard/user';
9
10
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
10
11
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
@@ -119,7 +120,8 @@ export function ProfileCardComponent({
119
120
  referenceElement: dom
120
121
  }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
121
122
  accountId: id,
122
- provider: provider
123
+ provider: provider,
124
+ text: fg('platform_editor_reduced_agent_profile_card') ? text : undefined
123
125
  }) : /*#__PURE__*/React.createElement(UserProfileCardContent, {
124
126
  accessLevel: accessLevel,
125
127
  id: id,
@@ -127,14 +129,6 @@ export function ProfileCardComponent({
127
129
  text: text
128
130
  }));
129
131
  }
130
- const AgentProfileCardContent = ({
131
- accountId,
132
- provider
133
- }) => /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
134
- accountId: accountId,
135
- cloudId: provider.cloudId,
136
- resourceClient: provider.resourceClient
137
- });
138
132
  const UserProfileCardContent = ({
139
133
  accessLevel,
140
134
  id,
@@ -179,4 +173,22 @@ const UserProfileCardContent = ({
179
173
  teamCentralBaseUrl: teamCentralBaseUrl,
180
174
  isRenderedInPortal: expValEquals('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
181
175
  }));
176
+ };
177
+ const AgentProfileCardContent = ({
178
+ accountId,
179
+ provider,
180
+ text
181
+ }) => {
182
+ // eslint-disable-next-line require-unicode-regexp
183
+ const agentName = (text !== null && text !== void 0 ? text : '').replace(/^@/, '');
184
+ return fg('platform_editor_reduced_agent_profile_card') ? /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
185
+ accountId: accountId,
186
+ cloudId: provider.cloudId,
187
+ resourceClient: provider.resourceClient,
188
+ agentName: agentName
189
+ }) : /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
190
+ accountId: accountId,
191
+ cloudId: provider.cloudId,
192
+ resourceClient: provider.resourceClient
193
+ });
182
194
  };
@@ -136,7 +136,8 @@ export var MentionNodeView = /*#__PURE__*/function () {
136
136
  api: api
137
137
  }),
138
138
  destroyProfileCard = _profileCardRenderer.destroyProfileCard,
139
- removeProfileCard = _profileCardRenderer.removeProfileCard;
139
+ removeProfileCard = _profileCardRenderer.removeProfileCard,
140
+ updateNode = _profileCardRenderer.updateNode;
140
141
  // Accessibility attributes - based on `packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx`
141
142
  if (this.domElement && options !== null && options !== void 0 && options.profilecardProvider) {
142
143
  if (node.attrs.text) {
@@ -149,6 +150,7 @@ export var MentionNodeView = /*#__PURE__*/function () {
149
150
  }
150
151
  this.destroyProfileCard = destroyProfileCard;
151
152
  this.removeProfileCard = removeProfileCard;
153
+ this.updateProfileCardNode = updateNode;
152
154
  }
153
155
  return _createClass(MentionNodeView, [{
154
156
  key: "setClassList",
@@ -326,10 +328,14 @@ export var MentionNodeView = /*#__PURE__*/function () {
326
328
  }, {
327
329
  key: "update",
328
330
  value: function update(node) {
331
+ var _this$updateProfileCa;
329
332
  if (!this.nodeIsEqual(node)) {
330
333
  return false;
331
334
  }
332
335
  this.node = node;
336
+ // Keep the profile card renderer's node reference in sync so that the
337
+ // click handler always reads up-to-date attrs.
338
+ (_this$updateProfileCa = this.updateProfileCardNode) === null || _this$updateProfileCa === void 0 || _this$updateProfileCa.call(this, node);
333
339
  return true;
334
340
  }
335
341
  }, {
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
1
4
  import React from 'react';
2
5
  import { bind } from 'bind-event-listener';
3
6
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -13,6 +16,9 @@ export var profileCardRenderer = function profileCardRenderer(_ref) {
13
16
  portalProviderAPI = _ref.portalProviderAPI,
14
17
  node = _ref.node,
15
18
  api = _ref.api;
19
+ // Keep a mutable reference to the latest node so the click handler always
20
+ // reads up-to-date attrs
21
+ var currentNode = node;
16
22
  var renderingProfileCard = false;
17
23
  var navigatingToProfile = false;
18
24
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
@@ -41,16 +47,28 @@ export var profileCardRenderer = function profileCardRenderer(_ref) {
41
47
  cleanupSelection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : _api$selection.sharedState.onChange(function (_ref2) {
42
48
  var nextSharedState = _ref2.nextSharedState;
43
49
  var selection = nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.selection;
44
- if (selection instanceof NodeSelection ? selection.node === node : false) {
50
+ if (selection instanceof NodeSelection ? fg('platform_editor_reduced_agent_profile_card') ? selection.node.sameMarkup(currentNode) : selection.node === node : false) {
45
51
  return;
46
52
  }
47
53
  removeProfileCard === null || removeProfileCard === void 0 || removeProfileCard();
48
54
  });
49
55
  };
50
56
  var renderEditorProfileCard = function renderEditorProfileCard() {
57
+ var activeMention = fg('platform_editor_reduced_agent_profile_card') ? function (_dom$querySelector, _currentNode, _currentNode2) {
58
+ // Read the display name from the DOM element at click time — this is
59
+ // always up-to-date even when node.attrs.text is absent
60
+ var primitiveText = dom instanceof HTMLElement ? (_dom$querySelector = dom.querySelector('.editor-mention-primitive')) === null || _dom$querySelector === void 0 || (_dom$querySelector = _dom$querySelector.textContent) === null || _dom$querySelector === void 0 ? void 0 : _dom$querySelector.trim() : undefined;
61
+ return {
62
+ attrs: _objectSpread(_objectSpread({}, (_currentNode = currentNode) === null || _currentNode === void 0 ? void 0 : _currentNode.attrs), {}, {
63
+ text: ((_currentNode2 = currentNode) === null || _currentNode2 === void 0 || (_currentNode2 = _currentNode2.attrs) === null || _currentNode2 === void 0 ? void 0 : _currentNode2.text) || primitiveText || undefined
64
+ })
65
+ };
66
+ }() : {
67
+ attrs: node.attrs
68
+ };
51
69
  renderProfileCardPopup(function (referenceElement) {
52
70
  return /*#__PURE__*/React.createElement(ProfileCardComponent, {
53
- activeMention: node,
71
+ activeMention: activeMention,
54
72
  profilecardProvider: options === null || options === void 0 ? void 0 : options.profilecardProvider,
55
73
  dom: referenceElement,
56
74
  closeComponent: removeProfileCard
@@ -104,19 +122,19 @@ export var profileCardRenderer = function profileCardRenderer(_ref) {
104
122
  type: 'click',
105
123
  listener: function listener() {
106
124
  if (fg('people-teams_migrate-user-profile-card')) {
107
- var _node$attrs, _options$profilecardP;
108
- var userId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
125
+ var _currentNode$attrs, _node$attrs, _options$profilecardP;
126
+ var userId = fg('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs = currentNode.attrs) === null || _currentNode$attrs === void 0 ? void 0 : _currentNode$attrs.id : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.id;
109
127
  if (!userId) {
110
128
  return;
111
129
  }
112
130
  navigatingToProfile = false;
113
131
  options === null || options === void 0 || (_options$profilecardP = options.profilecardProvider) === null || _options$profilecardP === void 0 || _options$profilecardP.then(function (provider) {
114
- var _node$attrs2;
132
+ var _currentNode$attrs2, _node$attrs2;
115
133
  if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
116
134
  renderDefaultProfileCard(userId, provider);
117
135
  return;
118
136
  }
119
- if (isAgentMentionType((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
137
+ if (isAgentMentionType(fg('platform_editor_reduced_agent_profile_card') ? (_currentNode$attrs2 = currentNode.attrs) === null || _currentNode$attrs2 === void 0 ? void 0 : _currentNode$attrs2.userType : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.userType)) {
120
138
  renderEditorProfileCard();
121
139
  } else {
122
140
  renderDefaultProfileCard(userId, provider);
@@ -134,6 +152,9 @@ export var profileCardRenderer = function profileCardRenderer(_ref) {
134
152
  listenerCleanup();
135
153
  removeProfileCard === null || removeProfileCard === void 0 || removeProfileCard();
136
154
  },
137
- removeProfileCard: removeProfileCard
155
+ removeProfileCard: removeProfileCard,
156
+ updateNode: function updateNode(nextNode) {
157
+ currentNode = nextNode;
158
+ }
138
159
  };
139
160
  };
@@ -42,7 +42,7 @@ var getAgentMentionName = function getAgentMentionName(text, fallbackName) {
42
42
  var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
43
43
  var AGENT_MENTION_INACTIVITY_MS = 3000;
44
44
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
45
- var PACKAGE_VERSION = "14.5.5";
45
+ var PACKAGE_VERSION = "14.5.7";
46
46
  var setProvider = function setProvider(provider) {
47
47
  return function (state, dispatch) {
48
48
  if (dispatch) {
@@ -8,6 +8,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
8
8
  import { useEffect, useMemo, useState } from 'react';
9
9
  import { bind } from 'bind-event-listener';
10
10
  import Loadable from 'react-loadable';
11
+ import { fg } from '@atlaskit/platform-feature-flags';
11
12
  import { ProfileCardLazy } from '@atlaskit/profilecard/user';
12
13
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
14
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
@@ -178,7 +179,8 @@ export function ProfileCardComponent(_ref5) {
178
179
  referenceElement: dom
179
180
  }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
180
181
  accountId: id,
181
- provider: provider
182
+ provider: provider,
183
+ text: fg('platform_editor_reduced_agent_profile_card') ? text : undefined
182
184
  }) : /*#__PURE__*/React.createElement(UserProfileCardContent, {
183
185
  accessLevel: accessLevel,
184
186
  id: id,
@@ -186,20 +188,11 @@ export function ProfileCardComponent(_ref5) {
186
188
  text: text
187
189
  }));
188
190
  }
189
- var AgentProfileCardContent = function AgentProfileCardContent(_ref8) {
190
- var accountId = _ref8.accountId,
191
- provider = _ref8.provider;
192
- return /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
193
- accountId: accountId,
194
- cloudId: provider.cloudId,
195
- resourceClient: provider.resourceClient
196
- });
197
- };
198
- var UserProfileCardContent = function UserProfileCardContent(_ref9) {
199
- var accessLevel = _ref9.accessLevel,
200
- id = _ref9.id,
201
- provider = _ref9.provider,
202
- text = _ref9.text;
191
+ var UserProfileCardContent = function UserProfileCardContent(_ref8) {
192
+ var accessLevel = _ref8.accessLevel,
193
+ id = _ref8.id,
194
+ provider = _ref8.provider,
195
+ text = _ref8.text;
203
196
  var actions = useMemo(function () {
204
197
  return provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
205
198
  }, [accessLevel, id, provider, text]);
@@ -239,4 +232,21 @@ var UserProfileCardContent = function UserProfileCardContent(_ref9) {
239
232
  teamCentralBaseUrl: teamCentralBaseUrl,
240
233
  isRenderedInPortal: expValEquals('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
241
234
  }));
235
+ };
236
+ var AgentProfileCardContent = function AgentProfileCardContent(_ref9) {
237
+ var accountId = _ref9.accountId,
238
+ provider = _ref9.provider,
239
+ text = _ref9.text;
240
+ // eslint-disable-next-line require-unicode-regexp
241
+ var agentName = (text !== null && text !== void 0 ? text : '').replace(/^@/, '');
242
+ return fg('platform_editor_reduced_agent_profile_card') ? /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
243
+ accountId: accountId,
244
+ cloudId: provider.cloudId,
245
+ resourceClient: provider.resourceClient,
246
+ agentName: agentName
247
+ }) : /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
248
+ accountId: accountId,
249
+ cloudId: provider.cloudId,
250
+ resourceClient: provider.resourceClient
251
+ });
242
252
  };
@@ -18,6 +18,7 @@ export declare class MentionNodeView implements NodeView {
18
18
  private cleanup;
19
19
  private destroyProfileCard;
20
20
  private removeProfileCard;
21
+ private updateProfileCardNode;
21
22
  private mentionPrimitiveElement;
22
23
  private disabledTooltip;
23
24
  private unsubscribeFromDisabledStateChanges;
@@ -12,4 +12,5 @@ export declare const profileCardRenderer: ({ dom, options, portalProviderAPI, no
12
12
  }) => {
13
13
  destroyProfileCard: () => void;
14
14
  removeProfileCard: () => void;
15
+ updateNode: (nextNode: PMNode) => void;
15
16
  };
@@ -1,5 +1,5 @@
1
+ import type { MentionAttributes } from '@atlaskit/adf-schema';
1
2
  import type { ProfilecardProvider } from '@atlaskit/editor-common/provider-factory';
2
- import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { ProfileCardClientData, TeamCentralReportingLinesData } from '@atlaskit/profilecard/types';
4
4
  interface ProfileCardStateProps {
5
5
  id: string | undefined;
@@ -18,7 +18,9 @@ export declare const useProfileCardState: ({ id, provider, }: ProfileCardStatePr
18
18
  * Renders the profile card popup for an editor mention node.
19
19
  */
20
20
  export declare function ProfileCardComponent({ profilecardProvider, activeMention, dom, closeComponent, }: {
21
- activeMention: PMNode;
21
+ activeMention: {
22
+ attrs: MentionAttributes;
23
+ };
22
24
  closeComponent: () => void;
23
25
  dom: HTMLElement;
24
26
  profilecardProvider?: Promise<ProfilecardProvider> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "14.5.6",
3
+ "version": "14.5.8",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,7 +41,7 @@
41
41
  "@atlaskit/profilecard": "^26.5.0",
42
42
  "@atlaskit/teams-app-config": "^2.1.0",
43
43
  "@atlaskit/theme": "^26.1.0",
44
- "@atlaskit/tmp-editor-statsig": "^118.0.0",
44
+ "@atlaskit/tmp-editor-statsig": "^119.0.0",
45
45
  "@atlaskit/tokens": "^15.3.0",
46
46
  "@atlaskit/tooltip": "^23.1.0",
47
47
  "@atlaskit/user-picker": "^13.4.0",
@@ -123,6 +123,9 @@
123
123
  },
124
124
  "rovo_chat_agent_selection": {
125
125
  "type": "boolean"
126
+ },
127
+ "platform_editor_reduced_agent_profile_card": {
128
+ "type": "boolean"
126
129
  }
127
130
  }
128
131
  }