@atlaskit/editor-plugin-mentions 1.4.1 → 1.5.1

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.
@@ -0,0 +1,173 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import React, { useEffect, useState } from 'react';
6
+ import { MentionWithProfileCard } from '@atlaskit/editor-common/mention';
7
+ import { browser } from '@atlaskit/editor-common/utils';
8
+ import { ResourcedMention } from '@atlaskit/mention/element';
9
+ import { isResolvingMentionProvider, MentionNameStatus } from '@atlaskit/mention/resource';
10
+ import { isPromise } from '@atlaskit/mention/types';
11
+
12
+ // Workaround for a firefox issue where dom selection is off sync
13
+ // https://product-fabric.atlassian.net/browse/ED-12442
14
+ var refreshBrowserSelection = function refreshBrowserSelection() {
15
+ var domSelection = window.getSelection();
16
+ if (domSelection) {
17
+ var domRange = domSelection && domSelection.rangeCount === 1 && domSelection.getRangeAt(0).cloneRange();
18
+ if (domRange) {
19
+ domSelection.removeAllRanges();
20
+ domSelection.addRange(domRange);
21
+ }
22
+ }
23
+ };
24
+ /**
25
+ * This is the new preferred way to render mentions in the editor.
26
+ * Introduced behind the `platform.editor.mentions-in-editor-popup-on-click` feature flag.
27
+ */
28
+ export var Mention = function Mention(props) {
29
+ var accessLevel = props.accessLevel,
30
+ eventHandlers = props.eventHandlers,
31
+ id = props.id,
32
+ text = props.text,
33
+ localId = props.localId,
34
+ mentionProvider = props.mentionProvider,
35
+ profilecardProviderPromise = props.profilecardProvider;
36
+ var _useState = useState(undefined),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ profilecardProvider = _useState2[0],
39
+ setProfilecardProvider = _useState2[1];
40
+ var resolvedName = useResolvedName(id, text, mentionProvider);
41
+
42
+ // Resolve the profilecard provider
43
+ useEffect(function () {
44
+ var isCancelled = false;
45
+ var resolveProfilecardProvider = /*#__PURE__*/function () {
46
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
47
+ var _profilecardProvider;
48
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
49
+ while (1) switch (_context.prev = _context.next) {
50
+ case 0:
51
+ _context.prev = 0;
52
+ _context.next = 3;
53
+ return profilecardProviderPromise;
54
+ case 3:
55
+ _profilecardProvider = _context.sent;
56
+ if (!isCancelled) {
57
+ setProfilecardProvider(_profilecardProvider);
58
+ }
59
+ _context.next = 10;
60
+ break;
61
+ case 7:
62
+ _context.prev = 7;
63
+ _context.t0 = _context["catch"](0);
64
+ if (!isCancelled) {
65
+ setProfilecardProvider(undefined);
66
+ }
67
+ case 10:
68
+ case "end":
69
+ return _context.stop();
70
+ }
71
+ }, _callee, null, [[0, 7]]);
72
+ }));
73
+ return function resolveProfilecardProvider() {
74
+ return _ref.apply(this, arguments);
75
+ };
76
+ }();
77
+ if (profilecardProviderPromise) {
78
+ resolveProfilecardProvider();
79
+ }
80
+ return function () {
81
+ isCancelled = true;
82
+ };
83
+ }, [profilecardProviderPromise]);
84
+ useEffect(function () {
85
+ // Workaround an issue where the selection is not updated immediately after adding
86
+ // a mention when "sanitizePrivateContent" is enabled in the editor on safari.
87
+ // This affects both insertion and paste behaviour it is applied to the component.
88
+ // https://product-fabric.atlassian.net/browse/ED-14859
89
+ if (browser.safari) {
90
+ setTimeout(refreshBrowserSelection, 0);
91
+ }
92
+ }, []);
93
+ var actionHandlers = {};
94
+ ['onClick', 'onMouseEnter', 'onMouseLeave'].forEach(function (handler) {
95
+ actionHandlers[handler] = eventHandlers && eventHandlers[handler] || function () {};
96
+ });
97
+ if (profilecardProvider) {
98
+ return /*#__PURE__*/React.createElement(MentionWithProfileCard, _extends({
99
+ id: id,
100
+ text: resolvedName,
101
+ accessLevel: accessLevel,
102
+ mentionProvider: mentionProvider,
103
+ profilecardProvider: profilecardProvider,
104
+ localId: localId
105
+ }, actionHandlers));
106
+ } else {
107
+ return /*#__PURE__*/React.createElement(ResourcedMention, _extends({
108
+ id: id,
109
+ text: resolvedName,
110
+ accessLevel: accessLevel,
111
+ mentionProvider: mentionProvider,
112
+ localId: localId
113
+ }, actionHandlers));
114
+ }
115
+ };
116
+ var useResolvedName = function useResolvedName(id, text, mentionProvider) {
117
+ var _useState3 = useState(text),
118
+ _useState4 = _slicedToArray(_useState3, 2),
119
+ resolvedName = _useState4[0],
120
+ setResolvedName = _useState4[1];
121
+ var processName = function processName(name) {
122
+ if (name.status === MentionNameStatus.OK) {
123
+ return "@".concat(name.name || '');
124
+ } else {
125
+ return "@_|unknown|_";
126
+ }
127
+ };
128
+ useEffect(function () {
129
+ if (mentionProvider) {
130
+ mentionProvider.then( /*#__PURE__*/function () {
131
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(provider) {
132
+ var nameDetail;
133
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
134
+ while (1) switch (_context2.prev = _context2.next) {
135
+ case 0:
136
+ if (!(!text && isResolvingMentionProvider(provider))) {
137
+ _context2.next = 13;
138
+ break;
139
+ }
140
+ nameDetail = provider.resolveMentionName(id);
141
+ if (!isPromise(nameDetail)) {
142
+ _context2.next = 10;
143
+ break;
144
+ }
145
+ _context2.t0 = processName;
146
+ _context2.next = 6;
147
+ return nameDetail;
148
+ case 6:
149
+ _context2.t1 = _context2.sent;
150
+ return _context2.abrupt("return", (0, _context2.t0)(_context2.t1));
151
+ case 10:
152
+ return _context2.abrupt("return", processName(nameDetail));
153
+ case 11:
154
+ _context2.next = 14;
155
+ break;
156
+ case 13:
157
+ return _context2.abrupt("return", text);
158
+ case 14:
159
+ case "end":
160
+ return _context2.stop();
161
+ }
162
+ }, _callee2);
163
+ }));
164
+ return function (_x) {
165
+ return _ref2.apply(this, arguments);
166
+ };
167
+ }()).then(function (resolvedName) {
168
+ setResolvedName(resolvedName);
169
+ });
170
+ }
171
+ }, [id, text, mentionProvider]);
172
+ return resolvedName;
173
+ };
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { AnalyticsEventPayload } from '@atlaskit/analytics-next';
3
+ import { type ProfilecardProvider } from '@atlaskit/editor-common/src/provider-factory/profile-card-provider';
3
4
  import type { NextEditorPlugin, OptionalPlugin, TypeAheadHandler } from '@atlaskit/editor-common/types';
