@atlaskit/mention 27.17.1 → 27.18.1

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 +40 -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 +2 -2
  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,152 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
+ var CacheEntry = /*#__PURE__*/function () {
8
+ function CacheEntry(pres, timeout) {
9
+ _classCallCheck(this, CacheEntry);
10
+ this.presence = pres;
11
+ this.expiry = Date.now() + timeout;
12
+ }
13
+ return _createClass(CacheEntry, [{
14
+ key: "expired",
15
+ value: function expired() {
16
+ return Date.now() > this.expiry;
17
+ }
18
+ }]);
19
+ }();
20
+ export var DefaultPresenceCache = /*#__PURE__*/function () {
21
+ function DefaultPresenceCache(cacheTimeout, cacheTrigger) {
22
+ _classCallCheck(this, DefaultPresenceCache);
23
+ this.expiryInMillis = cacheTimeout ? cacheTimeout : DefaultPresenceCache.defaultTimeout;
24
+ this.flushTrigger = cacheTrigger ? cacheTrigger : DefaultPresenceCache.defaultFlushTrigger;
25
+ this.cache = {};
26
+ this.size = 0;
27
+ }
28
+
29
+ /**
30
+ * Precondition: _delete is only called internally if userId exists in cache
31
+ * Removes cache entry
32
+ * @param userId
33
+ */
34
+ return _createClass(DefaultPresenceCache, [{
35
+ key: "_delete",
36
+ value: function _delete(userId) {
37
+ delete this.cache[userId];
38
+ this.size--;
39
+ }
40
+
41
+ /**
42
+ * Checks a cache entry and calls delete if the info has expired
43
+ * @param userId
44
+ */
45
+ }, {
46
+ key: "_deleteIfExpired",
47
+ value: function _deleteIfExpired(userId) {
48
+ if (this.contains(userId) && this.cache[userId].expired()) {
49
+ this._delete(userId);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Cleans expired entries from cache
55
+ */
56
+ }, {
57
+ key: "_removeExpired",
58
+ value: function _removeExpired() {
59
+ var _this = this;
60
+ Object.keys(this.cache).forEach(function (id) {
61
+ _this._deleteIfExpired(id);
62
+ });
63
+ }
64
+
65
+ /**
66
+ * Checks if a user exists in the cache
67
+ * @param userId
68
+ */
69
+ }, {
70
+ key: "contains",
71
+ value: function contains(userId) {
72
+ return this.cache.hasOwnProperty(userId);
73
+ }
74
+
75
+ /**
76
+ * Retrieves a presence from the cache after checking for expired entries
77
+ * @param userId - to index the cache
78
+ * @returns Presence - the presence that matches the userId
79
+ */
80
+ }, {
81
+ key: "get",
82
+ value: function get(userId) {
83
+ this._deleteIfExpired(userId);
84
+ if (!this.contains(userId)) {
85
+ return {};
86
+ }
87
+ return this.cache[userId].presence;
88
+ }
89
+
90
+ /**
91
+ * Retrieve multiple presences at once from the cache
92
+ * @param userIds - to index the cache
93
+ * @returns PresenceMap - A map of userIds to cached Presences
94
+ */
95
+ }, {
96
+ key: "getBulk",
97
+ value: function getBulk(userIds) {
98
+ var presences = {};
99
+ var _iterator = _createForOfIteratorHelper(userIds),
100
+ _step;
101
+ try {
102
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
103
+ var _userId = _step.value;
104
+ if (this.contains(_userId)) {
105
+ presences[_userId] = this.get(_userId);
106
+ }
107
+ }
108
+ } catch (err) {
109
+ _iterator.e(err);
110
+ } finally {
111
+ _iterator.f();
112
+ }
113
+ return presences;
114
+ }
115
+
116
+ /**
117
+ * For a given list of ids, returns a subset
118
+ * of all the ids with missing cache entries.
119
+ * @param userIds - to index the cache
120
+ * @returns string[] - ids missing from the cache
121
+ */
122
+ }, {
123
+ key: "getMissingUserIds",
124
+ value: function getMissingUserIds(userIds) {
125
+ var _this2 = this;
126
+ return userIds.filter(function (id) {
127
+ return !_this2.contains(id);
128
+ });
129
+ }
130
+
131
+ /**
132
+ * Precondition: presMap only contains ids of users not in cache
133
+ * expired users must first be removed then reinserted with updated presence
134
+ * Updates the cache by adding the new Presence entries and setting the expiry time
135
+ * @param presMap
136
+ */
137
+ }, {
138
+ key: "update",
139
+ value: function update(presMap) {
140
+ var _this3 = this;
141
+ if (this.size >= this.flushTrigger) {
142
+ this._removeExpired();
143
+ }
144
+ Object.keys(presMap).forEach(function (userId) {
145
+ _this3.cache[userId] = new CacheEntry(presMap[userId], _this3.expiryInMillis);
146
+ _this3.size++;
147
+ });
148
+ }
149
+ }]);
150
+ }();
151
+ _defineProperty(DefaultPresenceCache, "defaultTimeout", 20000);
152
+ _defineProperty(DefaultPresenceCache, "defaultFlushTrigger", 50);
@@ -0,0 +1,84 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
+ export var DefaultPresenceParser = /*#__PURE__*/function () {
8
+ function DefaultPresenceParser() {
9
+ _classCallCheck(this, DefaultPresenceParser);
10
+ }
11
+ return _createClass(DefaultPresenceParser, [{
12
+ key: "mapState",
13
+ value: function mapState(state) {
14
+ if (state === 'unavailable') {
15
+ return 'offline';
16
+ } else if (state === 'available') {
17
+ return 'online';
18
+ } else {
19
+ return state;
20
+ }
21
+ }
22
+ }, {
23
+ key: "parse",
24
+ value: function parse(response) {
25
+ var presences = {};
26
+ if (response.hasOwnProperty('data') && response['data'].hasOwnProperty('PresenceBulk')) {
27
+ var results = response['data'].PresenceBulk;
28
+ // Store map of state and time indexed by userId. Ignore null results.
29
+ var _iterator = _createForOfIteratorHelper(results),
30
+ _step;
31
+ try {
32
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
33
+ var user = _step.value;
34
+ if (user.userId && user.state) {
35
+ var state = DefaultPresenceParser.extractState(user) || user.state;
36
+ presences[user.userId] = {
37
+ status: this.mapState(state)
38
+ };
39
+ } else if (!user.hasOwnProperty('userId') || !user.hasOwnProperty('state')) {
40
+ // eslint-disable-next-line no-console
41
+ console.error('Unexpected response from presence service contains keys: ' + Object.keys(user));
42
+ }
43
+ }
44
+ } catch (err) {
45
+ _iterator.e(err);
46
+ } finally {
47
+ _iterator.f();
48
+ }
49
+ }
50
+ return presences;
51
+ }
52
+ }], [{
53
+ key: "extractState",
54
+ value: function extractState(presence) {
55
+ if (DefaultPresenceParser.isFocusState(presence)) {
56
+ return DefaultPresenceParser.FOCUS_STATE;
57
+ }
58
+ return presence.state;
59
+ }
60
+
61
+ /*
62
+ This is a bit of an odd exception. In the case where a user is in "Focus Mode", their presence state
63
+ is returned as 'busy' along with a `stateMetadata` object containing a `focus` field.
64
+ In this case we ignore the value of the `state` field and treat the presence as a 'focus' state.
65
+ */
66
+ }, {
67
+ key: "isFocusState",
68
+ value: function isFocusState(presence) {
69
+ if (presence.stateMetadata) {
70
+ try {
71
+ var metadata = JSON.parse(presence.stateMetadata);
72
+ return metadata && !!metadata.focus;
73
+ } catch (e) {
74
+ // eslint-disable-next-line no-console
75
+ console.error("Failed to parse presence's stateMetadata for user with id ".concat(presence.userId, ": ").concat(presence.stateMetadata));
76
+ // eslint-disable-next-line no-console
77
+ console.error(e);
78
+ }
79
+ }
80
+ return false;
81
+ }
82
+ }]);
83
+ }();
84
+ _defineProperty(DefaultPresenceParser, "FOCUS_STATE", 'focus');
@@ -0,0 +1,9 @@
1
+ import _createClass from "@babel/runtime/helpers/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ export var HttpError = /*#__PURE__*/_createClass(function HttpError(statusCode, statusMessage) {
4
+ _classCallCheck(this, HttpError);
5
+ this.statusCode = statusCode;
6
+ this.message = statusMessage;
7
+ this.name = 'HttpError';
8
+ this.stack = new Error().stack;
9
+ });
@@ -1,202 +1,17 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
6
- import { MentionNameStatus } from '../types';
7
- import { fireAnalyticsMentionHydrationEvent } from '../util/analytics';
8
-
9
- /** A queue for user ids */
10
-
11
- export var DefaultMentionNameResolver = /*#__PURE__*/function () {
12
- function DefaultMentionNameResolver(client) {
13
- var _this = this;
14
- var analyticsProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
15
- var onResolvedAll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {};
16
- _classCallCheck(this, DefaultMentionNameResolver);
17
- _defineProperty(this, "nameCache", new Map());
18
- _defineProperty(this, "nameQueue", new Map());
19
- _defineProperty(this, "nameStartTime", new Map());
20
- _defineProperty(this, "processingQueue", new Map());
21
- _defineProperty(this, "debounce", 0);
22
- _defineProperty(this, "debounceOnResolve", null);
23
- _defineProperty(this, "isOnResolvedAllCalled", false);
24
- _defineProperty(this, "processQueue", function () {
25
- clearTimeout(_this.debounce);
26
- _this.debounce = 0;
27
- var _this$splitQueueAtLim = _this.splitQueueAtLimit(),
28
- queue = _this$splitQueueAtLim.queue,
29
- extraQueue = _this$splitQueueAtLim.extraQueue;
30
- _this.nameQueue = extraQueue;
31
- _this.processingQueue = mergeNameResolverQueues(_this.processingQueue, queue);
32
- _this.client.lookupMentionNames(Array.from(queue.keys())).then(function (response) {
33
- response.forEach(function (mentionDetail) {
34
- var id = mentionDetail.id;
35
- queue.delete(id);
36
- _this.resolveQueueItem(mentionDetail);
37
- });
38
- queue.forEach(function (_callback, id) {
39
- // No response from client for these ids treat as unknown
40
- _this.resolveQueueItem({
41
- id: id,
42
- status: MentionNameStatus.UNKNOWN
43
- });
44
- });
45
- }).catch(function () {
46
- // Service completely failed, reject all items in the queue
47
- queue.forEach(function (_callback, id) {
48
- _this.resolveQueueItem({
49
- id: id,
50
- status: MentionNameStatus.SERVICE_ERROR
51
- });
52
- });
53
- });
54
-
55
- // Make sure anything left in the queue gets processed.
56
- if (_this.nameQueue.size > 0) {
57
- _this.scheduleProcessQueue();
58
- } else {
59
- _this.scheduleOnAllResolved();
60
- }
61
- });
62
- this.client = client;
63
- this.fireHydrationEvent = fireAnalyticsMentionHydrationEvent(analyticsProps);
64
- // If provided, this will be called once all pending mentions in the queue are resolved.
65
- // A sample usage is scrolling to a mention on page load, after the mentions have loadad.
66
- this.onResolvedAll = onResolvedAll;
67
- }
68
- return _createClass(DefaultMentionNameResolver, [{
69
- key: "lookupName",
70
- value: function lookupName(id) {
71
- var _this2 = this;
72
- var name = this.nameCache.get(id);
73
- if (name) {
74
- this.fireAnalytics(true, name);
75
- if (this.nameQueue.size === 0) {
76
- this.scheduleOnAllResolved();
77
- }
78
- return name;
79
- }
80
- return new Promise(function (resolve) {
81
- var processingItems = _this2.processingQueue.get(id);
82
- if (processingItems) {
83
- _this2.processingQueue.set(id, [].concat(_toConsumableArray(processingItems), [resolve]));
84
- }
85
- var queuedItems = _this2.nameQueue.get(id) || [];
86
- _this2.nameQueue.set(id, [].concat(_toConsumableArray(queuedItems), [resolve]));
87
- if (queuedItems.length === 0 && !processingItems) {
88
- _this2.nameStartTime.set(id, Date.now());
89
- }
90
- _this2.scheduleProcessQueue();
91
- if (_this2.isQueueAtLimit()) {
92
- _this2.processQueue();
93
- }
94
- });
95
- }
96
- }, {
97
- key: "cacheName",
98
- value: function cacheName(id, name) {
99
- this.nameCache.set(id, {
100
- id: id,
101
- name: name,
102
- status: MentionNameStatus.OK
103
- });
104
- }
105
- }, {
106
- key: "scheduleProcessQueue",
107
- value: function scheduleProcessQueue() {
108
- if (!this.debounce) {
109
- this.debounce = window.setTimeout(this.processQueue, DefaultMentionNameResolver.waitForBatch);
110
- }
111
- }
112
- }, {
113
- key: "scheduleOnAllResolved",
114
- value: function scheduleOnAllResolved() {
115
- var _this3 = this;
116
- if (this.debounceOnResolve) {
117
- clearTimeout(this.debounceOnResolve);
118
- }
119
- this.debounceOnResolve = window.setTimeout(function () {
120
- if (_this3.isOnResolvedAllCalled) {
121
- return;
122
- }
123
- _this3.onResolvedAll();
124
- _this3.isOnResolvedAllCalled = true;
125
- }, DefaultMentionNameResolver.waitForResolveAll);
126
- }
127
- }, {
128
- key: "isQueueAtLimit",
129
- value: function isQueueAtLimit() {
130
- return this.nameQueue.size >= this.client.getLookupLimit();
131
- }
132
- }, {
133
- key: "splitQueueAtLimit",
134
- value: function splitQueueAtLimit() {
135
- var values = Array.from(this.nameQueue.entries());
136
- var splitPoint = this.client.getLookupLimit();
137
- return {
138
- queue: new Map(values.slice(0, splitPoint)),
139
- extraQueue: new Map(values.slice(splitPoint))
140
- };
141
- }
142
- }, {
143
- key: "resolveQueueItem",
144
- value: function resolveQueueItem(mentionDetail) {
145
- var id = mentionDetail.id;
146
- var resolvers = this.processingQueue.get(id);
147
- if (resolvers) {
148
- this.processingQueue.delete(id);
149
- this.nameCache.set(id, mentionDetail);
150
- resolvers.forEach(function (resolve) {
151
- try {
152
- resolve(mentionDetail);
153
- } catch (_unused) {
154
- // ignore - exception in consumer
155
- }
156
- });
157
- this.fireAnalytics(false, mentionDetail);
158
- }
159
- }
160
- }, {
161
- key: "fireAnalytics",
162
- value: function fireAnalytics(fromCache, mentionDetail) {
163
- var id = mentionDetail.id;
164
- var action = mentionDetail.status === MentionNameStatus.OK ? 'completed' : 'failed';
165
- var start = this.nameStartTime.get(id);
166
- var duration = start ? Date.now() - start : 0;
167
- this.nameStartTime.delete(id);
168
- this.fireHydrationEvent(action, id, fromCache, duration);
169
- }
170
- }]);
171
- }();
1
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
172
2
 
