@atlaskit/editor-plugin-mentions 12.2.10 → 12.3.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.
@@ -5,24 +5,41 @@ import "./ProfileCardComponent.compiled.css";
5
5
  import * as React from 'react';
6
6
  import { ax, ix } from "@compiled/react/runtime";
7
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
8
- import { useEffect, useState, useMemo } from 'react';
8
+ import { useEffect, useMemo, useState } from 'react';
9
9
  import { bind } from 'bind-event-listener';
10
+ import Loadable from 'react-loadable';
10
11
  import { ProfileCardLazy } from '@atlaskit/profilecard/user';
11
12
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
13
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
12
14
  import { Popup } from './PopperWrapper';
15
+ var AgentProfileCardResourcedLazy = Loadable({
16
+ loader: function loader() {
17
+ return import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-mentions-agent-profile-card-resourced" */
18
+ '@atlaskit/profilecard/agent-profile-card-resourced').then(function (_ref) {
19
+ var AgentProfileCardResourced = _ref.AgentProfileCardResourced;
20
+ return AgentProfileCardResourced;
21
+ });
22
+ },
23
+ loading: function loading() {
24
+ return null;
25
+ }
26
+ });
13
27
  var styles = {
14
28
  loadingStyles: "_2rko12b0 _16qs130s"
15
29
  };
