@atlaskit/emoji 67.0.3 → 67.0.5

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 (280) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/admin.js +0 -2
  3. package/dist/cjs/api/EmojiLoader.js +1 -8
  4. package/dist/cjs/api/EmojiRepository.js +16 -80
  5. package/dist/cjs/api/EmojiRepositoryRegex.js +2 -0
  6. package/dist/cjs/api/EmojiResource.js +20 -170
  7. package/dist/cjs/api/EmojiUtils.js +27 -67
  8. package/dist/cjs/api/internal/Comparators.js +8 -62
  9. package/dist/cjs/api/internal/UsageFrequencyTracker.js +4 -34
  10. package/dist/cjs/api/media/MediaEmojiCache.js +8 -58
  11. package/dist/cjs/api/media/MediaImageLoader.js +4 -28
  12. package/dist/cjs/api/media/SiteEmojiResource.js +14 -55
  13. package/dist/cjs/api/media/TokenManager.js +4 -18
  14. package/dist/cjs/components/common/CachingEmoji.js +18 -52
  15. package/dist/cjs/components/common/DeleteButton.js +0 -10
  16. package/dist/cjs/components/common/Emoji.js +44 -102
  17. package/dist/cjs/components/common/EmojiActions.js +25 -61
  18. package/dist/cjs/components/common/EmojiButton.js +5 -18
  19. package/dist/cjs/components/common/EmojiDeletePreview.js +7 -38
  20. package/dist/cjs/components/common/EmojiErrorMessage.js +3 -9
  21. package/dist/cjs/components/common/EmojiPlaceholder.js +7 -16
  22. package/dist/cjs/components/common/EmojiPreviewComponent.js +1 -6
  23. package/dist/cjs/components/common/EmojiUploadPicker.js +31 -86
  24. package/dist/cjs/components/common/EmojiUploadPreview.js +7 -36
  25. package/dist/cjs/components/common/FileChooser.js +5 -18
  26. package/dist/cjs/components/common/LoadingEmojiComponent.js +5 -24
  27. package/dist/cjs/components/common/Popup.js +16 -44
  28. package/dist/cjs/components/common/RecordSelectionDefault.js +0 -7
  29. package/dist/cjs/components/common/ResourcedEmoji.js +0 -15
  30. package/dist/cjs/components/common/ResourcedEmojiComponent.js +29 -69
  31. package/dist/cjs/components/common/RetryableButton.js +4 -19
  32. package/dist/cjs/components/common/Scrollable.js +6 -36
  33. package/dist/cjs/components/common/ToneSelector.js +3 -24
  34. package/dist/cjs/components/common/UfoErrorBoundary.js +1 -19
  35. package/dist/cjs/components/common/UploadEmoji.js +2 -13
  36. package/dist/cjs/components/common/internal-types.js +0 -1
  37. package/dist/cjs/components/common/setSkinToneAriaLabelText.js +0 -6
  38. package/dist/cjs/components/common/styles.js +9 -17
  39. package/dist/cjs/components/hooks.js +0 -2
  40. package/dist/cjs/components/i18n.js +0 -2
  41. package/dist/cjs/components/picker/CategorySelector.js +4 -50
  42. package/dist/cjs/components/picker/CategoryTracker.js +3 -14
  43. package/dist/cjs/components/picker/EmojiPicker.js +3 -42
  44. package/dist/cjs/components/picker/EmojiPickerCategoryHeading.js +2 -10
  45. package/dist/cjs/components/picker/EmojiPickerComponent.js +59 -140
  46. package/dist/cjs/components/picker/EmojiPickerEmojiRow.js +7 -14
  47. package/dist/cjs/components/picker/EmojiPickerFooter.js +1 -8
  48. package/dist/cjs/components/picker/EmojiPickerList.js +32 -83
  49. package/dist/cjs/components/picker/EmojiPickerListSearch.js +11 -48
  50. package/dist/cjs/components/picker/EmojiPickerSizes.js +1 -2
  51. package/dist/cjs/components/picker/EmojiPickerVirtualItems.js +1 -38
  52. package/dist/cjs/components/picker/VirtualList.js +11 -41
  53. package/dist/cjs/components/picker/categories.js +0 -14
  54. package/dist/cjs/components/picker/styles.js +15 -20
  55. package/dist/cjs/components/picker/utils.js +0 -4
  56. package/dist/cjs/components/typeahead/EmojiTypeAhead.js +10 -45
  57. package/dist/cjs/components/typeahead/EmojiTypeAheadComponent.js +11 -74
  58. package/dist/cjs/components/typeahead/EmojiTypeAheadItem.js +7 -37
  59. package/dist/cjs/components/typeahead/EmojiTypeAheadList.js +10 -63
  60. package/dist/cjs/components/typeahead/styles.js +2 -4
  61. package/dist/cjs/components/uploader/EmojiUploadComponent.js +6 -42
  62. package/dist/cjs/components/uploader/EmojiUploader.js +3 -31
  63. package/dist/cjs/components/uploader/styles.js +3 -4
  64. package/dist/cjs/context/EmojiCommonProvider.js +0 -6
  65. package/dist/cjs/context/EmojiContext.js +0 -2
  66. package/dist/cjs/context/EmojiContextProvider.js +1 -17
  67. package/dist/cjs/element.js +0 -4
  68. package/dist/cjs/hooks/useEmoji.js +5 -20
  69. package/dist/cjs/hooks/useEmojiContext.js +0 -4
  70. package/dist/cjs/hooks/usePrevious.js +0 -2
  71. package/dist/cjs/i18n/cs.js +0 -1
  72. package/dist/cjs/i18n/da.js +0 -1
  73. package/dist/cjs/i18n/de.js +0 -1
  74. package/dist/cjs/i18n/en.js +0 -1
  75. package/dist/cjs/i18n/en_GB.js +0 -1
  76. package/dist/cjs/i18n/en_ZZ.js +0 -1
  77. package/dist/cjs/i18n/es.js +0 -1
  78. package/dist/cjs/i18n/et.js +0 -1
  79. package/dist/cjs/i18n/fi.js +0 -1
  80. package/dist/cjs/i18n/fr.js +0 -1
  81. package/dist/cjs/i18n/hu.js +0 -1
  82. package/dist/cjs/i18n/index.js +0 -30
  83. package/dist/cjs/i18n/it.js +0 -1
  84. package/dist/cjs/i18n/ja.js +0 -1
  85. package/dist/cjs/i18n/ko.js +0 -1
  86. package/dist/cjs/i18n/nb.js +0 -1
  87. package/dist/cjs/i18n/nl.js +0 -1
  88. package/dist/cjs/i18n/pl.js +0 -1
  89. package/dist/cjs/i18n/pt_BR.js +0 -1
  90. package/dist/cjs/i18n/pt_PT.js +0 -1
  91. package/dist/cjs/i18n/ru.js +0 -1
  92. package/dist/cjs/i18n/sk.js +0 -1
  93. package/dist/cjs/i18n/sv.js +0 -1
  94. package/dist/cjs/i18n/th.js +0 -1
  95. package/dist/cjs/i18n/tr.js +0 -1
  96. package/dist/cjs/i18n/uk.js +0 -1
  97. package/dist/cjs/i18n/vi.js +0 -1
  98. package/dist/cjs/i18n/zh.js +0 -1
  99. package/dist/cjs/i18n/zh_TW.js +0 -1
  100. package/dist/cjs/index.js +0 -24
  101. package/dist/cjs/picker.js +0 -2
  102. package/dist/cjs/resource.js +0 -5
  103. package/dist/cjs/typeahead.js +0 -3
  104. package/dist/cjs/types.js +0 -17
  105. package/dist/cjs/util/DuplicateLimitedQueue.js +13 -31
  106. package/dist/cjs/util/StoredDuplicateLimitedQueue.js +4 -26
  107. package/dist/cjs/util/analytics/analytics.js +14 -97
  108. package/dist/cjs/util/analytics/index.js +0 -4
  109. package/dist/cjs/util/analytics/samplingUfo.js +3 -59
  110. package/dist/cjs/util/analytics/ufoExperiences.js +0 -12
  111. package/dist/cjs/util/analytics/useSampledUFOComponentExperience.js +3 -10
  112. package/dist/cjs/util/constants.js +5 -5
  113. package/dist/cjs/util/filters.js +0 -4
  114. package/dist/cjs/util/image.js +3 -18
  115. package/dist/cjs/util/logger.js +0 -6
  116. package/dist/cjs/util/mouse.js +3 -6
  117. package/dist/cjs/util/shared-styles.js +0 -4
  118. package/dist/cjs/util/storage-available.js +10 -8
  119. package/dist/cjs/util/type-helpers.js +2 -57
  120. package/dist/cjs/util/useInView.js +0 -6
  121. package/dist/cjs/utils.js +0 -3
  122. package/dist/cjs/version.json +1 -1
  123. package/dist/es2019/api/EmojiLoader.js +2 -4
  124. package/dist/es2019/api/EmojiRepository.js +15 -82
  125. package/dist/es2019/api/EmojiRepositoryRegex.js +2 -0
  126. package/dist/es2019/api/EmojiResource.js +21 -114
  127. package/dist/es2019/api/EmojiUtils.js +11 -18
  128. package/dist/es2019/api/internal/Comparators.js +12 -48
  129. package/dist/es2019/api/internal/UsageFrequencyTracker.js +7 -24
  130. package/dist/es2019/api/media/MediaEmojiCache.js +9 -52
  131. package/dist/es2019/api/media/MediaImageLoader.js +2 -16
  132. package/dist/es2019/api/media/SiteEmojiResource.js +11 -31
  133. package/dist/es2019/api/media/TokenManager.js +4 -14
  134. package/dist/es2019/components/common/CachingEmoji.js +5 -12
  135. package/dist/es2019/components/common/DeleteButton.js +2 -3
  136. package/dist/es2019/components/common/Emoji.js +19 -47
  137. package/dist/es2019/components/common/EmojiActions.js +3 -16
  138. package/dist/es2019/components/common/EmojiButton.js +0 -5
  139. package/dist/es2019/components/common/EmojiDeletePreview.js +0 -11
  140. package/dist/es2019/components/common/EmojiErrorMessage.js +1 -2
  141. package/dist/es2019/components/common/EmojiPlaceholder.js +0 -5
  142. package/dist/es2019/components/common/EmojiPreviewComponent.js +1 -0
  143. package/dist/es2019/components/common/EmojiUploadPicker.js +2 -25
  144. package/dist/es2019/components/common/EmojiUploadPreview.js +0 -6
  145. package/dist/es2019/components/common/FileChooser.js +0 -6
  146. package/dist/es2019/components/common/LoadingEmojiComponent.js +2 -14
  147. package/dist/es2019/components/common/Popup.js +4 -22
  148. package/dist/es2019/components/common/RecordSelectionDefault.js +1 -1
  149. package/dist/es2019/components/common/ResourcedEmoji.js +1 -6
  150. package/dist/es2019/components/common/ResourcedEmojiComponent.js +2 -13
  151. package/dist/es2019/components/common/RetryableButton.js +1 -8
  152. package/dist/es2019/components/common/Scrollable.js +2 -12
  153. package/dist/es2019/components/common/ToneSelector.js +2 -8
  154. package/dist/es2019/components/common/UfoErrorBoundary.js +0 -2
  155. package/dist/es2019/components/common/UploadEmoji.js +2 -3
  156. package/dist/es2019/components/common/internal-types.js +0 -1
  157. package/dist/es2019/components/common/styles.js +12 -8
  158. package/dist/es2019/components/picker/CategorySelector.js +0 -22
  159. package/dist/es2019/components/picker/CategoryTracker.js +3 -13
  160. package/dist/es2019/components/picker/EmojiPicker.js +3 -17
  161. package/dist/es2019/components/picker/EmojiPickerCategoryHeading.js +2 -3
  162. package/dist/es2019/components/picker/EmojiPickerComponent.js +10 -43
  163. package/dist/es2019/components/picker/EmojiPickerEmojiRow.js +0 -2
  164. package/dist/es2019/components/picker/EmojiPickerFooter.js +0 -2
  165. package/dist/es2019/components/picker/EmojiPickerList.js +10 -45
  166. package/dist/es2019/components/picker/EmojiPickerListSearch.js +2 -19
  167. package/dist/es2019/components/picker/EmojiPickerSizes.js +1 -0
  168. package/dist/es2019/components/picker/EmojiPickerVirtualItems.js +1 -8
  169. package/dist/es2019/components/picker/VirtualList.js +3 -24
  170. package/dist/es2019/components/picker/styles.js +22 -10
  171. package/dist/es2019/components/picker/utils.js +0 -1
  172. package/dist/es2019/components/typeahead/EmojiTypeAhead.js +4 -21
  173. package/dist/es2019/components/typeahead/EmojiTypeAheadComponent.js +0 -42
  174. package/dist/es2019/components/typeahead/EmojiTypeAheadItem.js +0 -7
  175. package/dist/es2019/components/typeahead/EmojiTypeAheadList.js +4 -45
  176. package/dist/es2019/components/typeahead/styles.js +2 -1
  177. package/dist/es2019/components/uploader/EmojiUploadComponent.js +2 -15
  178. package/dist/es2019/components/uploader/EmojiUploader.js +2 -10
  179. package/dist/es2019/components/uploader/styles.js +5 -2
  180. package/dist/es2019/context/EmojiCommonProvider.js +0 -2
  181. package/dist/es2019/context/EmojiContextProvider.js +0 -1
  182. package/dist/es2019/hooks/useEmoji.js +2 -6
  183. package/dist/es2019/hooks/useEmojiContext.js +1 -1
  184. package/dist/es2019/index.js +12 -6
  185. package/dist/es2019/types.js +1 -11
  186. package/dist/es2019/util/DuplicateLimitedQueue.js +13 -35
  187. package/dist/es2019/util/StoredDuplicateLimitedQueue.js +5 -12
  188. package/dist/es2019/util/analytics/analytics.js +7 -23
  189. package/dist/es2019/util/analytics/samplingUfo.js +6 -32
  190. package/dist/es2019/util/analytics/ufoExperiences.js +0 -3
  191. package/dist/es2019/util/analytics/useSampledUFOComponentExperience.js +3 -7
  192. package/dist/es2019/util/constants.js +5 -4
  193. package/dist/es2019/util/filters.js +0 -3
  194. package/dist/es2019/util/image.js +3 -8
  195. package/dist/es2019/util/mouse.js +3 -3
  196. package/dist/es2019/util/storage-available.js +10 -7
  197. package/dist/es2019/util/type-helpers.js +6 -9
  198. package/dist/es2019/util/useInView.js +0 -2
  199. package/dist/es2019/version.json +1 -1
  200. package/dist/esm/api/EmojiLoader.js +2 -6
  201. package/dist/esm/api/EmojiRepository.js +16 -71
  202. package/dist/esm/api/EmojiRepositoryRegex.js +2 -0
  203. package/dist/esm/api/EmojiResource.js +20 -158
  204. package/dist/esm/api/EmojiUtils.js +27 -47
  205. package/dist/esm/api/internal/Comparators.js +12 -53
  206. package/dist/esm/api/internal/UsageFrequencyTracker.js +5 -29
  207. package/dist/esm/api/media/MediaEmojiCache.js +9 -55
  208. package/dist/esm/api/media/MediaImageLoader.js +4 -27
  209. package/dist/esm/api/media/SiteEmojiResource.js +14 -43
  210. package/dist/esm/api/media/TokenManager.js +6 -16
  211. package/dist/esm/components/common/CachingEmoji.js +18 -30
  212. package/dist/esm/components/common/DeleteButton.js +2 -3
  213. package/dist/esm/components/common/Emoji.js +44 -78
  214. package/dist/esm/components/common/EmojiActions.js +25 -40
  215. package/dist/esm/components/common/EmojiButton.js +4 -9
  216. package/dist/esm/components/common/EmojiDeletePreview.js +7 -24
  217. package/dist/esm/components/common/EmojiErrorMessage.js +3 -4
  218. package/dist/esm/components/common/EmojiPlaceholder.js +6 -11
  219. package/dist/esm/components/common/EmojiPreviewComponent.js +1 -0
  220. package/dist/esm/components/common/EmojiUploadPicker.js +30 -64
  221. package/dist/esm/components/common/EmojiUploadPreview.js +7 -19
  222. package/dist/esm/components/common/FileChooser.js +5 -11
  223. package/dist/esm/components/common/LoadingEmojiComponent.js +4 -20
  224. package/dist/esm/components/common/Popup.js +16 -36
  225. package/dist/esm/components/common/RecordSelectionDefault.js +1 -1
  226. package/dist/esm/components/common/ResourcedEmoji.js +1 -6
  227. package/dist/esm/components/common/ResourcedEmojiComponent.js +29 -51
  228. package/dist/esm/components/common/RetryableButton.js +4 -11
  229. package/dist/esm/components/common/Scrollable.js +6 -29
  230. package/dist/esm/components/common/ToneSelector.js +3 -13
  231. package/dist/esm/components/common/UfoErrorBoundary.js +1 -13
  232. package/dist/esm/components/common/UploadEmoji.js +2 -3
  233. package/dist/esm/components/common/internal-types.js +0 -1
  234. package/dist/esm/components/common/setSkinToneAriaLabelText.js +0 -2
  235. package/dist/esm/components/common/styles.js +12 -9
  236. package/dist/esm/components/picker/CategorySelector.js +4 -32
  237. package/dist/esm/components/picker/CategoryTracker.js +3 -13
  238. package/dist/esm/components/picker/EmojiPicker.js +5 -27
  239. package/dist/esm/components/picker/EmojiPickerCategoryHeading.js +4 -5
  240. package/dist/esm/components/picker/EmojiPickerComponent.js +60 -114
  241. package/dist/esm/components/picker/EmojiPickerEmojiRow.js +6 -8
  242. package/dist/esm/components/picker/EmojiPickerFooter.js +0 -2
  243. package/dist/esm/components/picker/EmojiPickerList.js +32 -77
  244. package/dist/esm/components/picker/EmojiPickerListSearch.js +11 -35
  245. package/dist/esm/components/picker/EmojiPickerSizes.js +1 -0
  246. package/dist/esm/components/picker/EmojiPickerVirtualItems.js +2 -26
  247. package/dist/esm/components/picker/VirtualList.js +11 -28
  248. package/dist/esm/components/picker/styles.js +22 -11
  249. package/dist/esm/components/picker/utils.js +0 -1
  250. package/dist/esm/components/typeahead/EmojiTypeAhead.js +11 -39
  251. package/dist/esm/components/typeahead/EmojiTypeAheadComponent.js +11 -65
  252. package/dist/esm/components/typeahead/EmojiTypeAheadItem.js +7 -24
  253. package/dist/esm/components/typeahead/EmojiTypeAheadList.js +10 -53
  254. package/dist/esm/components/typeahead/styles.js +2 -1
  255. package/dist/esm/components/uploader/EmojiUploadComponent.js +5 -25
  256. package/dist/esm/components/uploader/EmojiUploader.js +4 -22
  257. package/dist/esm/components/uploader/styles.js +5 -2
  258. package/dist/esm/context/EmojiCommonProvider.js +0 -2
  259. package/dist/esm/context/EmojiContextProvider.js +1 -6
  260. package/dist/esm/hooks/useEmoji.js +5 -13
  261. package/dist/esm/hooks/useEmojiContext.js +1 -1
  262. package/dist/esm/index.js +12 -6
  263. package/dist/esm/types.js +1 -11
  264. package/dist/esm/util/DuplicateLimitedQueue.js +13 -29
  265. package/dist/esm/util/StoredDuplicateLimitedQueue.js +5 -22
  266. package/dist/esm/util/analytics/analytics.js +14 -50
  267. package/dist/esm/util/analytics/samplingUfo.js +3 -51
  268. package/dist/esm/util/analytics/ufoExperiences.js +0 -3
  269. package/dist/esm/util/analytics/useSampledUFOComponentExperience.js +3 -7
  270. package/dist/esm/util/constants.js +5 -4
  271. package/dist/esm/util/filters.js +0 -3
  272. package/dist/esm/util/image.js +3 -8
  273. package/dist/esm/util/logger.js +0 -2
  274. package/dist/esm/util/mouse.js +3 -3
  275. package/dist/esm/util/storage-available.js +10 -7
  276. package/dist/esm/util/type-helpers.js +2 -12
  277. package/dist/esm/util/useInView.js +0 -2
  278. package/dist/esm/version.json +1 -1
  279. package/dist/types/types.d.ts +1 -1
  280. package/package.json +2 -2
