@atlaskit/editor-plugin-mentions 13.3.15 → 14.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.
@@ -19,6 +19,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
19
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
20
20
  import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
21
21
  import { createSingleMentionFragment } from '../../editor-commands';
22
+ import { mentionPluginKey } from '../../pm-plugins/key';
23
+ import { ACTIONS } from '../../pm-plugins/main';
22
24
  import { mentionPlaceholderPluginKey, MENTION_PLACEHOLDER_ACTIONS } from '../../pm-plugins/mentionPlaceholder';
23
25
  import { getMentionPluginState } from '../../pm-plugins/utils';
24
26
  import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
@@ -31,6 +33,9 @@ var isAgentUserType = function isAgentUserType(userType) {
31
33
  var isAgentMention = function isAgentMention(mention) {
32
34
  return isAgentUserType(mention.userType) || mention.appType === 'agent';
33
35
  };
36
+ var isAgentTypeAheadItem = function isAgentTypeAheadItem(item) {
37
+ return item.mention ? isAgentMention(item.mention) : false;
38
+ };
34
39
  var createInviteItem = function createInviteItem(_ref) {
35
40
  var mentionProvider = _ref.mentionProvider,
36
41
  onInviteItemMount = _ref.onInviteItemMount,
@@ -317,23 +322,31 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
317
322
  },
318
323
  getSections: function getSections(_ref9) {
319
324
  var intl = _ref9.intl;
320
- return [{
325
+ return [_objectSpread({
321
326
  id: 'people',
322
327
  title: intl.formatMessage(mentionMessages.typeAheadSectionPeople),
323
328
  filter: function filter(item) {
324
- var _item$mention;
325
- return !isAgentUserType(((_item$mention = item.mention) === null || _item$mention === void 0 ? void 0 : _item$mention.userType) || '');
329
+ return !isAgentTypeAheadItem(item);
326
330
  },
327
331
  limit: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? 5 : 6
328
- }, {
332
+ }, expVal('platform_editor_agent_mentions', 'isEnabled', false) ? {
333
+ sectionTitleDisplay: {
334
+ showWhenQueryPresent: false,
335
+ showWhenOnlySection: true
336
+ }
337
+ } : {}), _objectSpread({
329
338
  id: 'agents',
330
339
  title: intl.formatMessage(mentionMessages.typeAheadSectionAgents),
331
340
  filter: function filter(item) {
332
- var _item$mention2;
333
- return isAgentUserType(((_item$mention2 = item.mention) === null || _item$mention2 === void 0 ? void 0 : _item$mention2.userType) || '');
341
+ return isAgentTypeAheadItem(item);
334
342
  },
335
343
  limit: expVal('platform_editor_agent_mentions', 'isEnabled', false) ? 5 : undefined
336
- }];
344
+ }, expVal('platform_editor_agent_mentions', 'isEnabled', false) ? {
345
+ sectionTitleDisplay: {
346
+ showWhenQueryPresent: false,
347
+ showWhenOnlySection: true
348
+ }
349
+ } : {})];
337
350
  },
338
351
  onOpen: function onOpen() {
339
352
  firstQueryWithoutResults = null;
@@ -347,23 +360,23 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
347
360
  var schema = state.schema;
348
361
  var pluginState = getMentionPluginState(state);
349
362
  var mentionProvider = pluginState.mentionProvider;
350
- var _item$mention3 = item.mention,
351
- id = _item$mention3.id,
352
- name = _item$mention3.name,
353
- nickname = _item$mention3.nickname,
354
- accessLevel = _item$mention3.accessLevel,
355
- userType = _item$mention3.userType,
356
- isXProductUser = _item$mention3.isXProductUser;
363
+ var _item$mention = item.mention,
364
+ id = _item$mention.id,
365
+ name = _item$mention.name,
366
+ nickname = _item$mention.nickname,
367
+ accessLevel = _item$mention.accessLevel,
368
+ userType = _item$mention.userType,
369
+ isXProductUser = _item$mention.isXProductUser;
357
370
  var _ref1 = (_api$contextIdentifie3 = api === null || api === void 0 || (_api$contextIdentifie4 = api.contextIdentifier) === null || _api$contextIdentifie4 === void 0 ? void 0 : _api$contextIdentifie4.sharedState.currentState()) !== null && _api$contextIdentifie3 !== void 0 ? _api$contextIdentifie3 : {},
358
371
  contextIdentifierProvider = _ref1.contextIdentifierProvider;
359
372
  var mentionContext = _objectSpread(_objectSpread({}, contextIdentifierProvider), {}, {
360
373
  sessionId: sessionId
361
374
  });
362
375
  var isAgentMentionsExperimentEnabled = expVal('platform_editor_agent_mentions', 'isEnabled', false);
363
- var shouldSuppressInviteForAgentMention = isAgentMentionsExperimentEnabled && isAgentMention(item.mention);
376
+ var isAgentMentionInsertion = isAgentMentionsExperimentEnabled && isAgentMention(item.mention);
364
377
  // userType can be missing for provider-only agent mentions. Copy/paste cannot
365
378
  // see appType, so persist APP only when there is no explicit userType.
366
- var persistedUserType = isAgentMentionsExperimentEnabled && isAgentMention(item.mention) && userType == null ? 'APP' : userType;
379
+ var persistedUserType = isAgentMentionInsertion && userType == null ? 'APP' : userType;
367
380
  if (mentionProvider && !isInviteItem(item.mention)) {
368
381
  mentionProvider.recordMentionSelection(item.mention, mentionContext);
369
382
  }
@@ -388,12 +401,12 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
388
401
  // If query already includes @, use it as is
389
402
  if (email && mentionProvider.showInlineInviteRecaptcha) {
390
403
  mentionProvider.showInlineInviteRecaptcha(email);
391
- var tr = state.tr;
392
- tr.setMeta(mentionPlaceholderPluginKey, {
404
+ var _tr = state.tr;
405
+ _tr.setMeta(mentionPlaceholderPluginKey, {
393
406
  action: MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER,
394
407
  placeholder: "@".concat(query)
395
408
  });
396
- return tr;
409
+ return _tr;
397
410
  }
398
411
  } else if (mentionProvider.onInviteItemClick) {
399
412
  // Fallback to old behavior for backward compatibility
@@ -420,7 +433,7 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
420
433
  localId: mentionLocalId,
421
434
  method: 'typed',
422
435
  type: 'added'
423
- }, shouldSuppressInviteForAgentMention ? {
436
+ }, isAgentMentionInsertion ? {
424
437
  shouldSuppressMentionNotification: true
425
438
  } : {});
426
439
  if (taskItemId) {
@@ -433,22 +446,22 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
433
446
  }
434
447
  fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, mentionLocalId, sourceListItem.map(function (x) {
435
448
  return x.mention;
436
- }), query, contextIdentifierProvider, taskListId, taskItemId));
449
+ }), query, contextIdentifierProvider, taskListId, taskItemId, isAgentMentionInsertion));
437
450
 