16
- var LoadingWrapper = function LoadingWrapper(_ref) {
17
- var children = _ref.children,
18
- isLoading = _ref.isLoading;
30
+ var LoadingWrapper = function LoadingWrapper(_ref2) {
31
+ var children = _ref2.children,
32
+ isLoading = _ref2.isLoading;
19
33
  return isLoading ? /*#__PURE__*/React.createElement("div", {
20
34
  className: ax([styles.loadingStyles])
21
35
  }, children) : children;
22
36
  };
23
- export var useProfileCardState = function useProfileCardState(_ref2) {
24
- var id = _ref2.id,
25
- provider = _ref2.provider;
37
+ export var isAgentMentionType = function isAgentMentionType(userType) {
38
+ return userType === 'APP' || userType === 'AGENT';
39
+ };
40
+ export var useProfileCardState = function useProfileCardState(_ref3) {
41
+ var id = _ref3.id,
42
+ provider = _ref3.provider;
26
43
  var _useState = useState(),
27
44
  _useState2 = _slicedToArray(_useState, 2),
28
45
  data = _useState2[0],
@@ -51,7 +68,7 @@ export var useProfileCardState = function useProfileCardState(_ref2) {
51
68
  // From: packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx
52
69
  useEffect(function () {
53
70
  var fetchData = /*#__PURE__*/function () {
54
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
71
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
55
72
  var _yield$Promise$all, _yield$Promise$all2, _data, reportingLines, shouldGiveKudos, _teamCentralBaseUrl, _t;
56
73
  return _regeneratorRuntime.wrap(function (_context) {
57
74
  while (1) switch (_context.prev = _context.next) {
@@ -98,7 +115,7 @@ export var useProfileCardState = function useProfileCardState(_ref2) {
98
115
  }, _callee, null, [[2, 4, 5, 6]]);
99
116
  }));
100
117
  return function fetchData() {
101
- return _ref3.apply(this, arguments);
118
+ return _ref4.apply(this, arguments);
102
119
  };
103
120
  }();
104
121
  fetchData();
@@ -112,12 +129,16 @@ export var useProfileCardState = function useProfileCardState(_ref2) {
112
129
  hasError: hasError
113
130
  };
114
131
  };
115
- export function ProfileCardComponent(_ref4) {
116
- var _ref6;
117
- var profilecardProvider = _ref4.profilecardProvider,
118
- activeMention = _ref4.activeMention,
119
- dom = _ref4.dom,
120
- closeComponent = _ref4.closeComponent;
132
+
133
+ /**
134
+ * Renders the profile card popup for an editor mention node.
135
+ */
136
+ export function ProfileCardComponent(_ref5) {
137
+ var _ref7;
138
+ var profilecardProvider = _ref5.profilecardProvider,
139
+ activeMention = _ref5.activeMention,
140
+ dom = _ref5.dom,
141
+ closeComponent = _ref5.closeComponent;
121
142
  var _useState11 = useState(undefined),
122
143
  _useState12 = _slicedToArray(_useState11, 2),
123
144
  provider = _useState12[0],
@@ -127,10 +148,58 @@ export function ProfileCardComponent(_ref4) {
127
148
  setProvider(p);
128
149
  });
129
150
  }, [profilecardProvider]);
130
- var _ref5 = (_ref6 = activeMention.attrs) !== null && _ref6 !== void 0 ? _ref6 : {},
131
- id = _ref5.id,
132
- text = _ref5.text,
133
- accessLevel = _ref5.accessLevel;
151
+ var _ref6 = (_ref7 = activeMention.attrs) !== null && _ref7 !== void 0 ? _ref7 : {},
152
+ id = _ref6.id,
153
+ text = _ref6.text,
154
+ accessLevel = _ref6.accessLevel,
155
+ userType = _ref6.userType;
156
+ useEffect(function () {
157
+ return bind(window, {
158
+ type: 'keydown',
159
+ listener: function listener(e) {
160
+ if (e.key === 'Escape') {
161
+ closeComponent();
162
+ }
163
+ }
164
+ });
165
+ });
166
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
167
+ return /*#__PURE__*/React.createElement(Popup, {
168
+ referenceElement: dom
169
+ }, /*#__PURE__*/React.createElement(UserProfileCardContent, {
170
+ accessLevel: accessLevel,
171
+ id: id,
172
+ provider: provider,
173
+ text: text
174
+ }));
175
+ }
176
+ var isAgentMention = isAgentMentionType(userType);
177
+ return /*#__PURE__*/React.createElement(Popup, {
178
+ referenceElement: dom
179
+ }, isAgentMention && provider && id ? /*#__PURE__*/React.createElement(AgentProfileCardContent, {
180
+ accountId: id,
181
+ provider: provider
182
+ }) : /*#__PURE__*/React.createElement(UserProfileCardContent, {
183
+ accessLevel: accessLevel,
184
+ id: id,
185
+ provider: provider,
186
+ text: text
187
+ }));
188
+ }
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;
134
203
  var actions = useMemo(function () {
135
204
  return provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
136
205
  }, [accessLevel, id, provider, text]);
@@ -144,19 +213,7 @@ export function ProfileCardComponent(_ref4) {
144
213
  teamCentralBaseUrl = _useProfileCardState.teamCentralBaseUrl,
145
214
  isLoading = _useProfileCardState.isLoading,
146
215
  hasError = _useProfileCardState.hasError;
147
- useEffect(function () {
148
- return bind(window, {
149
- type: 'keydown',
150
- listener: function listener(e) {
151
- if (e.key === 'Escape') {
152
- closeComponent();
153
- }
154
- }
155
- });
156
- });
157
- return /*#__PURE__*/React.createElement(Popup, {
158
- referenceElement: dom
159
- }, /*#__PURE__*/React.createElement(LoadingWrapper, {
216
+ return /*#__PURE__*/React.createElement(LoadingWrapper, {
160
217
  isLoading: isLoading
161
218
  }, /*#__PURE__*/React.createElement(ProfileCardLazy, {
162
219
  avatarUrl: data === null || data === void 0 ? void 0 : data.avatarUrl,
@@ -181,5 +238,5 @@ export function ProfileCardComponent(_ref4) {
181
238
  isKudosEnabled: shouldShowGiveKudos,
182
239
  teamCentralBaseUrl: teamCentralBaseUrl,
183
240
  isRenderedInPortal: expValEquals('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
184
- })));
185
- }
241
+ }));
242
+ };
@@ -17,6 +17,7 @@ import { MENTION_ITEM_HEIGHT, MentionItem } from '@atlaskit/mention/item';
17
17
  import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
18
18
  import { fg } from '@atlaskit/platform-feature-flags';
19
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
20
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
20
21
  import { createSingleMentionFragment } from '../../editor-commands';
21
22
  import { mentionPlaceholderPluginKey, MENTION_PLACEHOLDER_ACTIONS } from '../../pm-plugins/mentionPlaceholder';
22
23
  import { getMentionPluginState } from '../../pm-plugins/utils';
@@ -24,9 +25,12 @@ import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
24
25
  import InviteItemWithEmailDomain from '../InviteItem/InviteItemWithEmailDomain';
25
26
  import { buildTypeAheadCancelPayload, buildTypeAheadInsertedPayload, buildTypeAheadInviteItemClickedPayload, buildTypeAheadInviteItemViewedPayload, buildTypeAheadRenderedPayload } from './analytics';
26
27
  import { isInviteItem, isTeamStats, isTeamType, shouldKeepInviteItem } from './utils';
27
- var isAgentType = function isAgentType(userType) {
28
+ var isAgentUserType = function isAgentUserType(userType) {
28
29
  return userType === 'APP' || userType === 'AGENT';
29
30
  };
31
+ var isAgentMention = function isAgentMention(mention) {
32
+ return isAgentUserType(mention.userType) || mention.appType === 'agent';
33
+ };
30
34
  var createInviteItem = function createInviteItem(_ref) {
31
35
  var mentionProvider = _ref.mentionProvider,
32
36
  onInviteItemMount = _ref.onInviteItemMount,
@@ -316,7 +320,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
316
320
  title: intl.formatMessage(mentionMessages.typeAheadSectionPeople),
317
321
  filter: function filter(item) {
318
322
  var _item$mention;
319
- return !isAgentType(((_item$mention = item.mention) === null || _item$mention === void 0 ? void 0 : _item$mention.userType) || '');
323
+ return !isAgentUserType(((_item$mention = item.mention) === null || _item$mention === void 0 ? void 0 : _item$mention.userType) || '');
320
324
  },
321
325
  limit: 6
322
326
  }, {
@@ -324,7 +328,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
324
328
  title: intl.formatMessage(mentionMessages.typeAheadSectionAgents),
325
329
  filter: function filter(item) {
326
330
  var _item$mention2;
327
- return isAgentType(((_item$mention2 = item.mention) === null || _item$mention2 === void 0 ? void 0 : _item$mention2.userType) || '');
331
+ return isAgentUserType(((_item$mention2 = item.mention) === null || _item$mention2 === void 0 ? void 0 : _item$mention2.userType) || '');
328
332
  }
329
333
  }];
330
334
  },
