@atlaskit/editor-core 188.10.4 → 188.10.7

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/create-editor/ReactEditorView.js +3 -4
  3. package/dist/cjs/create-editor/create-editor.js +3 -6
  4. package/dist/cjs/create-editor/feature-flags-from-props.js +7 -9
  5. package/dist/cjs/labs/next/presets/universal.js +2 -1
  6. package/dist/cjs/plugins/index.js +0 -7
  7. package/dist/cjs/utils/performance/instrumented-plugin.js +4 -10
  8. package/dist/cjs/utils/performance/safer-transactions.js +2 -5
  9. package/dist/cjs/version-wrapper.js +1 -1
  10. package/dist/es2019/create-editor/ReactEditorView.js +3 -4
  11. package/dist/es2019/create-editor/create-editor.js +3 -6
  12. package/dist/es2019/create-editor/feature-flags-from-props.js +7 -9
  13. package/dist/es2019/labs/next/presets/universal.js +2 -1
  14. package/dist/es2019/plugins/index.js +0 -1
  15. package/dist/es2019/utils/performance/instrumented-plugin.js +4 -8
  16. package/dist/es2019/utils/performance/safer-transactions.js +2 -5
  17. package/dist/es2019/version-wrapper.js +1 -1
  18. package/dist/esm/create-editor/ReactEditorView.js +3 -4
  19. package/dist/esm/create-editor/create-editor.js +3 -6
  20. package/dist/esm/create-editor/feature-flags-from-props.js +7 -9
  21. package/dist/esm/labs/next/presets/universal.js +2 -1
  22. package/dist/esm/plugins/index.js +0 -1
  23. package/dist/esm/utils/performance/instrumented-plugin.js +4 -10
  24. package/dist/esm/utils/performance/safer-transactions.js +2 -5
  25. package/dist/esm/version-wrapper.js +1 -1
  26. package/dist/types/plugins/index.d.ts +0 -1
  27. package/dist/types/plugins/insert-block/types.d.ts +2 -4
  28. package/dist/types/types/editor-props.d.ts +1 -1
  29. package/dist/types/utils/performance/instrumented-plugin.d.ts +0 -3
  30. package/dist/types/utils/performance/safer-transactions.d.ts +1 -2
  31. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  32. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -4
  33. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  34. package/dist/types-ts4.5/utils/performance/instrumented-plugin.d.ts +0 -3
  35. package/dist/types-ts4.5/utils/performance/safer-transactions.d.ts +1 -2
  36. package/package.json +2 -2
  37. package/report.api.md +1 -9
  38. package/tmp/api-report-tmp.d.ts +1 -9
  39. package/dist/cjs/plugins/mentions/analytics.js +0 -157
  40. package/dist/cjs/plugins/mentions/index.js +0 -142
  41. package/dist/cjs/plugins/mentions/messages.js +0 -29
  42. package/dist/cjs/plugins/mentions/nodeviews/mention.js +0 -117
  43. package/dist/cjs/plugins/mentions/pm-plugins/key.js +0 -8
  44. package/dist/cjs/plugins/mentions/pm-plugins/main.js +0 -156
  45. package/dist/cjs/plugins/mentions/pm-plugins/utils.js +0 -23
  46. package/dist/cjs/plugins/mentions/type-ahead/index.js +0 -362
  47. package/dist/cjs/plugins/mentions/types.js +0 -5
  48. package/dist/cjs/plugins/mentions/ui/InviteItem/index.js +0 -76
  49. package/dist/cjs/plugins/mentions/ui/InviteItem/styles.js +0 -19
  50. package/dist/cjs/plugins/mentions/ui/Mention/index.js +0 -98
  51. package/dist/cjs/plugins/mentions/ui/ToolbarMention/index.js +0 -63
  52. package/dist/cjs/plugins/mentions/utils.js +0 -32
  53. package/dist/es2019/plugins/mentions/analytics.js +0 -147
  54. package/dist/es2019/plugins/mentions/index.js +0 -124
  55. package/dist/es2019/plugins/mentions/messages.js +0 -23
  56. package/dist/es2019/plugins/mentions/nodeviews/mention.js +0 -80
  57. package/dist/es2019/plugins/mentions/pm-plugins/key.js +0 -2
  58. package/dist/es2019/plugins/mentions/pm-plugins/main.js +0 -143
  59. package/dist/es2019/plugins/mentions/pm-plugins/utils.js +0 -14
  60. package/dist/es2019/plugins/mentions/type-ahead/index.js +0 -338
  61. package/dist/es2019/plugins/mentions/types.js +0 -1
  62. package/dist/es2019/plugins/mentions/ui/InviteItem/index.js +0 -66
  63. package/dist/es2019/plugins/mentions/ui/InviteItem/styles.js +0 -47
  64. package/dist/es2019/plugins/mentions/ui/Mention/index.js +0 -71
  65. package/dist/es2019/plugins/mentions/ui/ToolbarMention/index.js +0 -33
  66. package/dist/es2019/plugins/mentions/utils.js +0 -20
  67. package/dist/esm/plugins/mentions/analytics.js +0 -150
  68. package/dist/esm/plugins/mentions/index.js +0 -130
  69. package/dist/esm/plugins/mentions/messages.js +0 -23
  70. package/dist/esm/plugins/mentions/nodeviews/mention.js +0 -107
  71. package/dist/esm/plugins/mentions/pm-plugins/key.js +0 -2
  72. package/dist/esm/plugins/mentions/pm-plugins/main.js +0 -148
  73. package/dist/esm/plugins/mentions/pm-plugins/utils.js +0 -16
  74. package/dist/esm/plugins/mentions/type-ahead/index.js +0 -350
  75. package/dist/esm/plugins/mentions/types.js +0 -1
  76. package/dist/esm/plugins/mentions/ui/InviteItem/index.js +0 -65
  77. package/dist/esm/plugins/mentions/ui/InviteItem/styles.js +0 -12
  78. package/dist/esm/plugins/mentions/ui/Mention/index.js +0 -91
  79. package/dist/esm/plugins/mentions/ui/ToolbarMention/index.js +0 -53
  80. package/dist/esm/plugins/mentions/utils.js +0 -26
  81. package/dist/types/plugins/mentions/analytics.d.ts +0 -13
  82. package/dist/types/plugins/mentions/index.d.ts +0 -19
  83. package/dist/types/plugins/mentions/messages.d.ts +0 -22
  84. package/dist/types/plugins/mentions/nodeviews/mention.d.ts +0 -9
  85. package/dist/types/plugins/mentions/pm-plugins/key.d.ts +0 -3
  86. package/dist/types/plugins/mentions/pm-plugins/main.d.ts +0 -6
  87. package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  88. package/dist/types/plugins/mentions/type-ahead/index.d.ts +0 -17
  89. package/dist/types/plugins/mentions/types.d.ts +0 -24
  90. package/dist/types/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  91. package/dist/types/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  92. package/dist/types/plugins/mentions/ui/Mention/index.d.ts +0 -19
  93. package/dist/types/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  94. package/dist/types/plugins/mentions/utils.d.ts +0 -8
  95. package/dist/types-ts4.5/plugins/mentions/analytics.d.ts +0 -13
  96. package/dist/types-ts4.5/plugins/mentions/index.d.ts +0 -22
  97. package/dist/types-ts4.5/plugins/mentions/messages.d.ts +0 -22
  98. package/dist/types-ts4.5/plugins/mentions/nodeviews/mention.d.ts +0 -9
  99. package/dist/types-ts4.5/plugins/mentions/pm-plugins/key.d.ts +0 -3
  100. package/dist/types-ts4.5/plugins/mentions/pm-plugins/main.d.ts +0 -6
  101. package/dist/types-ts4.5/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  102. package/dist/types-ts4.5/plugins/mentions/type-ahead/index.d.ts +0 -17
  103. package/dist/types-ts4.5/plugins/mentions/types.d.ts +0 -24
  104. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  105. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  106. package/dist/types-ts4.5/plugins/mentions/ui/Mention/index.d.ts +0 -19
  107. package/dist/types-ts4.5/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  108. package/dist/types-ts4.5/plugins/mentions/utils.d.ts +0 -8
