@atlaskit/mention 27.17.1 → 27.18.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 (225) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/cjs/api/AbstractMentionResource.js +111 -0
  3. package/dist/cjs/api/AbstractPresenceResource.js +41 -0
  4. package/dist/cjs/api/AbstractResource.js +48 -0
  5. package/dist/cjs/api/Callback.js +5 -0
  6. package/dist/cjs/api/DefaultMentionNameResolver.js +178 -0
  7. package/dist/cjs/api/DefaultPresenceCache.js +159 -0
  8. package/dist/cjs/api/DefaultPresenceParser.js +91 -0
  9. package/dist/cjs/api/HttpError.js +16 -0
  10. package/dist/cjs/api/MentionNameResolver.js +13 -201
  11. package/dist/cjs/api/MentionResource.js +52 -157
  12. package/dist/cjs/api/PresenceResource.js +39 -263
  13. package/dist/cjs/api/Queue.js +5 -0
  14. package/dist/cjs/api/isResolvingMentionProvider.js +9 -0
  15. package/dist/cjs/api/mergeNameResolverQueues.js +36 -0
  16. package/dist/cjs/components/Mention/MentionInternal.js +247 -0
  17. package/dist/cjs/components/Mention/ResourcedMention.js +5 -4
  18. package/dist/cjs/components/Mention/index.js +29 -243
  19. package/dist/cjs/components/MentionAvatar/index.js +5 -4
  20. package/dist/cjs/components/MentionItem/index.js +18 -12
  21. package/dist/cjs/components/MentionList/index.js +4 -3
  22. package/dist/cjs/components/MentionPicker/MentionPicker.js +231 -0
  23. package/dist/cjs/components/MentionPicker/index.js +18 -225
  24. package/dist/cjs/components/MessagesIntlProvider/index.js +2 -2
  25. package/dist/cjs/components/ResourcedMentionList/ResourcedMentionListWithoutAnalytics.js +228 -0
  26. package/dist/cjs/components/ResourcedMentionList/index.js +14 -223
  27. package/dist/cjs/index.js +17 -15
  28. package/dist/cjs/is-agent-mention.js +12 -0
  29. package/dist/cjs/is-app-mention.js +10 -0
  30. package/dist/cjs/is-promise.js +9 -0
  31. package/dist/cjs/is-restricted.js +10 -0
  32. package/dist/cjs/is-special-mention-text.js +9 -0
  33. package/dist/cjs/is-special-mention.js +10 -0
  34. package/dist/cjs/is-team-mention.js +10 -0
  35. package/dist/cjs/resource.js +15 -12
  36. package/dist/cjs/team-resource.js +9 -9
  37. package/dist/cjs/typeahead.js +4 -0
  38. package/dist/cjs/types.js +71 -30
  39. package/dist/cjs/util/actual-mouse-move.js +14 -0
  40. package/dist/cjs/util/analytics.js +91 -107
  41. package/dist/cjs/util/build-sli-payload.js +27 -0
  42. package/dist/cjs/util/fire-analytics-mention-event.js +32 -0
  43. package/dist/cjs/util/fire-analytics-mention-hydration-event.js +33 -0
  44. package/dist/cjs/util/fire-analytics-mention-typeahead-event.js +34 -0
  45. package/dist/cjs/util/fire-analytics.js +18 -0
  46. package/dist/cjs/util/fire-sli-analytics-event.js +16 -0
  47. package/dist/cjs/util/get-messages-for-locale.js +233 -0
  48. package/dist/cjs/util/i18n.js +9 -254
  49. package/dist/cjs/util/left-click.js +9 -0
  50. package/dist/cjs/util/mouse-location.js +12 -0
  51. package/dist/cjs/util/mouse.js +1 -26
  52. package/dist/cjs/util/package-name.js +7 -0
  53. package/dist/cjs/util/package-version.js +7 -0
  54. package/dist/cjs/util/prop-formatter.js +25 -0
  55. package/dist/es2019/api/AbstractMentionResource.js +73 -0
  56. package/dist/es2019/api/AbstractPresenceResource.js +17 -0
  57. package/dist/es2019/api/AbstractResource.js +33 -0
  58. package/dist/es2019/api/Callback.js +1 -0
  59. package/dist/es2019/api/DefaultMentionNameResolver.js +152 -0
  60. package/dist/es2019/api/DefaultPresenceCache.js +111 -0
  61. package/dist/es2019/api/DefaultPresenceParser.js +58 -0
  62. package/dist/es2019/api/HttpError.js +8 -0
  63. package/dist/es2019/api/MentionNameResolver.js +13 -176
  64. package/dist/es2019/api/MentionResource.js +28 -122
  65. package/dist/es2019/api/PresenceResource.js +19 -185
  66. package/dist/es2019/api/Queue.js +1 -0
  67. package/dist/es2019/api/isResolvingMentionProvider.js +1 -0
  68. package/dist/es2019/api/mergeNameResolverQueues.js +25 -0
  69. package/dist/es2019/components/Mention/MentionInternal.js +225 -0
  70. package/dist/es2019/components/Mention/ResourcedMention.js +4 -3
  71. package/dist/es2019/components/Mention/index.js +19 -223
  72. package/dist/es2019/components/MentionAvatar/index.js +3 -2
  73. package/dist/es2019/components/MentionItem/index.js +14 -8
  74. package/dist/es2019/components/MentionList/index.js +2 -1
  75. package/dist/es2019/components/MentionPicker/MentionPicker.js +198 -0
  76. package/dist/es2019/components/MentionPicker/index.js +15 -198
  77. package/dist/es2019/components/MessagesIntlProvider/index.js +1 -1
  78. package/dist/es2019/components/ResourcedMentionList/ResourcedMentionListWithoutAnalytics.js +187 -0
  79. package/dist/es2019/components/ResourcedMentionList/index.js +9 -187
  80. package/dist/es2019/element.js +5 -0
  81. package/dist/es2019/index.js +13 -9
  82. package/dist/es2019/is-agent-mention.js +6 -0
  83. package/dist/es2019/is-app-mention.js +4 -0
  84. package/dist/es2019/is-promise.js +1 -0
  85. package/dist/es2019/is-restricted.js +4 -0
  86. package/dist/es2019/is-special-mention-text.js +3 -0
  87. package/dist/es2019/is-special-mention.js +4 -0
  88. package/dist/es2019/is-team-mention.js +4 -0
  89. package/dist/es2019/item.js +5 -0
  90. package/dist/es2019/resource.js +15 -5
  91. package/dist/es2019/team-resource.js +10 -4
  92. package/dist/es2019/typeahead.js +5 -0
  93. package/dist/es2019/types.js +30 -21
  94. package/dist/es2019/util/actual-mouse-move.js +8 -0
  95. package/dist/es2019/util/analytics.js +35 -91
  96. package/dist/es2019/util/build-sli-payload.js +18 -0
  97. package/dist/es2019/util/fire-analytics-mention-event.js +24 -0
  98. package/dist/es2019/util/fire-analytics-mention-hydration-event.js +25 -0
  99. package/dist/es2019/util/fire-analytics-mention-typeahead-event.js +24 -0
  100. package/dist/es2019/util/fire-analytics.js +10 -0
  101. package/dist/es2019/util/fire-sli-analytics-event.js +8 -0
  102. package/dist/es2019/util/get-messages-for-locale.js +145 -0
  103. package/dist/es2019/util/i18n.js +2 -165
  104. package/dist/es2019/util/left-click.js +3 -0
  105. package/dist/es2019/util/mouse-location.js +6 -0
  106. package/dist/es2019/util/mouse.js +0 -18
  107. package/dist/es2019/util/package-name.js +1 -0
  108. package/dist/es2019/util/package-version.js +1 -0
  109. package/dist/es2019/util/prop-formatter.js +18 -0
  110. package/dist/esm/api/AbstractMentionResource.js +104 -0
  111. package/dist/esm/api/AbstractPresenceResource.js +34 -0
  112. package/dist/esm/api/AbstractResource.js +41 -0
  113. package/dist/esm/api/Callback.js +1 -0
  114. package/dist/esm/api/DefaultMentionNameResolver.js +171 -0
  115. package/dist/esm/api/DefaultPresenceCache.js +152 -0
  116. package/dist/esm/api/DefaultPresenceParser.js +84 -0
  117. package/dist/esm/api/HttpError.js +9 -0
  118. package/dist/esm/api/MentionNameResolver.js +13 -198
  119. package/dist/esm/api/MentionResource.js +30 -154
  120. package/dist/esm/api/PresenceResource.js +22 -256
  121. package/dist/esm/api/Queue.js +1 -0
  122. package/dist/esm/api/isResolvingMentionProvider.js +3 -0
  123. package/dist/esm/api/mergeNameResolverQueues.js +29 -0
  124. package/dist/esm/components/Mention/MentionInternal.js +242 -0
  125. package/dist/esm/components/Mention/ResourcedMention.js +4 -3
  126. package/dist/esm/components/Mention/index.js +19 -240
  127. package/dist/esm/components/MentionAvatar/index.js +3 -2
  128. package/dist/esm/components/MentionItem/index.js +14 -8
  129. package/dist/esm/components/MentionList/index.js +2 -1
  130. package/dist/esm/components/MentionPicker/MentionPicker.js +225 -0
  131. package/dist/esm/components/MentionPicker/index.js +15 -225
  132. package/dist/esm/components/MessagesIntlProvider/index.js +1 -1
  133. package/dist/esm/components/ResourcedMentionList/ResourcedMentionListWithoutAnalytics.js +221 -0
  134. package/dist/esm/components/ResourcedMentionList/index.js +9 -221
  135. package/dist/esm/element.js +5 -0
  136. package/dist/esm/index.js +13 -9
  137. package/dist/esm/is-agent-mention.js +6 -0
  138. package/dist/esm/is-app-mention.js +4 -0
  139. package/dist/esm/is-promise.js +3 -0
  140. package/dist/esm/is-restricted.js +4 -0
  141. package/dist/esm/is-special-mention-text.js +3 -0
  142. package/dist/esm/is-special-mention.js +4 -0
  143. package/dist/esm/is-team-mention.js +4 -0
  144. package/dist/esm/item.js +5 -0
  145. package/dist/esm/resource.js +15 -5
  146. package/dist/esm/team-resource.js +10 -4
  147. package/dist/esm/typeahead.js +5 -0
  148. package/dist/esm/types.js +30 -23
  149. package/dist/esm/util/actual-mouse-move.js +8 -0
  150. package/dist/esm/util/analytics.js +35 -105
  151. package/dist/esm/util/build-sli-payload.js +20 -0
  152. package/dist/esm/util/fire-analytics-mention-event.js +26 -0
  153. package/dist/esm/util/fire-analytics-mention-hydration-event.js +27 -0
  154. package/dist/esm/util/fire-analytics-mention-typeahead-event.js +28 -0
  155. package/dist/esm/util/fire-analytics.js +12 -0
  156. package/dist/esm/util/fire-sli-analytics-event.js +10 -0
  157. package/dist/esm/util/get-messages-for-locale.js +163 -0
  158. package/dist/esm/util/i18n.js +2 -183
  159. package/dist/esm/util/left-click.js +3 -0
  160. package/dist/esm/util/mouse-location.js +6 -0
  161. package/dist/esm/util/mouse.js +0 -18
  162. package/dist/esm/util/package-name.js +1 -0
  163. package/dist/esm/util/package-version.js +1 -0
  164. package/dist/esm/util/prop-formatter.js +18 -0
  165. package/dist/types/api/AbstractMentionResource.d.ts +15 -0
  166. package/dist/types/api/AbstractPresenceResource.d.ts +6 -0
  167. package/dist/types/api/AbstractResource.d.ts +11 -0
  168. package/dist/types/api/Callback.d.ts +4 -0
  169. package/dist/types/api/DefaultMentionNameResolver.d.ts +27 -0
  170. package/dist/types/api/DefaultPresenceCache.d.ts +57 -0
  171. package/dist/types/api/DefaultPresenceParser.d.ts +8 -0
  172. package/dist/types/api/HttpError.d.ts +7 -0
  173. package/dist/types/api/MentionNameResolver.d.ts +14 -35
  174. package/dist/types/api/MentionResource.d.ts +18 -33
  175. package/dist/types/api/PresenceResource.d.ts +15 -69
  176. package/dist/types/api/Queue.d.ts +2 -0
  177. package/dist/types/api/isResolvingMentionProvider.d.ts +2 -0
  178. package/dist/types/api/mergeNameResolverQueues.d.ts +6 -0
  179. package/dist/types/components/Mention/MentionInternal.d.ts +27 -0
  180. package/dist/types/components/Mention/ResourcedMention.d.ts +1 -1
  181. package/dist/types/components/Mention/index.d.ts +9 -20
  182. package/dist/types/components/MentionAvatar/index.d.ts +1 -1
  183. package/dist/types/components/MentionItem/index.d.ts +4 -1
  184. package/dist/types/components/MentionPicker/MentionPicker.d.ts +46 -0
  185. package/dist/types/components/MentionPicker/index.d.ts +5 -42
  186. package/dist/types/components/ResourcedMentionList/ResourcedMentionListWithoutAnalytics.d.ts +30 -0
  187. package/dist/types/components/ResourcedMentionList/index.d.ts +5 -27
  188. package/dist/types/element.d.ts +3 -0
  189. package/dist/types/index.d.ts +15 -10
  190. package/dist/types/is-agent-mention.d.ts +2 -0
  191. package/dist/types/is-app-mention.d.ts +2 -0
  192. package/dist/types/is-promise.d.ts +1 -0
  193. package/dist/types/is-restricted.d.ts +1 -0
  194. package/dist/types/is-special-mention-text.d.ts +1 -0
  195. package/dist/types/is-special-mention.d.ts +2 -0
  196. package/dist/types/is-team-mention.d.ts +2 -0
  197. package/dist/types/item.d.ts +3 -0
  198. package/dist/types/resource.d.ts +15 -6
  199. package/dist/types/team-resource.d.ts +10 -4
  200. package/dist/types/typeahead.d.ts +3 -0
  201. package/dist/types/types.d.ts +28 -8
  202. package/dist/types/util/actual-mouse-move.d.ts +2 -0
  203. package/dist/types/util/analytics.d.ts +33 -10
  204. package/dist/types/util/build-sli-payload.d.ts +4 -0
  205. package/dist/types/util/fire-analytics-mention-event.d.ts +1 -0
  206. package/dist/types/util/fire-analytics-mention-hydration-event.d.ts +1 -0
  207. package/dist/types/util/fire-analytics-mention-typeahead-event.d.ts +1 -0
  208. package/dist/types/util/fire-analytics.d.ts +1 -0
  209. package/dist/types/util/fire-sli-analytics-event.d.ts +1 -0
  210. package/dist/types/util/get-messages-for-locale.d.ts +11 -0
  211. package/dist/types/util/i18n.d.ts +0 -15
  212. package/dist/types/util/left-click.d.ts +2 -0
  213. package/dist/types/util/mouse-location.d.ts +3 -0
  214. package/dist/types/util/mouse.d.ts +0 -4
  215. package/dist/types/util/package-name.d.ts +1 -0
  216. package/dist/types/util/package-version.d.ts +1 -0
  217. package/dist/types/util/prop-formatter.d.ts +5 -0
  218. package/package.json +1 -1
  219. package/dist/cjs/i18n/index.js +0 -216
  220. package/dist/es2019/i18n/index.js +0 -37
  221. package/dist/esm/i18n/index.js +0 -37
  222. package/dist/types/i18n/index.d.ts +0 -37
  223. /package/dist/cjs/components/Mention/{index.compiled.css → MentionInternal.compiled.css} +0 -0
  224. /package/dist/es2019/components/Mention/{index.compiled.css → MentionInternal.compiled.css} +0 -0
  225. /package/dist/esm/components/Mention/{index.compiled.css → MentionInternal.compiled.css} +0 -0