@@ -352,6 +356,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
352
356
  var mentionContext = _objectSpread(_objectSpread({}, contextIdentifierProvider), {}, {
353
357
  sessionId: sessionId
354
358
  });
359
+ var shouldSuppressInviteForAgentMention = expVal('platform_editor_agent_mentions', 'isEnabled', false) && isAgentMention(item.mention);
355
360
  if (mentionProvider && !isInviteItem(item.mention)) {
356
361
  mentionProvider.recordMentionSelection(item.mention, mentionContext);
357
362
  }
@@ -403,21 +408,20 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
403
408
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
404
409
  var mentionLocalId = uuid();
405
410
  if (handleMentionsChanged) {
411
+ var mentionChange = _objectSpread({
412
+ id: id,
413
+ localId: mentionLocalId,
414
+ method: 'typed',
415
+ type: 'added'
416
+ }, shouldSuppressInviteForAgentMention ? {
417
+ shouldSuppressMentionNotification: true
418
+ } : {});
406
419
  if (taskItemId) {
407
- handleMentionsChanged([{
408
- type: 'added',
409
- localId: mentionLocalId,
410
- id: id,
411
- taskLocalId: taskItemId,
412
- method: 'typed'
413
- }]);
420
+ handleMentionsChanged([_objectSpread(_objectSpread({}, mentionChange), {}, {
421
+ taskLocalId: taskItemId
422
+ })]);
414
423
  } else {
415
- handleMentionsChanged([{
416
- type: 'added',
417
- localId: mentionLocalId,
418
- id: id,
419
- method: 'typed'
420
- }]);
424
+ handleMentionsChanged([mentionChange]);
421
425
  }
422
426
  }