4
5
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
6
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
@@ -13,6 +14,7 @@ export interface TeamInfoAttrAnalytics {
13
14
  export interface MentionPluginConfig {
14
15
  HighlightComponent?: React.ComponentType<React.PropsWithChildren<unknown>>;
15
16
  insertDisplayName?: boolean;
17
+ profilecardProvider?: Promise<ProfilecardProvider>;
16
18
  }
17
19
  export interface MentionPluginOptions extends MentionPluginConfig {
18
20
  sanitizePrivateContent?: boolean;
@@ -9,6 +9,10 @@ export interface MentionProps {
9
9
  accessLevel?: string;
10
10
  localId?: string;
11
11
  }
12
+ /**
13
+ * @deprecated should be replaced with `editor-plugin-mentions/src/ui/Mention/mention.tsx`
14
+ * when the feature flag `platform.editor.mentions-in-editor-popup-on-click` is tidied up.
15
+ */
12
16
  export default class Mention extends PureComponent<MentionProps, {}> {
13
17
  static displayName: string;
14
18
  private providerFactory;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { type ProfilecardProvider } from '@atlaskit/editor-common/src/provider-factory/profile-card-provider';
3
+ import type { MentionEventHandlers } from '@atlaskit/editor-common/ui';
4
+ import { type MentionProvider } from '@atlaskit/mention/resource';
5
+ export interface MentionProps {
6
+ id: string;
7
+ eventHandlers?: MentionEventHandlers;
8
+ text: string;
9
+ accessLevel?: string;
10
+ localId?: string;
11
+ mentionProvider?: Promise<MentionProvider>;
12
+ profilecardProvider?: Promise<ProfilecardProvider>;
13
+ }
14
+ /**
15
+ * This is the new preferred way to render mentions in the editor.
16
+ * Introduced behind the `platform.editor.mentions-in-editor-popup-on-click` feature flag.
17
+ */
18
+ export declare const Mention: (props: MentionProps) => JSX.Element;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import type { AnalyticsEventPayload } from '@atlaskit/analytics-next';
3
+ import { type ProfilecardProvider } from '@atlaskit/editor-common/src/provider-factory/profile-card-provider';
3
4
  import type { NextEditorPlugin, OptionalPlugin, TypeAheadHandler } from '@atlaskit/editor-common/types';
4
5
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
5
6
  import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
@@ -13,6 +14,7 @@ export interface TeamInfoAttrAnalytics {
13
14
  export interface MentionPluginConfig {
14
15
  HighlightComponent?: React.ComponentType<React.PropsWithChildren<unknown>>;
15
16
  insertDisplayName?: boolean;
17
+ profilecardProvider?: Promise<ProfilecardProvider>;
16
18
  }
17
19
  export interface MentionPluginOptions extends MentionPluginConfig {
18
20
  sanitizePrivateContent?: boolean;
@@ -9,6 +9,10 @@ export interface MentionProps {
9
9
  accessLevel?: string;
10
10
  localId?: string;
11
11
  }
12
+ /**
13
+ * @deprecated should be replaced with `editor-plugin-mentions/src/ui/Mention/mention.tsx`
14
+ * when the feature flag `platform.editor.mentions-in-editor-popup-on-click` is tidied up.
15
+ */
12
16
  export default class Mention extends PureComponent<MentionProps, {}> {
13
17
  static displayName: string;
14
18
  private providerFactory;
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import { type ProfilecardProvider } from '@atlaskit/editor-common/src/provider-factory/profile-card-provider';
3
+ import type { MentionEventHandlers } from '@atlaskit/editor-common/ui';
4
+ import { type MentionProvider } from '@atlaskit/mention/resource';
5
+ export interface MentionProps {
6
+ id: string;
7
+ eventHandlers?: MentionEventHandlers;
8
+ text: string;
9
+ accessLevel?: string;
10
+ localId?: string;
11
+ mentionProvider?: Promise<MentionProvider>;
12
+ profilecardProvider?: Promise<ProfilecardProvider>;
13
+ }
14
+ /**
15
+ * This is the new preferred way to render mentions in the editor.
16
+ * Introduced behind the `platform.editor.mentions-in-editor-popup-on-click` feature flag.
17
+ */
18
+ export declare const Mention: (props: MentionProps) => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "1.4.1",
3
+ "version": "1.5.1",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,13 +35,14 @@
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^36.10.7",
37
37
  "@atlaskit/analytics-gas-types": "^5.1.0",
38
- "@atlaskit/editor-common": "^81.0.0",
38
+ "@atlaskit/editor-common": "^82.0.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^1.2.0",
40
40
  "@atlaskit/editor-plugin-context-identifier": "^1.1.0",
41
41
  "@atlaskit/editor-plugin-type-ahead": "^1.2.0",
42
42
  "@atlaskit/editor-prosemirror": "4.0.1",
43
43
  "@atlaskit/icon": "^22.3.0",
44
- "@atlaskit/mention": "^23.0.0",
44
+ "@atlaskit/mention": "^23.1.0",
45
+ "@atlaskit/platform-feature-flags": "^0.2.5",
45
46
  "@atlaskit/theme": "^12.8.0",
46
47
  "@atlaskit/tokens": "^1.49.0",
47
48
  "@babel/runtime": "^7.0.0",
@@ -57,7 +58,6 @@
57
58
  "@af/visual-regression": "*",
58
59
  "@atlaskit/ssr": "*",
59
60
  "@atlaskit/visual-regression": "*",
60
- "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
61
61
  "@testing-library/react": "^12.1.5",
62
62
  "react-dom": "^16.8.0",
63
63
  "typescript": "~5.4.2",
@@ -104,5 +104,9 @@
104
104
  "@atlassian/tangerine/project-structure"
105
105
  ]
106
106
  },
107
- "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
107
+ "platform-feature-flags": {
108
+ "platform.editor.mentions-in-editor-popup-on-click": {
109
+ "type": "boolean"
110
+ }
111
+ }
108
112
  }
package/report.api.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  ## API Report File for "@atlaskit/editor-plugin-mentions"
4
4
 
5
- > Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
5
+ > Do not edit this file. This report is auto-generated using
6
+ > [API Extractor](https://api-extractor.com/).
6
7
  > [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
7
8
 
8
9
  ### Table of contents
@@ -29,44 +30,44 @@ import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
29
30
 
30
31
  // @public (undocumented)
31
32
  export interface MentionPluginConfig {
32
- // (undocumented)
33
- HighlightComponent?: React.ComponentType;
34
- // (undocumented)
35
- insertDisplayName?: boolean;
33
+ // (undocumented)
34
+ HighlightComponent?: React.ComponentType;
35
+ // (undocumented)
36
+ insertDisplayName?: boolean;
36
37
  }
37
38
 
38
39
  // @public (undocumented)
39
40
  interface MentionPluginOptions extends MentionPluginConfig {
40
- // (undocumented)
41
- allowZeroWidthSpaceAfter?: boolean;
42
- // (undocumented)
43
- sanitizePrivateContent?: boolean;
41
+ // (undocumented)
42
+ allowZeroWidthSpaceAfter?: boolean;
43
+ // (undocumented)
44
+ sanitizePrivateContent?: boolean;
44
45
  }
45
46
 
46
47
  // @public (undocumented)
47
48
  type MentionPluginState = {
48
- mentionProvider?: MentionProvider;
49
- contextIdentifierProvider?: ContextIdentifierProvider;
50
- mentions?: Array<MentionDescription>;
51
- canInsertMention?: boolean;
49
+ mentionProvider?: MentionProvider;
50
+ contextIdentifierProvider?: ContextIdentifierProvider;
51
+ mentions?: Array<MentionDescription>;
52
+ canInsertMention?: boolean;
52
53
  };
53
54
 
54
55
  // @public (undocumented)
55
56
  type MentionSharedState = MentionPluginState & {
56
- typeAheadHandler: TypeAheadHandler;
57
+ typeAheadHandler: TypeAheadHandler;
57
58
  };
58
59
 
59
60
  // @public (undocumented)
60
61
  export type MentionsPlugin = NextEditorPlugin<
61
- 'mention',
62
- {
63
- pluginConfiguration: MentionPluginOptions | undefined;
64
- dependencies: [OptionalPlugin<AnalyticsPlugin>, TypeAheadPlugin];
65
- sharedState: MentionSharedState | undefined;
66
- actions: {
67
- openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
68
- };
69
- }
62
+ 'mention',
63
+ {
64
+ pluginConfiguration: MentionPluginOptions | undefined;
65
+ dependencies: [OptionalPlugin<AnalyticsPlugin>, TypeAheadPlugin];
66
+ sharedState: MentionSharedState | undefined;
67
+ actions: {
68
+ openTypeAhead: (inputMethod: TypeAheadInputMethod) => boolean;
69
+ };
70
+ }
70
71
  >;
71
72
 
72
73
  // @public (undocumented)
@@ -83,9 +84,9 @@ export const mentionsPlugin: MentionsPlugin;
83
84
 
84
85
  ```json
85
86
  {
86
- "react": "^16.8.0",
87
- "react-dom": "^16.8.0",
88
- "react-intl-next": "npm:react-intl@^5.18.1"
87
+ "react": "^16.8.0",
88
+ "react-dom": "^16.8.0",
89
+ "react-intl-next": "npm:react-intl@^5.18.1"
89
90
  }
90
91
  ```
91
92