@@ -1,6 +1,5 @@
1
1
  import { MAX_ORDINAL } from '../../util/constants';
2
2
  import { isEmojiVariationDescription } from '../../util/type-helpers';
3
-
4
3
  /**
5
4
  * Create the default sort comparator to be used for the user queries against emoji
6
5
  *
@@ -11,25 +10,22 @@ import { isEmojiVariationDescription } from '../../util/type-helpers';
11
10
  export function createSearchEmojiComparator(query, orderedIds) {
12
11
  const textQuery = query ? query.replace(/:/g, '').toLowerCase().trim() : undefined;
13
12
  const comparators = [];
14
-
15
13
  if (query) {
16
14
  comparators.push(new AsciiMatchComparator(query));
17
- } // Add the comparators to the 'chain'. The order of adding each comparator is important to the sort that is applied by the
18
- // ChainedEmojiComparator. (Which is why you may see the same 'if' a few times.)
15
+ }
19
16
 
17
+ // Add the comparators to the 'chain'. The order of adding each comparator is important to the sort that is applied by the
18
+ // ChainedEmojiComparator. (Which is why you may see the same 'if' a few times.)
20
19
 
21
20
  if (textQuery) {
22
21
  comparators.push(new ExactShortNameMatchComparator(textQuery));
23
22
  }
24
-
25
23
  if (orderedIds && orderedIds.length) {
26
24
  comparators.push(new UsageFrequencyComparator(orderedIds));
27
25
  }
28
-
29
26
  if (textQuery) {
30
27
  comparators.push(new QueryStringPositionMatchComparator(textQuery, 'shortName'), new QueryStringPositionMatchComparator(textQuery, 'name'));
31
28
  }
32
-
33
29
  comparators.push(OrderComparator.Instance, AlphabeticalShortnameComparator.Instance);
34
30
  const comparator = new ChainedEmojiComparator(...comparators);
35
31
  comparator.compare = comparator.compare.bind(comparator);
@@ -40,6 +36,7 @@ export function createUsageOnlyEmojiComparator(orderedIds) {
40
36
  comparator.compare = comparator.compare.bind(comparator);
41
37
  return comparator;
42
38
  }
39
+
43
40
  /**
44
41
  * Returns a number representing the result of comparing e1 and e2.
45
42
  * Compatible with Array.sort, which is to say -
@@ -59,55 +56,46 @@ export class ChainedEmojiComparator {
59
56
  constructor(...comparators) {
60
57
  this.chain = comparators;
61
58
  }
62
-
63
59
  compare(e1, e2) {
64
60
  for (let i = 0; i < this.chain.length; i++) {
65
61
  const result = this.chain[i].compare(e1, e2);
66
-
67
62
  if (result !== 0) {
68
63
  return result;
69
64
  }
70
65
  }
71
-
72
66
  return 0;
73
67
  }
74
-
75
68
  }
69
+
76
70
  /**
77
71
  * Orders two emoji such that if one of them has an ascii representation that exactly matches the query then it will
78
72
  * be ordered first.
79
73
  */