173
3
  /**
174
- * Merge the two queues making sure to merge callback arrays for items in queueB already in queueA.
175
- * 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.
176
13
  */
177
- _defineProperty(DefaultMentionNameResolver, "waitForBatch", 100);
178
- // ms
179
- _defineProperty(DefaultMentionNameResolver, "waitForResolveAll", 800);
180
- export function mergeNameResolverQueues(queueA, queueB) {
181
- var queueBeingMerged = new Map(_toConsumableArray(queueA));
182
14
 
183
- // now add the items from the second queue that are not already in the
184
- // merged queue being built
185
- _toConsumableArray(queueB).forEach(function (item) {
186
- var _item = _slicedToArray(item, 2),
187
- key = _item[0],
188
- queueBCallbacks = _item[1];
189
- var itemAlreadyInMergedQueue = queueBeingMerged.has(key);
190
- if (!itemAlreadyInMergedQueue) {
191
- queueBeingMerged.set(key, queueBCallbacks);
192
- } else {
193
- var _queueBeingMerged$get;
194
- // item already in merged queue, merge the callback arrays
195
- var queueACallbacks = (_queueBeingMerged$get = queueBeingMerged.get(key)) !== null && _queueBeingMerged$get !== void 0 ? _queueBeingMerged$get : [];
196
- var mergedCallbacks = new Set([].concat(_toConsumableArray(queueBCallbacks), _toConsumableArray(queueACallbacks)));
197
- var deduplicatedCallbacks = Array.from(mergedCallbacks.values()); // prevents calling them twice
198
- queueBeingMerged.set(key, deduplicatedCallbacks);
199
- }
200
- });
201
- return queueBeingMerged;
202
- }
15
+ /**
16
+ * @deprecated Use `import { Queue } from '@atlaskit/mention/mention-name-resolver'` instead.
17
+ */
@@ -1,25 +1,25 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
+ import _createClass from "@babel/runtime/helpers/createClass";
3
5
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
4
6
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
5
7
  import _inherits from "@babel/runtime/helpers/inherits";
