@atlaskit/editor-plugin-mentions 5.0.0 → 5.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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/editor-commands/index.js +90 -0
- package/dist/cjs/mentionsPlugin.js +9 -0
- package/dist/cjs/pm-plugins/main.js +1 -1
- package/dist/cjs/ui/type-ahead/index.js +19 -0
- package/dist/es2019/editor-commands/index.js +84 -0
- package/dist/es2019/mentionsPlugin.js +9 -0
- package/dist/es2019/pm-plugins/main.js +1 -1
- package/dist/es2019/ui/type-ahead/index.js +19 -0
- package/dist/esm/editor-commands/index.js +83 -0
- package/dist/esm/mentionsPlugin.js +9 -0
- package/dist/esm/pm-plugins/main.js +1 -1
- package/dist/esm/ui/type-ahead/index.js +19 -0
- package/dist/types/editor-commands/index.d.ts +32 -0
- package/dist/types/mentionsPluginType.d.ts +19 -1
- package/dist/types-ts4.5/editor-commands/index.d.ts +32 -0
- package/dist/types-ts4.5/mentionsPluginType.d.ts +19 -1
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-mentions
|
|
2
2
|
|
|
3
|
+
## 5.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#181692](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/181692)
|
|
8
|
+
[`919d15a436698`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/919d15a436698) -
|
|
9
|
+
Add insertMention API to mentions so that consumers can create mentions from a toolbar.
|
|
10
|
+
|
|
3
11
|
## 5.0.0
|
|
4
12
|
|
|
5
13
|
### Major Changes
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.insertMention = exports.createSingleMentionFragment = void 0;
|
|
8
|
+
var _uuid = _interopRequireDefault(require("uuid"));
|
|
9
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
|
+
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
|
+
var _resource = require("@atlaskit/mention/resource");
|
|
12
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
13
|
+
var createSingleMentionFragment = exports.createSingleMentionFragment = function createSingleMentionFragment(_ref) {
|
|
14
|
+
var mentionInsertDisplayName = _ref.mentionInsertDisplayName,
|
|
15
|
+
mentionProvider = _ref.mentionProvider,
|
|
16
|
+
tr = _ref.tr,
|
|
17
|
+
sanitizePrivateContent = _ref.sanitizePrivateContent;
|
|
18
|
+
return function (_ref2) {
|
|
19
|
+
var name = _ref2.name,
|
|
20
|
+
id = _ref2.id,
|
|
21
|
+
userType = _ref2.userType,
|
|
22
|
+
nickname = _ref2.nickname,
|
|
23
|
+
localId = _ref2.localId,
|
|
24
|
+
accessLevel = _ref2.accessLevel,
|
|
25
|
+
isXProductUser = _ref2.isXProductUser;
|
|
26
|
+
var schema = tr.doc.type.schema;
|
|
27
|
+
var trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
|
|
28
|
+
var renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
|
|
29
|
+
if (isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
|
|
30
|
+
mentionProvider.inviteXProductUser(id, name);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Don't insert into document if document data is sanitized.
|
|
34
|
+
var text = sanitizePrivateContent ? '' : "@".concat(renderName);
|
|
35
|
+
if (sanitizePrivateContent && (0, _resource.isResolvingMentionProvider)(mentionProvider)) {
|
|
36
|
+
// Cache (locally) for later rendering
|
|
37
|
+
mentionProvider.cacheMentionName(id, renderName);
|
|
38
|
+
}
|
|
39
|
+
var annotationMarksForPos = (0, _platformFeatureFlags.fg)(
|
|
40
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
41
|
+
'editor_inline_comments_paste_insert_nodes') ? (0, _utils.getAnnotationMarksForPos)(tr.selection.$head) : undefined;
|
|
42
|
+
var mentionNode = schema.nodes.mention.createChecked({
|
|
43
|
+
text: text,
|
|
44
|
+
id: id,
|
|
45
|
+
accessLevel: accessLevel,
|
|
46
|
+
userType: userType === 'DEFAULT' ? null : userType,
|
|
47
|
+
localId: localId !== null && localId !== void 0 ? localId : (0, _uuid.default)()
|
|
48
|
+
}, null,
|
|
49
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
50
|
+
(0, _platformFeatureFlags.fg)('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
51
|
+
var space = schema.text(' ',
|
|
52
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
53
|
+
(0, _platformFeatureFlags.fg)('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
54
|
+
return _model.Fragment.from([mentionNode, space]);
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
var insertMention = exports.insertMention = function insertMention(_ref3) {
|
|
58
|
+
var sanitizePrivateContent = _ref3.sanitizePrivateContent,
|
|
59
|
+
api = _ref3.api,
|
|
60
|
+
mentionInsertDisplayName = _ref3.mentionInsertDisplayName;
|
|
61
|
+
return function (_ref4) {
|
|
62
|
+
var name = _ref4.name,
|
|
63
|
+
id = _ref4.id,
|
|
64
|
+
userType = _ref4.userType,
|
|
65
|
+
localId = _ref4.localId,
|
|
66
|
+
nickname = _ref4.nickname,
|
|
67
|
+
accessLevel = _ref4.accessLevel,
|
|
68
|
+
isXProductUser = _ref4.isXProductUser;
|
|
69
|
+
return function (_ref5) {
|
|
70
|
+
var _api$mention$sharedSt;
|
|
71
|
+
var tr = _ref5.tr;
|
|
72
|
+
var mentionProvider = api === null || api === void 0 || (_api$mention$sharedSt = api.mention.sharedState.currentState()) === null || _api$mention$sharedSt === void 0 ? void 0 : _api$mention$sharedSt.mentionProvider;
|
|
73
|
+
var mentionFragment = createSingleMentionFragment({
|
|
74
|
+
sanitizePrivateContent: sanitizePrivateContent,
|
|
75
|
+
mentionProvider: mentionProvider,
|
|
76
|
+
mentionInsertDisplayName: mentionInsertDisplayName,
|
|
77
|
+
tr: tr
|
|
78
|
+
})({
|
|
79
|
+
name: name,
|
|
80
|
+
id: id,
|
|
81
|
+
userType: userType,
|
|
82
|
+
nickname: nickname,
|
|
83
|
+
localId: localId,
|
|
84
|
+
accessLevel: accessLevel,
|
|
85
|
+
isXProductUser: isXProductUser
|
|
86
|
+
});
|
|
87
|
+
return tr.insert(tr.selection.from, mentionFragment);
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
@@ -19,6 +19,7 @@ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
|
19
19
|
var _resource = require("@atlaskit/mention/resource");
|
|
20
20
|
var _types = require("@atlaskit/mention/types");
|
|
21
21
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
22
|
+
var _editorCommands = require("./editor-commands");
|
|
22
23
|
var _mentionNodeSpec = require("./nodeviews/mentionNodeSpec");
|
|
23
24
|
var _key = require("./pm-plugins/key");
|
|
24
25
|
var _main = require("./pm-plugins/main");
|
|
@@ -79,6 +80,7 @@ function Component(_ref) {
|
|
|
79
80
|
return null;
|
|
80
81
|
}
|
|
81
82
|
var mentionsPlugin = exports.mentionsPlugin = function mentionsPlugin(_ref3) {
|
|
83
|
+
var _options$sanitizePriv, _options$insertDispla;
|
|
82
84
|
var options = _ref3.config,
|
|
83
85
|
api = _ref3.api;
|
|
84
86
|
var sessionId = (0, _uuid.default)();
|
|
@@ -147,6 +149,13 @@ var mentionsPlugin = exports.mentionsPlugin = function mentionsPlugin(_ref3) {
|
|
|
147
149
|
typeAhead: typeAhead
|
|
148
150
|
});
|
|
149
151
|
},
|
|
152
|
+
commands: {
|
|
153
|
+
insertMention: (0, _editorCommands.insertMention)({
|
|
154
|
+
sanitizePrivateContent: (_options$sanitizePriv = options === null || options === void 0 ? void 0 : options.sanitizePrivateContent) !== null && _options$sanitizePriv !== void 0 ? _options$sanitizePriv : false,
|
|
155
|
+
mentionInsertDisplayName: (_options$insertDispla = options === null || options === void 0 ? void 0 : options.insertDisplayName) !== null && _options$insertDispla !== void 0 ? _options$insertDispla : false,
|
|
156
|
+
api: api
|
|
157
|
+
})
|
|
158
|
+
},
|
|
150
159
|
actions: {
|
|
151
160
|
openTypeAhead: function openTypeAhead(inputMethod) {
|
|
152
161
|
var _api$typeAhead;
|
|
@@ -23,7 +23,7 @@ var ACTIONS = exports.ACTIONS = {
|
|
|
23
23
|
SET_PROVIDER: 'SET_PROVIDER'
|
|
24
24
|
};
|
|
25
25
|
var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
|
|
26
|
-
var PACKAGE_VERSION = "
|
|
26
|
+
var PACKAGE_VERSION = "5.0.0";
|
|
27
27
|
var setProvider = function setProvider(provider) {
|
|
28
28
|
return function (state, dispatch) {
|
|
29
29
|
if (dispatch) {
|
|
@@ -20,6 +20,7 @@ var _item = require("@atlaskit/mention/item");
|
|
|
20
20
|
var _resource = require("@atlaskit/mention/resource");
|
|
21
21
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
22
22
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
23
|
+
var _editorCommands = require("../../editor-commands");
|
|
23
24
|
var _utils3 = require("../../pm-plugins/utils");
|
|
24
25
|
var _InviteItem = _interopRequireWildcard(require("../InviteItem"));
|
|
25
26
|
var _analytics = require("./analytics");
|
|
@@ -369,6 +370,24 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
369
370
|
mentionProvider.inviteXProductUser(id, name);
|
|
370
371
|
}
|
|
371
372
|
|
|
373
|
+
// This replaces logic below
|
|
374
|
+
if ((0, _platformFeatureFlags.fg)('platform_mention_insert_mention_refactor')) {
|
|
375
|
+
return insert((0, _editorCommands.createSingleMentionFragment)({
|
|
376
|
+
mentionProvider: mentionProvider,
|
|
377
|
+
mentionInsertDisplayName: mentionInsertDisplayName,
|
|
378
|
+
tr: state.tr,
|
|
379
|
+
sanitizePrivateContent: sanitizePrivateContent
|
|
380
|
+
})({
|
|
381
|
+
name: name,
|
|
382
|
+
id: id,
|
|
383
|
+
userType: userType,
|
|
384
|
+
nickname: nickname,
|
|
385
|
+
localId: mentionLocalId,
|
|
386
|
+
accessLevel: accessLevel,
|
|
387
|
+
isXProductUser: isXProductUser
|
|
388
|
+
}));
|
|
389
|
+
}
|
|
390
|
+
|
|
372
391
|
// Don't insert into document if document data is sanitized.
|
|
373
392
|
var text = sanitizePrivateContent ? '' : "@".concat(renderName);
|
|
374
393
|
if (sanitizePrivateContent && (0, _resource.isResolvingMentionProvider)(mentionProvider)) {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import uuid from 'uuid';
|
|
2
|
+
import { getAnnotationMarksForPos } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
+
export const createSingleMentionFragment = ({
|
|
7
|
+
mentionInsertDisplayName,
|
|
8
|
+
mentionProvider,
|
|
9
|
+
tr,
|
|
10
|
+
sanitizePrivateContent
|
|
11
|
+
}) => ({
|
|
12
|
+
name,
|
|
13
|
+
id,
|
|
14
|
+
userType,
|
|
15
|
+
nickname,
|
|
16
|
+
localId,
|
|
17
|
+
accessLevel,
|
|
18
|
+
isXProductUser
|
|
19
|
+
}) => {
|
|
20
|
+
const schema = tr.doc.type.schema;
|
|
21
|
+
const trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
|
|
22
|
+
const renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
|
|
23
|
+
if (isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
|
|
24
|
+
mentionProvider.inviteXProductUser(id, name);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Don't insert into document if document data is sanitized.
|
|
28
|
+
const text = sanitizePrivateContent ? '' : `@${renderName}`;
|
|
29
|
+
if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
|
|
30
|
+
// Cache (locally) for later rendering
|
|
31
|
+
mentionProvider.cacheMentionName(id, renderName);
|
|
32
|
+
}
|
|
33
|
+
const annotationMarksForPos = fg(
|
|
34
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
35
|
+
'editor_inline_comments_paste_insert_nodes') ? getAnnotationMarksForPos(tr.selection.$head) : undefined;
|
|
36
|
+
const mentionNode = schema.nodes.mention.createChecked({
|
|
37
|
+
text,
|
|
38
|
+
id,
|
|
39
|
+
accessLevel,
|
|
40
|
+
userType: userType === 'DEFAULT' ? null : userType,
|
|
41
|
+
localId: localId !== null && localId !== void 0 ? localId : uuid()
|
|
42
|
+
}, null,
|
|
43
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
44
|
+
fg('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
45
|
+
const space = schema.text(' ',
|
|
46
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
47
|
+
fg('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
48
|
+
return Fragment.from([mentionNode, space]);
|
|
49
|
+
};
|
|
50
|
+
export const insertMention = ({
|
|
51
|
+
sanitizePrivateContent,
|
|
52
|
+
api,
|
|
53
|
+
mentionInsertDisplayName
|
|
54
|
+
}) => ({
|
|
55
|
+
name,
|
|
56
|
+
id,
|
|
57
|
+
userType,
|
|
58
|
+
localId,
|
|
59
|
+
nickname,
|
|
60
|
+
accessLevel,
|
|
61
|
+
isXProductUser
|
|
62
|
+
}) => {
|
|
63
|
+
return ({
|
|
64
|
+
tr
|
|
65
|
+
}) => {
|
|
66
|
+
var _api$mention$sharedSt;
|
|
67
|
+
const mentionProvider = api === null || api === void 0 ? void 0 : (_api$mention$sharedSt = api.mention.sharedState.currentState()) === null || _api$mention$sharedSt === void 0 ? void 0 : _api$mention$sharedSt.mentionProvider;
|
|
68
|
+
const mentionFragment = createSingleMentionFragment({
|
|
69
|
+
sanitizePrivateContent,
|
|
70
|
+
mentionProvider,
|
|
71
|
+
mentionInsertDisplayName,
|
|
72
|
+
tr
|
|
73
|
+
})({
|
|
74
|
+
name,
|
|
75
|
+
id,
|
|
76
|
+
userType,
|
|
77
|
+
nickname,
|
|
78
|
+
localId,
|
|
79
|
+
accessLevel,
|
|
80
|
+
isXProductUser
|
|
81
|
+
});
|
|
82
|
+
return tr.insert(tr.selection.from, mentionFragment);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -8,6 +8,7 @@ import { IconMention } from '@atlaskit/editor-common/quick-insert';
|
|
|
8
8
|
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
9
9
|
import { MentionNameStatus, isPromise } from '@atlaskit/mention/types';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
11
|
+
import { insertMention } from './editor-commands';
|
|
11
12
|
import { mentionNodeSpec } from './nodeviews/mentionNodeSpec';
|
|
12
13
|
import { mentionPluginKey } from './pm-plugins/key';
|
|
13
14
|
import { ACTIONS, createMentionPlugin } from './pm-plugins/main';
|
|
@@ -78,6 +79,7 @@ const mentionsPlugin = ({
|
|
|
78
79
|
config: options,
|
|
79
80
|
api
|
|
80
81
|
}) => {
|
|
82
|
+
var _options$sanitizePriv, _options$insertDispla;
|
|
81
83
|
const sessionId = uuid();
|
|
82
84
|
let previousMediaProvider;
|
|
83
85
|
const fireEvent = (payload, channel) => {
|
|
@@ -145,6 +147,13 @@ const mentionsPlugin = ({
|
|
|
145
147
|
typeAhead: typeAhead
|
|
146
148
|
});
|
|
147
149
|
},
|
|
150
|
+
commands: {
|
|
151
|
+
insertMention: insertMention({
|
|
152
|
+
sanitizePrivateContent: (_options$sanitizePriv = options === null || options === void 0 ? void 0 : options.sanitizePrivateContent) !== null && _options$sanitizePriv !== void 0 ? _options$sanitizePriv : false,
|
|
153
|
+
mentionInsertDisplayName: (_options$insertDispla = options === null || options === void 0 ? void 0 : options.insertDisplayName) !== null && _options$insertDispla !== void 0 ? _options$insertDispla : false,
|
|
154
|
+
api
|
|
155
|
+
})
|
|
156
|
+
},
|
|
148
157
|
actions: {
|
|
149
158
|
openTypeAhead(inputMethod) {
|
|
150
159
|
var _api$typeAhead, _api$typeAhead$action;
|
|
@@ -12,7 +12,7 @@ export const ACTIONS = {
|
|
|
12
12
|
SET_PROVIDER: 'SET_PROVIDER'
|
|
13
13
|
};
|
|
14
14
|
const PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
|
|
15
|
-
const PACKAGE_VERSION = "
|
|
15
|
+
const PACKAGE_VERSION = "5.0.0";
|
|
16
16
|
const setProvider = provider => (state, dispatch) => {
|
|
17
17
|
if (dispatch) {
|
|
18
18
|
dispatch(state.tr.setMeta(mentionPluginKey, {
|
|
@@ -8,6 +8,7 @@ import { MENTION_ITEM_HEIGHT, MentionItem } from '@atlaskit/mention/item';
|
|
|
8
8
|
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
11
|
+
import { createSingleMentionFragment } from '../../editor-commands';
|
|
11
12
|
import { getMentionPluginState } from '../../pm-plugins/utils';
|
|
12
13
|
import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
|
|
13
14
|
import { buildTypeAheadCancelPayload, buildTypeAheadInsertedPayload, buildTypeAheadInviteItemClickedPayload, buildTypeAheadInviteItemViewedPayload, buildTypeAheadRenderedPayload } from './analytics';
|
|
@@ -352,6 +353,24 @@ export const createTypeAheadConfig = ({
|
|
|
352
353
|
mentionProvider.inviteXProductUser(id, name);
|
|
353
354
|
}
|
|
354
355
|
|
|
356
|
+
// This replaces logic below
|
|
357
|
+
if (fg('platform_mention_insert_mention_refactor')) {
|
|
358
|
+
return insert(createSingleMentionFragment({
|
|
359
|
+
mentionProvider,
|
|
360
|
+
mentionInsertDisplayName,
|
|
361
|
+
tr: state.tr,
|
|
362
|
+
sanitizePrivateContent
|
|
363
|
+
})({
|
|
364
|
+
name,
|
|
365
|
+
id,
|
|
366
|
+
userType,
|
|
367
|
+
nickname,
|
|
368
|
+
localId: mentionLocalId,
|
|
369
|
+
accessLevel,
|
|
370
|
+
isXProductUser
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
|
|
355
374
|
// Don't insert into document if document data is sanitized.
|
|
356
375
|
const text = sanitizePrivateContent ? '' : `@${renderName}`;
|
|
357
376
|
if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import uuid from 'uuid';
|
|
2
|
+
import { getAnnotationMarksForPos } from '@atlaskit/editor-common/utils';
|
|
3
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
5
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
|
+
export var createSingleMentionFragment = function createSingleMentionFragment(_ref) {
|
|
7
|
+
var mentionInsertDisplayName = _ref.mentionInsertDisplayName,
|
|
8
|
+
mentionProvider = _ref.mentionProvider,
|
|
9
|
+
tr = _ref.tr,
|
|
10
|
+
sanitizePrivateContent = _ref.sanitizePrivateContent;
|
|
11
|
+
return function (_ref2) {
|
|
12
|
+
var name = _ref2.name,
|
|
13
|
+
id = _ref2.id,
|
|
14
|
+
userType = _ref2.userType,
|
|
15
|
+
nickname = _ref2.nickname,
|
|
16
|
+
localId = _ref2.localId,
|
|
17
|
+
accessLevel = _ref2.accessLevel,
|
|
18
|
+
isXProductUser = _ref2.isXProductUser;
|
|
19
|
+
var schema = tr.doc.type.schema;
|
|
20
|
+
var trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
|
|
21
|
+
var renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
|
|
22
|
+
if (isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
|
|
23
|
+
mentionProvider.inviteXProductUser(id, name);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Don't insert into document if document data is sanitized.
|
|
27
|
+
var text = sanitizePrivateContent ? '' : "@".concat(renderName);
|
|
28
|
+
if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
|
|
29
|
+
// Cache (locally) for later rendering
|
|
30
|
+
mentionProvider.cacheMentionName(id, renderName);
|
|
31
|
+
}
|
|
32
|
+
var annotationMarksForPos = fg(
|
|
33
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
34
|
+
'editor_inline_comments_paste_insert_nodes') ? getAnnotationMarksForPos(tr.selection.$head) : undefined;
|
|
35
|
+
var mentionNode = schema.nodes.mention.createChecked({
|
|
36
|
+
text: text,
|
|
37
|
+
id: id,
|
|
38
|
+
accessLevel: accessLevel,
|
|
39
|
+
userType: userType === 'DEFAULT' ? null : userType,
|
|
40
|
+
localId: localId !== null && localId !== void 0 ? localId : uuid()
|
|
41
|
+
}, null,
|
|
42
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
43
|
+
fg('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
44
|
+
var space = schema.text(' ',
|
|
45
|
+
// eslint-disable-next-line @atlaskit/platform/ensure-feature-flag-prefix
|
|
46
|
+
fg('editor_inline_comments_paste_insert_nodes') ? annotationMarksForPos : undefined);
|
|
47
|
+
return Fragment.from([mentionNode, space]);
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export var insertMention = function insertMention(_ref3) {
|
|
51
|
+
var sanitizePrivateContent = _ref3.sanitizePrivateContent,
|
|
52
|
+
api = _ref3.api,
|
|
53
|
+
mentionInsertDisplayName = _ref3.mentionInsertDisplayName;
|
|
54
|
+
return function (_ref4) {
|
|
55
|
+
var name = _ref4.name,
|
|
56
|
+
id = _ref4.id,
|
|
57
|
+
userType = _ref4.userType,
|
|
58
|
+
localId = _ref4.localId,
|
|
59
|
+
nickname = _ref4.nickname,
|
|
60
|
+
accessLevel = _ref4.accessLevel,
|
|
61
|
+
isXProductUser = _ref4.isXProductUser;
|
|
62
|
+
return function (_ref5) {
|
|
63
|
+
var _api$mention$sharedSt;
|
|
64
|
+
var tr = _ref5.tr;
|
|
65
|
+
var mentionProvider = api === null || api === void 0 || (_api$mention$sharedSt = api.mention.sharedState.currentState()) === null || _api$mention$sharedSt === void 0 ? void 0 : _api$mention$sharedSt.mentionProvider;
|
|
66
|
+
var mentionFragment = createSingleMentionFragment({
|
|
67
|
+
sanitizePrivateContent: sanitizePrivateContent,
|
|
68
|
+
mentionProvider: mentionProvider,
|
|
69
|
+
mentionInsertDisplayName: mentionInsertDisplayName,
|
|
70
|
+
tr: tr
|
|
71
|
+
})({
|
|
72
|
+
name: name,
|
|
73
|
+
id: id,
|
|
74
|
+
userType: userType,
|
|
75
|
+
nickname: nickname,
|
|
76
|
+
localId: localId,
|
|
77
|
+
accessLevel: accessLevel,
|
|
78
|
+
isXProductUser: isXProductUser
|
|
79
|
+
});
|
|
80
|
+
return tr.insert(tr.selection.from, mentionFragment);
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -13,6 +13,7 @@ import { IconMention } from '@atlaskit/editor-common/quick-insert';
|
|
|
13
13
|
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
14
14
|
import { MentionNameStatus, isPromise } from '@atlaskit/mention/types';
|
|
15
15
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
|
+
import { insertMention } from './editor-commands';
|
|
16
17
|
import { mentionNodeSpec } from './nodeviews/mentionNodeSpec';
|
|
17
18
|
import { mentionPluginKey } from './pm-plugins/key';
|
|
18
19
|
import { ACTIONS, createMentionPlugin } from './pm-plugins/main';
|
|
@@ -70,6 +71,7 @@ function Component(_ref) {
|
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
72
73
|
var mentionsPlugin = function mentionsPlugin(_ref3) {
|
|
74
|
+
var _options$sanitizePriv, _options$insertDispla;
|
|
73
75
|
var options = _ref3.config,
|
|
74
76
|
api = _ref3.api;
|
|
75
77
|
var sessionId = uuid();
|
|
@@ -138,6 +140,13 @@ var mentionsPlugin = function mentionsPlugin(_ref3) {
|
|
|
138
140
|
typeAhead: typeAhead
|
|
139
141
|
});
|
|
140
142
|
},
|
|
143
|
+
commands: {
|
|
144
|
+
insertMention: insertMention({
|
|
145
|
+
sanitizePrivateContent: (_options$sanitizePriv = options === null || options === void 0 ? void 0 : options.sanitizePrivateContent) !== null && _options$sanitizePriv !== void 0 ? _options$sanitizePriv : false,
|
|
146
|
+
mentionInsertDisplayName: (_options$insertDispla = options === null || options === void 0 ? void 0 : options.insertDisplayName) !== null && _options$insertDispla !== void 0 ? _options$insertDispla : false,
|
|
147
|
+
api: api
|
|
148
|
+
})
|
|
149
|
+
},
|
|
141
150
|
actions: {
|
|
142
151
|
openTypeAhead: function openTypeAhead(inputMethod) {
|
|
143
152
|
var _api$typeAhead;
|
|
@@ -15,7 +15,7 @@ export var ACTIONS = {
|
|
|
15
15
|
SET_PROVIDER: 'SET_PROVIDER'
|
|
16
16
|
};
|
|
17
17
|
var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
|
|
18
|
-
var PACKAGE_VERSION = "
|
|
18
|
+
var PACKAGE_VERSION = "5.0.0";
|
|
19
19
|
var setProvider = function setProvider(provider) {
|
|
20
20
|
return function (state, dispatch) {
|
|
21
21
|
if (dispatch) {
|
|
@@ -15,6 +15,7 @@ import { MENTION_ITEM_HEIGHT, MentionItem } from '@atlaskit/mention/item';
|
|
|
15
15
|
import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
|
|
16
16
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
17
17
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
18
|
+
import { createSingleMentionFragment } from '../../editor-commands';
|
|
18
19
|
import { getMentionPluginState } from '../../pm-plugins/utils';
|
|
19
20
|
import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
|
|
20
21
|
import { buildTypeAheadCancelPayload, buildTypeAheadInsertedPayload, buildTypeAheadInviteItemClickedPayload, buildTypeAheadInviteItemViewedPayload, buildTypeAheadRenderedPayload } from './analytics';
|
|
@@ -358,6 +359,24 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref6) {
|
|
|
358
359
|
mentionProvider.inviteXProductUser(id, name);
|
|
359
360
|
}
|
|
360
361
|
|
|
362
|
+
// This replaces logic below
|
|
363
|
+
if (fg('platform_mention_insert_mention_refactor')) {
|
|
364
|
+
return insert(createSingleMentionFragment({
|
|
365
|
+
mentionProvider: mentionProvider,
|
|
366
|
+
mentionInsertDisplayName: mentionInsertDisplayName,
|
|
367
|
+
tr: state.tr,
|
|
368
|
+
sanitizePrivateContent: sanitizePrivateContent
|
|
369
|
+
})({
|
|
370
|
+
name: name,
|
|
371
|
+
id: id,
|
|
372
|
+
userType: userType,
|
|
373
|
+
nickname: nickname,
|
|
374
|
+
localId: mentionLocalId,
|
|
375
|
+
accessLevel: accessLevel,
|
|
376
|
+
isXProductUser: isXProductUser
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
379
|
+
|
|
361
380
|
// Don't insert into document if document data is sanitized.
|
|
362
381
|
var text = sanitizePrivateContent ? '' : "@".concat(renderName);
|
|
363
382
|
if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { type MentionProvider, type MentionDescription } from '@atlaskit/mention/resource';
|
|
5
|
+
import type { MentionsPlugin } from '../mentionsPluginType';
|
|
6
|
+
export type InsertMentionParameters = Pick<MentionDescription, 'name' | 'id' | 'userType' | 'isXProductUser' | 'nickname' | 'accessLevel'> & {
|
|
7
|
+
/**
|
|
8
|
+
* The name is the name that will be displayed in the editor and stored in the ADF.
|
|
9
|
+
* If using "sanitizePrivateContent" with the mentions plugin, you can pass an empty
|
|
10
|
+
* name (ie. `name: ''`) to ensure the name is resolved by the mention provider (based
|
|
11
|
+
* on the id).
|
|
12
|
+
*
|
|
13
|
+
* !Warning: This is set without check if it matches the value in the mention provider, that
|
|
14
|
+
* must be done on the client side if using this.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
localId?: string;
|
|
18
|
+
};
|
|
19
|
+
type InternalParams = {
|
|
20
|
+
sanitizePrivateContent: boolean;
|
|
21
|
+
api: ExtractInjectionAPI<MentionsPlugin> | undefined;
|
|
22
|
+
mentionInsertDisplayName: boolean;
|
|
23
|
+
};
|
|
24
|
+
type SingleMentionFragmentParams = {
|
|
25
|
+
mentionProvider: MentionProvider | undefined;
|
|
26
|
+
sanitizePrivateContent: boolean | undefined;
|
|
27
|
+
mentionInsertDisplayName: boolean | undefined;
|
|
28
|
+
tr: Transaction;
|
|
29
|
+
};
|
|
30
|
+
export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
|
|
31
|
+
export declare const insertMention: ({ sanitizePrivateContent, api, mentionInsertDisplayName }: InternalParams) => ({ name, id, userType, localId, nickname, accessLevel, isXProductUser, }: InsertMentionParameters) => EditorCommand;
|
|
32
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { BasePlugin } from '@atlaskit/editor-plugin-base';
|
|
4
4
|
import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
7
7
|
import type { MentionProvider } from '@atlaskit/mention/resource';
|
|
8
|
+
import type { InsertMentionParameters } from './editor-commands';
|
|
8
9
|
import type { MentionPluginOptions, MentionSharedState } from './types';
|
|
9
10
|
export type MentionActionOpenTypeAhead = (inputMethod: TypeAheadInputMethod) => boolean;
|
|
10
11
|
export type MentionActionAnnounceMentionsInsertion = (mentionIds: {
|
|
@@ -31,4 +32,21 @@ export type MentionsPlugin = NextEditorPlugin<'mention', {
|
|
|
31
32
|
dependencies: MentionPluginDependencies;
|
|
32
33
|
sharedState: MentionSharedState | undefined;
|
|
33
34
|
actions: MentionActions;
|
|
35
|
+
commands: {
|
|
36
|
+
/**
|
|
37
|
+
* Inserts mention node into the document based on parameters.
|
|
38
|
+
*
|
|
39
|
+
* !Warning at this stage only inserts single mentions
|
|
40
|
+
*
|
|
41
|
+
* @param params.name string
|
|
42
|
+
* @param params.id string
|
|
43
|
+
* @param params.userType string (optional)
|
|
44
|
+
* @param params.nickname string (optional)
|
|
45
|
+
* @param params.localId string (optional)
|
|
46
|
+
* @param params.accessLevel string (optional)
|
|
47
|
+
* @param params.isXProductUser boolean (optional)
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
insertMention: (params: InsertMentionParameters) => EditorCommand;
|
|
51
|
+
};
|
|
34
52
|
}>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import { type MentionProvider, type MentionDescription } from '@atlaskit/mention/resource';
|
|
5
|
+
import type { MentionsPlugin } from '../mentionsPluginType';
|
|
6
|
+
export type InsertMentionParameters = Pick<MentionDescription, 'name' | 'id' | 'userType' | 'isXProductUser' | 'nickname' | 'accessLevel'> & {
|
|
7
|
+
/**
|
|
8
|
+
* The name is the name that will be displayed in the editor and stored in the ADF.
|
|
9
|
+
* If using "sanitizePrivateContent" with the mentions plugin, you can pass an empty
|
|
10
|
+
* name (ie. `name: ''`) to ensure the name is resolved by the mention provider (based
|
|
11
|
+
* on the id).
|
|
12
|
+
*
|
|
13
|
+
* !Warning: This is set without check if it matches the value in the mention provider, that
|
|
14
|
+
* must be done on the client side if using this.
|
|
15
|
+
*/
|
|
16
|
+
name: string;
|
|
17
|
+
localId?: string;
|
|
18
|
+
};
|
|
19
|
+
type InternalParams = {
|
|
20
|
+
sanitizePrivateContent: boolean;
|
|
21
|
+
api: ExtractInjectionAPI<MentionsPlugin> | undefined;
|
|
22
|
+
mentionInsertDisplayName: boolean;
|
|
23
|
+
};
|
|
24
|
+
type SingleMentionFragmentParams = {
|
|
25
|
+
mentionProvider: MentionProvider | undefined;
|
|
26
|
+
sanitizePrivateContent: boolean | undefined;
|
|
27
|
+
mentionInsertDisplayName: boolean | undefined;
|
|
28
|
+
tr: Transaction;
|
|
29
|
+
};
|
|
30
|
+
export declare const createSingleMentionFragment: ({ mentionInsertDisplayName, mentionProvider, tr, sanitizePrivateContent, }: SingleMentionFragmentParams) => ({ name, id, userType, nickname, localId, accessLevel, isXProductUser, }: InsertMentionParameters) => Fragment;
|
|
31
|
+
export declare const insertMention: ({ sanitizePrivateContent, api, mentionInsertDisplayName }: InternalParams) => ({ name, id, userType, localId, nickname, accessLevel, isXProductUser, }: InsertMentionParameters) => EditorCommand;
|
|
32
|
+
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { NextEditorPlugin, OptionalPlugin, EditorCommand } from '@atlaskit/editor-common/types';
|
|
2
2
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
3
3
|
import type { BasePlugin } from '@atlaskit/editor-plugin-base';
|
|
4
4
|
import type { ContextIdentifierPlugin } from '@atlaskit/editor-plugin-context-identifier';
|
|
5
5
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
6
6
|
import type { TypeAheadInputMethod, TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
|
|
7
7
|
import type { MentionProvider } from '@atlaskit/mention/resource';
|
|
8
|
+
import type { InsertMentionParameters } from './editor-commands';
|
|
8
9
|
import type { MentionPluginOptions, MentionSharedState } from './types';
|
|
9
10
|
export type MentionActionOpenTypeAhead = (inputMethod: TypeAheadInputMethod) => boolean;
|
|
10
11
|
export type MentionActionAnnounceMentionsInsertion = (mentionIds: {
|
|
@@ -31,4 +32,21 @@ export type MentionsPlugin = NextEditorPlugin<'mention', {
|
|
|
31
32
|
dependencies: MentionPluginDependencies;
|
|
32
33
|
sharedState: MentionSharedState | undefined;
|
|
33
34
|
actions: MentionActions;
|
|
35
|
+
commands: {
|
|
36
|
+
/**
|
|
37
|
+
* Inserts mention node into the document based on parameters.
|
|
38
|
+
*
|
|
39
|
+
* !Warning at this stage only inserts single mentions
|
|
40
|
+
*
|
|
41
|
+
* @param params.name string
|
|
42
|
+
* @param params.id string
|
|
43
|
+
* @param params.userType string (optional)
|
|
44
|
+
* @param params.nickname string (optional)
|
|
45
|
+
* @param params.localId string (optional)
|
|
46
|
+
* @param params.accessLevel string (optional)
|
|
47
|
+
* @param params.isXProductUser boolean (optional)
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
insertMention: (params: InsertMentionParameters) => EditorCommand;
|
|
51
|
+
};
|
|
34
52
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-mentions",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Mentions plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/portal": "^5.1.0",
|
|
49
49
|
"@atlaskit/profilecard": "^23.21.0",
|
|
50
50
|
"@atlaskit/theme": "^18.0.0",
|
|
51
|
-
"@atlaskit/tmp-editor-statsig": "^8.
|
|
51
|
+
"@atlaskit/tmp-editor-statsig": "^8.8.0",
|
|
52
52
|
"@atlaskit/tokens": "^5.4.0",
|
|
53
53
|
"@babel/runtime": "^7.0.0",
|
|
54
54
|
"@compiled/react": "^0.18.3",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"uuid": "^3.1.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@atlaskit/editor-common": "^107.
|
|
60
|
+
"@atlaskit/editor-common": "^107.7.0",
|
|
61
61
|
"react": "^18.2.0",
|
|
62
62
|
"react-dom": "^18.2.0",
|
|
63
63
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
@@ -117,6 +117,9 @@
|
|
|
117
117
|
"platform_editor_mention_provider_via_plugin_config": {
|
|
118
118
|
"type": "boolean"
|
|
119
119
|
},
|
|
120
|
+
"platform_mention_insert_mention_refactor": {
|
|
121
|
+
"type": "boolean"
|
|
122
|
+
},
|
|
120
123
|
"dst-a11y__replace-anchor-with-link__editor-ai": {
|
|
121
124
|
"type": "boolean"
|
|
122
125
|
}
|