@atlaskit/editor-plugin-mentions 0.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/.eslintrc.js +7 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +9 -0
- package/dist/cjs/analytics.js +157 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/messages.js +29 -0
- package/dist/cjs/nodeviews/mention.js +117 -0
- package/dist/cjs/plugin.js +135 -0
- package/dist/cjs/pm-plugins/key.js +8 -0
- package/dist/cjs/pm-plugins/main.js +156 -0
- package/dist/cjs/pm-plugins/utils.js +23 -0
- package/dist/cjs/type-ahead/index.js +362 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/InviteItem/index.js +76 -0
- package/dist/cjs/ui/InviteItem/styles.js +19 -0
- package/dist/cjs/ui/Mention/index.js +98 -0
- package/dist/cjs/ui/ToolbarMention/index.js +63 -0
- package/dist/cjs/utils.js +32 -0
- package/dist/es2019/analytics.js +147 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/messages.js +23 -0
- package/dist/es2019/nodeviews/mention.js +80 -0
- package/dist/es2019/plugin.js +123 -0
- package/dist/es2019/pm-plugins/key.js +2 -0
- package/dist/es2019/pm-plugins/main.js +143 -0
- package/dist/es2019/pm-plugins/utils.js +14 -0
- package/dist/es2019/type-ahead/index.js +338 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/InviteItem/index.js +67 -0
- package/dist/es2019/ui/InviteItem/styles.js +47 -0
- package/dist/es2019/ui/Mention/index.js +70 -0
- package/dist/es2019/ui/ToolbarMention/index.js +33 -0
- package/dist/es2019/utils.js +20 -0
- package/dist/esm/analytics.js +150 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/messages.js +23 -0
- package/dist/esm/nodeviews/mention.js +107 -0
- package/dist/esm/plugin.js +129 -0
- package/dist/esm/pm-plugins/key.js +2 -0
- package/dist/esm/pm-plugins/main.js +148 -0
- package/dist/esm/pm-plugins/utils.js +16 -0
- package/dist/esm/type-ahead/index.js +350 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/InviteItem/index.js +66 -0
- package/dist/esm/ui/InviteItem/styles.js +12 -0
- package/dist/esm/ui/Mention/index.js +90 -0
- package/dist/esm/ui/ToolbarMention/index.js +53 -0
- package/dist/esm/utils.js +26 -0
- package/dist/types/analytics.d.ts +13 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/messages.d.ts +22 -0
- package/dist/types/nodeviews/mention.d.ts +9 -0
- package/dist/types/plugin.d.ts +3 -0
- package/dist/types/pm-plugins/key.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +6 -0
- package/dist/types/pm-plugins/utils.d.ts +4 -0
- package/dist/types/type-ahead/index.d.ts +17 -0
- package/dist/types/types.d.ts +38 -0
- package/dist/types/ui/InviteItem/index.d.ts +24 -0
- package/dist/types/ui/InviteItem/styles.d.ts +8 -0
- package/dist/types/ui/Mention/index.d.ts +19 -0
- package/dist/types/ui/ToolbarMention/index.d.ts +13 -0
- package/dist/types/utils.d.ts +8 -0
- package/dist/types-ts4.5/analytics.d.ts +13 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/messages.d.ts +22 -0
- package/dist/types-ts4.5/nodeviews/mention.d.ts +9 -0
- package/dist/types-ts4.5/plugin.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/utils.d.ts +4 -0
- package/dist/types-ts4.5/type-ahead/index.d.ts +17 -0
- package/dist/types-ts4.5/types.d.ts +41 -0
- package/dist/types-ts4.5/ui/InviteItem/index.d.ts +24 -0
- package/dist/types-ts4.5/ui/InviteItem/styles.d.ts +8 -0
- package/dist/types-ts4.5/ui/Mention/index.d.ts +19 -0
- package/dist/types-ts4.5/ui/ToolbarMention/index.d.ts +13 -0
- package/dist/types-ts4.5/utils.d.ts +8 -0
- package/package.json +112 -0
- package/report.api.md +92 -0
- package/tmp/api-report-tmp.d.ts +63 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { OPERATIONAL_EVENT_TYPE, UI_EVENT_TYPE } from '@atlaskit/analytics-gas-types';
|
|
5
|
+
import { isSpecialMention } from '@atlaskit/mention/resource';
|
|
6
|
+
import { isTeamType } from './utils';
|
|
7
|
+
var componentName = 'mention';
|
|
8
|
+
export var buildAnalyticsPayload = function buildAnalyticsPayload(actionSubject, action, eventType, sessionId) {
|
|
9
|
+
var otherAttributes = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
10
|
+
var tags = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
11
|
+
return {
|
|
12
|
+
action: action,
|
|
13
|
+
actionSubject: actionSubject,
|
|
14
|
+
eventType: eventType,
|
|
15
|
+
attributes: _objectSpread({
|
|
16
|
+
componentName: componentName,
|
|
17
|
+
sessionId: sessionId
|
|
18
|
+
}, otherAttributes),
|
|
19
|
+
tags: tags
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
var emptyQueryResponse = {
|
|
23
|
+
queryLength: 0,
|
|
24
|
+
spaceInQuery: false
|
|
25
|
+
};
|
|
26
|
+
var extractAttributesFromQuery = function extractAttributesFromQuery(query) {
|
|
27
|
+
if (query) {
|
|
28
|
+
return {
|
|
29
|
+
queryLength: query.length,
|
|
30
|
+
spaceInQuery: query.indexOf(' ') !== -1
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return emptyQueryResponse;
|
|
34
|
+
};
|
|
35
|
+
export var buildTypeAheadCancelPayload = function buildTypeAheadCancelPayload(duration, upKeyCount, downKeyCount, sessionId, query) {
|
|
36
|
+
var _extractAttributesFro = extractAttributesFromQuery(query),
|
|
37
|
+
queryLength = _extractAttributesFro.queryLength,
|
|
38
|
+
spaceInQuery = _extractAttributesFro.spaceInQuery;
|
|
39
|
+
return buildAnalyticsPayload('mentionTypeahead', 'cancelled', UI_EVENT_TYPE, sessionId, {
|
|
40
|
+
duration: duration,
|
|
41
|
+
downKeyCount: downKeyCount,
|
|
42
|
+
upKeyCount: upKeyCount,
|
|
43
|
+
queryLength: queryLength,
|
|
44
|
+
spaceInQuery: spaceInQuery
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
var getPosition = function getPosition(mentionList, selectedMention) {
|
|
48
|
+
if (mentionList) {
|
|
49
|
+
var index = mentionList.findIndex(function (mention) {
|
|
50
|
+
return mention.id === selectedMention.id;
|
|
51
|
+
});
|
|
52
|
+
return index === -1 ? undefined : index;
|
|
53
|
+
}
|
|
54
|
+
return;
|
|
55
|
+
};
|
|
56
|
+
var isClicked = function isClicked(insertType) {
|
|
57
|
+
return insertType === 'selected';
|
|
58
|
+
};
|
|
59
|
+
export var buildTypeAheadInviteItemViewedPayload = function buildTypeAheadInviteItemViewedPayload(sessionId, contextIdentifierProvider, userRole) {
|
|
60
|
+
var _ref = contextIdentifierProvider || {},
|
|
61
|
+
containerId = _ref.containerId,
|
|
62
|
+
objectId = _ref.objectId,
|
|
63
|
+
childObjectId = _ref.childObjectId;
|
|
64
|
+
return buildAnalyticsPayload('inviteItem', 'rendered', UI_EVENT_TYPE, sessionId, {
|
|
65
|
+
containerId: containerId,
|
|
66
|
+
objectId: objectId,
|
|
67
|
+
childObjectId: childObjectId,
|
|
68
|
+
userRole: userRole
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
export var buildTypeAheadInviteExposurePayload = function buildTypeAheadInviteExposurePayload(sessionId, contextIdentifierProvider, inviteExperimentCohort, userRole) {
|
|
72
|
+
var _ref2 = contextIdentifierProvider || {},
|
|
73
|
+
containerId = _ref2.containerId,
|
|
74
|
+
objectId = _ref2.objectId,
|
|
75
|
+
childObjectId = _ref2.childObjectId;
|
|
76
|
+
return buildAnalyticsPayload('feature', 'exposed', OPERATIONAL_EVENT_TYPE, sessionId, {
|
|
77
|
+
flagKey: 'confluence.frontend.invite.from.mention',
|
|
78
|
+
value: inviteExperimentCohort || 'not-enrolled',
|
|
79
|
+
containerId: containerId,
|
|
80
|
+
objectId: objectId,
|
|
81
|
+
childObjectId: childObjectId,
|
|
82
|
+
userRole: userRole
|
|
83
|
+
}, ['measurement', 'hasCustomAttributes']);
|
|
84
|
+
};
|
|
85
|
+
export var buildTypeAheadInviteItemClickedPayload = function buildTypeAheadInviteItemClickedPayload(duration, upKeyCount, downKeyCount, sessionId, insertType, query, contextIdentifierProvider, userRole) {
|
|
86
|
+
var _extractAttributesFro2 = extractAttributesFromQuery(query),
|
|
87
|
+
queryLength = _extractAttributesFro2.queryLength,
|
|
88
|
+
spaceInQuery = _extractAttributesFro2.spaceInQuery;
|
|
89
|
+
var _ref3 = contextIdentifierProvider || {},
|
|
90
|
+
containerId = _ref3.containerId,
|
|
91
|
+
objectId = _ref3.objectId,
|
|
92
|
+
childObjectId = _ref3.childObjectId;
|
|
93
|
+
return buildAnalyticsPayload('inviteItem', isClicked(insertType) ? 'clicked' : 'pressed', UI_EVENT_TYPE, sessionId, {
|
|
94
|
+
duration: duration,
|
|
95
|
+
queryLength: queryLength,
|
|
96
|
+
spaceInQuery: spaceInQuery,
|
|
97
|
+
upKeyCount: upKeyCount,
|
|
98
|
+
downKeyCount: downKeyCount,
|
|
99
|
+
containerId: containerId,
|
|
100
|
+
objectId: objectId,
|
|
101
|
+
childObjectId: childObjectId,
|
|
102
|
+
userRole: userRole
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
export var buildTypeAheadInsertedPayload = function buildTypeAheadInsertedPayload(duration, upKeyCount, downKeyCount, sessionId, insertType, mention, mentionList, query, contextIdentifierProvider) {
|
|
106
|
+
var _extractAttributesFro3 = extractAttributesFromQuery(query),
|
|
107
|
+
queryLength = _extractAttributesFro3.queryLength,
|
|
108
|
+
spaceInQuery = _extractAttributesFro3.spaceInQuery;
|
|
109
|
+
var analyticsPayload = buildAnalyticsPayload('mentionTypeahead', isClicked(insertType) ? 'clicked' : 'pressed', UI_EVENT_TYPE, sessionId, {
|
|
110
|
+
duration: duration,
|
|
111
|
+
position: getPosition(mentionList, mention),
|
|
112
|
+
keyboardKey: isClicked(insertType) ? undefined : insertType,
|
|
113
|
+
source: mention.source,
|
|
114
|
+
queryLength: queryLength,
|
|
115
|
+
spaceInQuery: spaceInQuery,
|
|
116
|
+
isSpecial: isSpecialMention(mention),
|
|
117
|
+
accessLevel: mention.accessLevel || '',
|
|
118
|
+
userType: mention.userType,
|
|
119
|
+
userId: mention.id,
|
|
120
|
+
upKeyCount: upKeyCount,
|
|
121
|
+
downKeyCount: downKeyCount,
|
|
122
|
+
memberCount: isTeamType(mention.userType) && mention.context ? mention.context.memberCount : null,
|
|
123
|
+
includesYou: isTeamType(mention.userType) && mention.context ? mention.context.includesYou : null
|
|
124
|
+
});
|
|
125
|
+
if (contextIdentifierProvider) {
|
|
126
|
+
analyticsPayload.containerId = contextIdentifierProvider.containerId || undefined;
|
|
127
|
+
analyticsPayload.objectId = contextIdentifierProvider.objectId || undefined;
|
|
128
|
+
analyticsPayload.childObjectId = contextIdentifierProvider.childObjectId || undefined;
|
|
129
|
+
}
|
|
130
|
+
return analyticsPayload;
|
|
131
|
+
};
|
|
132
|
+
export var buildTypeAheadRenderedPayload = function buildTypeAheadRenderedPayload(duration, userIds, query, teams) {
|
|
133
|
+
var _extractAttributesFro4 = extractAttributesFromQuery(query),
|
|
134
|
+
queryLength = _extractAttributesFro4.queryLength,
|
|
135
|
+
spaceInQuery = _extractAttributesFro4.spaceInQuery;
|
|
136
|
+
var actionSubject = userIds ? 'mentionTypeahead' : 'teamMentionTypeahead';
|
|
137
|
+
return {
|
|
138
|
+
action: 'rendered',
|
|
139
|
+
actionSubject: actionSubject,
|
|
140
|
+
eventType: OPERATIONAL_EVENT_TYPE,
|
|
141
|
+
attributes: {
|
|
142
|
+
componentName: componentName,
|
|
143
|
+
duration: duration,
|
|
144
|
+
userIds: userIds,
|
|
145
|
+
teams: teams,
|
|
146
|
+
queryLength: queryLength,
|
|
147
|
+
spaceInQuery: spaceInQuery
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { mentionsPlugin } from './plugin';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineMessages } from 'react-intl-next';
|
|
2
|
+
export var messages = defineMessages({
|
|
3
|
+
inviteItemTitle: {
|
|
4
|
+
id: 'fabric.editor.inviteItem.title',
|
|
5
|
+
defaultMessage: '{userRole, select, admin {Invite} trusted {Invite} other {Add}} teammate to {productName}',
|
|
6
|
+
description: 'Title of the invite teammate item in typeahead plugin'
|
|
7
|
+
},
|
|
8
|
+
mentionsAddLabel: {
|
|
9
|
+
id: 'fabric.editor.mentionsAddLabel',
|
|
10
|
+
defaultMessage: 'add-icon',
|
|
11
|
+
description: 'icon label to describe adding a new mention'
|
|
12
|
+
},
|
|
13
|
+
mentionsIconLabel: {
|
|
14
|
+
id: 'fabric.editor.mentionsIconLabel',
|
|
15
|
+
defaultMessage: 'Mention',
|
|
16
|
+
description: 'icon label to describe the mention icon'
|
|
17
|
+
},
|
|
18
|
+
mentionsNodeLabel: {
|
|
19
|
+
id: 'fabric.editor.mentionNode.label',
|
|
20
|
+
defaultMessage: 'Tagged user',
|
|
21
|
+
description: 'Label to indicate mention node to Screen reader users, that preceeds with user name ex: "Tagged user @XXX'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl-next';
|
|
6
|
+
import { WithProviders } from '@atlaskit/editor-common/provider-factory';
|
|
7
|
+
import { isResolvingMentionProvider, MentionNameStatus } from '@atlaskit/mention';
|
|
8
|
+
import { isPromise } from '@atlaskit/mention/types';
|
|
9
|
+
import { messages } from '../messages';
|
|
10
|
+
import Mention from '../ui/Mention';
|
|
11
|
+
var UNKNOWN_USER_ID = '_|unknown|_';
|
|
12
|
+
var MentionAssistiveTextComponent = function MentionAssistiveTextComponent(_ref) {
|
|
13
|
+
var id = _ref.id,
|
|
14
|
+
text = _ref.text,
|
|
15
|
+
providers = _ref.providers,
|
|
16
|
+
accessLevel = _ref.accessLevel,
|
|
17
|
+
mentionProvider = _ref.mentionProvider;
|
|
18
|
+
var _useState = useState(text),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
resolvedName = _useState2[0],
|
|
21
|
+
setResolvedName = _useState2[1];
|
|
22
|
+
var intl = useIntl();
|
|
23
|
+
var processName = function processName(name) {
|
|
24
|
+
if (name.status === MentionNameStatus.OK) {
|
|
25
|
+
return "@".concat(name.name || '');
|
|
26
|
+
} else {
|
|
27
|
+
return "@".concat(UNKNOWN_USER_ID);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
useEffect(function () {
|
|
31
|
+
if (mentionProvider) {
|
|
32
|
+
mentionProvider.then( /*#__PURE__*/function () {
|
|
33
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(provider) {
|
|
34
|
+
var nameDetail;
|
|
35
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
36
|
+
while (1) switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
if (!(!text && isResolvingMentionProvider(provider))) {
|
|
39
|
+
_context.next = 13;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
nameDetail = provider.resolveMentionName(id);
|
|
43
|
+
if (!isPromise(nameDetail)) {
|
|
44
|
+
_context.next = 10;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
_context.t0 = processName;
|
|
48
|
+
_context.next = 6;
|
|
49
|
+
return nameDetail;
|
|
50
|
+
case 6:
|
|
51
|
+
_context.t1 = _context.sent;
|
|
52
|
+
return _context.abrupt("return", (0, _context.t0)(_context.t1));
|
|
53
|
+
case 10:
|
|
54
|
+
return _context.abrupt("return", processName(nameDetail));
|
|
55
|
+
case 11:
|
|
56
|
+
_context.next = 14;
|
|
57
|
+
break;
|
|
58
|
+
case 13:
|
|
59
|
+
return _context.abrupt("return", text);
|
|
60
|
+
case 14:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee);
|
|
65
|
+
}));
|
|
66
|
+
return function (_x) {
|
|
67
|
+
return _ref2.apply(this, arguments);
|
|
68
|
+
};
|
|
69
|
+
}()).then(function (resolvedName) {
|
|
70
|
+
setResolvedName(resolvedName);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}, [id, text, mentionProvider]);
|
|
74
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
|
|
75
|
+
className: 'assistive'
|
|
76
|
+
}, "".concat(intl.formatMessage(messages.mentionsNodeLabel), " ").concat(resolvedName)), /*#__PURE__*/React.createElement("span", {
|
|
77
|
+
"aria-hidden": "true"
|
|
78
|
+
}, /*#__PURE__*/React.createElement(Mention, {
|
|
79
|
+
id: id,
|
|
80
|
+
text: resolvedName,
|
|
81
|
+
accessLevel: accessLevel,
|
|
82
|
+
providers: providers
|
|
83
|
+
})));
|
|
84
|
+
};
|
|
85
|
+
export var MentionNodeView = function MentionNodeView(props) {
|
|
86
|
+
var providerFactory = props.providerFactory;
|
|
87
|
+
var _props$node$attrs = props.node.attrs,
|
|
88
|
+
id = _props$node$attrs.id,
|
|
89
|
+
text = _props$node$attrs.text,
|
|
90
|
+
accessLevel = _props$node$attrs.accessLevel;
|
|
91
|
+
var renderAssistiveTextWithProviders = function renderAssistiveTextWithProviders(providers) {
|
|
92
|
+
var _ref3 = providers,
|
|
93
|
+
mentionProvider = _ref3.mentionProvider;
|
|
94
|
+
return /*#__PURE__*/React.createElement(MentionAssistiveTextComponent, {
|
|
95
|
+
mentionProvider: mentionProvider,
|
|
96
|
+
id: id,
|
|
97
|
+
text: text,
|
|
98
|
+
providers: providerFactory,
|
|
99
|
+
accessLevel: accessLevel
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return /*#__PURE__*/React.createElement(WithProviders, {
|
|
103
|
+
providers: ['mentionProvider', 'profilecardProvider'],
|
|
104
|
+
providerFactory: providerFactory,
|
|
105
|
+
renderNode: renderAssistiveTextWithProviders
|
|
106
|
+
});
|
|
107
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import uuid from 'uuid';
|
|
6
|
+
import { mention } from '@atlaskit/adf-schema';
|
|
7
|
+
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
8
|
+
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
|
+
import { IconMention } from '@atlaskit/editor-common/quick-insert';
|
|
10
|
+
import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
|
|
11
|
+
import { ELEMENTS_CHANNEL } from '@atlaskit/mention/resource';
|
|
12
|
+
import { mentionPluginKey } from './pm-plugins/key';
|
|
13
|
+
import { createMentionPlugin } from './pm-plugins/main';
|
|
14
|
+
import { createTypeAheadConfig } from './type-ahead';
|
|
15
|
+
import ToolbarMention from './ui/ToolbarMention';
|
|
16
|
+
var mentionsPlugin = function mentionsPlugin(_ref) {
|
|
17
|
+
var options = _ref.config,
|
|
18
|
+
api = _ref.api;
|
|
19
|
+
var sessionId = uuid();
|
|
20
|
+
var fireEvent = function fireEvent(payload) {
|
|
21
|
+
var _api$analytics$shared, _api$analytics;
|
|
22
|
+
var _ref2 = (_api$analytics$shared = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.sharedState.currentState()) !== null && _api$analytics$shared !== void 0 ? _api$analytics$shared : {},
|
|
23
|
+
createAnalyticsEvent = _ref2.createAnalyticsEvent;
|
|
24
|
+
if (!createAnalyticsEvent) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (payload.attributes && !payload.attributes.sessionId) {
|
|
28
|
+
payload.attributes.sessionId = sessionId;
|
|
29
|
+
}
|
|
30
|
+
createAnalyticsEvent(payload).fire(ELEMENTS_CHANNEL);
|
|
31
|
+
};
|
|
32
|
+
var typeAhead = createTypeAheadConfig({
|
|
33
|
+
sanitizePrivateContent: options === null || options === void 0 ? void 0 : options.sanitizePrivateContent,
|
|
34
|
+
mentionInsertDisplayName: options === null || options === void 0 ? void 0 : options.insertDisplayName,
|
|
35
|
+
HighlightComponent: options === null || options === void 0 ? void 0 : options.HighlightComponent,
|
|
36
|
+
fireEvent: fireEvent
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
name: 'mention',
|
|
40
|
+
nodes: function nodes() {
|
|
41
|
+
return [{
|
|
42
|
+
name: 'mention',
|
|
43
|
+
node: mention
|
|
44
|
+
}];
|
|
45
|
+
},
|
|
46
|
+
pmPlugins: function pmPlugins() {
|
|
47
|
+
return [{
|
|
48
|
+
name: 'mention',
|
|
49
|
+
plugin: function plugin(pmPluginFactoryParams) {
|
|
50
|
+
return createMentionPlugin(pmPluginFactoryParams, fireEvent, options);
|
|
51
|
+
}
|
|
52
|
+
}];
|
|
53
|
+
},
|
|
54
|
+
secondaryToolbarComponent: function secondaryToolbarComponent(_ref3) {
|
|
55
|
+
var editorView = _ref3.editorView,
|
|
56
|
+
disabled = _ref3.disabled;
|
|
57
|
+
var openMentionTypeAhead = function openMentionTypeAhead() {
|
|
58
|
+
var _api$typeAhead;
|
|
59
|
+
api === null || api === void 0 || (_api$typeAhead = api.typeAhead) === null || _api$typeAhead === void 0 || (_api$typeAhead = _api$typeAhead.actions) === null || _api$typeAhead === void 0 || _api$typeAhead.open({
|
|
60
|
+
triggerHandler: typeAhead,
|
|
61
|
+
inputMethod: INPUT_METHOD.INSERT_MENU
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
return /*#__PURE__*/React.createElement(WithPluginState, {
|
|
65
|
+
editorView: editorView,
|
|
66
|
+
plugins: {
|
|
67
|
+
mentionState: mentionPluginKey
|
|
68
|
+
},
|
|
69
|
+
render: function render(_ref4) {
|
|
70
|
+
var _ref4$mentionState = _ref4.mentionState,
|
|
71
|
+
mentionState = _ref4$mentionState === void 0 ? {} : _ref4$mentionState;
|
|
72
|
+
return !mentionState.mentionProvider ? null : /*#__PURE__*/React.createElement(ToolbarMention, {
|
|
73
|
+
editorView: editorView,
|
|
74
|
+
onInsertMention: openMentionTypeAhead,
|
|
75
|
+
isDisabled: disabled || (api === null || api === void 0 ? void 0 : api.typeAhead.actions.isAllowed(editorView.state))
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
actions: {
|
|
81
|
+
openTypeAhead: function openTypeAhead(inputMethod) {
|
|
82
|
+
var _api$typeAhead2;
|
|
83
|
+
return Boolean(api === null || api === void 0 || (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 || (_api$typeAhead2 = _api$typeAhead2.actions) === null || _api$typeAhead2 === void 0 ? void 0 : _api$typeAhead2.open({
|
|
84
|
+
triggerHandler: typeAhead,
|
|
85
|
+
inputMethod: inputMethod
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
getSharedState: function getSharedState(editorState) {
|
|
90
|
+
if (!editorState) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
var mentionPluginState = mentionPluginKey.getState(editorState);
|
|
94
|
+
return _objectSpread(_objectSpread({}, mentionPluginState), {}, {
|
|
95
|
+
typeAheadHandler: typeAhead
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
pluginsOptions: {
|
|
99
|
+
quickInsert: function quickInsert(_ref5) {
|
|
100
|
+
var formatMessage = _ref5.formatMessage;
|
|
101
|
+
return [{
|
|
102
|
+
id: 'mention',
|
|
103
|
+
title: formatMessage(messages.mention),
|
|
104
|
+
description: formatMessage(messages.mentionDescription),
|
|
105
|
+
keywords: ['team', 'user'],
|
|
106
|
+
priority: 400,
|
|
107
|
+
keyshortcut: '@',
|
|
108
|
+
icon: function icon() {
|
|
109
|
+
return /*#__PURE__*/React.createElement(IconMention, null);
|
|
110
|
+
},
|
|
111
|
+
action: function action(insert, state) {
|
|
112
|
+
var tr = insert(undefined);
|
|
113
|
+
var pluginState = mentionPluginKey.getState(state);
|
|
114
|
+
if (pluginState && pluginState.canInsertMention === false) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
api === null || api === void 0 || api.typeAhead.actions.openAtTransaction({
|
|
118
|
+
triggerHandler: typeAhead,
|
|
119
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
120
|
+
})(tr);
|
|
121
|
+
return tr;
|
|
122
|
+
}
|
|
123
|
+
}];
|
|
124
|
+
},
|
|
125
|
+
typeAhead: typeAhead
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
export { mentionsPlugin };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
5
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
6
|
+
import { buildSliPayload, SLI_EVENT_TYPE, SMART_EVENT_TYPE } from '@atlaskit/mention/resource';
|
|
7
|
+
import { MentionNodeView } from '../nodeviews/mention';
|
|
8
|
+
import { mentionPluginKey } from './key';
|
|
9
|
+
import { canMentionBeCreatedInRange } from './utils';
|
|
10
|
+
var ACTIONS = {
|
|
11
|
+
SET_PROVIDER: 'SET_PROVIDER',
|
|
12
|
+
SET_CONTEXT: 'SET_CONTEXT'
|
|
13
|
+
};
|
|
14
|
+
var setProvider = function setProvider(provider) {
|
|
15
|
+
return function (state, dispatch) {
|
|
16
|
+
if (dispatch) {
|
|
17
|
+
dispatch(state.tr.setMeta(mentionPluginKey, {
|
|
18
|
+
action: ACTIONS.SET_PROVIDER,
|
|
19
|
+
params: {
|
|
20
|
+
provider: provider
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export var setContext = function setContext(context) {
|
|
28
|
+
return function (state, dispatch) {
|
|
29
|
+
if (dispatch) {
|
|
30
|
+
dispatch(state.tr.setMeta(mentionPluginKey, {
|
|
31
|
+
action: ACTIONS.SET_CONTEXT,
|
|
32
|
+
params: {
|
|
33
|
+
context: context
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
|
|
41
|
+
var mentionProvider;
|
|
42
|
+
var sendAnalytics = function sendAnalytics(event, actionSubject, action, attributes) {
|
|
43
|
+
if (event === SLI_EVENT_TYPE || event === SMART_EVENT_TYPE) {
|
|
44
|
+
fireEvent(buildSliPayload(actionSubject, action, attributes));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
return new SafePlugin({
|
|
48
|
+
key: mentionPluginKey,
|
|
49
|
+
state: {
|
|
50
|
+
init: function init(_, state) {
|
|
51
|
+
var canInsertMention = canMentionBeCreatedInRange(state.selection.from, state.selection.to)(state);
|
|
52
|
+
return {
|
|
53
|
+
canInsertMention: canInsertMention
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
apply: function apply(tr, pluginState, oldState, newState) {
|
|
57
|
+
var _ref = tr.getMeta(mentionPluginKey) || {
|
|
58
|
+
action: null,
|
|
59
|
+
params: null
|
|
60
|
+
},
|
|
61
|
+
action = _ref.action,
|
|
62
|
+
params = _ref.params;
|
|
63
|
+
var hasNewPluginState = false;
|
|
64
|
+
var newPluginState = pluginState;
|
|
65
|
+
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
66
|
+
if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
|
|
67
|
+
newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
68
|
+
canInsertMention: canMentionBeCreatedInRange(newState.selection.from, newState.selection.to)(newState)
|
|
69
|
+
});
|
|
70
|
+
hasNewPluginState = true;
|
|
71
|
+
}
|
|
72
|
+
switch (action) {
|
|
73
|
+
case ACTIONS.SET_PROVIDER:
|
|
74
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
75
|
+
mentionProvider: params.provider
|
|
76
|
+
});
|
|
77
|
+
hasNewPluginState = true;
|
|
78
|
+
break;
|
|
79
|
+
case ACTIONS.SET_CONTEXT:
|
|
80
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
81
|
+
contextIdentifierProvider: params.context
|
|
82
|
+
});
|
|
83
|
+
hasNewPluginState = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (hasNewPluginState) {
|
|
87
|
+
pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
|
|
88
|
+
}
|
|
89
|
+
return newPluginState;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
props: {
|
|
93
|
+
nodeViews: {
|
|
94
|
+
mention: getInlineNodeViewProducer({
|
|
95
|
+
pmPluginFactoryParams: pmPluginFactoryParams,
|
|
96
|
+
Component: MentionNodeView,
|
|
97
|
+
extraComponentProps: {
|
|
98
|
+
providerFactory: pmPluginFactoryParams.providerFactory,
|
|
99
|
+
options: options
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
view: function view(editorView) {
|
|
105
|
+
var providerHandler = function providerHandler(name, providerPromise) {
|
|
106
|
+
switch (name) {
|
|
107
|
+
case 'mentionProvider':
|
|
108
|
+
if (!providerPromise) {
|
|
109
|
+
return setProvider(undefined)(editorView.state, editorView.dispatch);
|
|
110
|
+
}
|
|
111
|
+
providerPromise.then(function (provider) {
|
|
112
|
+
if (mentionProvider) {
|
|
113
|
+
mentionProvider.unsubscribe('mentionPlugin');
|
|
114
|
+
}
|
|
115
|
+
mentionProvider = provider;
|
|
116
|
+
setProvider(provider)(editorView.state, editorView.dispatch);
|
|
117
|
+
provider.subscribe('mentionPlugin', undefined, undefined, undefined, undefined, sendAnalytics);
|
|
118
|
+
}).catch(function () {
|
|
119
|
+
return setProvider(undefined)(editorView.state, editorView.dispatch);
|
|
120
|
+
});
|
|
121
|
+
break;
|
|
122
|
+
case 'contextIdentifierProvider':
|
|
123
|
+
if (!providerPromise) {
|
|
124
|
+
return setContext(undefined)(editorView.state, editorView.dispatch);
|
|
125
|
+
}
|
|
126
|
+
providerPromise.then(function (provider) {
|
|
127
|
+
setContext(provider)(editorView.state, editorView.dispatch);
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
};
|
|
133
|
+
pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
|
|
134
|
+
pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
|
|
135
|
+
return {
|
|
136
|
+
destroy: function destroy() {
|
|
137
|
+
if (pmPluginFactoryParams.providerFactory) {
|
|
138
|
+
pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
|
|
139
|
+
pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
|
|
140
|
+
}
|
|
141
|
+
if (mentionProvider) {
|
|
142
|
+
mentionProvider.unsubscribe('mentionPlugin');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { canInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
import { mentionPluginKey } from './key';
|
|
3
|
+
export function getMentionPluginState(state) {
|
|
4
|
+
return mentionPluginKey.getState(state);
|
|
5
|
+
}
|
|
6
|
+
export var canMentionBeCreatedInRange = function canMentionBeCreatedInRange(from, to) {
|
|
7
|
+
return function (state) {
|
|
8
|
+
var $from = state.doc.resolve(from);
|
|
9
|
+
var $to = state.doc.resolve(to);
|
|
10
|
+
var mention = state.schema.nodes.mention.createChecked();
|
|
11
|
+
if ($from.parent === $to.parent && canInsert($from, mention)) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
};
|