@atlaskit/editor-plugin-mentions 17.0.1 → 17.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/cjs/mentionsPlugin.js +1 -0
  3. package/dist/cjs/pm-plugins/main.js +1 -1
  4. package/dist/cjs/ui/PopperWrapper.js +14 -9
  5. package/dist/cjs/ui/ProfileCardComponent.js +36 -11
  6. package/dist/cjs/ui/type-ahead/MentionItemWithProfileCard.js +106 -0
  7. package/dist/cjs/ui/type-ahead/index.js +80 -71
  8. package/dist/cjs/ui/type-ahead/utils.js +7 -1
  9. package/dist/cjs/ui/useFocusTrap.js +5 -3
  10. package/dist/es2019/mentionsPlugin.js +1 -0
  11. package/dist/es2019/pm-plugins/main.js +1 -1
  12. package/dist/es2019/ui/PopperWrapper.js +10 -8
  13. package/dist/es2019/ui/ProfileCardComponent.js +35 -10
  14. package/dist/es2019/ui/type-ahead/MentionItemWithProfileCard.js +91 -0
  15. package/dist/es2019/ui/type-ahead/index.js +22 -8
  16. package/dist/es2019/ui/type-ahead/utils.js +2 -0
  17. package/dist/es2019/ui/useFocusTrap.js +4 -3
  18. package/dist/esm/mentionsPlugin.js +1 -0
  19. package/dist/esm/pm-plugins/main.js +1 -1
  20. package/dist/esm/ui/PopperWrapper.js +13 -8
  21. package/dist/esm/ui/ProfileCardComponent.js +36 -11
  22. package/dist/esm/ui/type-ahead/MentionItemWithProfileCard.js +98 -0
  23. package/dist/esm/ui/type-ahead/index.js +78 -69
  24. package/dist/esm/ui/type-ahead/utils.js +6 -0
  25. package/dist/esm/ui/useFocusTrap.js +5 -3
  26. package/dist/types/ui/PopperWrapper.d.ts +15 -2
  27. package/dist/types/ui/ProfileCardComponent.d.ts +6 -1
  28. package/dist/types/ui/type-ahead/MentionItemWithProfileCard.d.ts +15 -0
  29. package/dist/types/ui/type-ahead/index.d.ts +3 -1
  30. package/dist/types/ui/type-ahead/utils.d.ts +2 -0
  31. package/dist/types/ui/useFocusTrap.d.ts +2 -1
  32. package/package.json +8 -5
@@ -1,6 +1,6 @@
1
1
  import React, { useRef, useLayoutEffect, useEffect, Suspense } from 'react';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
- import { Popper as ReactPopper } from '@atlaskit/popper';
3
+ import { Popper as ReactPopper } from '@atlaskit/popper/main';
4
4
  import Portal from '@atlaskit/portal';
5
5
  import { layers } from '@atlaskit/theme/constants';
