@atlaskit/editor-core 188.10.5 → 188.11.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.
Files changed (181) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/architecture/0003-explicit-plugin-dependencies.md +1 -1
  3. package/dist/cjs/labs/next/presets/universal.js +4 -3
  4. package/dist/cjs/messages.js +1 -2
  5. package/dist/cjs/plugins/index.js +0 -14
  6. package/dist/cjs/version-wrapper.js +1 -1
  7. package/dist/es2019/labs/next/presets/universal.js +3 -2
  8. package/dist/es2019/messages.js +1 -2
  9. package/dist/es2019/plugins/index.js +0 -2
  10. package/dist/es2019/version-wrapper.js +1 -1
  11. package/dist/esm/labs/next/presets/universal.js +3 -2
  12. package/dist/esm/messages.js +1 -2
  13. package/dist/esm/plugins/index.js +0 -2
  14. package/dist/esm/version-wrapper.js +1 -1
  15. package/dist/types/messages.d.ts +1 -2
  16. package/dist/types/plugins/index.d.ts +0 -2
  17. package/dist/types/plugins/insert-block/types.d.ts +2 -4
  18. package/dist/types/types/editor-props.d.ts +1 -1
  19. package/dist/types/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  20. package/dist/types/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  21. package/dist/types/ui/ContentStyles/index.d.ts +2 -2
  22. package/dist/types-ts4.5/messages.d.ts +1 -2
  23. package/dist/types-ts4.5/plugins/index.d.ts +0 -2
  24. package/dist/types-ts4.5/plugins/insert-block/types.d.ts +2 -4
  25. package/dist/types-ts4.5/types/editor-props.d.ts +1 -1
  26. package/dist/types-ts4.5/ui/Appearance/FullPage/StyledComponents.d.ts +1 -1
  27. package/dist/types-ts4.5/ui/ConfigPanel/FormErrorBoundary.d.ts +1 -1
  28. package/dist/types-ts4.5/ui/ContentStyles/index.d.ts +2 -2
  29. package/package.json +7 -10
  30. package/report.api.md +1 -9
  31. package/tmp/api-report-tmp.d.ts +1 -9
  32. package/dist/cjs/plugins/date/actions.js +0 -105
  33. package/dist/cjs/plugins/date/commands.js +0 -118
  34. package/dist/cjs/plugins/date/index.js +0 -13
  35. package/dist/cjs/plugins/date/nodeviews/date.js +0 -44
  36. package/dist/cjs/plugins/date/nodeviews/messages.js +0 -14
  37. package/dist/cjs/plugins/date/plugin.js +0 -197
  38. package/dist/cjs/plugins/date/pm-plugins/keymap.js +0 -41
  39. package/dist/cjs/plugins/date/pm-plugins/main.js +0 -39
  40. package/dist/cjs/plugins/date/pm-plugins/plugin-key.js +0 -8
  41. package/dist/cjs/plugins/date/pm-plugins/types.js +0 -5
  42. package/dist/cjs/plugins/date/pm-plugins/utils.js +0 -70
  43. package/dist/cjs/plugins/date/types.js +0 -5
  44. package/dist/cjs/plugins/date/ui/DatePicker/date-picker-input.js +0 -244
  45. package/dist/cjs/plugins/date/ui/DatePicker/index.js +0 -168
  46. package/dist/cjs/plugins/date/utils/formatParse.js +0 -88
  47. package/dist/cjs/plugins/date/utils/internal.js +0 -176
  48. package/dist/cjs/plugins/mentions/analytics.js +0 -157
  49. package/dist/cjs/plugins/mentions/index.js +0 -142
  50. package/dist/cjs/plugins/mentions/messages.js +0 -29
  51. package/dist/cjs/plugins/mentions/nodeviews/mention.js +0 -117
  52. package/dist/cjs/plugins/mentions/pm-plugins/key.js +0 -8
  53. package/dist/cjs/plugins/mentions/pm-plugins/main.js +0 -156
  54. package/dist/cjs/plugins/mentions/pm-plugins/utils.js +0 -23
  55. package/dist/cjs/plugins/mentions/type-ahead/index.js +0 -362
  56. package/dist/cjs/plugins/mentions/types.js +0 -5
  57. package/dist/cjs/plugins/mentions/ui/InviteItem/index.js +0 -76
  58. package/dist/cjs/plugins/mentions/ui/InviteItem/styles.js +0 -19
  59. package/dist/cjs/plugins/mentions/ui/Mention/index.js +0 -98
  60. package/dist/cjs/plugins/mentions/ui/ToolbarMention/index.js +0 -63
  61. package/dist/cjs/plugins/mentions/utils.js +0 -32
  62. package/dist/es2019/plugins/date/actions.js +0 -93
  63. package/dist/es2019/plugins/date/commands.js +0 -113
  64. package/dist/es2019/plugins/date/index.js +0 -1
  65. package/dist/es2019/plugins/date/nodeviews/date.js +0 -47
  66. package/dist/es2019/plugins/date/nodeviews/messages.js +0 -8
  67. package/dist/es2019/plugins/date/plugin.js +0 -183
  68. package/dist/es2019/plugins/date/pm-plugins/keymap.js +0 -34
  69. package/dist/es2019/plugins/date/pm-plugins/main.js +0 -35
  70. package/dist/es2019/plugins/date/pm-plugins/plugin-key.js +0 -2
  71. package/dist/es2019/plugins/date/pm-plugins/types.js +0 -1
  72. package/dist/es2019/plugins/date/pm-plugins/utils.js +0 -70
  73. package/dist/es2019/plugins/date/types.js +0 -1
  74. package/dist/es2019/plugins/date/ui/DatePicker/date-picker-input.js +0 -233
  75. package/dist/es2019/plugins/date/ui/DatePicker/index.js +0 -152
  76. package/dist/es2019/plugins/date/utils/formatParse.js +0 -83
  77. package/dist/es2019/plugins/date/utils/internal.js +0 -151
  78. package/dist/es2019/plugins/mentions/analytics.js +0 -147
  79. package/dist/es2019/plugins/mentions/index.js +0 -124
  80. package/dist/es2019/plugins/mentions/messages.js +0 -23
  81. package/dist/es2019/plugins/mentions/nodeviews/mention.js +0 -80
  82. package/dist/es2019/plugins/mentions/pm-plugins/key.js +0 -2
  83. package/dist/es2019/plugins/mentions/pm-plugins/main.js +0 -143
  84. package/dist/es2019/plugins/mentions/pm-plugins/utils.js +0 -14
  85. package/dist/es2019/plugins/mentions/type-ahead/index.js +0 -338
  86. package/dist/es2019/plugins/mentions/types.js +0 -1
  87. package/dist/es2019/plugins/mentions/ui/InviteItem/index.js +0 -66
  88. package/dist/es2019/plugins/mentions/ui/InviteItem/styles.js +0 -47
  89. package/dist/es2019/plugins/mentions/ui/Mention/index.js +0 -71
  90. package/dist/es2019/plugins/mentions/ui/ToolbarMention/index.js +0 -33
  91. package/dist/es2019/plugins/mentions/utils.js +0 -20
  92. package/dist/esm/plugins/date/actions.js +0 -99
  93. package/dist/esm/plugins/date/commands.js +0 -112
  94. package/dist/esm/plugins/date/index.js +0 -1
  95. package/dist/esm/plugins/date/nodeviews/date.js +0 -37
  96. package/dist/esm/plugins/date/nodeviews/messages.js +0 -8
  97. package/dist/esm/plugins/date/plugin.js +0 -185
  98. package/dist/esm/plugins/date/pm-plugins/keymap.js +0 -34
  99. package/dist/esm/plugins/date/pm-plugins/main.js +0 -34
  100. package/dist/esm/plugins/date/pm-plugins/plugin-key.js +0 -2
  101. package/dist/esm/plugins/date/pm-plugins/types.js +0 -1
  102. package/dist/esm/plugins/date/pm-plugins/utils.js +0 -61
  103. package/dist/esm/plugins/date/types.js +0 -1
  104. package/dist/esm/plugins/date/ui/DatePicker/date-picker-input.js +0 -238
  105. package/dist/esm/plugins/date/ui/DatePicker/index.js +0 -162
  106. package/dist/esm/plugins/date/utils/formatParse.js +0 -79
  107. package/dist/esm/plugins/date/utils/internal.js +0 -165
  108. package/dist/esm/plugins/mentions/analytics.js +0 -150
  109. package/dist/esm/plugins/mentions/index.js +0 -130
  110. package/dist/esm/plugins/mentions/messages.js +0 -23
  111. package/dist/esm/plugins/mentions/nodeviews/mention.js +0 -107
  112. package/dist/esm/plugins/mentions/pm-plugins/key.js +0 -2
  113. package/dist/esm/plugins/mentions/pm-plugins/main.js +0 -148
  114. package/dist/esm/plugins/mentions/pm-plugins/utils.js +0 -16
  115. package/dist/esm/plugins/mentions/type-ahead/index.js +0 -350
  116. package/dist/esm/plugins/mentions/types.js +0 -1
  117. package/dist/esm/plugins/mentions/ui/InviteItem/index.js +0 -65
  118. package/dist/esm/plugins/mentions/ui/InviteItem/styles.js +0 -12
  119. package/dist/esm/plugins/mentions/ui/Mention/index.js +0 -91
  120. package/dist/esm/plugins/mentions/ui/ToolbarMention/index.js +0 -53
  121. package/dist/esm/plugins/mentions/utils.js +0 -26
  122. package/dist/types/plugins/date/actions.d.ts +0 -47
  123. package/dist/types/plugins/date/commands.d.ts +0 -12
  124. package/dist/types/plugins/date/index.d.ts +0 -1
  125. package/dist/types/plugins/date/nodeviews/date.d.ts +0 -3
  126. package/dist/types/plugins/date/nodeviews/messages.d.ts +0 -7
  127. package/dist/types/plugins/date/plugin.d.ts +0 -3
  128. package/dist/types/plugins/date/pm-plugins/keymap.d.ts +0 -3
  129. package/dist/types/plugins/date/pm-plugins/main.d.ts +0 -6
  130. package/dist/types/plugins/date/pm-plugins/plugin-key.d.ts +0 -3
  131. package/dist/types/plugins/date/pm-plugins/types.d.ts +0 -12
  132. package/dist/types/plugins/date/pm-plugins/utils.d.ts +0 -5
  133. package/dist/types/plugins/date/types.d.ts +0 -1
  134. package/dist/types/plugins/date/ui/DatePicker/date-picker-input.d.ts +0 -24
  135. package/dist/types/plugins/date/ui/DatePicker/index.d.ts +0 -36
  136. package/dist/types/plugins/date/utils/formatParse.d.ts +0 -27
  137. package/dist/types/plugins/date/utils/internal.d.ts +0 -33
  138. package/dist/types/plugins/mentions/analytics.d.ts +0 -13
  139. package/dist/types/plugins/mentions/index.d.ts +0 -19
  140. package/dist/types/plugins/mentions/messages.d.ts +0 -22
  141. package/dist/types/plugins/mentions/nodeviews/mention.d.ts +0 -9
  142. package/dist/types/plugins/mentions/pm-plugins/key.d.ts +0 -3
  143. package/dist/types/plugins/mentions/pm-plugins/main.d.ts +0 -6
  144. package/dist/types/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  145. package/dist/types/plugins/mentions/type-ahead/index.d.ts +0 -17
  146. package/dist/types/plugins/mentions/types.d.ts +0 -24
  147. package/dist/types/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  148. package/dist/types/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  149. package/dist/types/plugins/mentions/ui/Mention/index.d.ts +0 -19
  150. package/dist/types/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  151. package/dist/types/plugins/mentions/utils.d.ts +0 -8
  152. package/dist/types-ts4.5/plugins/date/actions.d.ts +0 -58
  153. package/dist/types-ts4.5/plugins/date/commands.d.ts +0 -14
  154. package/dist/types-ts4.5/plugins/date/index.d.ts +0 -1
  155. package/dist/types-ts4.5/plugins/date/nodeviews/date.d.ts +0 -3
  156. package/dist/types-ts4.5/plugins/date/nodeviews/messages.d.ts +0 -7
  157. package/dist/types-ts4.5/plugins/date/plugin.d.ts +0 -3
  158. package/dist/types-ts4.5/plugins/date/pm-plugins/keymap.d.ts +0 -3
  159. package/dist/types-ts4.5/plugins/date/pm-plugins/main.d.ts +0 -6
  160. package/dist/types-ts4.5/plugins/date/pm-plugins/plugin-key.d.ts +0 -3
  161. package/dist/types-ts4.5/plugins/date/pm-plugins/types.d.ts +0 -12
  162. package/dist/types-ts4.5/plugins/date/pm-plugins/utils.d.ts +0 -5
  163. package/dist/types-ts4.5/plugins/date/types.d.ts +0 -1
  164. package/dist/types-ts4.5/plugins/date/ui/DatePicker/date-picker-input.d.ts +0 -24
  165. package/dist/types-ts4.5/plugins/date/ui/DatePicker/index.d.ts +0 -36
  166. package/dist/types-ts4.5/plugins/date/utils/formatParse.d.ts +0 -27
  167. package/dist/types-ts4.5/plugins/date/utils/internal.d.ts +0 -33
  168. package/dist/types-ts4.5/plugins/mentions/analytics.d.ts +0 -13
  169. package/dist/types-ts4.5/plugins/mentions/index.d.ts +0 -22
  170. package/dist/types-ts4.5/plugins/mentions/messages.d.ts +0 -22
  171. package/dist/types-ts4.5/plugins/mentions/nodeviews/mention.d.ts +0 -9
  172. package/dist/types-ts4.5/plugins/mentions/pm-plugins/key.d.ts +0 -3
  173. package/dist/types-ts4.5/plugins/mentions/pm-plugins/main.d.ts +0 -6
  174. package/dist/types-ts4.5/plugins/mentions/pm-plugins/utils.d.ts +0 -4
  175. package/dist/types-ts4.5/plugins/mentions/type-ahead/index.d.ts +0 -17
  176. package/dist/types-ts4.5/plugins/mentions/types.d.ts +0 -24
  177. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/index.d.ts +0 -22
  178. package/dist/types-ts4.5/plugins/mentions/ui/InviteItem/styles.d.ts +0 -8
  179. package/dist/types-ts4.5/plugins/mentions/ui/Mention/index.d.ts +0 -19
  180. package/dist/types-ts4.5/plugins/mentions/ui/ToolbarMention/index.d.ts +0 -13
  181. package/dist/types-ts4.5/plugins/mentions/utils.d.ts +0 -8