@@ -0,0 +1,111 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ class CacheEntry {
3
+ constructor(pres, timeout) {
4
+ this.presence = pres;
5
+ this.expiry = Date.now() + timeout;
6
+ }
7
+ expired() {
8
+ return Date.now() > this.expiry;
9
+ }
10
+ }
11
+ export class DefaultPresenceCache {
12
+ constructor(cacheTimeout, cacheTrigger) {
13
+ this.expiryInMillis = cacheTimeout ? cacheTimeout : DefaultPresenceCache.defaultTimeout;
14
+ this.flushTrigger = cacheTrigger ? cacheTrigger : DefaultPresenceCache.defaultFlushTrigger;
15
+ this.cache = {};
16
+ this.size = 0;
17
+ }
18
+
19
+ /**
20
+ * Precondition: _delete is only called internally if userId exists in cache
21
+ * Removes cache entry
22
+ * @param userId
23
+ */
24
+ _delete(userId) {
25
+ delete this.cache[userId];
26
+ this.size--;
27
+ }
28
+
29
+ /**
30
+ * Checks a cache entry and calls delete if the info has expired
31
+ * @param userId
32
+ */
33
+ _deleteIfExpired(userId) {
34
+ if (this.contains(userId) && this.cache[userId].expired()) {
35
+ this._delete(userId);
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Cleans expired entries from cache
41
+ */
42
+ _removeExpired() {
43
+ Object.keys(this.cache).forEach(id => {
44
+ this._deleteIfExpired(id);
45
+ });
46
+ }
47
+
48
+ /**
49
+ * Checks if a user exists in the cache
50
+ * @param userId
51
+ */
52
+ contains(userId) {
53
+ return this.cache.hasOwnProperty(userId);
54
+ }
55
+
56
+ /**
57
+ * Retrieves a presence from the cache after checking for expired entries
58
+ * @param userId - to index the cache
59
+ * @returns Presence - the presence that matches the userId
60
+ */
61
+ get(userId) {
62
+ this._deleteIfExpired(userId);
63
+ if (!this.contains(userId)) {
64
+ return {};
65
+ }
66
+ return this.cache[userId].presence;
67
+ }
68
+
69
+ /**
70
+ * Retrieve multiple presences at once from the cache
71
+ * @param userIds - to index the cache
72
+ * @returns PresenceMap - A map of userIds to cached Presences
73
+ */
74
+ getBulk(userIds) {
75
+ const presences = {};
76
+ for (const userId of userIds) {
77
+ if (this.contains(userId)) {
78
+ presences[userId] = this.get(userId);
79
+ }
80
+ }
81
+ return presences;
82
+ }
83
+
84
+ /**
85
+ * For a given list of ids, returns a subset
86
+ * of all the ids with missing cache entries.
87
+ * @param userIds - to index the cache
88
+ * @returns string[] - ids missing from the cache
89
+ */
90
+ getMissingUserIds(userIds) {
91
+ return userIds.filter(id => !this.contains(id));
92
+ }
93
+
94
+ /**
95
+ * Precondition: presMap only contains ids of users not in cache
96
+ * expired users must first be removed then reinserted with updated presence
97
+ * Updates the cache by adding the new Presence entries and setting the expiry time
98
+ * @param presMap
99
+ */
100
+ update(presMap) {
101
+ if (this.size >= this.flushTrigger) {
102
+ this._removeExpired();
103
+ }
104
+ Object.keys(presMap).forEach(userId => {
105
+ this.cache[userId] = new CacheEntry(presMap[userId], this.expiryInMillis);
106
+ this.size++;
107
+ });
108
+ }
109
+ }
110
+ _defineProperty(DefaultPresenceCache, "defaultTimeout", 20000);
111
+ _defineProperty(DefaultPresenceCache, "defaultFlushTrigger", 50);
@@ -0,0 +1,58 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ export class DefaultPresenceParser {
3
+ mapState(state) {
4
+ if (state === 'unavailable') {
5
+ return 'offline';
6
+ } else if (state === 'available') {
7
+ return 'online';
8
+ } else {
9
+ return state;
10
+ }
11
+ }
12
+ parse(response) {
13
+ const presences = {};
14
+ if (response.hasOwnProperty('data') && response['data'].hasOwnProperty('PresenceBulk')) {
15
+ const results = response['data'].PresenceBulk;
16
+ // Store map of state and time indexed by userId. Ignore null results.
17
+ for (const user of results) {
18
+ if (user.userId && user.state) {
19
+ const state = DefaultPresenceParser.extractState(user) || user.state;
20
+ presences[user.userId] = {
21
+ status: this.mapState(state)
22
+ };
23
+ } else if (!user.hasOwnProperty('userId') || !user.hasOwnProperty('state')) {
24
+ // eslint-disable-next-line no-console
25
+ console.error('Unexpected response from presence service contains keys: ' + Object.keys(user));
26
+ }
27
+ }
28
+ }
29
+ return presences;
30
+ }
31
+ static extractState(presence) {
32
+ if (DefaultPresenceParser.isFocusState(presence)) {
33
+ return DefaultPresenceParser.FOCUS_STATE;
34
+ }
35
+ return presence.state;
36
+ }
37
+
38
+ /*
39
+ This is a bit of an odd exception. In the case where a user is in "Focus Mode", their presence state
40
+ is returned as 'busy' along with a `stateMetadata` object containing a `focus` field.
41
+ In this case we ignore the value of the `state` field and treat the presence as a 'focus' state.
42
+ */
43
+ static isFocusState(presence) {
44
+ if (presence.stateMetadata) {
45
+ try {
46
+ const metadata = JSON.parse(presence.stateMetadata);
47
+ return metadata && !!metadata.focus;
48
+ } catch (e) {
49
+ // eslint-disable-next-line no-console
50
+ console.error(`Failed to parse presence's stateMetadata for user with id ${presence.userId}: ${presence.stateMetadata}`);
51
+ // eslint-disable-next-line no-console
52
+ console.error(e);
53
+ }
54
+ }
55
+ return false;
56
+ }
57
+ }
58
+ _defineProperty(DefaultPresenceParser, "FOCUS_STATE", 'focus');
@@ -0,0 +1,8 @@
1
+ export class HttpError {
2
+ constructor(statusCode, statusMessage) {
3
+ this.statusCode = statusCode;
4
+ this.message = statusMessage;
5
+ this.name = 'HttpError';
6
+ this.stack = new Error().stack;
7
+ }
8
+ }
@@ -1,180 +1,17 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { MentionNameStatus } from '../types';
3
- import { fireAnalyticsMentionHydrationEvent } from '../util/analytics';
4
-
5
- /** A queue for user ids */
6
-
7
- export class DefaultMentionNameResolver {
8
- constructor(client, analyticsProps = {}, onResolvedAll = () => {}) {
9
- _defineProperty(this, "nameCache", new Map());
10
- _defineProperty(this, "nameQueue", new Map());
11
- _defineProperty(this, "nameStartTime", new Map());
12
- _defineProperty(this, "processingQueue", new Map());
13
- _defineProperty(this, "debounce", 0);
14
- _defineProperty(this, "debounceOnResolve", null);
15
- _defineProperty(this, "isOnResolvedAllCalled", false);
16
- _defineProperty(this, "processQueue", () => {
17
- clearTimeout(this.debounce);
18
- this.debounce = 0;
19
- const {
20
- queue,
21
- extraQueue
22
- } = this.splitQueueAtLimit();
23
- this.nameQueue = extraQueue;
24
- this.processingQueue = mergeNameResolverQueues(this.processingQueue, queue);
25
- this.client.lookupMentionNames(Array.from(queue.keys())).then(response => {
26
- response.forEach(mentionDetail => {
27
- const {
28
- id
29
- } = mentionDetail;
30
- queue.delete(id);
31
- this.resolveQueueItem(mentionDetail);
32
- });
33
- queue.forEach((_callback, id) => {
34
- // No response from client for these ids treat as unknown
35
- this.resolveQueueItem({
36
- id,
37
- status: MentionNameStatus.UNKNOWN
38
- });
39
- });
40
- }).catch(() => {
41
- // Service completely failed, reject all items in the queue
42
- queue.forEach((_callback, id) => {
43
- this.resolveQueueItem({
44
- id,
45
- status: MentionNameStatus.SERVICE_ERROR
46
- });
47
- });
48
- });
49
-
50
- // Make sure anything left in the queue gets processed.
51
- if (this.nameQueue.size > 0) {
52
- this.scheduleProcessQueue();
53
- } else {
54
- this.scheduleOnAllResolved();
55
- }
56
- });
57
- this.client = client;
58
- this.fireHydrationEvent = fireAnalyticsMentionHydrationEvent(analyticsProps);
59
- // If provided, this will be called once all pending mentions in the queue are resolved.
60
- // A sample usage is scrolling to a mention on page load, after the mentions have loadad.
61
- this.onResolvedAll = onResolvedAll;
62
- }
63
- lookupName(id) {
64
- const name = this.nameCache.get(id);
65
- if (name) {
66
- this.fireAnalytics(true, name);
67
- if (this.nameQueue.size === 0) {
68
- this.scheduleOnAllResolved();
69
- }
70
- return name;
71
- }
72
- return new Promise(resolve => {
73
- const processingItems = this.processingQueue.get(id);
74
- if (processingItems) {
75
- this.processingQueue.set(id, [...processingItems, resolve]);
76
- }
77
- const queuedItems = this.nameQueue.get(id) || [];
78
- this.nameQueue.set(id, [...queuedItems, resolve]);
79
- if (queuedItems.length === 0 && !processingItems) {
80
- this.nameStartTime.set(id, Date.now());
81
- }
82
- this.scheduleProcessQueue();
83
- if (this.isQueueAtLimit()) {
84
- this.processQueue();
85
- }
86
- });
87
- }
88
- cacheName(id, name) {
89
- this.nameCache.set(id, {
90
- id,
91
- name,
92
- status: MentionNameStatus.OK
93
- });
94
- }
95
- scheduleProcessQueue() {
96
- if (!this.debounce) {
97
- this.debounce = window.setTimeout(this.processQueue, DefaultMentionNameResolver.waitForBatch);
98
- }
99
- }
100
- scheduleOnAllResolved() {
101
- if (this.debounceOnResolve) {
102
- clearTimeout(this.debounceOnResolve);
103
- }
104
- this.debounceOnResolve = window.setTimeout(() => {
105
- if (this.isOnResolvedAllCalled) {
106
- return;
107
- }
108
- this.onResolvedAll();
109
- this.isOnResolvedAllCalled = true;
110
- }, DefaultMentionNameResolver.waitForResolveAll);
111
- }
112
- isQueueAtLimit() {
113
- return this.nameQueue.size >= this.client.getLookupLimit();
114
- }
115
- splitQueueAtLimit() {
116
- const values = Array.from(this.nameQueue.entries());
117
- const splitPoint = this.client.getLookupLimit();
118
- return {
119
- queue: new Map(values.slice(0, splitPoint)),
120
- extraQueue: new Map(values.slice(splitPoint))
121
- };
122
- }
123
- resolveQueueItem(mentionDetail) {
124
- const {
125
- id
126
- } = mentionDetail;
127
- const resolvers = this.processingQueue.get(id);
128
- if (resolvers) {
129
- this.processingQueue.delete(id);
130
- this.nameCache.set(id, mentionDetail);
131
- resolvers.forEach(resolve => {
132
- try {
133
- resolve(mentionDetail);
134
- } catch {
135
- // ignore - exception in consumer
136
- }
137
- });
138
- this.fireAnalytics(false, mentionDetail);
139
- }
140
- }
141
- fireAnalytics(fromCache, mentionDetail) {
142
- const {
143
- id
144
- } = mentionDetail;
145
- const action = mentionDetail.status === MentionNameStatus.OK ? 'completed' : 'failed';
146
- const start = this.nameStartTime.get(id);
147
- const duration = start ? Date.now() - start : 0;
148
- this.nameStartTime.delete(id);
149
- this.fireHydrationEvent(action, id, fromCache, duration);
150
- }
151
- }
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
152
2
 
153
3
  /**
154
- * Merge the two queues making sure to merge callback arrays for items in queueB already in queueA.
155
- * This addresses [this ticket](https://product-fabric.atlassian.net/browse/QS-3789).
4
+ * @deprecated Use `import { DefaultMentionNameResolver } from '@atlaskit/mention/mention-name-resolver'` instead.
5
+ */
6
+ export { DefaultMentionNameResolver } from './DefaultMentionNameResolver';
7
+ /**
8
+ * @deprecated Use `import { mergeNameResolverQueues } from '@atlaskit/mention/mention-name-resolver'` instead.
9
+ */
10
+ export { mergeNameResolverQueues } from './mergeNameResolverQueues';
11
+ /**
12
+ * @deprecated Use `import { Callback } from '@atlaskit/mention/mention-name-resolver'` instead.
156
13
  */
157
- _defineProperty(DefaultMentionNameResolver, "waitForBatch", 100);
158
- // ms
159
- _defineProperty(DefaultMentionNameResolver, "waitForResolveAll", 800);
160
- export function mergeNameResolverQueues(queueA, queueB) {
161
- const queueBeingMerged = new Map([...queueA]);
162
14
 
163
- // now add the items from the second queue that are not already in the
164
- // merged queue being built
165
- [...queueB].forEach(item => {
166
- const [key, queueBCallbacks] = item;
167
- const itemAlreadyInMergedQueue = queueBeingMerged.has(key);
168
- if (!itemAlreadyInMergedQueue) {
169
- queueBeingMerged.set(key, queueBCallbacks);
170
- } else {
171
- var _queueBeingMerged$get;
172
- // item already in merged queue, merge the callback arrays
173
- const queueACallbacks = (_queueBeingMerged$get = queueBeingMerged.get(key)) !== null && _queueBeingMerged$get !== void 0 ? _queueBeingMerged$get : [];
174
- const mergedCallbacks = new Set([...queueBCallbacks, ...queueACallbacks]);
175
- const deduplicatedCallbacks = Array.from(mergedCallbacks.values()); // prevents calling them twice
176
- queueBeingMerged.set(key, deduplicatedCallbacks);
177
- }
178
- });
179
- return queueBeingMerged;
180
- }
15
+ /**
16
+ * @deprecated Use `import { Queue } from '@atlaskit/mention/mention-name-resolver'` instead.
17
+ */
@@ -1,13 +1,13 @@
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
2
+ import debounce from 'lodash/debounce';
1
3
  import { utils as serviceUtils } from '@atlaskit/util-service-support';
2
- import { isAppMention, isTeamMention, MentionNameStatus, SliNames, Actions } from '../types';
4
+ import { isAppMention } from '../is-app-mention';
5
+ import { isTeamMention } from '../is-team-mention';
6
+ import { MentionNameStatus, SliNames, Actions } from '../types';
7
+ import { SLI_EVENT_TYPE } from '../util/analytics';
3
8
  import debug from '../util/logger';
9
+ import { AbstractMentionResource } from './AbstractMentionResource';
4
10
  const MAX_QUERY_ITEMS = 100;
5
- const MAX_NOTIFIED_ITEMS = 20;
6
- // Re-exporting types to prevent breaking change
7
- // Re-exporting types to prevent breaking change
8
-
9
- import { SLI_EVENT_TYPE } from '../util/analytics';
10
- import debounce from 'lodash/debounce';
11
11
 
12
12
  /**
13
13
  * Configuration for the TeamMentionResource, which extends {@link MentionResourceConfig}
@@ -27,110 +27,6 @@ const emptySecurityProvider = () => {
27
27
  headers: {}
28
28
  };
29
29
  };
30
- class AbstractResource {
31
- constructor() {
32
- this.changeListeners = new Map();
33
- this.allResultsListeners = new Map();
34
- this.errListeners = new Map();
35
- this.infoListeners = new Map();
36
- this.analyticsListeners = new Map();
37
- }
38
- subscribe(key, callback, errCallback, infoCallback, allResultsCallback, analyticsListeners) {
39
- if (callback) {
40
- this.changeListeners.set(key, callback);
41
- }
42
- if (errCallback) {
43
- this.errListeners.set(key, errCallback);
44
- }
45
- if (infoCallback) {
46
- this.infoListeners.set(key, infoCallback);
47
- }
48
- if (allResultsCallback) {
49
- this.allResultsListeners.set(key, allResultsCallback);
50
- }
51
- if (analyticsListeners) {
52
- this.analyticsListeners.set(key, analyticsListeners);
53
- }
54
- }
55
- unsubscribe(key) {
56
- this.changeListeners.delete(key);
57
- this.errListeners.delete(key);
58
- this.infoListeners.delete(key);
59
- this.allResultsListeners.delete(key);
60
- this.analyticsListeners.delete(key);
61
- }
62
- }
63
- class AbstractMentionResource extends AbstractResource {
64
- shouldHighlightMention(_mention) {
65
- return false;
66
- }
67
-
68
- // eslint-disable-next-line class-methods-use-this
69
- filter(query) {
70
- throw new Error(`not yet implemented.\nParams: query=${query}`);
71
- }
72
-
73
- // eslint-disable-next-line class-methods-use-this, no-unused-vars
74
- recordMentionSelection(_mention) {
75
- // Do nothing
76
- }
77
- isFiltering(_query) {
78
- return false;
79
- }
80
- _notifyListeners(mentionsResult, stats) {
81
- debug('ak-mention-resource._notifyListeners', mentionsResult && mentionsResult.mentions && mentionsResult.mentions.length, this.changeListeners);
82
- this.changeListeners.forEach((listener, key) => {
83
- try {
84
- listener(mentionsResult.mentions.slice(0, MAX_NOTIFIED_ITEMS), mentionsResult.query, stats);
85
- } catch (e) {
86
- // ignore error from listener
87
- debug(`error from listener '${key}', ignoring`, e);
88
- }
89
- });
90
- }
91
- _notifyAllResultsListeners(mentionsResult) {
92
- debug('ak-mention-resource._notifyAllResultsListeners', mentionsResult && mentionsResult.mentions && mentionsResult.mentions.length, this.changeListeners);
93
- this.allResultsListeners.forEach((listener, key) => {
94
- try {
95
- listener(mentionsResult.mentions.slice(0, MAX_NOTIFIED_ITEMS), mentionsResult.query);
96
- } catch (e) {
97
- // ignore error from listener
98
- debug(`error from listener '${key}', ignoring`, e);
99
- }
100
- });
101
- }
102
- _notifyErrorListeners(error, query) {
103
- this.errListeners.forEach((listener, key) => {
104
- try {
105
- listener(error, query);
106
- } catch (e) {
107
- // ignore error from listener
108
- debug(`error from listener '${key}', ignoring`, e);
109
- }
110
- });
111
- }
112
- _notifyInfoListeners(info) {
113
- this.infoListeners.forEach((listener, key) => {
114
- try {
115
- listener(info);
116
- } catch (e) {
117
- // ignore error fromr listener
118
- debug(`error from listener '${key}', ignoring`, e);
119
- }
120
- });
121
- }
122
- _notifyAnalyticsListeners(event, actionSubject, action, attributes) {
123
- this.analyticsListeners.forEach((listener, key) => {
124
- try {
125
- listener(event, actionSubject, action, attributes);
126
- } catch (e) {
127
- // ignore error from listener
128
- debug(`error from listener '${key}', ignoring`, e);
129
- }
130
- });
131
- }
132
- }
133
-
134
30
  /**
135
31
  * Provides a Javascript API
136
32
  */
@@ -342,14 +238,24 @@ export class MentionResource extends AbstractMentionResource {
342
238
  };
343
239
  }
344
240
  }