@@ -1,143 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { SLI_EVENT_TYPE, SMART_EVENT_TYPE, buildSliPayload } from '@atlaskit/mention/resource';
3
- import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
4
- import { MentionNodeView } from '../nodeviews/mention';
5
- import { mentionPluginKey } from './key';
6
- import { canMentionBeCreatedInRange } from './utils';
7
- const ACTIONS = {
8
- SET_PROVIDER: 'SET_PROVIDER',
9
- SET_CONTEXT: 'SET_CONTEXT'
10
- };
11
- const setProvider = provider => (state, dispatch) => {
12
- if (dispatch) {
13
- dispatch(state.tr.setMeta(mentionPluginKey, {
14
- action: ACTIONS.SET_PROVIDER,
15
- params: {
16
- provider
17
- }
18
- }));
19
- }
20
- return true;
21
- };
22
- export const setContext = context => (state, dispatch) => {
23
- if (dispatch) {
24
- dispatch(state.tr.setMeta(mentionPluginKey, {
25
- action: ACTIONS.SET_CONTEXT,
26
- params: {
27
- context
28
- }
29
- }));
30
- }
31
- return true;
32
- };
33
- export function createMentionPlugin(pmPluginFactoryParams, fireEvent, options) {
34
- let mentionProvider;
35
- const sendAnalytics = (event, actionSubject, action, attributes) => {
36
- if (event === SLI_EVENT_TYPE || event === SMART_EVENT_TYPE) {
37
- fireEvent(buildSliPayload(actionSubject, action, attributes));
38
- }
39
- };
40
- return new SafePlugin({
41
- key: mentionPluginKey,
42
- state: {
43
- init(_, state) {
44
- const canInsertMention = canMentionBeCreatedInRange(state.selection.from, state.selection.to)(state);
45
- return {
46
- canInsertMention
47
- };
48
- },
49
- apply(tr, pluginState, oldState, newState) {
50
- const {
51
- action,
52
- params
53
- } = tr.getMeta(mentionPluginKey) || {
54
- action: null,
55
- params: null
56
- };
57
- let hasNewPluginState = false;
58
- let newPluginState = pluginState;
59
- const hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
60
- if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
61
- newPluginState = {
62
- ...pluginState,
63
- canInsertMention: canMentionBeCreatedInRange(newState.selection.from, newState.selection.to)(newState)
64
- };
65
- hasNewPluginState = true;
66
- }
67
- switch (action) {
68
- case ACTIONS.SET_PROVIDER:
69
- newPluginState = {
70
- ...newPluginState,
71
- mentionProvider: params.provider
72
- };
73
- hasNewPluginState = true;
74
- break;
75
- case ACTIONS.SET_CONTEXT:
76
- newPluginState = {
77
- ...newPluginState,
78
- contextIdentifierProvider: params.context
79
- };
80
- hasNewPluginState = true;
81
- break;
82
- }
83
- if (hasNewPluginState) {
84
- pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
85
- }
86
- return newPluginState;
87
- }
88
- },
89
- props: {
90
- nodeViews: {
91
- mention: getInlineNodeViewProducer({
92
- pmPluginFactoryParams,
93
- Component: MentionNodeView,
94
- extraComponentProps: {
95
- providerFactory: pmPluginFactoryParams.providerFactory,
96
- options
97
- }
98
- })
99
- }
100
- },
101
- view(editorView) {
102
- const providerHandler = (name, providerPromise) => {
103
- switch (name) {
104
- case 'mentionProvider':
105
- if (!providerPromise) {
106
- return setProvider(undefined)(editorView.state, editorView.dispatch);
107
- }
108
- providerPromise.then(provider => {
109
- if (mentionProvider) {
110
- mentionProvider.unsubscribe('mentionPlugin');
111
- }
112
- mentionProvider = provider;
113
- setProvider(provider)(editorView.state, editorView.dispatch);
114
- provider.subscribe('mentionPlugin', undefined, undefined, undefined, undefined, sendAnalytics);
115
- }).catch(() => setProvider(undefined)(editorView.state, editorView.dispatch));
116
- break;
117
- case 'contextIdentifierProvider':
118
- if (!providerPromise) {
119
- return setContext(undefined)(editorView.state, editorView.dispatch);
120
- }
121
- providerPromise.then(provider => {
122
- setContext(provider)(editorView.state, editorView.dispatch);
123
- });
124
- break;
125
- }
126
- return;
127
- };
128
- pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
129
- pmPluginFactoryParams.providerFactory.subscribe('contextIdentifierProvider', providerHandler);
130
- return {
131
- destroy() {
132
- if (pmPluginFactoryParams.providerFactory) {
133
- pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
134
- pmPluginFactoryParams.providerFactory.unsubscribe('contextIdentifierProvider', providerHandler);
135
- }
136
- if (mentionProvider) {
137
- mentionProvider.unsubscribe('mentionPlugin');
138
- }
139
- }
140
- };
141
- }
142
- });
143
- }
@@ -1,14 +0,0 @@
1
- import { mentionPluginKey } from './key';
2
- import { canInsert } from '@atlaskit/editor-prosemirror/utils';
3
- export function getMentionPluginState(state) {
4
- return mentionPluginKey.getState(state);
5
- }
6
- export const canMentionBeCreatedInRange = (from, to) => state => {
7
- const $from = state.doc.resolve(from);
8
- const $to = state.doc.resolve(to);
9
- const mention = state.schema.nodes.mention.createChecked();
10
- if ($from.parent === $to.parent && canInsert($from, mention)) {
11
- return true;
12
- }
13
- return false;
14
- };
@@ -1,338 +0,0 @@
1
- import React from 'react';
2
- import uuid from 'uuid';
3
- import { Fragment } from '@atlaskit/editor-prosemirror/model';
4
- import { isResolvingMentionProvider } from '@atlaskit/mention/resource';
5
- import { MENTION_ITEM_HEIGHT, MentionItem } from '@atlaskit/mention/item';
6
- import { TypeAheadAvailableNodes } from '@atlaskit/editor-common/type-ahead';
7
- import { buildTypeAheadCancelPayload, buildTypeAheadInsertedPayload, buildTypeAheadInviteExposurePayload, buildTypeAheadInviteItemClickedPayload, buildTypeAheadInviteItemViewedPayload, buildTypeAheadRenderedPayload } from '../analytics';
8
- import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../ui/InviteItem';
9
- import { isInviteItem, isTeamType, isTeamStats, shouldKeepInviteItem } from '../utils';
10
- import { getMentionPluginState } from '../pm-plugins/utils';
11
- const createInviteItem = ({
12
- mentionProvider,
13
- onInviteItemMount
14
- }) => ({
15
- title: INVITE_ITEM_DESCRIPTION.id,
16
- render: ({
17
- isSelected,
18
- onClick,
19
- onHover
20
- }) => /*#__PURE__*/React.createElement(InviteItem, {
21
- productName: mentionProvider ? mentionProvider.productName : undefined,
22
- selected: isSelected,
23
- onMount: onInviteItemMount,
24
- onMouseEnter: onHover,
25
- onSelection: onClick,
26
- userRole: mentionProvider.userRole
27
- }),
28
- mention: INVITE_ITEM_DESCRIPTION
29
- });
30
- const withInviteItem = ({
31
- mentionProvider,
32
- firstQueryWithoutResults,
33
- currentQuery,
34
- onInviteItemMount
35
- }) => mentionItems => {
36
- const inviteItem = createInviteItem({
37
- mentionProvider,
38
- onInviteItemMount
39
- });
40
- const keepInviteItem = shouldKeepInviteItem(currentQuery, firstQueryWithoutResults);
41
- if (mentionItems.length === 0) {
42
- return keepInviteItem ? [inviteItem] : [];
43
- }
44
- return [...mentionItems,
45
- // invite item should be shown at the bottom
46
- inviteItem];
47
- };
48
- export const mentionToTypeaheadItem = mention => {
49
- return {
50
- title: mention.id,
51
- render: ({
52
- isSelected,
53
- onClick,
54
- onHover
55
- }) => /*#__PURE__*/React.createElement(MentionItem, {
56
- mention: mention,
57
- selected: isSelected,
58
- onMouseEnter: onHover,
59
- onSelection: onClick
60
- }),
61
- getCustomComponentHeight: () => {
62
- return MENTION_ITEM_HEIGHT;
63
- },
64
- mention
65
- };
66
- };
67
- export function memoize(fn) {
68
- // Cache results here
69
- const seen = new Map();
70
- function memoized(mention) {
71
- // Check cache for hits
72
- const hit = seen.get(mention.id);
73
- if (hit) {
74
- return hit;
75
- }
76
-
77
- // Generate new result and cache it
78
- const result = fn(mention);
79
- seen.set(mention.id, result);
80
- return result;
81
- }
82
- return {
83
- call: memoized,
84
- clear: seen.clear.bind(seen)
85
- };
86
- }
87
- const memoizedToItem = memoize(mentionToTypeaheadItem);
88
- const buildAndSendElementsTypeAheadAnalytics = fireEvent => ({
89
- query,
90
- mentions,
91
- stats
92
- }) => {
93
- let duration = 0;
94
- let userOrTeamIds = null;
95
- let teams = null;
96
- if (!isTeamStats(stats)) {
97
- // is from primary mention endpoint which could be just user mentions or user/team mentions
98
- duration = stats && stats.duration;
99
- teams = null;
100
- userOrTeamIds = mentions.map(mention => mention.id);
101
- } else {
102
- // is from dedicated team-only mention endpoint
103
- duration = stats && stats.teamMentionDuration;
104
- userOrTeamIds = null;
105
- teams = mentions.map(mention => isTeamType(mention.userType) ? {
106
- teamId: mention.id,
107
- includesYou: mention.context.includesYou,
108
- memberCount: mention.context.memberCount
109
- } : null).filter(m => !!m);
110
- }
111
- const payload = buildTypeAheadRenderedPayload(duration, userOrTeamIds, query, teams);
112
- fireEvent(payload);
113
- };
114
-
115
- /**
116
- * When a team mention is selected, we render a team link and list of member/user mentions
117
- * in editor content
118
- */
119
- const buildNodesForTeamMention = (schema, selectedMention, mentionProvider, sanitizePrivateContent) => {
120
- const {
121
- nodes,
122
- marks
123
- } = schema;
124
- const {
125
- name,
126
- id: teamId,
127
- accessLevel,
128
- context
129
- } = selectedMention;
130
-
131
- // build team link
132
- const defaultTeamLink = `${window.location.origin}/people/team/${teamId}`;
133
- const teamLink = context && context.teamLink ? context.teamLink : defaultTeamLink;
134
- const teamLinkNode = schema.text(name, [marks.link.create({
135
- href: teamLink
136
- })]);
137
- const openBracketText = schema.text('(');
138
- const closeBracketText = schema.text(')');
139
- const emptySpaceText = schema.text(' ');
140
- const inlineNodes = [teamLinkNode, emptySpaceText, openBracketText];
141
- const members = context && context.members ? context.members : [];
142
- members.forEach((member, index) => {
143
- const {
144
- name,
145
- id
146
- } = member;
147
- const mentionName = `@${name}`;
148
- const text = sanitizePrivateContent ? '' : mentionName;
149
- if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
150
- mentionProvider.cacheMentionName(id, name);
151
- }
152
- const userMentionNode = nodes.mention.createChecked({
153
- text,
154
- id: member.id,
155
- accessLevel,
156
- userType: 'DEFAULT'
157
- });
158
- inlineNodes.push(userMentionNode);
159
- // should not add empty space after the last user mention.
160
- if (index !== members.length - 1) {
161
- inlineNodes.push(emptySpaceText);
162
- }
163
- });
164
- inlineNodes.push(closeBracketText);
165
- return Fragment.fromArray(inlineNodes);
166
- };
167
- export const createTypeAheadConfig = ({
168
- sanitizePrivateContent,
169
- mentionInsertDisplayName,
170
- fireEvent,
171
- HighlightComponent
172
- }) => {
173
- let sessionId = uuid();
174
- let firstQueryWithoutResults = null;
175
- const subscriptionKeys = new Set();
176
- const typeAhead = {
177
- id: TypeAheadAvailableNodes.MENTION,
178
- trigger: '@',
179
- // Custom regex must have a capture group around trigger
180
- // so it's possible to use it without needing to scan through all triggers again
181
- customRegex: '\\(?(@)',
182
- getHighlight: state => {
183
- const CustomHighlightComponent = HighlightComponent;
184
- if (CustomHighlightComponent) {
185
- return /*#__PURE__*/React.createElement(CustomHighlightComponent, null);
186
- }
187
- return null;
188
- },
189
- getItems({
190
- query,
191
- editorState
192
- }) {
193
- const pluginState = getMentionPluginState(editorState);
194
- if (!(pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider)) {
195
- return Promise.resolve([]);
196
- }
197
- const {
198
- mentionProvider,
199
- contextIdentifierProvider
200
- } = pluginState;
201
- return new Promise(resolve => {
202
- const key = `loadingMentionsForTypeAhead_${uuid()}`;
203
- const mentionsSubscribeCallback = (mentions, resultQuery = '', stats) => {
204
- if (query !== resultQuery) {
205
- return;
206
- }
207
- mentionProvider.unsubscribe(key);
208
- subscriptionKeys.delete(key);
209
- const mentionItems = mentions.map(mention => memoizedToItem.call(mention));
210
- buildAndSendElementsTypeAheadAnalytics(fireEvent)({
211
- query,
212
- mentions,
213
- stats
214
- });
215
- if (mentions.length === 0 && firstQueryWithoutResults === null) {
216
- firstQueryWithoutResults = query;
217
- }
218
-
219
- // Growth (El-dorado) experiment design hard requirement
220
- if (mentionItems.length <= 2) {
221
- const {
222
- inviteExperimentCohort,
223
- userRole
224
- } = mentionProvider;
225
- fireEvent(buildTypeAheadInviteExposurePayload(sessionId, contextIdentifierProvider, inviteExperimentCohort, userRole));
226
- }
227
- if (!mentionProvider.shouldEnableInvite || mentionItems.length > 2) {
228
- resolve(mentionItems);
229
- } else {
230
- const items = withInviteItem({
231
- mentionProvider,
232
- firstQueryWithoutResults: firstQueryWithoutResults || '',
233
- currentQuery: query,
234
- onInviteItemMount: () => {
235
- fireEvent(buildTypeAheadInviteItemViewedPayload(sessionId, contextIdentifierProvider, mentionProvider.userRole));
236
- }
237
- })(mentionItems);
238
- resolve(items);
239
- }
240
- };
241
- subscriptionKeys.add(key);
242
- mentionProvider.subscribe(key, mentionsSubscribeCallback);
243
- mentionProvider.filter(query || '', {
244
- ...contextIdentifierProvider,
245
- sessionId
246
- });
247
- });
248
- },
249
- onOpen: () => {
250
- firstQueryWithoutResults = null;
251
- },
252
- selectItem(state, item, insert, {
253
- mode,
254
- stats,
255
- query,
256
- sourceListItem
257
- }) {
258
- const {
259
- schema
260
- } = state;
261
- const pluginState = getMentionPluginState(state);
262
- const {
263
- mentionProvider
264
- } = pluginState;
265
- const {
266
- id,
267
- name,
268
- nickname,
269
- accessLevel,
270
- userType
271
- } = item.mention;
272
- const trimmedNickname = nickname && nickname.startsWith('@') ? nickname.slice(1) : nickname;
273
- const renderName = mentionInsertDisplayName || !trimmedNickname ? name : trimmedNickname;
274
- const mentionContext = {
275
- ...pluginState.contextIdentifierProvider,
276
- sessionId
277
- };
278
- if (mentionProvider && !isInviteItem(item.mention)) {
279
- mentionProvider.recordMentionSelection(item.mention, mentionContext);
280
- }
281
-
282
- // use same timer as StatsModifier
283
- const pickerElapsedTime = stats.startedAt ? performance.now() - stats.startedAt : 0;
284
- if (mentionProvider && mentionProvider.shouldEnableInvite && isInviteItem(item.mention)) {
285
- // Don't fire event and the callback with selection by space press
286
- if (mode !== 'space') {
287
- fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, pluginState.contextIdentifierProvider, mentionProvider.userRole));
288
- if (mentionProvider.onInviteItemClick) {
289
- mentionProvider.onInviteItemClick('mention');
290
- }
291
- }
292
- return state.tr;
293
- }
294
- fireEvent(buildTypeAheadInsertedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, sourceListItem.map(x => x.mention), query, pluginState.contextIdentifierProvider));
295
- sessionId = uuid();
296
- if (mentionProvider && isTeamType(userType)) {
297
- return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
298
- }
299
-
300
- // Don't insert into document if document data is sanitized.
301
- const text = sanitizePrivateContent ? '' : `@${renderName}`;
302
- if (sanitizePrivateContent && isResolvingMentionProvider(mentionProvider)) {
303
- // Cache (locally) for later rendering
304
- mentionProvider.cacheMentionName(id, renderName);
305
- }
306
- const mentionNode = schema.nodes.mention.createChecked({
307
- text,
308
- id,
309
- accessLevel,
310
- userType: userType === 'DEFAULT' ? null : userType
311
- });
312
- const space = schema.text(' ');
313
- return insert(Fragment.from([mentionNode, space]));
314
- },
315
- dismiss({
316
- editorState,
317
- query,
318
- stats,
319
- wasItemInserted
320
- }) {
321
- firstQueryWithoutResults = null;
322
- const pickerElapsedTime = stats.startedAt ? performance.now() - stats.startedAt : 0;
323
- if (!wasItemInserted) {
324
- fireEvent(buildTypeAheadCancelPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, query || ''));
325
- }
326
- const pluginState = getMentionPluginState(editorState);
327
- if (pluginState !== null && pluginState !== void 0 && pluginState.mentionProvider) {
328
- const mentionProvider = pluginState.mentionProvider;
329
- for (let key of subscriptionKeys) {
330
- mentionProvider.unsubscribe(key);
331
- }
332
- }
333
- subscriptionKeys.clear();
334
- sessionId = uuid();
335
- }
336
- };
337
- return typeAhead;
338
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,66 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- /** @jsx jsx */
3
- import { jsx } from '@emotion/react';
4
- import AddIcon from '@atlaskit/icon/glyph/add';
5
- import { N300 } from '@atlaskit/theme/colors';
6
- import React, { useCallback, useEffect } from 'react';
7
- import { FormattedMessage, injectIntl } from 'react-intl-next';
8
- import { avatarStyle, capitalizedStyle, mentionItemStyle, nameSectionStyle, rowStyle, mentionItemSelectedStyle } from './styles';
9
- import { messages } from '../../messages';
10
- export const INVITE_ITEM_DESCRIPTION = {
11
- id: 'invite-teammate'
12
- };
13
- const leftClick = event => {
14
- return event.button === 0 && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey;
15
- };
16
- const InviteItem = ({
17
- productName,
18
- onMount,
19
- onMouseEnter,
20
- onSelection,
21
- selected,
22
- userRole,
23
- intl
24
- }) => {
25
- const onSelected = useCallback(event => {
26
- if (leftClick(event) && onSelection) {
27
- event.preventDefault();
28
- onSelection(INVITE_ITEM_DESCRIPTION, event);
29
- }
30
- }, [onSelection]);
31
- const onItemMouseEnter = useCallback(event => {
32
- if (onMouseEnter) {
33
- onMouseEnter(INVITE_ITEM_DESCRIPTION, event);
34
- }
35
- }, [onMouseEnter]);
36
- useEffect(() => {
37
- if (onMount) {
38
- onMount();
39
- }
40
- }, [onMount]);
41
- return jsx("div", {
42
- css: [mentionItemStyle, selected && mentionItemSelectedStyle],
43
- onMouseDown: onSelected,
44
- onMouseEnter: onItemMouseEnter,
45
- "data-id": INVITE_ITEM_DESCRIPTION.id
46
- }, jsx("div", {
47
- css: rowStyle
48
- }, jsx("span", {
49
- css: avatarStyle
50
- }, jsx(AddIcon, {
51
- label: intl.formatMessage(messages.mentionsAddLabel),
52
- primaryColor: `var(--ds-icon-subtle, ${N300})`
53
- })), jsx("div", {
54
- css: nameSectionStyle,
55
- "data-testid": "name-section"
56
- }, jsx(FormattedMessage, _extends({}, messages.inviteItemTitle, {
57
- values: {
58
- userRole: userRole || 'basic',
59
- productName: jsx("span", {
60
- css: capitalizedStyle,
61
- "data-testid": "capitalized-message"
62
- }, productName)
63
- }
64
- })))));
65
- };
66
- export default injectIntl(InviteItem);
@@ -1,47 +0,0 @@
1
- import { css } from '@emotion/react';
2
- import { N30, N300 } from '@atlaskit/theme/colors';
3
- export const ROW_SIDE_PADDING = 14;
4
- export const rowStyle = css`
5
- align-items: center;
6
- display: flex;
7
- flex-direction: row;
8
- flex-wrap: wrap;
9
- overflow: hidden;
10
- padding: 6px ${ROW_SIDE_PADDING}px;
11
- text-overflow: ellipsis;
12
- vertical-align: middle;
13
- `;
14
- export const AVATAR_HEIGHT = 36;
15
- export const avatarStyle = css`
16
- position: relative;
17
- flex: initial;
18
- opacity: inherit;
19
- width: 36px;
20
- height: ${AVATAR_HEIGHT}px;
21
-
22
- > span {
23
- width: 24px;
24
- height: 24px;
25
- padding: 6px;
26
- }
27
- `;
28
- export const nameSectionStyle = css`
29
- flex: 1;
30
- min-width: 0;
31
- margin-left: 14px;
32
- color: ${`var(--ds-text-subtle, ${N300})`};
33
- opacity: inherit;
34
- `;
35
- export const mentionItemStyle = css`
36
- background-color: transparent;
37
- display: block;
38
- overflow: hidden;
39
- list-style-type: none;
40
- cursor: pointer;
41
- `;
42
- export const mentionItemSelectedStyle = css`
43
- background-color: ${`var(--ds-background-neutral-subtle-hovered, ${N30})`};
44
- `;
45
- export const capitalizedStyle = css`
46
- text-transform: capitalize;
47
- `;
@@ -1,71 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import React from 'react';
4
- import { PureComponent } from 'react';
5
- import { ResourcedMention } from '@atlaskit/mention/element';
6
- import { ProviderFactory, WithProviders } from '@atlaskit/editor-common/provider-factory';
7
- import { browser } from '@atlaskit/editor-common/utils';
8
-
9
- // Workaround for a firefox issue where dom selection is off sync
10
- // https://product-fabric.atlassian.net/browse/ED-12442
11
- const refreshBrowserSelection = () => {
12
- const domSelection = window.getSelection();
13
- if (domSelection) {
14
- const domRange = domSelection && domSelection.rangeCount === 1 && domSelection.getRangeAt(0).cloneRange();
15
- if (domRange) {
16
- domSelection.removeAllRanges();
17
- domSelection.addRange(domRange);
18
- }
19
- }
20
- };
21
- export default class Mention extends PureComponent {
22
- constructor(props) {
23
- super(props);
24
- _defineProperty(this, "renderWithProvider", providers => {
25
- const {
26
- accessLevel,
27
- eventHandlers,
28
- id,
29
- text
30
- } = this.props;
31
- const {
32
- mentionProvider
33
- } = providers;
34
- const actionHandlers = {};
35
- ['onClick', 'onMouseEnter', 'onMouseLeave'].forEach(handler => {
36
- actionHandlers[handler] = eventHandlers && eventHandlers[handler] || (() => {});
37
- });
38
- return /*#__PURE__*/React.createElement(ResourcedMention, _extends({
39
- id: id,
40
- text: text,
41
- accessLevel: accessLevel,
42
- mentionProvider: mentionProvider
43
- }, actionHandlers));
44
- });
45
- this.providerFactory = props.providers || new ProviderFactory();
46
- }
47
- componentDidMount() {
48
- // Workaround an issue where the selection is not updated immediately after adding
49
- // a mention when "sanitizePrivateContent" is enabled in the editor on safari.
50
- // This affects both insertion and paste behaviour it is applied to the component.
51
- // https://product-fabric.atlassian.net/browse/ED-14859
52
- if (browser.safari) {
53
- setTimeout(refreshBrowserSelection, 0);
54
- }
55
- }
56
- componentWillUnmount() {
57
- if (!this.props.providers) {
58
- // new ProviderFactory is created if no `providers` has been set
59
- // in this case when component is unmounted it's safe to destroy this providerFactory
60
- this.providerFactory.destroy();
61
- }
62
- }
63
- render() {
64
- return /*#__PURE__*/React.createElement(WithProviders, {
65
- providers: ['mentionProvider', 'profilecardProvider'],
66
- providerFactory: this.providerFactory,
67
- renderNode: this.renderWithProvider
68
- });
69
- }
70
- }
71
- _defineProperty(Mention, "displayName", 'Mention');