@@ -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');
@@ -1,33 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { PureComponent } from 'react';
3
- import MentionIcon from '@atlaskit/icon/glyph/editor/mention';
4
- import { ToolbarButton, TOOLBAR_BUTTON } from '@atlaskit/editor-common/ui-menu';
5
- import { injectIntl } from 'react-intl-next';
6
- import { messages } from '../../messages';
7
- class ToolbarMention extends PureComponent {
8
- constructor(...args) {
9
- super(...args);
10
- _defineProperty(this, "handleInsertMention", () => {
11
- if (!this.props.editorView) {
12
- return false;
13
- }
14
- this.props.onInsertMention();
15
- return true;
16
- });
17
- }
18
- render() {
19
- const mentionStringTranslated = this.props.intl.formatMessage(messages.mentionsIconLabel);
20
- return /*#__PURE__*/React.createElement(ToolbarButton, {
21
- testId: this.props.testId,
22
- buttonId: TOOLBAR_BUTTON.MENTION,
23
- spacing: "none",
24
- onClick: this.handleInsertMention,
25
- disabled: this.props.isDisabled,
26
- title: mentionStringTranslated + '@',
27
- iconBefore: /*#__PURE__*/React.createElement(MentionIcon, {
28
- label: mentionStringTranslated
29
- })
30
- });
31
- }
32
- }
33
- export default injectIntl(ToolbarMention);
@@ -1,20 +0,0 @@
1
- import { INVITE_ITEM_DESCRIPTION } from './ui/InviteItem';
2
- export const isTeamType = userType => userType === 'TEAM';
3
- export const isTeamStats = stat => stat && !isNaN(stat.teamMentionDuration);
4
- export const isInviteItem = mention => mention && mention.id === INVITE_ITEM_DESCRIPTION.id;
5
-
6
- /**
7
- * Actions
8
- */
9
- export const shouldKeepInviteItem = (query, firstQueryWithoutResults) => {
10
- if (!firstQueryWithoutResults) {
11
- return true;
12
- }
13
- let lastIndexWithResults = firstQueryWithoutResults.length - 1;
14
- let suffix = query.slice(lastIndexWithResults);
15
- if (query[lastIndexWithResults - 1] === ' ') {
16
- suffix = ' ' + suffix;
17
- }
18
- const depletedExtraWords = /\s[^\s]+\s/.test(suffix);
19
- return !depletedExtraWords;
20
- };
@@ -1,99 +0,0 @@
1
- import { NodeSelection, Selection } from '@atlaskit/editor-prosemirror/state';
2
- import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
- import { todayTimestampInUTC } from '@atlaskit/editor-common/utils';
4
- import { pluginKey } from './pm-plugins/plugin-key';
5
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
- import { isToday } from './utils/internal';
7
- export var createDate = function createDate(isQuickInsertAction) {
8
- return function (insert, state) {
9
- var dateNode = state.schema.nodes.date.createChecked({
10
- timestamp: todayTimestampInUTC()
11
- });
12
- var space = state.schema.text(' ');
13
- var tr = insert(Fragment.from([dateNode, space]), {
14
- selectInlineNode: true
15
- });
16
- var newPluginState = {
17
- isQuickInsertAction: isQuickInsertAction,
18
- showDatePickerAt: tr.selection.from,
19
- isNew: true,
20
- isDateEmpty: false,
21
- focusDateInput: false
22
- };
23
- return tr.setMeta(pluginKey, newPluginState);
24
- };
25
- };
26
-
27
- /** Focus input */
28
- export var focusDateInput = function focusDateInput() {
29
- return function (state, dispatch) {
30
- var pluginState = pluginKey.getState(state);
31
- if (!pluginState || pluginState.showDatePickerAt === null) {
32
- return false;
33
- }
34
- if (!dispatch) {
35
- return false;
36
- }
37
- var tr = state.tr.setMeta(pluginKey, {
38
- focusDateInput: true
39
- });
40
- dispatch(tr);
41
- return true;
42
- };
43
- };
44
- export var setDatePickerAt = function setDatePickerAt(showDatePickerAt) {
45
- return function (state, dispatch) {
46
- dispatch(state.tr.setMeta(pluginKey, {
47
- showDatePickerAt: showDatePickerAt
48
- }));
49
- return true;
50
- };
51
- };
52
- export var closeDatePicker = function closeDatePicker() {
53
- return function (state, dispatch) {
54
- var _ref = pluginKey.getState(state) || {},
55
- showDatePickerAt = _ref.showDatePickerAt;
56
- if (!dispatch) {
57
- return false;
58
- }
59
- var tr = showDatePickerAt ? state.tr.setMeta(pluginKey, {
60
- showDatePickerAt: null,
61
- isNew: false
62
- }).setSelection(Selection.near(state.tr.doc.resolve(showDatePickerAt + 2))) : state.tr.setMeta(pluginKey, {
63
- isNew: false
64
- });
65
- dispatch(tr);
66
- return false;
67
- };
68
- };
69
- export var closeDatePickerWithAnalytics = function closeDatePickerWithAnalytics(_ref2) {
70
- var _pluginInjectionApi$a;
71
- var date = _ref2.date,
72
- pluginInjectionApi = _ref2.pluginInjectionApi;
73
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || _pluginInjectionApi$a.attachAnalyticsEvent({
74
- eventType: EVENT_TYPE.TRACK,
75
- action: ACTION.COMMITTED,
76
- actionSubject: ACTION_SUBJECT.DATE,
77
- attributes: {
78
- commitMethod: INPUT_METHOD.BLUR,
79
- isValid: date !== undefined,
80
- isToday: isToday(date)
81
- }
82
- });
83
- return closeDatePicker();
84
- };
85
- export var openDatePicker = function openDatePicker() {
86
- return function (state, dispatch) {
87
- var $from = state.selection.$from;
88
- var node = state.doc.nodeAt($from.pos);
89
- if (node && node.type.name === state.schema.nodes.date.name) {
90
- var showDatePickerAt = $from.pos;
91
- if (dispatch) {
92
- dispatch(state.tr.setMeta(pluginKey, {
93
- showDatePickerAt: showDatePickerAt
94
- }).setSelection(NodeSelection.create(state.doc, showDatePickerAt)));
95
- }
96
- }
97
- return false;
98
- };
99
- };