438
451
  // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
439
452
  sessionId = uuid();
440
453
  if (mentionProvider && isTeamType(userType)) {
441
454
  return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
442
455
  }
443
- if (!shouldSuppressInviteForAgentMention && isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
456
+ if (!isAgentMentionInsertion && isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
444
457
  mentionProvider.inviteXProductUser(id, name);
445
458
  }
446
- return insert(createSingleMentionFragment({
459
+ var tr = insert(createSingleMentionFragment({
447
460
  mentionProvider: mentionProvider,
448
461
  mentionInsertDisplayName: mentionInsertDisplayName,
449
462
  tr: state.tr,
450
463
  sanitizePrivateContent: sanitizePrivateContent,
451
- suppressInviteXProductUser: shouldSuppressInviteForAgentMention
464
+ suppressInviteXProductUser: isAgentMentionInsertion
452
465
  })({
453
466
  name: name,
454
467
  id: id,
@@ -458,6 +471,15 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
458
471
  accessLevel: accessLevel,
459
472
  isXProductUser: isXProductUser
460
473
  }));
474
+ if (isAgentMentionInsertion) {
475
+ tr.setMeta(mentionPluginKey, {
476
+ action: ACTIONS.SET_PENDING_TYPED_AGENT_MENTION,
477
+ params: {
478
+ localId: mentionLocalId
479
+ }
480
+ });
481
+ }
482
+ return tr;
461
483
  },
462
484
  dismiss: function dismiss(_ref10) {
463
485
  var editorState = _ref10.editorState,
@@ -3,6 +3,8 @@ import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/edito
3
3
  import type { MentionsPlugin } from '../mentionsPluginType';
4
4
  import type { FireElementsChannelEvent, MentionPluginOptions, MentionPluginState } from '../types';
5
5
  export declare const ACTIONS: {
6
+ COMMIT_PENDING_TYPED_AGENT_MENTION: string;
7
+ SET_PENDING_TYPED_AGENT_MENTION: string;
6
8
  SET_PROVIDER: string;
7
9
  };
8
10
  interface CreateMentionPlugin {
@@ -43,8 +43,32 @@ export interface MentionsPluginOptions extends MentionPluginConfig {
43
43
  * @see https://product-fabric.atlassian.net/browse/ED-27496
44
44
  */
45
45
  export type MentionPluginOptions = MentionsPluginOptions;
46
+ export type AgentMentionDetails = {
47
+ id: string;
48
+ context: string | null;
49
+ nodeSize: number;
50
+ parentNodeType: string | null;
51
+ pos: number;
52
+ };
46
53
  export type MentionPluginState = {
47
54
  canInsertMention?: boolean;
55
+ /**
56
+ * @internal Tracks a typed agent mention while waiting for the platform-side
57
+ * ready-to-fire trigger. Consumers should continue to react only to
58
+ * lastInsertedAgentMention* fields.
59
+ */
60
+ pendingTypedAgentMention?: {
61
+ id: string;
62
+ localId: string;
63
+ nodeSize: number;
64
+ pos: number;
65
+ /**
66
+ * Generation value for the inactivity timer. This changes when local edits
67
+ * reset the pending mention window, so stale timer callbacks for the same
68
+ * localId cannot publish before the latest inactivity period has elapsed.
69
+ */
70
+ resetCount: number;
71
+ } | null;
48
72
  /**
49
73
  * Increments on each new agent mention insertion (including re-mentions of the same agent).
50
74
  * Used to trigger re-renders when the same agent is mentioned again.
@@ -8,5 +8,5 @@ export declare const MENTION_SOURCE = "mentionInEditor";
8
8
  export declare const buildTypeAheadCancelPayload: (duration: number, upKeyCount: number, downKeyCount: number, sessionId: string, query?: string) => AnalyticsEventPayload;
9
9
  export declare const buildTypeAheadInviteItemViewedPayload: (sessionId: string, contextIdentifierProvider?: ContextIdentifierProvider, userRole?: UserRole, additionalAttributes?: Record<string, unknown>) => AnalyticsEventPayload;
10
10
  export declare const buildTypeAheadInviteItemClickedPayload: (duration: number, upKeyCount: number, downKeyCount: number, sessionId: string, insertType: SelectItemMode, query?: string, contextIdentifierProvider?: ContextIdentifierProvider, userRole?: UserRole, additionalAttributes?: Record<string, unknown>) => AnalyticsEventPayload;
11
- export declare const buildTypeAheadInsertedPayload: (duration: number, upKeyCount: number, downKeyCount: number, sessionId: string, insertType: SelectItemMode, mention: MentionDescription, mentionLocalId: string, mentionList?: MentionDescription[], query?: string, contextIdentifierProvider?: ContextIdentifierProvider, taskListId?: string, taskItemId?: string) => AnalyticsEventPayload;
11
+ export declare const buildTypeAheadInsertedPayload: (duration: number, upKeyCount: number, downKeyCount: number, sessionId: string, insertType: SelectItemMode, mention: MentionDescription, mentionLocalId: string, mentionList?: MentionDescription[], query?: string, contextIdentifierProvider?: ContextIdentifierProvider, taskListId?: string, taskItemId?: string, isAgent?: boolean) => AnalyticsEventPayload;
12
12
  export declare const buildTypeAheadRenderedPayload: (duration: number, userIds: Array<string> | null, query: string, teams: TeamInfoAttrAnalytics[] | null, xProductMentionsLength: number) => AnalyticsEventPayload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "13.3.15",
3
+ "version": "14.1.0",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -16,42 +16,34 @@
16
16
  "module": "dist/esm/index.js",
17
17
  "module:es2019": "dist/es2019/index.js",
18
18
  "types": "dist/types/index.d.ts",
19
- "typesVersions": {
20
- ">=4.5 <4.9": {
21
- "*": [
22
- "dist/types-ts4.5/*",
23
- "dist/types-ts4.5/index.d.ts"
24
- ]
25
- }
26
- },
27
19
  "sideEffects": [
28
20
  "**/*.compiled.css"
29
21
  ],
30
22
  "atlaskit:src": "src/index.ts",
31
23
  "dependencies": {
32
- "@atlaskit/adf-schema": "^54.0.0",
33
- "@atlaskit/css": "^0.19.0",
34
- "@atlaskit/editor-plugin-analytics": "^11.0.0",
35
- "@atlaskit/editor-plugin-base": "^12.1.0",
36
- "@atlaskit/editor-plugin-context-identifier": "^11.0.0",
37
- "@atlaskit/editor-plugin-selection": "^11.0.0",
38
- "@atlaskit/editor-plugin-type-ahead": "^11.3.0",
39
- "@atlaskit/editor-prosemirror": "^7.3.0",
40
- "@atlaskit/icon": "^35.4.0",
41
- "@atlaskit/insm": "^0.4.0",
42
- "@atlaskit/link": "^3.4.0",
43
- "@atlaskit/mention": "^26.2.0",
44
- "@atlaskit/platform-feature-flags": "^1.1.0",
45
- "@atlaskit/popper": "^7.2.0",
46
- "@atlaskit/portal": "^5.5.0",
47
- "@atlaskit/primitives": "^19.0.0",
48
- "@atlaskit/profilecard": "^25.9.0",
49
- "@atlaskit/teams-app-config": "^1.12.0",
50
- "@atlaskit/theme": "^25.0.0",
51
- "@atlaskit/tmp-editor-statsig": "^103.0.0",
52
- "@atlaskit/tokens": "^13.4.0",
53
- "@atlaskit/tooltip": "^22.6.0",
54
- "@atlaskit/user-picker": "^12.1.0",
24
+ "@atlaskit/adf-schema": "^55.0.0",
25
+ "@atlaskit/css": "^1.0.0",
26
+ "@atlaskit/editor-plugin-analytics": "^12.0.0",
27
+ "@atlaskit/editor-plugin-base": "^13.0.0",
28
+ "@atlaskit/editor-plugin-context-identifier": "^12.0.0",
29
+ "@atlaskit/editor-plugin-selection": "^12.0.0",
30
+ "@atlaskit/editor-plugin-type-ahead": "^12.0.0",
31
+ "@atlaskit/editor-prosemirror": "^8.0.0",
32
+ "@atlaskit/icon": "^36.0.0",
33
+ "@atlaskit/insm": "^1.0.0",
34
+ "@atlaskit/link": "^4.0.0",
35
+ "@atlaskit/mention": "^27.0.0",
36
+ "@atlaskit/platform-feature-flags": "^2.0.0",
37
+ "@atlaskit/popper": "^8.0.0",
38
+ "@atlaskit/portal": "^6.0.0",
39
+ "@atlaskit/primitives": "^20.0.0",
40
+ "@atlaskit/profilecard": "^26.0.0",
41
+ "@atlaskit/teams-app-config": "^2.0.0",
42
+ "@atlaskit/theme": "^26.0.0",
43
+ "@atlaskit/tmp-editor-statsig": "^105.0.0",
44
+ "@atlaskit/tokens": "^14.0.0",
45
+ "@atlaskit/tooltip": "^23.0.0",
46
+ "@atlaskit/user-picker": "^13.0.0",
55
47
  "@babel/runtime": "^7.0.0",
56
48
  "@compiled/react": "^0.20.0",
57
49
  "bind-event-listener": "^3.0.0",
@@ -60,7 +52,7 @@
60
52
  "uuid": "^3.1.0"
61
53
  },
62
54
  "peerDependencies": {
63
- "@atlaskit/editor-common": "^115.15.0",
55
+ "@atlaskit/editor-common": "^116.1.0",
64
56
  "react": "^18.2.0",
65
57
  "react-dom": "^18.2.0",
66
58
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"