423
427
  fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, mentionLocalId, sourceListItem.map(function (x) {
@@ -429,14 +433,15 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
429
433
  if (mentionProvider && isTeamType(userType)) {
430
434
  return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
431
435
  }
432
- if (isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
436
+ if (!shouldSuppressInviteForAgentMention && isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
433
437
  mentionProvider.inviteXProductUser(id, name);
434
438
  }
435
439
  return insert(createSingleMentionFragment({
436
440
  mentionProvider: mentionProvider,
437
441
  mentionInsertDisplayName: mentionInsertDisplayName,
438
442
  tr: state.tr,
439
- sanitizePrivateContent: sanitizePrivateContent
443
+ sanitizePrivateContent: sanitizePrivateContent,
444
+ suppressInviteXProductUser: shouldSuppressInviteForAgentMention
440
445
  })({
441
446
  name: name,
442
447
  id: id,
@@ -25,8 +25,9 @@ type SingleMentionFragmentParams = {
25
25
  mentionInsertDisplayName: boolean | undefined;
26
26
  mentionProvider: MentionProvider | undefined;
27
27
  sanitizePrivateContent: boolean | undefined;
28
+ suppressInviteXProductUser?: boolean;
28
29
  tr: Transaction;
29
30
  };
30
- export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
31
+ export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, suppressInviteXProductUser, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
31
32
  export declare const insertMention: ({ sanitizePrivateContent, api, mentionInsertDisplayName }: InternalParams) => ({ name, id, userType, localId, nickname, accessLevel, isXProductUser, }: InsertMentionParameters) => EditorCommand;
32
33
  export {};
@@ -11,6 +11,7 @@ export type MentionActionOpenTypeAhead = (inputMethod: TypeAheadInputMethod) =>
11
11
  export type MentionActionAnnounceMentionsInsertion = (mentionIds: {
12
12
  id: string;
13
13
  localId: string;
14
+ shouldSuppressMentionNotification?: boolean;
14
15
  taskLocalId?: string;
15
16
  type: 'added' | 'deleted';
16
17
  }[]) => void;
@@ -17,12 +17,12 @@ export interface MentionPluginConfig {
17
17
  export type MentionsChangedHandler = (changes: {
18
18
  id: string;
19
19
  localId: string;
20
+ shouldSuppressMentionNotification?: boolean;
20
21
  taskLocalId?: string;
21
22
  type: 'added' | 'deleted';
22
23
  }[]) => void;
23
24
  export interface MentionsPluginOptions extends MentionPluginConfig {
24
25
  allowZeroWidthSpaceAfter?: boolean;
25
- handleMentionsChanged?: MentionsChangedHandler;
26
26
  /**
27
27
  * User ID to highlight as a self-mention (typically the current user).
28
28
  *
@@ -31,6 +31,7 @@ export interface MentionsPluginOptions extends MentionPluginConfig {
31
31
  * Takes priority over `MentionProvider.shouldHighlightMention()` if both are present.
32
32
  */
33
33
  currentUserId?: string;
34
+ handleMentionsChanged?: MentionsChangedHandler;
34
35
  mentionProvider?: Providers['mentionProvider'];
35
36
  sanitizePrivateContent?: boolean;
36
37
  }
@@ -5,6 +5,7 @@ interface ProfileCardStateProps {
5
5
  id: string | undefined;
6
6
  provider: ProfilecardProvider | undefined;
7
7
  }
8
+ export declare const isAgentMentionType: (userType: unknown) => boolean;
8
9
  export declare const useProfileCardState: ({ id, provider, }: ProfileCardStateProps) => {
9
10
  data: ProfileCardClientData | undefined;
10
11
  hasError: boolean;
@@ -13,6 +14,9 @@ export declare const useProfileCardState: ({ id, provider, }: ProfileCardStatePr
13
14
  shouldShowGiveKudos: boolean;
14
15
  teamCentralBaseUrl: string | undefined;
15
16
  };
17
+ /**
18
+ * Renders the profile card popup for an editor mention node.
19
+ */
16
20
  export declare function ProfileCardComponent({ profilecardProvider, activeMention, dom, closeComponent, }: {
17
21
  activeMention: PMNode;
18
22
  closeComponent: () => void;
@@ -15,6 +15,7 @@ type Props = {
15
15
  id: string;
16
16
  localId: string;
17
17
  method?: 'pasted' | 'typed';
18
+ shouldSuppressMentionNotification?: boolean;
18
19
  taskLocalId?: string;
19
20
  type: 'added' | 'deleted';
20
21
  }[]) => void;
@@ -25,8 +25,9 @@ type SingleMentionFragmentParams = {
25
25
  mentionInsertDisplayName: boolean | undefined;
26
26
  mentionProvider: MentionProvider | undefined;
27
27
  sanitizePrivateContent: boolean | undefined;
28
+ suppressInviteXProductUser?: boolean;
28
29
  tr: Transaction;
29
30
  };
30
- export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
31
+ export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, suppressInviteXProductUser, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
31
32
  export declare const insertMention: ({ sanitizePrivateContent, api, mentionInsertDisplayName }: InternalParams) => ({ name, id, userType, localId, nickname, accessLevel, isXProductUser, }: InsertMentionParameters) => EditorCommand;
32
33
  export {};
@@ -11,6 +11,7 @@ export type MentionActionOpenTypeAhead = (inputMethod: TypeAheadInputMethod) =>
11
11
  export type MentionActionAnnounceMentionsInsertion = (mentionIds: {
12
12
  id: string;
13
13
  localId: string;
14
+ shouldSuppressMentionNotification?: boolean;
14
15
  taskLocalId?: string;
15
16
  type: 'added' | 'deleted';
16
17
  }[]) => void;
@@ -17,12 +17,12 @@ export interface MentionPluginConfig {
17
17
  export type MentionsChangedHandler = (changes: {
18
18
  id: string;
19
19
  localId: string;
20
+ shouldSuppressMentionNotification?: boolean;
20
21
  taskLocalId?: string;
21
22
  type: 'added' | 'deleted';
22
23
  }[]) => void;
23
24
  export interface MentionsPluginOptions extends MentionPluginConfig {
24
25
  allowZeroWidthSpaceAfter?: boolean;
25
- handleMentionsChanged?: MentionsChangedHandler;
26
26
  /**
27
27
  * User ID to highlight as a self-mention (typically the current user).
28
28
  *
@@ -31,6 +31,7 @@ export interface MentionsPluginOptions extends MentionPluginConfig {
31
31
  * Takes priority over `MentionProvider.shouldHighlightMention()` if both are present.
32
32
  */
33
33
  currentUserId?: string;
34
+ handleMentionsChanged?: MentionsChangedHandler;
34
35
  mentionProvider?: Providers['mentionProvider'];
35
36
  sanitizePrivateContent?: boolean;
36
37
  }
@@ -5,6 +5,7 @@ interface ProfileCardStateProps {
5
5
  id: string | undefined;
6
6
  provider: ProfilecardProvider | undefined;
7
7
  }
8
+ export declare const isAgentMentionType: (userType: unknown) => boolean;
8
9
  export declare const useProfileCardState: ({ id, provider, }: ProfileCardStateProps) => {
9
10
  data: ProfileCardClientData | undefined;
10
11
  hasError: boolean;
@@ -13,6 +14,9 @@ export declare const useProfileCardState: ({ id, provider, }: ProfileCardStatePr
13
14
  shouldShowGiveKudos: boolean;
14
15
  teamCentralBaseUrl: string | undefined;
15
16
  };
17
+ /**
18
+ * Renders the profile card popup for an editor mention node.
19
+ */
16
20
  export declare function ProfileCardComponent({ profilecardProvider, activeMention, dom, closeComponent, }: {
17
21
  activeMention: PMNode;
18
22
  closeComponent: () => void;
@@ -15,6 +15,7 @@ type Props = {
15
15
  id: string;
16
16
  localId: string;
17
17
  method?: 'pasted' | 'typed';
18
+ shouldSuppressMentionNotification?: boolean;
18
19
  taskLocalId?: string;
19
20
  type: 'added' | 'deleted';
20
21
  }[]) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "12.2.10",
3
+ "version": "12.3.0",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -55,10 +55,11 @@
55
55
  "@compiled/react": "^0.20.0",
56
56
  "bind-event-listener": "^3.0.0",
57
57
  "focus-trap": "^2.4.5",
58
+ "react-loadable": "^5.1.0",
58
59
  "uuid": "^3.1.0"
59
60
  },
60
61
  "peerDependencies": {
61
- "@atlaskit/editor-common": "^114.50.0",
62
+ "@atlaskit/editor-common": "^114.54.0",
62
63
  "react": "^18.2.0",
63
64
  "react-dom": "^18.2.0",
64
65
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"