@atlaskit/editor-plugin-mentions 17.0.0 → 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 (47) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/cjs/mentionsPlugin.js +16 -6
  3. package/dist/cjs/pm-plugins/main.js +1 -1
  4. package/dist/cjs/ui/AnchoredPopup.js +5 -0
  5. package/dist/cjs/ui/InlineInvitePopupContainer.js +1 -2
  6. package/dist/cjs/ui/PopperWrapper.js +14 -9
  7. package/dist/cjs/ui/ProfileCardComponent.js +36 -11
  8. package/dist/cjs/ui/quick-insert/MentionQuickInsertMenuItem.js +41 -0
  9. package/dist/cjs/ui/quick-insert/getMentionQuickInsertComponents.js +41 -0
  10. package/dist/cjs/ui/type-ahead/MentionItemWithProfileCard.js +106 -0
  11. package/dist/cjs/ui/type-ahead/index.js +80 -71
  12. package/dist/cjs/ui/type-ahead/utils.js +7 -1
  13. package/dist/cjs/ui/useFocusTrap.js +5 -3
  14. package/dist/es2019/mentionsPlugin.js +13 -3
  15. package/dist/es2019/pm-plugins/main.js +1 -1
  16. package/dist/es2019/ui/AnchoredPopup.js +5 -0
  17. package/dist/es2019/ui/InlineInvitePopupContainer.js +1 -2
  18. package/dist/es2019/ui/PopperWrapper.js +10 -8
  19. package/dist/es2019/ui/ProfileCardComponent.js +35 -10
  20. package/dist/es2019/ui/quick-insert/MentionQuickInsertMenuItem.js +36 -0
  21. package/dist/es2019/ui/quick-insert/getMentionQuickInsertComponents.js +30 -0
  22. package/dist/es2019/ui/type-ahead/MentionItemWithProfileCard.js +91 -0
  23. package/dist/es2019/ui/type-ahead/index.js +22 -8
  24. package/dist/es2019/ui/type-ahead/utils.js +2 -0
  25. package/dist/es2019/ui/useFocusTrap.js +4 -3
  26. package/dist/esm/mentionsPlugin.js +13 -3
  27. package/dist/esm/pm-plugins/main.js +1 -1
  28. package/dist/esm/ui/AnchoredPopup.js +5 -0
  29. package/dist/esm/ui/InlineInvitePopupContainer.js +1 -2
  30. package/dist/esm/ui/PopperWrapper.js +13 -8
  31. package/dist/esm/ui/ProfileCardComponent.js +36 -11
  32. package/dist/esm/ui/quick-insert/MentionQuickInsertMenuItem.js +33 -0
  33. package/dist/esm/ui/quick-insert/getMentionQuickInsertComponents.js +34 -0
  34. package/dist/esm/ui/type-ahead/MentionItemWithProfileCard.js +98 -0
  35. package/dist/esm/ui/type-ahead/index.js +78 -69
  36. package/dist/esm/ui/type-ahead/utils.js +6 -0
  37. package/dist/esm/ui/useFocusTrap.js +5 -3
  38. package/dist/types/mentionsPluginType.d.ts +3 -1
  39. package/dist/types/ui/PopperWrapper.d.ts +15 -2
  40. package/dist/types/ui/ProfileCardComponent.d.ts +6 -1
  41. package/dist/types/ui/quick-insert/MentionQuickInsertMenuItem.d.ts +10 -0
  42. package/dist/types/ui/quick-insert/getMentionQuickInsertComponents.d.ts +8 -0
  43. package/dist/types/ui/type-ahead/MentionItemWithProfileCard.d.ts +15 -0
  44. package/dist/types/ui/type-ahead/index.d.ts +3 -1
  45. package/dist/types/ui/type-ahead/utils.d.ts +2 -0
  46. package/dist/types/ui/useFocusTrap.d.ts +2 -1
  47. package/package.json +9 -6
@@ -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
  };
@@ -12,11 +12,11 @@ import uuid from 'uuid';
12
12
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
13
  import { toolbarInsertBlockMessages as messages, mentionMessages } from '@atlaskit/editor-common/messages';
14
14
  import { WithProviders } from '@atlaskit/editor-common/provider-factory';