6
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
7
- import _createClass from "@babel/runtime/helpers/createClass";
8
8
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
9
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
10
  import _regeneratorRuntime from "@babel/runtime/regenerator";
11
11
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
12
12
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
13
+ /* eslint-disable @repo/internal/deprecations/deprecation-ticket-required -- VOLTC-139 tracks removal of these deprecated re-export shims. */
14
+ import debounce from 'lodash/debounce';
13
15
  import { utils as serviceUtils } from '@atlaskit/util-service-support';
14
- import { isAppMention, isTeamMention, MentionNameStatus, SliNames, Actions } from '../types';
16
+ import { isAppMention } from '../is-app-mention';
17
+ import { isTeamMention } from '../is-team-mention';
18
+ import { MentionNameStatus, SliNames, Actions } from '../types';
19
+ import { SLI_EVENT_TYPE } from '../util/analytics';
15
20
  import debug from '../util/logger';
21
+ import { AbstractMentionResource } from './AbstractMentionResource';
16
22
  var MAX_QUERY_ITEMS = 100;
17
- var MAX_NOTIFIED_ITEMS = 20;
18
- // Re-exporting types to prevent breaking change
19
- // Re-exporting types to prevent breaking change
20
-
21
- import { SLI_EVENT_TYPE } from '../util/analytics';
22
- import debounce from 'lodash/debounce';
23
23
 
