@atlaskit/emoji 64.5.0 → 64.6.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.
- package/CHANGELOG.md +23 -0
- package/admin/package.json +1 -0
- package/dist/cjs/api/EmojiResource.js +57 -5
- package/dist/cjs/api/media/SiteEmojiResource.js +59 -2
- package/dist/cjs/api/media/TokenManager.js +16 -7
- package/dist/cjs/components/common/CachingEmoji.js +32 -68
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/api/EmojiResource.js +21 -7
- package/dist/es2019/api/media/SiteEmojiResource.js +24 -0
- package/dist/es2019/api/media/TokenManager.js +13 -5
- package/dist/es2019/components/common/CachingEmoji.js +27 -70
- package/dist/es2019/version.json +1 -1
- package/dist/esm/api/EmojiResource.js +56 -6
- package/dist/esm/api/media/SiteEmojiResource.js +57 -2
- package/dist/esm/api/media/TokenManager.js +14 -5
- package/dist/esm/components/common/CachingEmoji.js +33 -69
- package/dist/esm/version.json +1 -1
- package/dist/types/api/EmojiResource.d.ts +5 -0
- package/dist/types/api/EmojiUtils.d.ts +1 -1
- package/dist/types/api/media/SiteEmojiResource.d.ts +4 -0
- package/dist/types/api/media/TokenManager.d.ts +2 -1
- package/dist/types/components/common/CachingEmoji.d.ts +1 -3
- package/dist/types/components/common/EmojiUploadPicker.d.ts +2 -2
- package/dist/types/components/common/ToneSelector.d.ts +1 -1
- package/dist/types/components/picker/EmojiPicker.d.ts +1 -1
- package/dist/types/components/picker/EmojiPickerComponent.d.ts +2 -2
- package/dist/types/components/typeahead/EmojiTypeAheadComponent.d.ts +2 -2
- package/dist/types/components/uploader/EmojiUploader.d.ts +1 -1
- package/dist/types/context/LegacyEmojiContextProvider.d.ts +3 -3
- package/dist/types/types.d.ts +6 -0
- package/dist/types/util/analytics/analytics.d.ts +21 -21
- package/element/package.json +1 -0
- package/package.json +5 -6
- package/picker/package.json +1 -0
- package/resource/package.json +1 -0
- package/typeahead/package.json +1 -0
- package/types/package.json +1 -0
- package/utils/package.json +1 -0
|
@@ -2,8 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { PureComponent } from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import { isEmojiDescription, isMediaEmoji, isPromise } from '../../util/type-helpers';
|
|
5
|
+
import { isMediaEmoji } from '../../util/type-helpers';
|
|
7
6
|
import debug from '../../util/logger';
|
|
8
7
|
import Emoji from './Emoji';
|
|
9
8
|
import EmojiPlaceholder from './EmojiPlaceholder';
|
|
@@ -48,53 +47,36 @@ export class CachingMediaEmoji extends PureComponent {
|
|
|
48
47
|
constructor(props, context) {
|
|
49
48
|
super(props);
|
|
50
49
|
|
|
51
|
-
_defineProperty(this, "
|
|
52
|
-
|
|
53
|
-
_defineProperty(this, "handleLoadError", (_emojiId, emoji) => {
|
|
54
|
-
const {
|
|
55
|
-
invalidImage
|
|
56
|
-
} = this.state;
|
|
50
|
+
_defineProperty(this, "handleLoadError", _emojiId => {
|
|
57
51
|
sampledUfoRenderedEmoji(_emojiId).failure({
|
|
58
52
|
metadata: {
|
|
59
53
|
reason: 'load error'
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
|
-
|
|
63
|
-
if (invalidImage || !emoji) {
|
|
64
|
-
// do nothing, bad image
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
56
|
this.setState({
|
|
69
|
-
|
|
57
|
+
invalidImage: true
|
|
70
58
|
});
|
|
71
59
|
});
|
|
72
60
|
|
|
73
61
|
this.state = {
|
|
74
|
-
cachedEmoji:
|
|
62
|
+
cachedEmoji: undefined
|
|
75
63
|
};
|
|
64
|
+
this.loadEmoji(props.emoji, context);
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
componentDidMount() {
|
|
79
|
-
this.mounted = true;
|
|
80
68
|
sampledUfoRenderedEmoji(this.props.emoji).markFMP();
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
71
|
+
componentDidUpdate() {
|
|
72
|
+
var _this$state$cachedEmo;
|
|
86
73
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (this.mounted) {
|
|
90
|
-
this.setState({
|
|
91
|
-
cachedEmoji: this.loadEmoji(nextProps.emoji, nextContext, false)
|
|
92
|
-
});
|
|
93
|
-
}
|
|
74
|
+
if (this.props.emoji.shortName !== ((_this$state$cachedEmo = this.state.cachedEmoji) === null || _this$state$cachedEmo === void 0 ? void 0 : _this$state$cachedEmo.shortName)) {
|
|
75
|
+
this.loadEmoji(this.props.emoji, this.context);
|
|
94
76
|
}
|
|
95
77
|
}
|
|
96
78
|
|
|
97
|
-
loadEmoji(emoji, context
|
|
79
|
+
loadEmoji(emoji, context) {
|
|
98
80
|
if (!context) {
|
|
99
81
|
return;
|
|
100
82
|
}
|
|
@@ -111,54 +93,29 @@ export class CachingMediaEmoji extends PureComponent {
|
|
|
111
93
|
return undefined;
|
|
112
94
|
}
|
|
113
95
|
|
|
114
|
-
const {
|
|
115
|
-
fitToHeight
|
|
116
|
-
} = this.props;
|
|
117
|
-
const useAlt = shouldUseAltRepresentation(emoji, fitToHeight);
|
|
118
|
-
const optimisticRendering = emojiProvider.optimisticMediaRendering(emoji, useAlt);
|
|
119
|
-
|
|
120
|
-
if (optimisticRendering && !forceLoad) {
|
|
121
|
-
debug('Optimistic rendering', emoji.shortName);
|
|
122
|
-
return emoji;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
96
|
debug('Loading image via media cache', emoji.shortName);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
cachedEmoji: undefined,
|
|
140
|
-
invalidImage: true
|
|
141
|
-
});
|
|
142
|
-
sampledUfoRenderedEmoji(emoji).failure({
|
|
143
|
-
metadata: {
|
|
144
|
-
reason: 'failed to load media emoji'
|
|
145
|
-
}
|
|
146
|
-
});
|
|
97
|
+
emojiProvider.getMediaEmojiDescriptionURLWithInlineToken(emoji).then(cachedEmoji => {
|
|
98
|
+
this.setState({
|
|
99
|
+
cachedEmoji,
|
|
100
|
+
invalidImage: false
|
|
101
|
+
});
|
|
102
|
+
}).catch(() => {
|
|
103
|
+
this.setState({
|
|
104
|
+
cachedEmoji: undefined,
|
|
105
|
+
invalidImage: true
|
|
106
|
+
});
|
|
107
|
+
sampledUfoRenderedEmoji(emoji).failure({
|
|
108
|
+
metadata: {
|
|
109
|
+
reason: 'failed to load media emoji'
|
|
147
110
|
}
|
|
148
111
|
});
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
if (isEmojiDescription(loadedEmoji)) {
|
|
153
|
-
return loadedEmoji;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return undefined;
|
|
112
|
+
});
|
|
157
113
|
}
|
|
158
114
|
|
|
159
115
|
render() {
|
|
160
116
|
const {
|
|
161
|
-
cachedEmoji
|
|
117
|
+
cachedEmoji,
|
|
118
|
+
invalidImage
|
|
162
119
|
} = this.state;
|
|
163
120
|
const {
|
|
164
121
|
children,
|
|
@@ -167,7 +124,7 @@ export class CachingMediaEmoji extends PureComponent {
|
|
|
167
124
|
} = this.props;
|
|
168
125
|
let emojiComponent;
|
|
169
126
|
|
|
170
|
-
if (cachedEmoji) {
|
|
127
|
+
if (cachedEmoji && !invalidImage) {
|
|
171
128
|
emojiComponent = /*#__PURE__*/React.createElement(Emoji, _extends({}, otherProps, {
|
|
172
129
|
emoji: cachedEmoji,
|
|
173
130
|
onLoadError: this.handleLoadError
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
1
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
5
|
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
@@ -7,13 +9,17 @@ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstruct
|
|
|
7
9
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
8
10
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
9
11
|
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
+
|
|
10
16
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
17
|
|
|
12
18
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
13
19
|
|
|
14
20
|
import { AbstractResource, utils as serviceUtils } from '@atlaskit/util-service-support';
|
|
15
21
|
import { selectedToneStorageKey } from '../util/constants';
|
|
16
|
-
import { isMediaEmoji, isPromise, toEmojiId } from '../util/type-helpers';
|
|
22
|
+
import { isMediaEmoji, isMediaRepresentation, isPromise, toEmojiId } from '../util/type-helpers';
|
|
17
23
|
import storageAvailable from '../util/storage-available';
|
|
18
24
|
import { ProviderTypes } from '../types';
|
|
19
25
|
import debug from '../util/logger';
|
|
@@ -27,13 +33,11 @@ import { ufoExperiences } from '../util/analytics';
|
|
|
27
33
|
*
|
|
28
34
|
* Follow this up with an isUploadSupported() check to see if the provider is actually
|
|
29
35
|
* configured to support uploads.
|
|
36
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
|
|
30
37
|
*/
|
|
31
38
|
export var supportsUploadFeature = function supportsUploadFeature(emojiProvider) {
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
prepareForUpload = _ref.prepareForUpload,
|
|
35
|
-
uploadCustomEmoji = _ref.uploadCustomEmoji;
|
|
36
|
-
return !!(isUploadSupported && prepareForUpload && uploadCustomEmoji);
|
|
39
|
+
var emojiUploadProvider = emojiProvider;
|
|
40
|
+
return !!emojiUploadProvider.isUploadSupported && !!emojiUploadProvider.uploadCustomEmoji && !!emojiUploadProvider.prepareForUpload;
|
|
37
41
|
};
|
|
38
42
|
export var EmojiResource = /*#__PURE__*/function (_AbstractResource) {
|
|
39
43
|
_inherits(EmojiResource, _AbstractResource);
|
|
@@ -223,6 +227,52 @@ export var EmojiResource = /*#__PURE__*/function (_AbstractResource) {
|
|
|
223
227
|
_get(_getPrototypeOf(EmojiResource.prototype), "notifyResult", this).call(this, result);
|
|
224
228
|
}
|
|
225
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Returns the EmojiDescription with a valid media path that includes query token and client attributes to access the emoji media inline.
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
}, {
|
|
235
|
+
key: "getMediaEmojiDescriptionURLWithInlineToken",
|
|
236
|
+
value: function () {
|
|
237
|
+
var _getMediaEmojiDescriptionURLWithInlineToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(emoji) {
|
|
238
|
+
var tokenisedMediaPath;
|
|
239
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
240
|
+
while (1) {
|
|
241
|
+
switch (_context.prev = _context.next) {
|
|
242
|
+
case 0:
|
|
243
|
+
if (!(this.siteEmojiResource && isMediaRepresentation(emoji.representation))) {
|
|
244
|
+
_context.next = 5;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
_context.next = 3;
|
|
249
|
+
return this.siteEmojiResource.generateTokenisedMediaURL(emoji);
|
|
250
|
+
|
|
251
|
+
case 3:
|
|
252
|
+
tokenisedMediaPath = _context.sent;
|
|
253
|
+
return _context.abrupt("return", _objectSpread(_objectSpread({}, emoji), {}, {
|
|
254
|
+
representation: _objectSpread(_objectSpread({}, emoji.representation), {}, {
|
|
255
|
+
mediaPath: tokenisedMediaPath
|
|
256
|
+
})
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
case 5:
|
|
260
|
+
return _context.abrupt("return", emoji);
|
|
261
|
+
|
|
262
|
+
case 6:
|
|
263
|
+
case "end":
|
|
264
|
+
return _context.stop();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}, _callee, this);
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
function getMediaEmojiDescriptionURLWithInlineToken(_x) {
|
|
271
|
+
return _getMediaEmojiDescriptionURLWithInlineToken.apply(this, arguments);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return getMediaEmojiDescriptionURLWithInlineToken;
|
|
275
|
+
}()
|
|
226
276
|
}, {
|
|
227
277
|
key: "loadMediaEmoji",
|
|
228
278
|
value: function loadMediaEmoji(emoji, useAlt) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
1
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
4
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
5
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
@@ -73,12 +75,65 @@ var SiteEmojiResource = /*#__PURE__*/function () {
|
|
|
73
75
|
this.mediaEmojiCache = new MediaEmojiCache(this.tokenManager);
|
|
74
76
|
}
|
|
75
77
|
/**
|
|
76
|
-
* Will
|
|
77
|
-
* the URL has changed.
|
|
78
|
+
* Will generate an emoji media path that is inclusive of client and token within the query parameter
|
|
78
79
|
*/
|
|
79
80
|
|
|
80
81
|
|
|
81
82
|
_createClass(SiteEmojiResource, [{
|
|
83
|
+
key: "generateTokenisedMediaURL",
|
|
84
|
+
value: function () {
|
|
85
|
+
var _generateTokenisedMediaURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(emoji) {
|
|
86
|
+
var currentMediaPathURL, currentMediaPathPARAMS, readToken;
|
|
87
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
88
|
+
while (1) {
|
|
89
|
+
switch (_context.prev = _context.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
if (!(emoji && isMediaRepresentation(emoji.representation))) {
|
|
92
|
+
_context.next = 9;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
currentMediaPathURL = new URL(emoji.representation.mediaPath);
|
|
97
|
+
currentMediaPathPARAMS = currentMediaPathURL.searchParams;
|
|
98
|
+
_context.next = 5;
|
|
99
|
+
return this.tokenManager.getToken('read');
|
|
100
|
+
|
|
101
|
+
case 5:
|
|
102
|
+
readToken = _context.sent;
|
|
103
|
+
|
|
104
|
+
if (currentMediaPathPARAMS.get('token') !== readToken.jwt) {
|
|
105
|
+
currentMediaPathPARAMS.set('token', readToken.jwt);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (currentMediaPathPARAMS.get('client') !== readToken.clientId) {
|
|
109
|
+
currentMediaPathPARAMS.set('client', readToken.clientId);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return _context.abrupt("return", currentMediaPathURL.toString());
|
|
113
|
+
|
|
114
|
+
case 9:
|
|
115
|
+
throw Error('Emoji resource is not of type Media Representation');
|
|
116
|
+
|
|
117
|
+
case 10:
|
|
118
|
+
case "end":
|
|
119
|
+
return _context.stop();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, _callee, this);
|
|
123
|
+
}));
|
|
124
|
+
|
|
125
|
+
function generateTokenisedMediaURL(_x) {
|
|
126
|
+
return _generateTokenisedMediaURL.apply(this, arguments);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return generateTokenisedMediaURL;
|
|
130
|
+
}()
|
|
131
|
+
/**
|
|
132
|
+
* Will load media emoji, returning a new EmojiDescription if, for example,
|
|
133
|
+
* the URL has changed.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
}, {
|
|
82
137
|
key: "loadMediaEmoji",
|
|
83
138
|
value: function loadMediaEmoji(emoji, useAlt) {
|
|
84
139
|
if (!isMediaEmoji(emoji)) {
|
|
@@ -2,7 +2,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
3
|
import { utils as serviceUtils } from '@atlaskit/util-service-support'; // expire 30 seconds early to factor in latency, slow services, etc
|
|
4
4
|
|
|
5
|
-
export var
|
|
5
|
+
export var EXPIRES_AT_LATENCY_IN_SECONDS = 30;
|
|
6
6
|
|
|
7
7
|
var TokenManager = /*#__PURE__*/function () {
|
|
8
8
|
function TokenManager(siteServiceConfig) {
|
|
@@ -13,6 +13,18 @@ var TokenManager = /*#__PURE__*/function () {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
_createClass(TokenManager, [{
|
|
16
|
+
key: "isValidToken",
|
|
17
|
+
value: function isValidToken(mediaApiToken) {
|
|
18
|
+
var nowInSeconds = Date.now() / 1000;
|
|
19
|
+
var expiresAt = mediaApiToken.expiresAt - EXPIRES_AT_LATENCY_IN_SECONDS;
|
|
20
|
+
|
|
21
|
+
if (nowInSeconds < expiresAt) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
16
28
|
key: "addToken",
|
|
17
29
|
value: function addToken(type, mediaApiToken) {
|
|
18
30
|
this.tokens.set(type, {
|
|
@@ -34,10 +46,7 @@ var TokenManager = /*#__PURE__*/function () {
|
|
|
34
46
|
activeTokenRefresh = _tokenDetail.activeTokenRefresh;
|
|
35
47
|
|
|
36
48
|
if (mediaApiToken) {
|
|
37
|
-
|
|
38
|
-
var expiresAt = mediaApiToken.expiresAt - expireAdjustment;
|
|
39
|
-
|
|
40
|
-
if (nowInSeconds < expiresAt && !forceRefresh) {
|
|
49
|
+
if (this.isValidToken(mediaApiToken) && !forceRefresh) {
|
|
41
50
|
// still valid
|
|
42
51
|
return Promise.resolve(mediaApiToken);
|
|
43
52
|
}
|
|
@@ -16,8 +16,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
16
16
|
|
|
17
17
|
import React from 'react';
|
|
18
18
|
import { PureComponent } from 'react';
|
|
19
|
-
import {
|
|
20
|
-
import { isEmojiDescription, isMediaEmoji, isPromise } from '../../util/type-helpers';
|
|
19
|
+
import { isMediaEmoji } from '../../util/type-helpers';
|
|
21
20
|
import debug from '../../util/logger';
|
|
22
21
|
import Emoji from './Emoji';
|
|
23
22
|
import EmojiPlaceholder from './EmojiPlaceholder';
|
|
@@ -69,57 +68,44 @@ export var CachingMediaEmoji = /*#__PURE__*/function (_PureComponent) {
|
|
|
69
68
|
|
|
70
69
|
_this = _super.call(this, props);
|
|
71
70
|
|
|
72
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
73
|
-
|
|
74
|
-
_defineProperty(_assertThisInitialized(_this), "handleLoadError", function (_emojiId, emoji) {
|
|
75
|
-
var invalidImage = _this.state.invalidImage;
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "handleLoadError", function (_emojiId) {
|
|
76
72
|
sampledUfoRenderedEmoji(_emojiId).failure({
|
|
77
73
|
metadata: {
|
|
78
74
|
reason: 'load error'
|
|
79
75
|
}
|
|
80
76
|
});
|
|
81
77
|
|
|
82
|
-
if (invalidImage || !emoji) {
|
|
83
|
-
// do nothing, bad image
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
78
|
_this.setState({
|
|
88
|
-
|
|
79
|
+
invalidImage: true
|
|
89
80
|
});
|
|
90
81
|
});
|
|
91
82
|
|
|
92
83
|
_this.state = {
|
|
93
|
-
cachedEmoji:
|
|
84
|
+
cachedEmoji: undefined
|
|
94
85
|
};
|
|
86
|
+
|
|
87
|
+
_this.loadEmoji(props.emoji, context);
|
|
88
|
+
|
|
95
89
|
return _this;
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
_createClass(CachingMediaEmoji, [{
|
|
99
93
|
key: "componentDidMount",
|
|
100
94
|
value: function componentDidMount() {
|
|
101
|
-
this.mounted = true;
|
|
102
95
|
sampledUfoRenderedEmoji(this.props.emoji).markFMP();
|
|
103
96
|
}
|
|
104
97
|
}, {
|
|
105
|
-
key: "
|
|
106
|
-
value: function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
value: function UNSAFE_componentWillReceiveProps(nextProps, nextContext) {
|
|
112
|
-
if (nextProps.emoji !== this.props.emoji) {
|
|
113
|
-
if (this.mounted) {
|
|
114
|
-
this.setState({
|
|
115
|
-
cachedEmoji: this.loadEmoji(nextProps.emoji, nextContext, false)
|
|
116
|
-
});
|
|
117
|
-
}
|
|
98
|
+
key: "componentDidUpdate",
|
|
99
|
+
value: function componentDidUpdate() {
|
|
100
|
+
var _this$state$cachedEmo;
|
|
101
|
+
|
|
102
|
+
if (this.props.emoji.shortName !== ((_this$state$cachedEmo = this.state.cachedEmoji) === null || _this$state$cachedEmo === void 0 ? void 0 : _this$state$cachedEmo.shortName)) {
|
|
103
|
+
this.loadEmoji(this.props.emoji, this.context);
|
|
118
104
|
}
|
|
119
105
|
}
|
|
120
106
|
}, {
|
|
121
107
|
key: "loadEmoji",
|
|
122
|
-
value: function loadEmoji(emoji, context
|
|
108
|
+
value: function loadEmoji(emoji, context) {
|
|
123
109
|
var _this2 = this;
|
|
124
110
|
|
|
125
111
|
if (!context) {
|
|
@@ -136,53 +122,31 @@ export var CachingMediaEmoji = /*#__PURE__*/function (_PureComponent) {
|
|
|
136
122
|
return undefined;
|
|
137
123
|
}
|
|
138
124
|
|
|
139
|
-
var fitToHeight = this.props.fitToHeight;
|
|
140
|
-
var useAlt = shouldUseAltRepresentation(emoji, fitToHeight);
|
|
141
|
-
var optimisticRendering = emojiProvider.optimisticMediaRendering(emoji, useAlt);
|
|
142
|
-
|
|
143
|
-
if (optimisticRendering && !forceLoad) {
|
|
144
|
-
debug('Optimistic rendering', emoji.shortName);
|
|
145
|
-
return emoji;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
125
|
debug('Loading image via media cache', emoji.shortName);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
}).catch(function () {
|
|
160
|
-
if (_this2.mounted) {
|
|
161
|
-
_this2.setState({
|
|
162
|
-
cachedEmoji: undefined,
|
|
163
|
-
invalidImage: true
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
sampledUfoRenderedEmoji(emoji).failure({
|
|
167
|
-
metadata: {
|
|
168
|
-
reason: 'failed to load media emoji'
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
126
|
+
emojiProvider.getMediaEmojiDescriptionURLWithInlineToken(emoji).then(function (cachedEmoji) {
|
|
127
|
+
_this2.setState({
|
|
128
|
+
cachedEmoji: cachedEmoji,
|
|
129
|
+
invalidImage: false
|
|
130
|
+
});
|
|
131
|
+
}).catch(function () {
|
|
132
|
+
_this2.setState({
|
|
133
|
+
cachedEmoji: undefined,
|
|
134
|
+
invalidImage: true
|
|
172
135
|
});
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (isEmojiDescription(loadedEmoji)) {
|
|
177
|
-
return loadedEmoji;
|
|
178
|
-
}
|
|
179
136
|
|
|
180
|
-
|
|
137
|
+
sampledUfoRenderedEmoji(emoji).failure({
|
|
138
|
+
metadata: {
|
|
139
|
+
reason: 'failed to load media emoji'
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
181
143
|
}
|
|
182
144
|
}, {
|
|
183
145
|
key: "render",
|
|
184
146
|
value: function render() {
|
|
185
|
-
var
|
|
147
|
+
var _this$state = this.state,
|
|
148
|
+
cachedEmoji = _this$state.cachedEmoji,
|
|
149
|
+
invalidImage = _this$state.invalidImage;
|
|
186
150
|
|
|
187
151
|
var _this$props = this.props,
|
|
188
152
|
children = _this$props.children,
|
|
@@ -191,7 +155,7 @@ export var CachingMediaEmoji = /*#__PURE__*/function (_PureComponent) {
|
|
|
191
155
|
|
|
192
156
|
var emojiComponent;
|
|
193
157
|
|
|
194
|
-
if (cachedEmoji) {
|
|
158
|
+
if (cachedEmoji && !invalidImage) {
|
|
195
159
|
emojiComponent = /*#__PURE__*/React.createElement(Emoji, _extends({}, otherProps, {
|
|
196
160
|
emoji: cachedEmoji,
|
|
197
161
|
onLoadError: this.handleLoadError
|
package/dist/esm/version.json
CHANGED
|
@@ -43,6 +43,7 @@ export interface ResolveReject<T> {
|
|
|
43
43
|
*
|
|
44
44
|
* Follow this up with an isUploadSupported() check to see if the provider is actually
|
|
45
45
|
* configured to support uploads.
|
|
46
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
|
|
46
47
|
*/
|
|
47
48
|
export declare const supportsUploadFeature: (emojiProvider: EmojiProvider) => emojiProvider is UploadingEmojiProvider;
|
|
48
49
|
export interface LastQuery {
|
|
@@ -68,6 +69,10 @@ export declare class EmojiResource extends AbstractResource<string, EmojiSearchR
|
|
|
68
69
|
protected isLoaded: () => false | EmojiRepository | undefined;
|
|
69
70
|
protected retryIfLoading<T>(retry: Retry<T>, defaultResponse: T): Promise<T>;
|
|
70
71
|
protected notifyResult(result: EmojiSearchResult): void;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the EmojiDescription with a valid media path that includes query token and client attributes to access the emoji media inline.
|
|
74
|
+
*/
|
|
75
|
+
getMediaEmojiDescriptionURLWithInlineToken(emoji: EmojiDescription): Promise<EmojiDescription>;
|
|
71
76
|
loadMediaEmoji(emoji: EmojiDescription, useAlt?: boolean): OptionalEmojiDescription | Promise<OptionalEmojiDescription>;
|
|
72
77
|
optimisticMediaRendering(emoji: EmojiDescription, useAlt?: boolean): boolean;
|
|
73
78
|
filter(query?: string, options?: SearchOptions): void;
|
|
@@ -15,4 +15,4 @@ export declare const denormaliseSkinEmoji: (emoji: EmojiServiceDescriptionWithVa
|
|
|
15
15
|
* emoji with local sprite definitions.
|
|
16
16
|
*/
|
|
17
17
|
export declare const denormaliseEmojiServiceResponse: (emojiData: EmojiServiceResponse) => EmojiResponse;
|
|
18
|
-
export declare const shouldUseAltRepresentation: (emoji: EmojiDescription, fitToHeight?:
|
|
18
|
+
export declare const shouldUseAltRepresentation: (emoji: EmojiDescription, fitToHeight?: number | undefined) => boolean;
|
|
@@ -17,6 +17,10 @@ export default class SiteEmojiResource {
|
|
|
17
17
|
private mediaEmojiCache;
|
|
18
18
|
protected tokenManager: TokenManager;
|
|
19
19
|
constructor(siteServiceConfig: ServiceConfig, mediaApiToken: MediaApiToken);
|
|
20
|
+
/**
|
|
21
|
+
* Will generate an emoji media path that is inclusive of client and token within the query parameter
|
|
22
|
+
*/
|
|
23
|
+
generateTokenisedMediaURL(emoji: EmojiDescription): Promise<string>;
|
|
20
24
|
/**
|
|
21
25
|
* Will load media emoji, returning a new EmojiDescription if, for example,
|
|
22
26
|
* the URL has changed.
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { MediaApiToken } from '../../types';
|
|
2
2
|
import { ServiceConfig } from '@atlaskit/util-service-support';
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const EXPIRES_AT_LATENCY_IN_SECONDS = 30;
|
|
4
4
|
export declare type TokenType = 'read' | 'upload';
|
|
5
5
|
export default class TokenManager {
|
|
6
6
|
private siteServiceConfig;
|
|
7
7
|
private tokens;
|
|
8
8
|
constructor(siteServiceConfig: ServiceConfig);
|
|
9
|
+
isValidToken(mediaApiToken: MediaApiToken): boolean;
|
|
9
10
|
addToken(type: TokenType, mediaApiToken: MediaApiToken): void;
|
|
10
11
|
getToken(type: TokenType, forceRefresh?: boolean): Promise<MediaApiToken>;
|
|
11
12
|
}
|
|
@@ -19,13 +19,11 @@ export declare const CachingEmoji: (props: CachingEmojiProps) => JSX.Element;
|
|
|
19
19
|
* rendering paths depending on caching strategy.
|
|
20
20
|
*/
|
|
21
21
|
export declare class CachingMediaEmoji extends PureComponent<CachingEmojiProps, State> {
|
|
22
|
-
private mounted;
|
|
23
22
|
static contextType: React.Context<EmojiContextType>;
|
|
24
23
|
context: ContextType<typeof EmojiContext>;
|
|
25
24
|
constructor(props: EmojiProps, context: ContextType<typeof EmojiContext>);
|
|
26
25
|
componentDidMount(): void;
|
|
27
|
-
|
|
28
|
-
UNSAFE_componentWillReceiveProps(nextProps: EmojiProps, nextContext: EmojiContextType): void;
|
|
26
|
+
componentDidUpdate(): void;
|
|
29
27
|
private loadEmoji;
|
|
30
28
|
private handleLoadError;
|
|
31
29
|
render(): JSX.Element;
|
|
@@ -33,8 +33,8 @@ export declare class EmojiUploadPicker extends PureComponent<Props & WrappedComp
|
|
|
33
33
|
clearUploadPicker: () => void;
|
|
34
34
|
render(): JSX.Element;
|
|
35
35
|
}
|
|
36
|
-
declare const _default: React.ForwardRefExoticComponent<
|
|
37
|
-
forwardedRef?:
|
|
36
|
+
declare const _default: React.ForwardRefExoticComponent<Omit<React.PropsWithChildren<Props & WrappedComponentProps<"intl">>, "intl"> & {
|
|
37
|
+
forwardedRef?: React.Ref<any> | undefined;
|
|
38
38
|
} & React.RefAttributes<any>> & {
|
|
39
39
|
WrappedComponent: React.ComponentType<Props & WrappedComponentProps<"intl">>;
|
|
40
40
|
};
|
|
@@ -14,5 +14,5 @@ export declare class ToneSelectorInternal extends PureComponent<Props & WithAnal
|
|
|
14
14
|
private onToneSelectedHandler;
|
|
15
15
|
render(): JSX.Element;
|
|
16
16
|
}
|
|
17
|
-
declare const ToneSelector: React.ForwardRefExoticComponent<
|
|
17
|
+
declare const ToneSelector: React.ForwardRefExoticComponent<Omit<Props & WithAnalyticsEventsProps, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
|
|
18
18
|
export default ToneSelector;
|
|
@@ -19,5 +19,5 @@ export declare class EmojiPickerInternal extends LoadingEmojiComponent<Props & W
|
|
|
19
19
|
renderLoading(): JSX.Element | null;
|
|
20
20
|
renderLoaded(loadedEmojiProvider: EmojiProvider, EmojiPickerComponent: ComponentClass<ComponentProps>): JSX.Element;
|
|
21
21
|
}
|
|
22
|
-
declare const EmojiPicker: import("react").ForwardRefExoticComponent<
|
|
22
|
+
declare const EmojiPicker: import("react").ForwardRefExoticComponent<Omit<Props & WithAnalyticsEventsProps, keyof WithAnalyticsEventsProps> & import("react").RefAttributes<any>>;
|
|
23
23
|
export default EmojiPicker;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PureComponent } from 'react';
|
|
2
2
|
import { MessageDescriptor } from 'react-intl-next';
|
|
3
3
|
import { EmojiProvider } from '../../api/EmojiResource';
|
|
4
|
-
import { EmojiDescription, EmojiId, OnEmojiEvent,
|
|
4
|
+
import { EmojiDescription, EmojiId, OnEmojiEvent, OptionalEmojiDescriptionWithVariations, ToneSelection } from '../../types';
|
|
5
5
|
import { CategoryId } from './categories';
|
|
6
6
|
import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
7
7
|
export interface PickerRefHandler {
|
|
@@ -42,7 +42,7 @@ export default class EmojiPickerComponent extends PureComponent<Props, State> {
|
|
|
42
42
|
componentWillUnmount(): void;
|
|
43
43
|
UNSAFE_componentWillReceiveProps(nextProps: Props): void;
|
|
44
44
|
componentDidUpdate(prevProps: Props): void;
|
|
45
|
-
onEmojiActive: (_emojiId: EmojiId, emoji?:
|
|
45
|
+
onEmojiActive: (_emojiId: EmojiId, emoji?: EmojiDescription | undefined) => void;
|
|
46
46
|
onCategoryActivated: (category: CategoryId | null) => void;
|
|
47
47
|
onCategorySelected: (categoryId: CategoryId | null) => void;
|
|
48
48
|
onFileChooserClicked: () => void;
|