15
- import { IconMention } from '@atlaskit/editor-common/quick-insert';
15
+ import { IconMention } from '@atlaskit/editor-common/assets';
16
16
  import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
17
17
  import { MentionNameStatus, isPromise } from '@atlaskit/mention/types';
18
18
  import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
19
- import { fg } from '@atlaskit/platform-feature-flags';
19
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
20
20
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
21
21
  import { insertMention } from './editor-commands';
22
22
  import { mentionNodeSpec } from './nodeviews/mentionNodeSpec';
@@ -26,6 +26,7 @@ import { ACTIONS, createMentionPlugin } from './pm-plugins/main';
26
26
  import { InlineInvitePopupContainer } from './ui/InlineInvitePopupContainer';
27
27
  import { SecondaryToolbarComponent } from './ui/SecondaryToolbarComponent';
28
28
  import { createTypeAheadConfig } from './ui/type-ahead';
29
+ import { getMentionQuickInsertComponents } from './ui/quick-insert/getMentionQuickInsertComponents';
29
30
  var processName = function processName(name, intl) {
30
31
  var unknownLabel = intl.formatMessage(mentionMessages.unknownLabel);
31
32
  if (name.status === MentionNameStatus.OK) {
@@ -102,9 +103,18 @@ var mentionsPlugin = function mentionsPlugin(_ref3) {
102
103
  handleMentionsChanged: options === null || options === void 0 ? void 0 : options.handleMentionsChanged,
103
104
  enableAgentSectioning: options === null || options === void 0 ? void 0 : options.enableAgentSectioning,
104
105
  showAgentMentionsLabsLozenge: options === null || options === void 0 ? void 0 : options.showAgentMentionsLabsLozenge,
106
+ profilecardProvider: options === null || options === void 0 ? void 0 : options.profilecardProvider,
105
107
  fireEvent: fireEvent,
106
108
  api: api
107
109
  });
110
+ var isRegisteredSlashCommandEnabled = isExperimentEnabled('platform_editor_slash_command');
111
+ if (isRegisteredSlashCommandEnabled) {
112
+ var _api$uiControlRegistr;
113
+ api === null || api === void 0 || (_api$uiControlRegistr = api.uiControlRegistry) === null || _api$uiControlRegistr === void 0 || _api$uiControlRegistr.actions.register(getMentionQuickInsertComponents({
114
+ api: api,
115
+ typeAhead: typeAhead
116
+ }));
117
+ }
108
118
  return {
109
119
  name: 'mention',
110
120
  nodes: function nodes() {
@@ -274,7 +284,7 @@ var mentionsPlugin = function mentionsPlugin(_ref3) {
274
284
  });
275
285
  },
276
286
  pluginsOptions: {
277
- quickInsert: function quickInsert(_ref9) {
287
+ quickInsert: isRegisteredSlashCommandEnabled ? undefined : function (_ref9) {
278
288
  var formatMessage = _ref9.formatMessage;
279
289
  return [{
280
290
  id: 'mention',
@@ -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 = "16.2.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) {
@@ -25,5 +25,10 @@ export function AnchoredPopup(_ref) {
25
25
  placement: "bottom-start",
26
26
  content: renderContent,
27
27
  trigger: renderTrigger
28
+ // Drops this popup's own `overflow: auto`, which otherwise clips the role picker's
29
+ // menu — it renders as a normal DOM child here (not a body portal) so it stays inside
30
+ // this popup's focus trap.
31
+ ,
32
+ shouldRenderToParent: true
28
33
  });
29
34
  }
@@ -95,7 +95,6 @@ export var InlineInvitePopupContainer = function InlineInvitePopupContainer(_ref
95
95
  }
96
96
  var invitedUser = (_result$invited$ = result.invited[0]) !== null && _result$invited$ !== void 0 ? _result$invited$ : result.requested[0];
97
97
  if (!invitedUser || !(api !== null && api !== void 0 && (_api$core2 = api.core) !== null && _api$core2 !== void 0 && (_api$core2 = _api$core2.actions) !== null && _api$core2 !== void 0 && _api$core2.execute) || !(api !== null && api !== void 0 && (_api$mention = api.mention) !== null && _api$mention !== void 0 && (_api$mention = _api$mention.commands) !== null && _api$mention !== void 0 && _api$mention.insertMention)) {
98
- removePendingMention();
99
98
  return;
100
99
  }
101
100
  var userId = invitedUser.id,
@@ -113,7 +112,7 @@ export var InlineInvitePopupContainer = function InlineInvitePopupContainer(_ref
113
112
  }));
114
113
  pendingMentionRef.current = null;
115
114
  setAnchorElement(null);
116
- }, [api, removePendingMention]);
115
+ }, [api]);
117
116
  var handleReady = useCallback(function (show) {
118
117
  if (!provider) {
119
118
  return;
@@ -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,33 @@
1
+ import React, { useCallback } from 'react';
2
+ import { useIntl } from 'react-intl';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { IconMention } from '@atlaskit/editor-common/assets';
6
+ import { QuickInsertMenuItem } from '@atlaskit/editor-common/quick-insert/menu-item';
7
+ import { mentionPluginKey } from '../../pm-plugins/key';
8
+ export var MentionQuickInsertMenuItem = function MentionQuickInsertMenuItem(_ref) {
9
+ var api = _ref.api,
10
+ typeAhead = _ref.typeAhead;
11
+ var _useIntl = useIntl(),
12
+ formatMessage = _useIntl.formatMessage;
13
+ var onSelect = useCallback(function (_ref2) {
14
+ var _mentionPluginKey$get, _api$typeAhead;
15
+ var editorView = _ref2.editorView,
16
+ insert = _ref2.insert;
17
+ if (((_mentionPluginKey$get = mentionPluginKey.getState(editorView.state)) === null || _mentionPluginKey$get === void 0 ? void 0 : _mentionPluginKey$get.canInsertMention) === false) {
18
+ return false;
19
+ }
20
+ var tr = insert(undefined);
21
+ api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || _api$typeAhead.actions.openAtTransaction({
22
+ triggerHandler: typeAhead,
23
+ inputMethod: INPUT_METHOD.QUICK_INSERT
24
+ })(tr);
25
+ return tr;
26
+ }, [api, typeAhead]);
27
+ return /*#__PURE__*/React.createElement(QuickInsertMenuItem, {
28
+ iconBefore: /*#__PURE__*/React.createElement(IconMention, null),
29
+ onSelect: onSelect,
30
+ shortcut: "@",
31
+ title: formatMessage(messages.mention)
32
+ });
33
+ };
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
3
+ import { createQuickInsertMatcher } from '@atlaskit/editor-common/quick-insert/create-quick-insert-matcher';
4
+ import { MEDIA_SECTION, MENTION_MENU_ITEM } from '@atlaskit/editor-common/quick-insert/keys';
5
+ import { MEDIA_SECTION_RANK } from '@atlaskit/editor-common/quick-insert/rank';
6
+ import { MentionQuickInsertMenuItem } from './MentionQuickInsertMenuItem';
7
+ export var getMentionQuickInsertComponents = function getMentionQuickInsertComponents(_ref) {
8
+ var api = _ref.api,
9
+ typeAhead = _ref.typeAhead;
10
+ return [{
11
+ key: MENTION_MENU_ITEM.key,
12
+ type: MENTION_MENU_ITEM.type,
13
+ parents: [{
14
+ key: MEDIA_SECTION.key,
15
+ type: MEDIA_SECTION.type,
16
+ rank: MEDIA_SECTION_RANK[MENTION_MENU_ITEM.key]
17
+ }],
18
+ match: createQuickInsertMatcher(function (_ref2) {
19
+ var formatMessage = _ref2.formatMessage;
20
+ return {
21
+ description: formatMessage(messages.mentionDescription),
22
+ keywords: ['team', 'user'],
23
+ shortcut: '@',
24
+ title: formatMessage(messages.mention)
25
+ };
26
+ }),
27
+ component: function component() {
28
+ return /*#__PURE__*/React.createElement(MentionQuickInsertMenuItem, {
29
+ api: api,
30
+ typeAhead: typeAhead
31
+ });
32
+ }
33
+ }];
34
+ };
@@ -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
+ }