24
24
  /**
25
25
  * Configuration for the TeamMentionResource, which extends {@link MentionResourceConfig}
@@ -39,139 +39,6 @@ var emptySecurityProvider = function emptySecurityProvider() {
39
39
  headers: {}
40
40
  };
41
41
  };
42
- var AbstractResource = /*#__PURE__*/function () {
43
- function AbstractResource() {
44
- _classCallCheck(this, AbstractResource);
45
- this.changeListeners = new Map();
46
- this.allResultsListeners = new Map();
47
- this.errListeners = new Map();
48
- this.infoListeners = new Map();
49
- this.analyticsListeners = new Map();
50
- }
51
- return _createClass(AbstractResource, [{
52
- key: "subscribe",
53
- value: function subscribe(key, callback, errCallback, infoCallback, allResultsCallback, analyticsListeners) {
54
- if (callback) {
55
- this.changeListeners.set(key, callback);
56
- }
57
- if (errCallback) {
58
- this.errListeners.set(key, errCallback);
59
- }
60
- if (infoCallback) {
61
- this.infoListeners.set(key, infoCallback);
62
- }
63
- if (allResultsCallback) {
64
- this.allResultsListeners.set(key, allResultsCallback);
65
- }
66
- if (analyticsListeners) {
67
- this.analyticsListeners.set(key, analyticsListeners);
68
- }
69
- }
70
- }, {
71
- key: "unsubscribe",
72
- value: function unsubscribe(key) {
73
- this.changeListeners.delete(key);
74
- this.errListeners.delete(key);
75
- this.infoListeners.delete(key);
76
- this.allResultsListeners.delete(key);
77
- this.analyticsListeners.delete(key);
78
- }
79
- }]);
80
- }();
81
- var AbstractMentionResource = /*#__PURE__*/function (_AbstractResource) {
82
- function AbstractMentionResource() {
83
- _classCallCheck(this, AbstractMentionResource);
84
- return _callSuper(this, AbstractMentionResource, arguments);
85
- }
86
- _inherits(AbstractMentionResource, _AbstractResource);
87
- return _createClass(AbstractMentionResource, [{
88
- key: "shouldHighlightMention",
89
- value: function shouldHighlightMention(_mention) {
90
- return false;
91
- }
92
-
93
- // eslint-disable-next-line class-methods-use-this
94
- }, {
95
- key: "filter",
96
- value: function filter(query) {
97
- throw new Error("not yet implemented.\nParams: query=".concat(query));
98
- }
99
-
100
- // eslint-disable-next-line class-methods-use-this, no-unused-vars
101
- }, {
102
- key: "recordMentionSelection",
103
- value: function recordMentionSelection(_mention) {
104
- // Do nothing
105
- }
106
- }, {
107
- key: "isFiltering",
108
- value: function isFiltering(_query) {
109
- return false;
110
- }
111
- }, {
112
- key: "_notifyListeners",
113
- value: function _notifyListeners(mentionsResult, stats) {
114
- debug('ak-mention-resource._notifyListeners', mentionsResult && mentionsResult.mentions && mentionsResult.mentions.length, this.changeListeners);
115
- this.changeListeners.forEach(function (listener, key) {
116
- try {
117
- listener(mentionsResult.mentions.slice(0, MAX_NOTIFIED_ITEMS), mentionsResult.query, stats);
118
- } catch (e) {
119
- // ignore error from listener
120
- debug("error from listener '".concat(key, "', ignoring"), e);
121
- }
122
- });
123
- }
124
- }, {
125
- key: "_notifyAllResultsListeners",
126
- value: function _notifyAllResultsListeners(mentionsResult) {
127
- debug('ak-mention-resource._notifyAllResultsListeners', mentionsResult && mentionsResult.mentions && mentionsResult.mentions.length, this.changeListeners);
128
- this.allResultsListeners.forEach(function (listener, key) {
129
- try {
130
- listener(mentionsResult.mentions.slice(0, MAX_NOTIFIED_ITEMS), mentionsResult.query);
131
- } catch (e) {
132
- // ignore error from listener
133
- debug("error from listener '".concat(key, "', ignoring"), e);
134
- }
135
- });
136
- }
137
- }, {
138
- key: "_notifyErrorListeners",
139
- value: function _notifyErrorListeners(error, query) {
140
- this.errListeners.forEach(function (listener, key) {
141
- try {
142
- listener(error, query);
143
- } catch (e) {
144
- // ignore error from listener
145
- debug("error from listener '".concat(key, "', ignoring"), e);
146
- }
147
- });
148
- }
149
- }, {
150
- key: "_notifyInfoListeners",
151
- value: function _notifyInfoListeners(info) {
152
- this.infoListeners.forEach(function (listener, key) {
153
- try {
154
- listener(info);
155
- } catch (e) {
156
- // ignore error fromr listener
157
- debug("error from listener '".concat(key, "', ignoring"), e);
158
- }
159
- });
160
- }
161
- }, {
162
- key: "_notifyAnalyticsListeners",
163
- value: function _notifyAnalyticsListeners(event, actionSubject, action, attributes) {
164
- this.analyticsListeners.forEach(function (listener, key) {
165
- try {
166
- listener(event, actionSubject, action, attributes);
167
- } catch (e) {
168
- // ignore error from listener
169
- debug("error from listener '".concat(key, "', ignoring"), e);
170
- }
171
- });
172
- }
173
- }]);
174
- }(AbstractResource);
175
42
  /**
176
43
  * Provides a Javascript API
177
44
  */