6
6
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
@@ -73,20 +73,22 @@ function useResizeAwarePopper({
73
73
  */
74
74
  export function Popup({
75
75
  referenceElement,
76
- children
76
+ children,
77
+ placement = 'bottom-end',
78
+ offset = [0, 8],
79
+ disableFocusTrap = false
77
80
  }) {
78
81
  const [targetRef, setPopupRef] = React.useState(null);
79
82
  useFocusTrap({
80
- targetRef: targetRef
83
+ targetRef: targetRef,
84
+ enabled: !disableFocusTrap
81
85
  });
82
86
  return /*#__PURE__*/React.createElement(Suspense, null, /*#__PURE__*/React.createElement(Portal, {
83
87
  zIndex: layers.modal()
84
88
  }, /*#__PURE__*/React.createElement(ReactPopper, {
85
- referenceElement: referenceElement
86
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
87
- ,
88
- offset: [0, 8],
89
- placement: "bottom-end",
89
+ referenceElement: referenceElement,
90
+ offset: offset,
91
+ placement: placement,
90
92
  strategy: "fixed"
91
93
  // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
92
94
  ,
@@ -84,7 +84,11 @@ export function ProfileCardComponent({
84
84
  activeMention,
85
85
  dom,
86
86
  closeComponent,
87
- onAgentMentionChatClick
87
+ onAgentMentionChatClick,
88
+ placement,
89
+ offset,
90
+ disableFocusTrap,
91
+ hideActions
88
92
  }) {
89
93
  var _ref;
90
94
  const [provider, setProvider] = useState(undefined);
@@ -111,20 +115,28 @@ export function ProfileCardComponent({
111
115
  });
112
116
  if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
113
117
  return /*#__PURE__*/React.createElement(Popup, {
114
- referenceElement: dom
118
+ referenceElement: dom,
119
+ placement: placement,
120
+ offset: offset,
121
+ disableFocusTrap: disableFocusTrap
115
122
  }, /*#__PURE__*/React.createElement(UserProfileCardContent, {
116
123
  accessLevel: accessLevel,
117
124
  id: id,
118
125
  provider: provider,
119
- text: text
126
+ text: text,
127
+ hideActions: hideActions
120
128
  }));
121
129
  }
122
130
  const isAgentMention = isAgentMentionType(userType);
123
131
  return /*#__PURE__*/React.createElement(Popup, {
124
- referenceElement: dom
132
+ referenceElement: dom,
133
+ placement: placement,
134
+ offset: offset,
135
+ disableFocusTrap: disableFocusTrap
125
136
  }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
126
137
  accountId: id,
127
138
  provider: provider,
139
+ hideActions: hideActions,
128
140
  text: expVal('platform_editor_reduced_agent_profile_cards', 'isEnabled', false) ? text : undefined,
129
141
  onChatClick: onAgentMentionChatClick && fg('platform_editor_agent_mentions_drop_one_fixes') ? (event, agentStudioId) =>
130
142
  // agentMentionContext is already captured in the onAgentMentionChatClick
@@ -134,16 +146,18 @@ export function ProfileCardComponent({
134
146
  accessLevel: accessLevel,
135
147
  id: id,
136
148
  provider: provider,
137
- text: text
149
+ text: text,
150
+ hideActions: hideActions
138
151
  }));
139
152
  }
140
153
  const UserProfileCardContent = ({
141
154
  accessLevel,
142
155
  id,
143
156
  provider,
144
- text
157
+ text,
158
+ hideActions
145
159
  }) => {
146
- const actions = useMemo(() => provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel), [accessLevel, id, provider, text]);
160
+ const actions = useMemo(() => hideActions ? [] : provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel), [hideActions, accessLevel, id, provider, text]);
147
161
  const {
148
162
  data,
149
163
  reportingLinesData,
@@ -186,7 +200,8 @@ const AgentProfileCardContent = ({
186
200
  accountId,
187
201
  provider,
188
202
  text,
189
- onChatClick
203
+ onChatClick,
204
+ hideActions
190
205
  }) => {
191
206
  const agentName = (text !== null && text !== void 0 ? text : '').replace(LEADING_AT_SIGN_RE, '');
192
207
  return expVal('platform_editor_reduced_agent_profile_cards', 'isEnabled', false) ? /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
@@ -194,11 +209,21 @@ const AgentProfileCardContent = ({
194
209
  cloudId: provider.cloudId,
195
210
  resourceClient: provider.resourceClient,
196
211
  agentName: agentName,
197
- onChatClick: onChatClick
212
+ onChatClick: onChatClick,
213
+ hideAgentActions: hideActions,
214
+ hideConversationStarters: hideActions,
215
+ hideStarButton: hideActions,
216
+ hideAiDisclaimer: hideActions,
217
+ showCreatorNameWithoutLink: hideActions
198
218
  }) : /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
199
219
  accountId: accountId,
200
220
  cloudId: provider.cloudId,
201
221
  resourceClient: provider.resourceClient,
202
- onChatClick: onChatClick
222
+ onChatClick: onChatClick,
223
+ hideAgentActions: hideActions,
224
+ hideConversationStarters: hideActions,
225
+ hideStarButton: hideActions,
226
+ hideAiDisclaimer: hideActions,
227
+ showCreatorNameWithoutLink: hideActions
203
228
  });
204
229
  };
@@ -0,0 +1,91 @@
1
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { MentionItem } from '@atlaskit/mention/item';
3
+ import { Box } from '@atlaskit/primitives/compiled';
4
+ import { ProfileCardComponent } from '../ProfileCardComponent';
5
+ import { isAgentMention } from './utils';
6
+
7
+ // Delay before mounting the card and fetching the profile data
8
+ const SHOW_DELAY_MS = 600;
9
+ const HIDE_DELAY_MS = 200;
10
+ /**
11
+ * Renders a mentions typeahead row that shows a (reduced) profile card
12
+ * when hovered
13
+ */
14
+ export function MentionItemWithProfileCard({
15
+ mention,
16
+ selected,
17
+ onSelection,
18
+ height,
19
+ profilecardProvider
20
+ }) {
21
+ const [referenceElement, setReferenceElement] = useState(null);
22
+ const showTimerRef = useRef();
23
+ const hideTimerRef = useRef();
24
+ const clearTimers = useCallback(() => {
25
+ clearTimeout(showTimerRef.current);
26
+ clearTimeout(hideTimerRef.current);
27
+ }, []);
28
+ useEffect(() => clearTimers, [clearTimers]);
29
+ const isAgent = isAgentMention(mention);
30
+ const handleMouseEnter = useCallback((_mention, event) => {
31
+ // Currently showing profile cards for agents only
32
+ if (mention.isPlaceholder || !mention.id || !profilecardProvider || !isAgent) {
33
+ return;
34
+ }
35
+ const rowElement = event === null || event === void 0 ? void 0 : event.currentTarget;
36
+ if (!(rowElement instanceof HTMLElement)) {
37
+ return;
38
+ }
39
+ clearTimers();
40
+ showTimerRef.current = setTimeout(() => {
41
+ setReferenceElement(rowElement);
42
+ }, SHOW_DELAY_MS);
43
+ }, [mention.isPlaceholder, mention.id, isAgent, profilecardProvider, clearTimers]);
44
+ const scheduleHide = useCallback(() => {
45
+ clearTimeout(hideTimerRef.current);
46
+ hideTimerRef.current = setTimeout(() => {
47
+ setReferenceElement(null);
48
+ }, HIDE_DELAY_MS);
49
+ }, []);
50
+ const cancelHide = useCallback(() => {
51
+ clearTimeout(hideTimerRef.current);
52
+ }, []);
53
+ const handleMouseLeave = useCallback(() => {
54
+ clearTimeout(showTimerRef.current);
55
+ scheduleHide();
56
+ }, [scheduleHide]);
57
+ const closeCard = useCallback(() => {
58
+ clearTimers();
59
+ setReferenceElement(null);
60
+ }, [clearTimers]);
61
+ const userType = isAgent ? 'APP' : undefined;
62
+ const activeMention = useMemo(() => ({
63
+ attrs: {
64
+ id: mention.id,
65
+ text: mention.name,
66
+ userType,
67
+ accessLevel: mention.accessLevel
68
+ }
69
+ }), [mention.id, mention.name, mention.accessLevel, userType]);
70
+ return /*#__PURE__*/React.createElement(Box, {
71
+ testId: "mention-item-with-profile-card",
72
+ onMouseOver: cancelHide,
73
+ onMouseOut: scheduleHide,
74
+ onMouseLeave: handleMouseLeave,
75
+ onBlur: handleMouseLeave
76
+ }, /*#__PURE__*/React.createElement(MentionItem, {
77
+ mention: mention,
78
+ selected: selected,
79
+ onMouseEnter: handleMouseEnter,
80
+ onSelection: onSelection,
81
+ height: height
82
+ }), referenceElement && profilecardProvider && /*#__PURE__*/React.createElement(ProfileCardComponent, {
83
+ activeMention: activeMention,
84
+ profilecardProvider: profilecardProvider,
85
+ dom: referenceElement,
86
+ closeComponent: closeCard,
87
+ placement: "right",
88
+ disableFocusTrap: true,
89
+ hideActions: true
90
+ }));
91
+ }
@@ -20,9 +20,8 @@ import { getMentionPluginState } from '../../pm-plugins/utils';
20
20
  import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
21
21
  import InviteItemWithEmailDomain from '../InviteItem/InviteItemWithEmailDomain';
22
22
  import { buildTypeAheadCancelPayload, buildTypeAheadInsertedPayload, buildTypeAheadInviteItemClickedPayload, buildTypeAheadInviteItemViewedPayload, buildTypeAheadRenderedPayload } from './analytics';
23
- import { isInviteItem, isTeamStats, isTeamType, shouldKeepInviteItem } from './utils';
24
- const isAgentUserType = userType => userType === 'APP' || userType === 'AGENT';
25
- const isAgentMention = mention => isAgentUserType(mention.userType) || mention.appType === 'agent';
23
+ import { MentionItemWithProfileCard } from './MentionItemWithProfileCard';
24
+ import { isAgentMention, isInviteItem, isTeamStats, isTeamType, shouldKeepInviteItem } from './utils';
26
25
  const isAgentTypeAheadItem = item => item.mention ? isAgentMention(item.mention) : false;
27
26
 
28
27
  // A non-selectable loading placeholder injected by the provider (e.g.
@@ -84,7 +83,10 @@ const withInviteItem = ({
84
83
  // invite item should be shown at the bottom
85
84
  inviteItem];
86
85
  };
87
- const makeMentionToTypeaheadItem = useRefreshedItemHeight => mention => {
86
+ const makeMentionToTypeaheadItem = ({
87
+ useRefreshedItemHeight,
88
+ profilecardProvider
89
+ }) => mention => {
88
90
  const itemHeight = useRefreshedItemHeight ? MENTION_ITEM_HEIGHT_REFRESHED : MENTION_ITEM_HEIGHT;
89
91
  return {
90
92
  title: mention.id,
@@ -92,7 +94,13 @@ const makeMentionToTypeaheadItem = useRefreshedItemHeight => mention => {
92
94
  isSelected,
93
95
  onClick,
94
96
  onHover
95
- }) => /*#__PURE__*/React.createElement(MentionItem, {
97
+ }) => expVal('platform_editor_agent_mentions', 'isEnabled', false) && fg('platform_editor_mention_typeahead_profilecard') ? /*#__PURE__*/React.createElement(MentionItemWithProfileCard, {
98
+ mention: mention,
99
+ selected: isSelected,
100
+ onSelection: onClick,
101
+ height: itemHeight,
102
+ profilecardProvider: profilecardProvider
103
+ }) : /*#__PURE__*/React.createElement(MentionItem, {
96
104
  mention: mention,
97
105
  selected: isSelected,
98
106
  onMouseEnter: onHover,
@@ -105,7 +113,9 @@ const makeMentionToTypeaheadItem = useRefreshedItemHeight => mention => {
105
113
  mention
106
114
  };
107
115
  };
108
- export const mentionToTypeaheadItem = mention => makeMentionToTypeaheadItem(expVal('platform_editor_agent_mentions', 'isEnabled', false))(mention);
116
+ export const mentionToTypeaheadItem = mention => makeMentionToTypeaheadItem({
117
+ useRefreshedItemHeight: expVal('platform_editor_agent_mentions', 'isEnabled', false)
118
+ })(mention);
109
119
 
110
120
  /**
111
121
  * Caches mention typeahead items by mention ID.
@@ -302,7 +312,8 @@ export const createTypeAheadConfig = ({
302
312
  api,
303
313
  handleMentionsChanged,
304
314
  enableAgentSectioning = false,
305
- showAgentMentionsLabsLozenge = false
315
+ showAgentMentionsLabsLozenge = false,
316
+ profilecardProvider
306
317
  }) => {
307
318
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
308
319
  let sessionId = uuid();
@@ -315,7 +326,10 @@ export const createTypeAheadConfig = ({
315
326
  setFirstQueryWithoutResults: query => {
316
327
  firstQueryWithoutResults = query;
317
328
  },
318
- toItem: memoize(makeMentionToTypeaheadItem(enableAgentSectioning)).call
329
+ toItem: memoize(makeMentionToTypeaheadItem({
330
+ useRefreshedItemHeight: enableAgentSectioning,
331
+ profilecardProvider
332
+ })).call
319
333
  });
320
334
  const typeAhead = {
321
335
  id: TypeAheadAvailableNodes.MENTION,
@@ -12,6 +12,8 @@ export const isTeamType = userType => userType === 'TEAM';
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  export const isTeamStats = stat => stat && !isNaN(stat.teamMentionDuration);
14
14
  export const isInviteItem = mention => mention && mention.id === INVITE_ITEM_DESCRIPTION.id;
15
+ export const isAgentUserType = userType => userType === 'APP' || userType === 'AGENT';
16
+ export const isAgentMention = mention => isAgentUserType(mention.userType) || mention.appType === 'agent';
15
17
 
16
18
  /**
17
19
  * Actions
@@ -6,10 +6,11 @@
6
6
  import { useEffect } from 'react';
7
7
  import createFocusTrap from 'focus-trap';
8
8
  export const useFocusTrap = ({
9
- targetRef
9
+ targetRef,
10
+ enabled = true
10
11
  }) => {
11
12
  useEffect(() => {
12
- if (!targetRef) {
13
+ if (!targetRef || !enabled) {
13
14
  return;
14
15
  }
15
16
  const trapConfig = {
@@ -33,5 +34,5 @@ export const useFocusTrap = ({
33
34
  }
34
35
  focusTrap.deactivate();
35
36
  };
36
- }, [targetRef]);
37
+ }, [targetRef, enabled]);
37
38
  };
@@ -103,6 +103,7 @@ var mentionsPlugin = function mentionsPlugin(_ref3) {
103
103
  handleMentionsChanged: options === null || options === void 0 ? void 0 : options.handleMentionsChanged,
104
104
  enableAgentSectioning: options === null || options === void 0 ? void 0 : options.enableAgentSectioning,
105
105
  showAgentMentionsLabsLozenge: options === null || options === void 0 ? void 0 : options.showAgentMentionsLabsLozenge,
106
+ profilecardProvider: options === null || options === void 0 ? void 0 : options.profilecardProvider,
106
107
  fireEvent: fireEvent,
107
108
  api: api
108
109
  });
@@ -58,7 +58,7 @@ var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
58
58
  var AGENT_MENTION_INACTIVITY_MS = 3000;
59
59
  var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
60
60
  var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
61
- var PACKAGE_VERSION = "17.0.0";
61
+ var PACKAGE_VERSION = "17.0.1";
62
62
  var setProvider = function setProvider(provider) {
63
63
  return function (state, dispatch) {
64
64
  if (dispatch) {
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import React, { useRef, useLayoutEffect, useEffect, Suspense } from 'react';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
- import { Popper as ReactPopper } from '@atlaskit/popper';
4
+ import { Popper as ReactPopper } from '@atlaskit/popper/main';
5
5
  import Portal from '@atlaskit/portal';
6
6
  import { layers } from '@atlaskit/theme/constants';
7
7
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
@@ -74,22 +74,27 @@ function useResizeAwarePopper(_ref2) {
74
74
  */
75
75
  export function Popup(_ref3) {
76
76
  var referenceElement = _ref3.referenceElement,
77
- children = _ref3.children;
77
+ children = _ref3.children,
78
+ _ref3$placement = _ref3.placement,
79
+ placement = _ref3$placement === void 0 ? 'bottom-end' : _ref3$placement,
80
+ _ref3$offset = _ref3.offset,
81
+ offset = _ref3$offset === void 0 ? [0, 8] : _ref3$offset,
82
+ _ref3$disableFocusTra = _ref3.disableFocusTrap,
83
+ disableFocusTrap = _ref3$disableFocusTra === void 0 ? false : _ref3$disableFocusTra;
78
84
  var _React$useState = React.useState(null),
79
85
  _React$useState2 = _slicedToArray(_React$useState, 2),
80
86
  targetRef = _React$useState2[0],
81
87
  setPopupRef = _React$useState2[1];
82
88
  useFocusTrap({
83
- targetRef: targetRef
89
+ targetRef: targetRef,
90
+ enabled: !disableFocusTrap
84
91
  });
85
92
  return /*#__PURE__*/React.createElement(Suspense, null, /*#__PURE__*/React.createElement(Portal, {
86
93
  zIndex: layers.modal()
87
94
  }, /*#__PURE__*/React.createElement(ReactPopper, {
88
- referenceElement: referenceElement
89
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
90
- ,
91
- offset: [0, 8],
92
- placement: "bottom-end",
95
+ referenceElement: referenceElement,
96
+ offset: offset,
97
+ placement: placement,
93
98
  strategy: "fixed"
94
99
  // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
95
100
  ,
@@ -143,7 +143,11 @@ export function ProfileCardComponent(_ref5) {
143
143
  activeMention = _ref5.activeMention,
144
144
  dom = _ref5.dom,
145
145
  closeComponent = _ref5.closeComponent,
146
- onAgentMentionChatClick = _ref5.onAgentMentionChatClick;
146
+ onAgentMentionChatClick = _ref5.onAgentMentionChatClick,
147
+ placement = _ref5.placement,
148
+ offset = _ref5.offset,
149
+ disableFocusTrap = _ref5.disableFocusTrap,
150
+ hideActions = _ref5.hideActions;
147
151
  var _useState11 = useState(undefined),
148
152
  _useState12 = _slicedToArray(_useState11, 2),
149
153
  provider = _useState12[0],
@@ -170,20 +174,28 @@ export function ProfileCardComponent(_ref5) {
170
174
  });
171
175
  if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
172
176
  return /*#__PURE__*/React.createElement(Popup, {
173
- referenceElement: dom
177
+ referenceElement: dom,
178
+ placement: placement,
179
+ offset: offset,
180
+ disableFocusTrap: disableFocusTrap
174
181
  }, /*#__PURE__*/React.createElement(UserProfileCardContent, {
175
182
  accessLevel: accessLevel,
176
183
  id: id,
177
184
  provider: provider,
178
- text: text
185
+ text: text,
186
+ hideActions: hideActions
179
187
  }));
180
188
  }
181
189
  var isAgentMention = isAgentMentionType(userType);
182
190
  return /*#__PURE__*/React.createElement(Popup, {
183
- referenceElement: dom
191
+ referenceElement: dom,
192
+ placement: placement,
193
+ offset: offset,
194
+ disableFocusTrap: disableFocusTrap
184
195
  }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
185
196
  accountId: id,
186
197
  provider: provider,
198
+ hideActions: hideActions,
187
199
  text: expVal('platform_editor_reduced_agent_profile_cards', 'isEnabled', false) ? text : undefined,
188
200
  onChatClick: onAgentMentionChatClick && fg('platform_editor_agent_mentions_drop_one_fixes') ? function (event, agentStudioId) {
189
201
  return (
@@ -196,17 +208,19 @@ export function ProfileCardComponent(_ref5) {
196
208
  accessLevel: accessLevel,
197
209
  id: id,
198
210
  provider: provider,
199
- text: text
211
+ text: text,
212
+ hideActions: hideActions
200
213
  }));
201
214
  }
202
215
  var UserProfileCardContent = function UserProfileCardContent(_ref8) {
203
216
  var accessLevel = _ref8.accessLevel,
204
217
  id = _ref8.id,
205
218
  provider = _ref8.provider,
206
- text = _ref8.text;
219
+ text = _ref8.text,
220
+ hideActions = _ref8.hideActions;
207
221
  var actions = useMemo(function () {
208
- return provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
209
- }, [accessLevel, id, provider, text]);
222
+ return hideActions ? [] : provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
223
+ }, [hideActions, accessLevel, id, provider, text]);
210
224
  var _useProfileCardState = useProfileCardState({
211
225
  id: id,
212
226
  provider: provider
@@ -248,18 +262,29 @@ var AgentProfileCardContent = function AgentProfileCardContent(_ref9) {
248
262
  var accountId = _ref9.accountId,
249
263
  provider = _ref9.provider,
250
264
  text = _ref9.text,
251
- onChatClick = _ref9.onChatClick;
265
+ onChatClick = _ref9.onChatClick,
266
+ hideActions = _ref9.hideActions;
252
267
  var agentName = (text !== null && text !== void 0 ? text : '').replace(LEADING_AT_SIGN_RE, '');
253
268
  return expVal('platform_editor_reduced_agent_profile_cards', 'isEnabled', false) ? /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
254
269
  accountId: accountId,
255
270
  cloudId: provider.cloudId,
256
271
  resourceClient: provider.resourceClient,
257
272
  agentName: agentName,
258
- onChatClick: onChatClick
273
+ onChatClick: onChatClick,
274
+ hideAgentActions: hideActions,
275
+ hideConversationStarters: hideActions,
276
+ hideStarButton: hideActions,
277
+ hideAiDisclaimer: hideActions,
278
+ showCreatorNameWithoutLink: hideActions
259
279
  }) : /*#__PURE__*/React.createElement(AgentProfileCardResourcedLazy, {
260
280
  accountId: accountId,
261
281
  cloudId: provider.cloudId,
262
282
  resourceClient: provider.resourceClient,
263
- onChatClick: onChatClick
283
+ onChatClick: onChatClick,
284
+ hideAgentActions: hideActions,
285
+ hideConversationStarters: hideActions,
286
+ hideStarButton: hideActions,
287
+ hideAiDisclaimer: hideActions,
288
+ showCreatorNameWithoutLink: hideActions
264
289
  });
265
290
  };
@@ -0,0 +1,98 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { MentionItem } from '@atlaskit/mention/item';
4
+ import { Box } from '@atlaskit/primitives/compiled';
5
+ import { ProfileCardComponent } from '../ProfileCardComponent';
6
+ import { isAgentMention } from './utils';
7
+
8
+ // Delay before mounting the card and fetching the profile data
9
+ var SHOW_DELAY_MS = 600;
10
+ var HIDE_DELAY_MS = 200;
11
+ /**
12
+ * Renders a mentions typeahead row that shows a (reduced) profile card
13
+ * when hovered
14
+ */
15
+ export function MentionItemWithProfileCard(_ref) {
16
+ var mention = _ref.mention,
17
+ selected = _ref.selected,
18
+ onSelection = _ref.onSelection,
19
+ height = _ref.height,
20
+ profilecardProvider = _ref.profilecardProvider;
21
+ var _useState = useState(null),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ referenceElement = _useState2[0],
24
+ setReferenceElement = _useState2[1];
25
+ var showTimerRef = useRef();
26
+ var hideTimerRef = useRef();
27
+ var clearTimers = useCallback(function () {
28
+ clearTimeout(showTimerRef.current);
29
+ clearTimeout(hideTimerRef.current);
30
+ }, []);
31
+ useEffect(function () {
32
+ return clearTimers;
33
+ }, [clearTimers]);
34
+ var isAgent = isAgentMention(mention);
35
+ var handleMouseEnter = useCallback(function (_mention, event) {
36
+ // Currently showing profile cards for agents only
37
+ if (mention.isPlaceholder || !mention.id || !profilecardProvider || !isAgent) {
38
+ return;
39
+ }
40
+ var rowElement = event === null || event === void 0 ? void 0 : event.currentTarget;
41
+ if (!(rowElement instanceof HTMLElement)) {
42
+ return;
43
+ }
44
+ clearTimers();
45
+ showTimerRef.current = setTimeout(function () {
46
+ setReferenceElement(rowElement);
47
+ }, SHOW_DELAY_MS);
48
+ }, [mention.isPlaceholder, mention.id, isAgent, profilecardProvider, clearTimers]);
49
+ var scheduleHide = useCallback(function () {
50
+ clearTimeout(hideTimerRef.current);
51
+ hideTimerRef.current = setTimeout(function () {
52
+ setReferenceElement(null);
53
+ }, HIDE_DELAY_MS);
54
+ }, []);
55
+ var cancelHide = useCallback(function () {
56
+ clearTimeout(hideTimerRef.current);
57
+ }, []);
58
+ var handleMouseLeave = useCallback(function () {
59
+ clearTimeout(showTimerRef.current);
60
+ scheduleHide();
61
+ }, [scheduleHide]);
62
+ var closeCard = useCallback(function () {
63
+ clearTimers();
64
+ setReferenceElement(null);
65
+ }, [clearTimers]);
66
+ var userType = isAgent ? 'APP' : undefined;
67
+ var activeMention = useMemo(function () {
68
+ return {
69
+ attrs: {
70
+ id: mention.id,
71
+ text: mention.name,
72
+ userType: userType,
73
+ accessLevel: mention.accessLevel
74
+ }
75
+ };
76
+ }, [mention.id, mention.name, mention.accessLevel, userType]);
77
+ return /*#__PURE__*/React.createElement(Box, {
78
+ testId: "mention-item-with-profile-card",
79
+ onMouseOver: cancelHide,
80
+ onMouseOut: scheduleHide,
81
+ onMouseLeave: handleMouseLeave,
82
+ onBlur: handleMouseLeave
83
+ }, /*#__PURE__*/React.createElement(MentionItem, {
84
+ mention: mention,
85
+ selected: selected,
86
+ onMouseEnter: handleMouseEnter,
87
+ onSelection: onSelection,
88
+ height: height
89
+ }), referenceElement && profilecardProvider && /*#__PURE__*/React.createElement(ProfileCardComponent, {
90
+ activeMention: activeMention,
91
+ profilecardProvider: profilecardProvider,
92
+ dom: referenceElement,
93
+ closeComponent: closeCard,
94
+ placement: "right",
95
+ disableFocusTrap: true,
96
+ hideActions: true
97
+ }));
98
+ }