80
-
81
74
  export class AsciiMatchComparator {
82
75
  constructor(query) {
83
76
  this.query = query;
84
77
  }
85
-
86
78
  compare(e1, e2) {
87
79
  const e1HasAscii = e1.ascii && e1.ascii.indexOf(this.query) !== -1;
88
80
  const e2HasAscii = e2.ascii && e2.ascii.indexOf(this.query) !== -1;
89
-
90
81
  if (e1HasAscii && !e2HasAscii) {
91
82
  return -1;
92
83
  } else if (!e1HasAscii && e2HasAscii) {
93
84
  return 1;
94
85
  }
95
-
96
86
  return 0;
97
87
  }
98
-
99
88
  }
89
+
100
90
  /**
101
91
  * Orders two emoji such that the one who's shortname matches the query exactly comes first. If there are matching
102
92
  * shortnames then the type of emoji is taken into account with SITE emoji coming first.
103
93
  */
104
-
105
94
  export class ExactShortNameMatchComparator {
106
95
  constructor(query) {
107
96
  this.colonQuery = `:${query}:`;
108
97
  this.typeComparator = new EmojiTypeComparator(true);
109
98
  }
110
-
111
99
  compare(e1, e2) {
112
100
  if (e1.shortName === this.colonQuery && e2.shortName === this.colonQuery) {
113
101
  return this.typeComparator.compare(e1, e2);
@@ -116,18 +104,16 @@ export class ExactShortNameMatchComparator {
116
104
  } else if (e2.shortName === this.colonQuery) {
117
105
  return 1;
118
106
  }
119
-
120
107
  return 0;
121
108
  }
122
-
123
109
  }
110
+
124
111
  /**
125
112
  * Orders two emoji based on their type, with the types being STANDARD, ATLASSIAN and SITE (in that order).
126
113
  * If the comparator is configured to 'reverse' then the order will be SITE, ATLASSIAN, STANDARD.
127
114
  *
128
115
  * Regardless of the reverse setting, an unknown type will always come last.
129
116
  */
130
-
131
117
  export class EmojiTypeComparator {
132
118
  constructor(reverse) {
133
119
  if (reverse) {
@@ -136,35 +122,30 @@ export class EmojiTypeComparator {
136
122
  this.typeToNumber = new Map([['STANDARD', 0], ['ATLASSIAN', 1], ['SITE', 2]]);
137
123
  }
138
124
  }
139
-
140
125
  compare(e1, e2) {
141
126
  return this.emojiTypeToOrdinal(e1) - this.emojiTypeToOrdinal(e2);
142
127
  }
143
-
144
128
  emojiTypeToOrdinal(emoji) {
145
129
  let ordinal = this.typeToNumber.get(emoji.type);
146
-
147
130
  if (ordinal === undefined) {
148
131
  ordinal = 10;
149
132
  }
150
-
151
133
  return ordinal;
152
134
  }
153
-
154
135
  }
136
+
155
137
  /**
156
138
  * Order two emoji such as the one which is more frequently used comes first. If neither have any usage
157
139
  * information then leave their order unchanged.
158
140
  */
159
-
160
141
  export class UsageFrequencyComparator {
161
142
  // A Map of emoji base Id to their order in a least of most frequently used
162
- constructor(orderedIds) {
163
- this.positionLookup = new Map(); // Make ordering start from 1 to avoid having zero in the map (which is falsey)
164
143
 
144
+ constructor(orderedIds) {
145
+ this.positionLookup = new Map();
146
+ // Make ordering start from 1 to avoid having zero in the map (which is falsey)
165
147
  orderedIds.map((id, index) => this.positionLookup.set(id, index + 1));
166
148
  }
167
-
168
149
  compare(e1, e2) {
169
150
  if (!e1.id || !e2.id) {
170
151
  return 0; // this shouldn't occur. Leave position unchanged if there is any missing id.
@@ -174,31 +155,25 @@ export class UsageFrequencyComparator {
174
155
  let i2 = this.getPositionInOrder(e2);
175
156
  return i1 - i2;
176
157
  }
158
+
177
159
  /**
178
160
  * Get the ordinal representing the position of this emoji.
179
161
  *
180
162
  * @param id the id of the emoji
181
163
  */
182
-
183
-
184
164
  getPositionInOrder(emoji) {
185
165
  let id = emoji.id ? emoji.id : '0';
186
-
187
166
  if (isEmojiVariationDescription(emoji)) {
188
167
  id = emoji.baseId;
189
168
  }
190
-
191
169
  const position = this.positionLookup.get(id);
192
-
193
170
  if (position) {
194
171
  return position;
195
172
  } else {
196
173
  return MAX_ORDINAL;
197
174
  }
198
175
  }
199
-
200
176
  }
201
-
202
177
  /**
203
178
  * A comparator that will sort higher an emoji which matches the query string earliest in the indicated
204
179
  * property.
@@ -210,14 +185,11 @@ export class QueryStringPositionMatchComparator {
210
185
  */
211
186
  constructor(query, propertyToCompare) {
212
187
  this.query = query;
213
-
214
188
  if (!propertyToCompare) {
215
189
  throw new Error('propertyToCompare is required');
216
190
  }
217
-
218
191
  this.propertyName = propertyToCompare;
219
192
  }
220
-
221
193
  getScore(emoji) {
222
194
  // It is fine to do override the null check here because we are checking
223
195
  // it on the constructor.
@@ -225,35 +197,27 @@ export class QueryStringPositionMatchComparator {
225
197
  const score = propertyValue ? propertyValue.indexOf(this.query) : MAX_ORDINAL;
226
198
  return score === -1 ? MAX_ORDINAL : score;
227
199
  }
228
-
229
200
  compare(e1, e2) {
230
201
  return this.getScore(e1) - this.getScore(e2);
231
202
  }
232
-
233
203
  }
234
204
  export class OrderComparator {
235
205
  constructor() {}
236
-
237
206
  static get Instance() {
238
207
  return this.INSTANCE || (this.INSTANCE = new this());
239
208
  }
240
-
241
209
  compare(e1, e2) {
242
210
  let o1 = e1.order ? e1.order : MAX_ORDINAL;
243
211
  let o2 = e2.order ? e2.order : MAX_ORDINAL;
244
212
  return o1 - o2;
245
213
  }
246
-
247
214
  }
248
215
  export class AlphabeticalShortnameComparator {
249
216
  constructor() {}
250
-
251
217
  static get Instance() {
252
218
  return this.INSTANCE || (this.INSTANCE = new this());
253
219
  }
254
-
255
220
  compare(e1, e2) {
256
221
  return e1.shortName.localeCompare(e2.shortName);
257
222
  }
258
-
259
223
  }
@@ -4,6 +4,7 @@ import { localStoragePrefix } from '../../util/constants';
4
4
  import DuplicateLimitedQueue from '../../util/DuplicateLimitedQueue';
5
5
  import StoredDuplicateLimitedQueue from '../../util/StoredDuplicateLimitedQueue';
6
6
  import storageAvailable from '../../util/storage-available';
7
+
7
8
  /**
8
9
  * Keeps track of the last 150 emoji usages, although limiting the maximum count for a single emoji to 25 to
9
10
  * ensure we don't end up with only a single emoji being recorded. Usage is persisted to local storage for
@@ -13,38 +14,33 @@ import storageAvailable from '../../util/storage-available';
13
14
  * variations are not collapsed in this way and will be tracked per gender. This decision reflects the UI of
14
15
  * the EmojiPicker component.
15
16
  */
16
-
17
17
  export class UsageFrequencyTracker {
18
18
  constructor(useStorageIfPossible = true) {
19
19
  const options = UsageFrequencyTracker.queueOptions;
20
-
21
20
  if (useStorageIfPossible && options.storage) {
22
- const queueOptions = { ...options,
21
+ const queueOptions = {
22
+ ...options,
23
23
  storage: options.storage
24
24
  };
25
25
  this.queue = new StoredDuplicateLimitedQueue(queueOptions);
26
26
  } else {
27
27
  this.queue = new DuplicateLimitedQueue(options);
28
28
  }
29
-
30
29
  this.gateway = new Gateway(10);
31
30
  }
31
+
32
32
  /**
33
33
  * Record the fact that the supplied emoji was used. You should note that usage is updated asynchronously so you can not
34
34
  * count on getOrder() reflecting this usage immediately.
35
35
  *
36
36
  * @param emoji the emoji who's usage is to be recorded. If the emoji has no id then no usage will be recorded
37
37
  */
38
-
39
-
40
38
  recordUsage(emoji) {
41
39
  let emojiId = emoji.id;
42
-
43
40
  if (emojiId) {
44
41
  if (isEmojiVariationDescription(emoji)) {
45
42
  emojiId = emoji.baseId;
46
43
  }
47
-
48
44
  this.gateway.submit(() => {
49
45
  if (emojiId) {
50
46
  this.queue.enqueue(emojiId);
@@ -52,57 +48,48 @@ export class UsageFrequencyTracker {
52
48
  });
53
49
  }
54
50
  }
51
+
55
52
  /**
56
53
  * Returns an array of emoji id (without skin tone variations) sorted by most used to least used. If there
57
54
  * are no usages then an empty array will be returned.
58
55
  */
59
-
60
-
61
56
  getOrder() {
62
57
  return this.queue.getItemsOrderedByDuplicateCount();
63
58
  }
59
+
64
60
  /**
65
61
  * Exposed for testing only. Clear any recorded usage.
66
62
  */
67
-
68
-
69
63
  clear() {
70
64
  this.queue.clear();
71
65
  }
72
-
73
66
  }
74
-
75
67
  _defineProperty(UsageFrequencyTracker, "queueOptions", {
76
68
  storage: storageAvailable('localStorage') ? window.localStorage : undefined,
77
69
  storagePrefix: localStoragePrefix,
78
70
  maxDuplicates: 25,
79
71
  minUniqueItems: 5
80
72
  });
81
-
82
73
  export class Gateway {
83
74
  constructor(maximumPermitted) {
84
75
  if (maximumPermitted < 1) {
85
76
  throw new RangeError('The maximumPermitted parameter must be 1 or more.');
86
77
  }
87
-
88
78
  this.maximumPermitted = maximumPermitted;
89
79
  this.count = 0;
90
80
  }
81
+
91
82
  /**
92
83
  * Run the supplied function if the count of already submitted work allows it. Drop the work
93
84
  * if it's not allowed to run.
94
85
  *
95
86
  * Will return true if the function has been submitted or false if it was not submitted.
96
87
  */
97
-
98
-
99
88
  submit(f) {
100
89
  if (this.count >= this.maximumPermitted) {
101
90
  return false;
102
91
  }
103
-
104
92
  this.count++;
105
-
106
93
  const wrappedFunc = () => {
107
94
  try {
108
95
  f();
@@ -110,16 +97,12 @@ export class Gateway {
110
97
  this.completed();
111
98
  }
112
99
  };
113
-
114
100
  if (typeof window !== 'undefined') {
115
101
  window.setTimeout(wrappedFunc);
116
102
  }
117
-
118
103
  return true;
119
104
  }
120
-
121
105
  completed() {
122
106
  this.count--;
123
107
  }
124
-
125
108
  }
@@ -3,19 +3,13 @@ import { convertMediaToImageEmoji, isMediaRepresentation, isPromise } from '../.
3
3
  import MediaImageLoader from './MediaImageLoader';
4
4
  import debug from '../../util/logger';
5
5
  import { LRUMap } from 'lru_map';
6
-
7
6
  const getRequiredRepresentation = (emoji, useAlt) => useAlt ? emoji.altRepresentation : emoji.representation;
8
-
9
7
  const isUnsupportedBrowser = () => {
10
- const isIE =
11
- /*@cc_on!@*/
12
- false || !!document.documentMode; // Internet Explorer 6-11
13
-
8
+ const isIE = /*@cc_on!@*/false || !!document.documentMode; // Internet Explorer 6-11
14
9
  const isEdge = !isIE && !!window.StyleMedia; // Edge 20+
15
10
 
16
11
  return isIE || isEdge;
17
12
  };
18
-
19
13
  /**
20
14
  * For browsers that support caching for resources
21
15
  * regardless of originally supplied headers (basically everything but Firefox).
@@ -23,27 +17,21 @@ const isUnsupportedBrowser = () => {
23
17
  export class BrowserCacheStrategy {
24
18
  constructor(mediaImageLoader) {
25
19
  _defineProperty(this, "cachedImageUrls", new Set());
26
-
27
20
  debug('BrowserCacheStrategy');
28
21
  this.mediaImageLoader = mediaImageLoader;
29
22
  }
30
-
31
23
  loadEmoji(emoji, useAlt) {
32
24
  const representation = getRequiredRepresentation(emoji, useAlt);
33
-
34
25
  if (!isMediaRepresentation(representation)) {
35
26
  return emoji;
36
27
  }
37
-
38
28
  const {
39
29
  mediaPath
40
30
  } = representation;
41
-
42
31
  if (this.cachedImageUrls.has(mediaPath)) {
43
32
  // Already cached
44
33
  return emoji;
45
34
  }
46
-
47
35
  return this.mediaImageLoader.loadMediaImage(mediaPath).then(() => {
48
36
  // Media is loaded, can use original URL now, so just return original emoji
49
37
  this.cachedImageUrls.add(mediaPath);
@@ -52,11 +40,9 @@ export class BrowserCacheStrategy {
52
40
  return undefined;
53
41
  });
54
42
  }
55
-
56
43
  optimisticRendering() {
57
44
  return true;
58
45
  }
59
-
60
46
  static supported(mediaPath, mediaImageLoader) {
61
47
  // IE/Edge uses memory cache strategy else images can fail to load
62
48
  // from a clean cache/if they are downloaded from the service
@@ -64,8 +50,8 @@ export class BrowserCacheStrategy {
64
50
  if (isUnsupportedBrowser()) {
65
51
  return Promise.resolve(false);
66
52
  }
67
-
68
- return mediaImageLoader.loadMediaImage(mediaPath).then(() => // Image should be cached in browser, if supported it should be accessible from the cache by an <img/>
53
+ return mediaImageLoader.loadMediaImage(mediaPath).then(() =>
54
+ // Image should be cached in browser, if supported it should be accessible from the cache by an <img/>
69
55
  // Try to load without via image to confirm this support (this fails in Firefox)
70
56
  new Promise(resolve => {
71
57
  const img = new Image();
@@ -78,11 +64,11 @@ export class BrowserCacheStrategy {
78
64
  img.src = mediaPath;
79
65
  })).catch(() => false);
80
66
  }
81
-
82
67
  }
83
- const maxImageCached = 1000; // Don't cache images large than this - dataUrl size in characters
84
-
68
+ const maxImageCached = 1000;
69
+ // Don't cache images large than this - dataUrl size in characters
85
70
  const maxImageSize = 10000;
71
+
86
72
  /**
87
73
  * For browsers that do no cache images without equivalent headers (e.g. Firefox).
88
74
  *
@@ -92,53 +78,45 @@ const maxImageSize = 10000;
92
78
  * Images are still cached by the browser, but loading in asynchronous with
93
79
  * small delay noticable to the end user.
94
80
  */
95
-
96
81
  export class MemoryCacheStrategy {
97
82
  constructor(mediaImageLoader) {
98
83
  debug('MemoryCacheStrategy');
99
84
  this.mediaImageLoader = mediaImageLoader;
100
85
  this.dataURLCache = new LRUMap(maxImageCached);
101
86
  }
102
-
103
87
  loadEmoji(emoji, useAlt) {
104
88
  const representation = getRequiredRepresentation(emoji, useAlt);
105
-
106
89
  if (!isMediaRepresentation(representation)) {
107
90
  return emoji;
108
91
  }
109
-
110
92
  const {
111
93
  mediaPath
112
94
  } = representation;
113
95
  const dataURL = this.dataURLCache.get(mediaPath);
114
-
115
96
  if (dataURL) {
116
97
  // Already cached
117
98
  return convertMediaToImageEmoji(emoji, dataURL, useAlt);
118
- } // Not cached, load
119
-
99
+ }
120
100
 
101
+ // Not cached, load
121
102
  return this.mediaImageLoader.loadMediaImage(mediaPath).then(dataURL => {
122
103
  const loadedEmoji = convertMediaToImageEmoji(emoji, dataURL, useAlt);
123
-
124
104
  if (dataURL.length <= maxImageSize) {
125
105
  // Only cache if not large than max size
126
106
  this.dataURLCache.set(mediaPath, dataURL);
127
107
  } else {
128
108
  debug('No caching as image is too large', dataURL.length, dataURL.slice(0, 15), emoji.shortName);
129
109
  }
130
-
131
110
  return loadedEmoji;
132
111
  }).catch(() => {
133
112
  return undefined;
134
113
  });
135
114
  }
136
-
137
115
  optimisticRendering() {
138
116
  return false;
139
117
  }
140
-
141
118
  }
119
+
142
120
  /**
143
121
  * Provides a cache for Media Emoji.
144
122
  *
@@ -146,53 +124,40 @@ export class MemoryCacheStrategy {
146
124
  *
147
125
  * Otherwise, they are loaded and returned via a promise.
148
126
  */
149
-
150
127
  export default class MediaEmojiCache {
151
128
  constructor(tokenManager) {
152
129
  _defineProperty(this, "waitingInitUrls", []);
153
-
154
130
  debug('MediaEmojiCache');
155
131
  this.mediaImageLoader = new MediaImageLoader(tokenManager);
156
132
  }
157
-
158
133
  loadEmoji(emoji, useAlt) {
159
134
  const representation = getRequiredRepresentation(emoji, useAlt);
160
-
161
135
  if (!isMediaRepresentation(representation)) {
162
136
  return emoji;
163
137
  }
164
-
165
138
  const {
166
139
  mediaPath
167
140
  } = representation;
168
141
  const emojiCache = this.getCache(mediaPath);
169
-
170
142
  if (isPromise(emojiCache)) {
171
143
  // Promise based
172
144
  return emojiCache.then(cache => cache.loadEmoji(emoji, useAlt)).catch(() => undefined);
173
145
  }
174
-
175
146
  return emojiCache.loadEmoji(emoji, useAlt);
176
147
  }
177
-
178
148
  optimisticRendering(url) {
179
149
  const emojiCache = this.getCache(url);
180
-
181
150
  if (isPromise(emojiCache)) {
182
151
  // Promise based
183
152
  return emojiCache.then(cache => cache.optimisticRendering()).catch(() => false);
184
153
  }
185
-
186
154
  return emojiCache.optimisticRendering();
187
155
  }
188
-
189
156
  getCache(url) {
190
157
  if (this.cache) {
191
158
  return this.cache;
192
159
  }
193
-
194
160
  this.waitingInitUrls.push(url);
195
-
196
161
  if (!this.cacheLoading) {
197
162
  this.cacheLoading = this.initCache().then(cache => {
198
163
  this.cache = cache;
@@ -203,30 +168,22 @@ export default class MediaEmojiCache {
203
168
  throw err;
204
169
  });
205
170
  }
206
-
207
171
  return this.cacheLoading;
208
172
  }
209
-
210
173
  initCache() {
211
174
  const url = this.waitingInitUrls.pop();
212
-
213
175
  if (!url) {
214
176
  return Promise.reject('Unable to initialise cache based on provided url(s)');
215
177
  }
216
-
217
178
  return BrowserCacheStrategy.supported(url, this.mediaImageLoader).then(supported => {
218
179
  this.waitingInitUrls = []; // clear
219
-
220
180
  this.cacheLoading = undefined;
221
-
222
181
  if (supported) {
223
182
  return new BrowserCacheStrategy(this.mediaImageLoader);
224
183
  }
225
-
226
184
  return new MemoryCacheStrategy(this.mediaImageLoader);
227
185
  }).catch(() => {
228
186
  return this.initCache();
229
187
  });
230
188
  }
231
-
232
189
  }
@@ -6,22 +6,16 @@ const defaultMaxRetriesOnNotFound = 2;
6
6
  export default class MediaImageLoader {
7
7
  constructor(tokenManager, options) {
8
8
  _defineProperty(this, "mediaImageQueue", []);
9
-
10
9
  _defineProperty(this, "activeProcessing", 0);
11
-
12
10
  _defineProperty(this, "pendingRequests", new Map());
13
-
14
11
  this.concurrentDownloadLimit = options && options.concurrentDownloadLimit || defaultConcurrentDownloadLimit;
15
12
  this.tokenManager = tokenManager;
16
13
  }
17
-
18
14
  loadMediaImage(url) {
19
15
  const maybePending = this.pendingRequests.get(url);
20
-
21
16
  if (maybePending !== undefined) {
22
17
  return maybePending;
23
18
  }
24
-
25
19
  const pending = new Promise((resolve, reject) => {
26
20
  this.mediaImageQueue.push({
27
21
  url,
@@ -39,15 +33,12 @@ export default class MediaImageLoader {
39
33
  this.pendingRequests.set(url, pending);
40
34
  return pending;
41
35
  }
42
-
43
36
  getQueueSize() {
44
37
  return this.mediaImageQueue.length;
45
38
  }
46
-
47
39
  getActiveDownloads() {
48
40
  return this.activeProcessing;
49
41
  }
50
-
51
42
  processFromQueue() {
52
43
  while (this.activeProcessing < this.concurrentDownloadLimit && this.mediaImageQueue.length > 0) {
53
44
  this.activeProcessing++;
@@ -72,16 +63,13 @@ export default class MediaImageLoader {
72
63
  });
73
64
  }
74
65
  }
75
-
76
66
  completedItem() {
77
67
  this.activeProcessing--;
78
68
  this.processFromQueue();
79
69
  }
80
-
81
70
  delay(durationInMillis) {
82
71
  return new Promise(resolve => setTimeout(resolve, durationInMillis));
83
72
  }
84
-
85
73
  requestMediaEmoji(url, token, retryOnAuthError, retriesOnNotFound = defaultMaxRetriesOnNotFound) {
86
74
  return imageAcceptHeader().then(acceptHeader => {
87
75
  // Media REST API: https://media-api-internal.atlassian.io/api.html#file__fileId__image_get
@@ -103,20 +91,18 @@ export default class MediaImageLoader {
103
91
  } else if (response.ok) {
104
92
  return response.blob().then(blob => this.readBlob(blob));
105
93
  }
106
-
107
94
  throw new Error(`Unable to load media image. Status=${response.status} ${response.statusText}`);
108
95
  });
109
96
  });
110
97
  }
111
-
112
98
  readBlob(blob) {
113
99
  return new Promise((resolve, reject) => {
114
- const reader = new FileReader(); // TODO: [ts30] Add proper handling for null and ArrayBuffer
100
+ const reader = new FileReader();
115
101
 
102
+ // TODO: [ts30] Add proper handling for null and ArrayBuffer
116
103
  reader.addEventListener('load', () => resolve(reader.result));
117
104
  reader.addEventListener('error', () => reject(reader.error));
118
105
  reader.readAsDataURL(blob);
119
106
  });
120
107
  }
121
-
122
108
  }