@@ -484,15 +351,24 @@ export var MentionResource = /*#__PURE__*/function (_AbstractMentionResou) {
484
351
  }
485
352
  }]);
486
353
  }(AbstractMentionResource);
487
- export var HttpError = /*#__PURE__*/_createClass(function HttpError(statusCode, statusMessage) {
488
- _classCallCheck(this, HttpError);
489
- this.statusCode = statusCode;
490
- this.message = statusMessage;
491
- this.name = 'HttpError';
492
- this.stack = new Error().stack;
493
- });
494
- export var isResolvingMentionProvider = function isResolvingMentionProvider(p) {
495
- return !!(p && p.supportsMentionNameResolving && p.supportsMentionNameResolving());
496
- };
497
- export { AbstractResource, AbstractMentionResource };
498
- export default MentionResource;
354
+ export default MentionResource;
355
+
356
+ /**
357
+ * @deprecated Use `import { HttpError } from '@atlaskit/mention/mention-resource'` instead.
358
+ */
359
+ export { HttpError } from './HttpError';
360
+
361
+ /**
362
+ * @deprecated Use `import { isResolvingMentionProvider } from '@atlaskit/mention/mention-resource'` instead.
363
+ */
364
+ export { isResolvingMentionProvider } from './isResolvingMentionProvider';
365
+
366
+ /**
367
+ * @deprecated Use `import { AbstractResource } from '@atlaskit/mention/mention-resource'` instead.
368
+ */
369
+ export { AbstractResource } from './AbstractResource';
370
+
371
+ /**
372
+ * @deprecated Use `import { AbstractMentionResource } from '@atlaskit/mention/mention-resource'` instead.
373
+ */
374
+ export { AbstractMentionResource } from './AbstractMentionResource';