345
- export class HttpError {
346
- constructor(statusCode, statusMessage) {
347
- this.statusCode = statusCode;
348
- this.message = statusMessage;
349
- this.name = 'HttpError';
350
- this.stack = new Error().stack;
351
- }
352
- }
353
- export const isResolvingMentionProvider = p => !!(p && p.supportsMentionNameResolving && p.supportsMentionNameResolving());
354
- export { AbstractResource, AbstractMentionResource };
355
- export default MentionResource;
241
+ export default MentionResource;
242
+
243
+ /**
244
+ * @deprecated Use `import { HttpError } from '@atlaskit/mention/mention-resource'` instead.
245
+ */
246
+ export { HttpError } from './HttpError';
247
+
248
+ /**
249
+ * @deprecated Use `import { isResolvingMentionProvider } from '@atlaskit/mention/mention-resource'` instead.
250
+ */
251
+ export { isResolvingMentionProvider } from './isResolvingMentionProvider';
252
+
253
+ /**
254
+ * @deprecated Use `import { AbstractResource } from '@atlaskit/mention/mention-resource'` instead.
255
+ */
256
+ export { AbstractResource } from './AbstractResource';
257
+
258
+ /**
259
+ * @deprecated Use `import { AbstractMentionResource } from '@atlaskit/mention/mention-resource'` instead.
260
+ */
261
+ export { AbstractMentionResource } from './AbstractMentionResource';