@atlaskit/media-viewer 48.1.7 → 48.2.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 +11 -0
- package/dist/cjs/analytics/index.js +2 -3
- package/dist/cjs/analytics/ufoExperiences.js +1 -1
- package/dist/cjs/components/media-viewer.js +13 -1
- package/dist/cjs/errorMessage.js +5 -3
- package/dist/cjs/item-viewer.js +5 -4
- package/dist/cjs/media-viewer.js +21 -17
- package/dist/cjs/navigation.js +5 -4
- package/dist/cjs/styleWrappers.js +1 -0
- package/dist/cjs/v2/header-v2.js +159 -0
- package/dist/cjs/v2/item-viewer-v2.js +322 -0
- package/dist/cjs/v2/list-v2.js +71 -0
- package/dist/cjs/v2/media-viewer-v2.js +114 -0
- package/dist/cjs/viewers/archiveSidebar/archive.js +5 -3
- package/dist/cjs/zoomControls.js +6 -4
- package/dist/es2019/analytics/index.js +2 -5
- package/dist/es2019/analytics/ufoExperiences.js +1 -1
- package/dist/es2019/components/media-viewer.js +13 -1
- package/dist/es2019/errorMessage.js +5 -3
- package/dist/es2019/item-viewer.js +5 -4
- package/dist/es2019/media-viewer.js +8 -6
- package/dist/es2019/navigation.js +5 -4
- package/dist/es2019/styleWrappers.js +1 -0
- package/dist/es2019/v2/header-v2.js +138 -0
- package/dist/es2019/v2/item-viewer-v2.js +269 -0
- package/dist/es2019/v2/list-v2.js +52 -0
- package/dist/es2019/v2/media-viewer-v2.js +95 -0
- package/dist/es2019/viewers/archiveSidebar/archive.js +4 -3
- package/dist/es2019/zoomControls.js +6 -4
- package/dist/esm/analytics/index.js +2 -3
- package/dist/esm/analytics/ufoExperiences.js +1 -1
- package/dist/esm/components/media-viewer.js +13 -1
- package/dist/esm/errorMessage.js +5 -3
- package/dist/esm/item-viewer.js +5 -4
- package/dist/esm/media-viewer.js +21 -17
- package/dist/esm/navigation.js +5 -4
- package/dist/esm/styleWrappers.js +1 -0
- package/dist/esm/v2/header-v2.js +149 -0
- package/dist/esm/v2/item-viewer-v2.js +302 -0
- package/dist/esm/v2/list-v2.js +61 -0
- package/dist/esm/v2/media-viewer-v2.js +104 -0
- package/dist/esm/viewers/archiveSidebar/archive.js +5 -3
- package/dist/esm/zoomControls.js +6 -4
- package/dist/types/analytics/index.d.ts +2 -2
- package/dist/types/v2/header-v2.d.ts +18 -0
- package/dist/types/v2/item-viewer-v2.d.ts +21 -0
- package/dist/types/v2/list-v2.d.ts +22 -0
- package/dist/types/v2/media-viewer-v2.d.ts +14 -0
- package/dist/types-ts4.5/analytics/index.d.ts +2 -2
- package/dist/types-ts4.5/v2/header-v2.d.ts +18 -0
- package/dist/types-ts4.5/v2/item-viewer-v2.d.ts +21 -0
- package/dist/types-ts4.5/v2/list-v2.d.ts +22 -0
- package/dist/types-ts4.5/v2/media-viewer-v2.d.ts +14 -0
- package/package.json +11 -4
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import React, { useCallback, useEffect, useState, useRef } from 'react';
|
|
4
|
+
import Loadable from 'react-loadable';
|
|
5
|
+
import { isExternalImageIdentifier, isFileIdentifier } from '@atlaskit/media-client';
|
|
6
|
+
import { FormattedMessage } from 'react-intl-next';
|
|
7
|
+
import { messages } from '@atlaskit/media-ui';
|
|
8
|
+
import { isCodeViewerItem } from '@atlaskit/media-ui/codeViewer';
|
|
9
|
+
import { useFileState, useMediaClient, MediaFileStateError } from '@atlaskit/media-client-react';
|
|
10
|
+
import { Outcome } from '../domain';
|
|
11
|
+
import { Spinner } from '../loading';
|
|
12
|
+
import ErrorMessage from '../errorMessage';
|
|
13
|
+
import { MediaViewerError } from '../errors';
|
|
14
|
+
import { ErrorViewDownloadButton } from '../download';
|
|
15
|
+
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
16
|
+
import { createCommencedEvent } from '../analytics/events/operational/commenced';
|
|
17
|
+
import { createLoadSucceededEvent } from '../analytics/events/operational/loadSucceeded';
|
|
18
|
+
import { fireAnalytics, getFileAttributes } from '../analytics';
|
|
19
|
+
import { InteractiveImg } from '../viewers/image/interactive-img';
|
|
20
|
+
import ArchiveViewerLoader from '../viewers/archiveSidebar/archiveViewerLoader';
|
|
21
|
+
import { getRandomHex } from '@atlaskit/media-common';
|
|
22
|
+
import { startMediaFileUfoExperience, succeedMediaFileUfoExperience } from '../analytics/ufoExperiences';
|
|
23
|
+
var ImageViewer = Loadable({
|
|
24
|
+
loader: function loader() {
|
|
25
|
+
return import( /* webpackChunkName: "@atlaskit-internal_imageViewer" */'../viewers/image').then(function (mod) {
|
|
26
|
+
return mod.ImageViewer;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
loading: function loading() {
|
|
30
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
var VideoViewer = Loadable({
|
|
34
|
+
loader: function loader() {
|
|
35
|
+
return import( /* webpackChunkName: "@atlaskit-internal_videoViewer" */'../viewers/video').then(function (mod) {
|
|
36
|
+
return mod.VideoViewer;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
loading: function loading() {
|
|
40
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
var AudioViewer = Loadable({
|
|
44
|
+
loader: function loader() {
|
|
45
|
+
return import( /* webpackChunkName: "@atlaskit-internal_audioViewer" */'../viewers/audio').then(function (mod) {
|
|
46
|
+
return mod.AudioViewer;
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
loading: function loading() {
|
|
50
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
var DocViewer = Loadable({
|
|
54
|
+
loader: function loader() {
|
|
55
|
+
return import( /* webpackChunkName: "@atlaskit-internal_docViewer" */'../viewers/doc').then(function (mod) {
|
|
56
|
+
return mod.DocViewer;
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
loading: function loading() {
|
|
60
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var CodeViewer = Loadable({
|
|
64
|
+
loader: function loader() {
|
|
65
|
+
return import( /* webpackChunkName: "@atlaskit-internal_codeViewer" */'../viewers/codeViewer').then(function (mod) {
|
|
66
|
+
return mod.CodeViewer;
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
loading: function loading() {
|
|
70
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
// Consts
|
|
74
|
+
export var isExternalImageItem = function isExternalImageItem(fileItem) {
|
|
75
|
+
return fileItem === 'external-image';
|
|
76
|
+
};
|
|
77
|
+
export var isFileStateItem = function isFileStateItem(fileItem) {
|
|
78
|
+
return !isExternalImageItem(fileItem);
|
|
79
|
+
};
|
|
80
|
+
export var MAX_FILE_SIZE_SUPPORTED_BY_CODEVIEWER = 10 * 1024 * 1024;
|
|
81
|
+
export var ItemViewerV2Base = function ItemViewerV2Base(_ref) {
|
|
82
|
+
var identifier = _ref.identifier,
|
|
83
|
+
showControls = _ref.showControls,
|
|
84
|
+
onClose = _ref.onClose,
|
|
85
|
+
previewCount = _ref.previewCount,
|
|
86
|
+
contextId = _ref.contextId,
|
|
87
|
+
createAnalyticsEvent = _ref.createAnalyticsEvent;
|
|
88
|
+
// States and Refs
|
|
89
|
+
var _useState = useState(Outcome.pending()),
|
|
90
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
91
|
+
item = _useState2[0],
|
|
92
|
+
setItem = _useState2[1];
|
|
93
|
+
var traceContext = useRef({
|
|
94
|
+
traceId: getRandomHex(8)
|
|
95
|
+
});
|
|
96
|
+
var fileStateFlagsRef = useRef({
|
|
97
|
+
wasStatusUploading: false,
|
|
98
|
+
wasStatusProcessing: false
|
|
99
|
+
});
|
|
100
|
+
var createAnalyticsEventRef = useRef(createAnalyticsEvent);
|
|
101
|
+
createAnalyticsEventRef.current = createAnalyticsEvent;
|
|
102
|
+
|
|
103
|
+
// Hooks
|
|
104
|
+
var mediaClient = useMediaClient();
|
|
105
|
+
var _useFileState = useFileState(isExternalImageIdentifier(identifier) ? '' : identifier.id, {
|
|
106
|
+
collectionName: isExternalImageIdentifier(identifier) ? '' : identifier.collectionName,
|
|
107
|
+
skipRemote: isExternalImageIdentifier(identifier)
|
|
108
|
+
}),
|
|
109
|
+
fileState = _useFileState.fileState;
|
|
110
|
+
var renderDownloadButton = useCallback(function (fileState, error) {
|
|
111
|
+
var collectionName = isFileIdentifier(identifier) ? identifier.collectionName : undefined;
|
|
112
|
+
return /*#__PURE__*/React.createElement(ErrorViewDownloadButton, {
|
|
113
|
+
fileState: fileState,
|
|
114
|
+
mediaClient: mediaClient,
|
|
115
|
+
error: error,
|
|
116
|
+
collectionName: collectionName
|
|
117
|
+
});
|
|
118
|
+
}, [mediaClient, identifier]);
|
|
119
|
+
|
|
120
|
+
// Did mount
|
|
121
|
+
|
|
122
|
+
useEffect(function () {
|
|
123
|
+
if (isExternalImageIdentifier(identifier)) {
|
|
124
|
+
// external images do not need to talk to our backend,
|
|
125
|
+
// so therefore no need for media-client subscriptions.
|
|
126
|
+
// just set a successful outcome of type "external-image".
|
|
127
|
+
setItem(Outcome.successful('external-image'));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
fireAnalytics(createCommencedEvent(identifier === null || identifier === void 0 ? void 0 : identifier.id, traceContext.current), createAnalyticsEventRef.current);
|
|
131
|
+
startMediaFileUfoExperience();
|
|
132
|
+
|
|
133
|
+
// File Subscription
|
|
134
|
+
|
|
135
|
+
if (fileState) {
|
|
136
|
+
var status = fileState.status;
|
|
137
|
+
if (fileState.status !== 'error') {
|
|
138
|
+
// updateFileStateFlag
|
|
139
|
+
|
|
140
|
+
if (status === 'processing') {
|
|
141
|
+
fileStateFlagsRef.current.wasStatusProcessing = true;
|
|
142
|
+
} else if (status === 'uploading') {
|
|
143
|
+
fileStateFlagsRef.current.wasStatusUploading = true;
|
|
144
|
+
}
|
|
145
|
+
setItem(Outcome.successful(fileState));
|
|
146
|
+
} else {
|
|
147
|
+
var e = new MediaFileStateError(fileState.id, fileState.reason, fileState.message, fileState.details);
|
|
148
|
+
setItem(Outcome.failed(new MediaViewerError('itemviewer-fetch-metadata', e)));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}, [fileState, identifier]);
|
|
152
|
+
var onSuccess = useCallback(function () {
|
|
153
|
+
item.whenSuccessful(function (fileItem) {
|
|
154
|
+
if (isFileStateItem(fileItem)) {
|
|
155
|
+
var fileAttributes = getFileAttributes(fileItem);
|
|
156
|
+
fireAnalytics(createLoadSucceededEvent(fileAttributes, traceContext.current), createAnalyticsEventRef.current);
|
|
157
|
+
succeedMediaFileUfoExperience({
|
|
158
|
+
fileAttributes: fileAttributes,
|
|
159
|
+
fileStateFlags: fileStateFlagsRef.current
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}, [item]);
|
|
164
|
+
var onLoadFail = useCallback(function (mediaViewerError) {
|
|
165
|
+
setItem(Outcome.failed(mediaViewerError));
|
|
166
|
+
}, []);
|
|
167
|
+
var renderError = useCallback(function (error, fileItem) {
|
|
168
|
+
if (fileItem) {
|
|
169
|
+
var _fileState;
|
|
170
|
+
if (fileItem === 'external-image') {
|
|
171
|
+
// external image error outcome
|
|
172
|
+
_fileState = {
|
|
173
|
+
id: 'external-image',
|
|
174
|
+
status: 'error'
|
|
175
|
+
};
|
|
176
|
+
} else {
|
|
177
|
+
// FileState error outcome
|
|
178
|
+
_fileState = fileItem;
|
|
179
|
+
}
|
|
180
|
+
return /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
181
|
+
fileId: isFileIdentifier(identifier) ? identifier.id : 'undefined',
|
|
182
|
+
error: error,
|
|
183
|
+
fileState: _fileState,
|
|
184
|
+
fileStateFlags: fileStateFlagsRef.current,
|
|
185
|
+
traceContext: traceContext.current
|
|
186
|
+
}, /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(FormattedMessage, messages.try_downloading_file)), renderDownloadButton(_fileState, error));
|
|
187
|
+
} else {
|
|
188
|
+
return /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
189
|
+
fileId: isFileIdentifier(identifier) ? identifier.id : 'undefined',
|
|
190
|
+
error: error,
|
|
191
|
+
fileStateFlags: fileStateFlagsRef.current
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}, [identifier, renderDownloadButton, traceContext]);
|
|
195
|
+
return item.match({
|
|
196
|
+
successful: function successful(fileItem) {
|
|
197
|
+
if (fileItem === 'external-image') {
|
|
198
|
+
// render an external image
|
|
199
|
+
var _ref2 = identifier,
|
|
200
|
+
dataURI = _ref2.dataURI;
|
|
201
|
+
return /*#__PURE__*/React.createElement(InteractiveImg, {
|
|
202
|
+
src: dataURI,
|
|
203
|
+
onLoad: function onLoad() {
|
|
204
|
+
fireAnalytics(createLoadSucceededEvent({
|
|
205
|
+
fileId: 'external-image'
|
|
206
|
+
}), createAnalyticsEventRef.current);
|
|
207
|
+
succeedMediaFileUfoExperience({
|
|
208
|
+
fileAttributes: {
|
|
209
|
+
fileId: 'external-image'
|
|
210
|
+
},
|
|
211
|
+
fileStateFlags: fileStateFlagsRef.current
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
onError: function onError() {
|
|
215
|
+
setItem(Outcome.failed(new MediaViewerError('imageviewer-external-onerror')));
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
} else {
|
|
219
|
+
// render a FileState fetched through media-client
|
|
220
|
+
switch (fileItem.status) {
|
|
221
|
+
case 'processed':
|
|
222
|
+
case 'uploading':
|
|
223
|
+
case 'processing':
|
|
224
|
+
// TODO: renderItem
|
|
225
|
+
var collectionName = isFileIdentifier(identifier) ? identifier.collectionName : undefined;
|
|
226
|
+
var viewerProps = {
|
|
227
|
+
mediaClient: mediaClient,
|
|
228
|
+
item: fileItem,
|
|
229
|
+
collectionName: collectionName,
|
|
230
|
+
onClose: onClose,
|
|
231
|
+
previewCount: previewCount
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// TODO: fix all of the item errors
|
|
235
|
+
|
|
236
|
+
if (isCodeViewerItem(fileItem.name, fileItem.mimeType)) {
|
|
237
|
+
//Render error message if code file has size over 10MB.
|
|
238
|
+
//Required by https://product-fabric.atlassian.net/browse/MEX-1788
|
|
239
|
+
if (fileItem.size > MAX_FILE_SIZE_SUPPORTED_BY_CODEVIEWER) {
|
|
240
|
+
return renderError(new MediaViewerError('codeviewer-file-size-exceeds'), fileItem);
|
|
241
|
+
}
|
|
242
|
+
return /*#__PURE__*/React.createElement(CodeViewer, _extends({
|
|
243
|
+
onSuccess: onSuccess,
|
|
244
|
+
onError: onLoadFail
|
|
245
|
+
}, viewerProps));
|
|
246
|
+
}
|
|
247
|
+
var mediaType = fileItem.mediaType;
|
|
248
|
+
switch (mediaType) {
|
|
249
|
+
case 'image':
|
|
250
|
+
return /*#__PURE__*/React.createElement(ImageViewer, _extends({
|
|
251
|
+
onLoad: onSuccess,
|
|
252
|
+
onError: onLoadFail,
|
|
253
|
+
contextId: contextId,
|
|
254
|
+
traceContext: traceContext.current
|
|
255
|
+
}, viewerProps));
|
|
256
|
+
case 'audio':
|
|
257
|
+
return /*#__PURE__*/React.createElement(AudioViewer, _extends({
|
|
258
|
+
showControls: showControls,
|
|
259
|
+
onCanPlay: onSuccess,
|
|
260
|
+
onError: onLoadFail
|
|
261
|
+
}, viewerProps));
|
|
262
|
+
case 'video':
|
|
263
|
+
return /*#__PURE__*/React.createElement(VideoViewer, _extends({
|
|
264
|
+
showControls: showControls,
|
|
265
|
+
onCanPlay: onSuccess,
|
|
266
|
+
onError: onLoadFail
|
|
267
|
+
}, viewerProps));
|
|
268
|
+
case 'doc':
|
|
269
|
+
return /*#__PURE__*/React.createElement(DocViewer, _extends({
|
|
270
|
+
onSuccess: onSuccess,
|
|
271
|
+
onError: onLoadFail
|
|
272
|
+
}, viewerProps));
|
|
273
|
+
case 'archive':
|
|
274
|
+
return /*#__PURE__*/React.createElement(ArchiveViewerLoader, _extends({
|
|
275
|
+
onSuccess: onSuccess,
|
|
276
|
+
onError: onLoadFail
|
|
277
|
+
}, viewerProps));
|
|
278
|
+
}
|
|
279
|
+
return renderError(new MediaViewerError('unsupported'), fileItem);
|
|
280
|
+
case 'failed-processing':
|
|
281
|
+
return renderError(new MediaViewerError('itemviewer-file-failed-processing-status'), fileItem);
|
|
282
|
+
case 'error':
|
|
283
|
+
return renderError(new MediaViewerError('itemviewer-file-error-status'), fileItem);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
pending: function pending() {
|
|
288
|
+
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
289
|
+
},
|
|
290
|
+
failed: function failed(error) {
|
|
291
|
+
return renderError(error, item.data);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
var ViewerWithKey = function ViewerWithKey(props) {
|
|
296
|
+
var identifier = props.identifier;
|
|
297
|
+
var key = isFileIdentifier(identifier) ? identifier.id : identifier.dataURI;
|
|
298
|
+
return /*#__PURE__*/React.createElement(ItemViewerV2Base, _extends({}, props, {
|
|
299
|
+
key: key
|
|
300
|
+
}));
|
|
301
|
+
};
|
|
302
|
+
export var ItemViewerV2 = withAnalyticsEvents()(ViewerWithKey);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useState } from 'react';
|
|
3
|
+
import { hideControlsClassName } from '@atlaskit/media-ui';
|
|
4
|
+
import { ItemViewerV2 } from './item-viewer-v2';
|
|
5
|
+
import { HeaderWrapper, ListWrapper } from '../styleWrappers';
|
|
6
|
+
import { Navigation } from '../navigation';
|
|
7
|
+
import HeaderV2 from './header-v2';
|
|
8
|
+
export var ListV2 = function ListV2(_ref) {
|
|
9
|
+
var defaultSelectedItem = _ref.defaultSelectedItem,
|
|
10
|
+
onClose = _ref.onClose,
|
|
11
|
+
showControls = _ref.showControls,
|
|
12
|
+
extensions = _ref.extensions,
|
|
13
|
+
onSidebarButtonClick = _ref.onSidebarButtonClick,
|
|
14
|
+
contextId = _ref.contextId,
|
|
15
|
+
featureFlags = _ref.featureFlags,
|
|
16
|
+
isSidebarVisible = _ref.isSidebarVisible,
|
|
17
|
+
onNavigationChange = _ref.onNavigationChange,
|
|
18
|
+
items = _ref.items;
|
|
19
|
+
var _useState = useState(defaultSelectedItem),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
selectedItem = _useState2[0],
|
|
22
|
+
setSelectedItem = _useState2[1];
|
|
23
|
+
var _useState3 = useState(0),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
+
previewCount = _useState4[0],
|
|
26
|
+
setPreviewCount = _useState4[1];
|
|
27
|
+
var _useState5 = useState(false),
|
|
28
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
+
isArchiveSideBarVisible = _useState6[0],
|
|
30
|
+
setIsArchiveSideBarVisible = _useState6[1];
|
|
31
|
+
return /*#__PURE__*/React.createElement(ListWrapper, null, /*#__PURE__*/React.createElement(HeaderWrapper, {
|
|
32
|
+
className: hideControlsClassName,
|
|
33
|
+
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
34
|
+
}, /*#__PURE__*/React.createElement(HeaderV2, {
|
|
35
|
+
identifier: selectedItem,
|
|
36
|
+
onClose: onClose,
|
|
37
|
+
extensions: extensions,
|
|
38
|
+
onSidebarButtonClick: onSidebarButtonClick,
|
|
39
|
+
isSidebarVisible: isSidebarVisible,
|
|
40
|
+
isArchiveSideBarVisible: isArchiveSideBarVisible,
|
|
41
|
+
featureFlags: featureFlags,
|
|
42
|
+
onSetArchiveSideBarVisible: setIsArchiveSideBarVisible
|
|
43
|
+
})), /*#__PURE__*/React.createElement(ItemViewerV2, {
|
|
44
|
+
identifier: selectedItem,
|
|
45
|
+
showControls: showControls,
|
|
46
|
+
onClose: onClose,
|
|
47
|
+
previewCount: previewCount,
|
|
48
|
+
contextId: contextId,
|
|
49
|
+
featureFlags: featureFlags
|
|
50
|
+
}), /*#__PURE__*/React.createElement(Navigation, {
|
|
51
|
+
items: items,
|
|
52
|
+
selectedItem: selectedItem,
|
|
53
|
+
onChange: function onChange(selectedItem) {
|
|
54
|
+
onNavigationChange === null || onNavigationChange === void 0 || onNavigationChange(selectedItem);
|
|
55
|
+
showControls === null || showControls === void 0 || showControls();
|
|
56
|
+
setSelectedItem(selectedItem);
|
|
57
|
+
setPreviewCount(previewCount + 1);
|
|
58
|
+
},
|
|
59
|
+
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
60
|
+
}));
|
|
61
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import React, { useState, useLayoutEffect, useRef } from 'react';
|
|
4
|
+
import { IntlProvider, injectIntl } from 'react-intl-next';
|
|
5
|
+
import { Shortcut } from '@atlaskit/media-ui';
|
|
6
|
+
import { useAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
7
|
+
import { fireAnalytics } from '../analytics';
|
|
8
|
+
import { createModalEvent } from '../analytics/events/screen/modal';
|
|
9
|
+
import { createClosedEvent } from '../analytics/events/ui/closed';
|
|
10
|
+
import { ListV2 } from './list-v2';
|
|
11
|
+
import { Content } from '../content';
|
|
12
|
+
import { Blanket, SidebarWrapper } from '../styleWrappers';
|
|
13
|
+
import { start } from 'perf-marks';
|
|
14
|
+
import { mediaViewerPopupClass } from '../classnames';
|
|
15
|
+
import ScrollLock from 'react-scrolllock';
|
|
16
|
+
import FocusLock from 'react-focus-lock';
|
|
17
|
+
var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
18
|
+
var featureFlags = _ref.featureFlags,
|
|
19
|
+
items = _ref.items,
|
|
20
|
+
extensions = _ref.extensions,
|
|
21
|
+
contextId = _ref.contextId,
|
|
22
|
+
innerRef = _ref.innerRef,
|
|
23
|
+
_onClose = _ref.onClose,
|
|
24
|
+
selectedItem = _ref.selectedItem,
|
|
25
|
+
intl = _ref.intl;
|
|
26
|
+
var _useState = useState(false),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
isSidebarVisible = _useState2[0],
|
|
29
|
+
setIsSidebarVisible = _useState2[1];
|
|
30
|
+
var _useState3 = useState(),
|
|
31
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
32
|
+
selectedIdentifier = _useState4[0],
|
|
33
|
+
setSelectedIdentifier = _useState4[1];
|
|
34
|
+
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
35
|
+
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
36
|
+
var createAnalyticsEventRef = useRef(createAnalyticsEvent);
|
|
37
|
+
createAnalyticsEventRef.current = createAnalyticsEvent;
|
|
38
|
+
useLayoutEffect(function () {
|
|
39
|
+
fireAnalytics(createModalEvent(), createAnalyticsEventRef.current);
|
|
40
|
+
start('MediaViewer.SessionDuration');
|
|
41
|
+
}, []);
|
|
42
|
+
var defaultSelectedItem = selectedItem || items[0];
|
|
43
|
+
var renderSidebar = function renderSidebar() {
|
|
44
|
+
var sidebarSelectedIdentifier = selectedIdentifier || defaultSelectedItem;
|
|
45
|
+
if (sidebarSelectedIdentifier && isSidebarVisible && extensions && extensions.sidebar) {
|
|
46
|
+
return /*#__PURE__*/React.createElement(SidebarWrapper, {
|
|
47
|
+
"data-testid": "media-viewer-sidebar-content"
|
|
48
|
+
}, extensions.sidebar.renderer(sidebarSelectedIdentifier, {
|
|
49
|
+
close: function close() {
|
|
50
|
+
return setIsSidebarVisible(!isSidebarVisible);
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var content = /*#__PURE__*/React.createElement("div", {
|
|
56
|
+
ref: innerRef
|
|
57
|
+
}, /*#__PURE__*/React.createElement(Blanket, {
|
|
58
|
+
"data-testid": "media-viewer-popup",
|
|
59
|
+
className: mediaViewerPopupClass
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Shortcut, {
|
|
61
|
+
code: 'Escape',
|
|
62
|
+
handler: function handler() {
|
|
63
|
+
fireAnalytics(createClosedEvent('escKey'), createAnalyticsEventRef.current);
|
|
64
|
+
_onClose && _onClose();
|
|
65
|
+
}
|
|
66
|
+
}), /*#__PURE__*/React.createElement(Content, {
|
|
67
|
+
isSidebarVisible: isSidebarVisible,
|
|
68
|
+
onClose: function onClose(_e, analyticsEvent) {
|
|
69
|
+
var _analyticsEvent$paylo;
|
|
70
|
+
if ((analyticsEvent === null || analyticsEvent === void 0 || (_analyticsEvent$paylo = analyticsEvent.payload) === null || _analyticsEvent$paylo === void 0 ? void 0 : _analyticsEvent$paylo.actionSubject) === 'button') {
|
|
71
|
+
fireAnalytics(createClosedEvent('button'), createAnalyticsEventRef.current);
|
|
72
|
+
}
|
|
73
|
+
_onClose && _onClose();
|
|
74
|
+
}
|
|
75
|
+
}, /*#__PURE__*/React.createElement(ListV2, {
|
|
76
|
+
defaultSelectedItem: defaultSelectedItem || items[0],
|
|
77
|
+
items: items,
|
|
78
|
+
onClose: _onClose,
|
|
79
|
+
extensions: extensions,
|
|
80
|
+
onNavigationChange: setSelectedIdentifier,
|
|
81
|
+
onSidebarButtonClick: function onSidebarButtonClick() {
|
|
82
|
+
return setIsSidebarVisible(!isSidebarVisible);
|
|
83
|
+
},
|
|
84
|
+
isSidebarVisible: isSidebarVisible,
|
|
85
|
+
contextId: contextId,
|
|
86
|
+
featureFlags: featureFlags
|
|
87
|
+
})), renderSidebar()));
|
|
88
|
+
return intl ? content : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
89
|
+
locale: "en"
|
|
90
|
+
}, content);
|
|
91
|
+
};
|
|
92
|
+
var MediaViewerWithRef = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
93
|
+
return /*#__PURE__*/React.createElement(MediaViewerComponent, _extends({}, props, {
|
|
94
|
+
innerRef: ref
|
|
95
|
+
}));
|
|
96
|
+
});
|
|
97
|
+
var MediaViewerWithScrollLock = function MediaViewerWithScrollLock(props) {
|
|
98
|
+
return /*#__PURE__*/React.createElement(FocusLock, {
|
|
99
|
+
autoFocus: true
|
|
100
|
+
}, /*#__PURE__*/React.createElement(ScrollLock, null), /*#__PURE__*/React.createElement(MediaViewerWithRef, props));
|
|
101
|
+
};
|
|
102
|
+
export var MediaViewerV2 = injectIntl(MediaViewerWithScrollLock, {
|
|
103
|
+
enforceContext: false
|
|
104
|
+
});
|
|
@@ -158,7 +158,7 @@ export var ArchiveViewerBase = /*#__PURE__*/function (_BaseViewer) {
|
|
|
158
158
|
});
|
|
159
159
|
_defineProperty(_assertThisInitialized(_this), "onViewerLoad", function (selectedArchiveEntry) {
|
|
160
160
|
return function () {
|
|
161
|
-
fireAnalytics(createZipEntryLoadSucceededEvent(_this.props.item, selectedArchiveEntry), _this.props);
|
|
161
|
+
fireAnalytics(createZipEntryLoadSucceededEvent(_this.props.item, selectedArchiveEntry), _this.props.createAnalyticsEvent);
|
|
162
162
|
};
|
|
163
163
|
});
|
|
164
164
|
_defineProperty(_assertThisInitialized(_this), "onViewerError", function (primaryErrorReason, selectedArchiveEntry) {
|
|
@@ -320,8 +320,10 @@ export var ArchiveViewerBase = /*#__PURE__*/function (_BaseViewer) {
|
|
|
320
320
|
}, {
|
|
321
321
|
key: "renderPreviewError",
|
|
322
322
|
value: function renderPreviewError(error, entry) {
|
|
323
|
-
var
|
|
324
|
-
|
|
323
|
+
var _this$props2 = this.props,
|
|
324
|
+
item = _this$props2.item,
|
|
325
|
+
createAnalyticsEvent = _this$props2.createAnalyticsEvent;
|
|
326
|
+
fireAnalytics(createZipEntryLoadFailedEvent(item, error, entry), createAnalyticsEvent);
|
|
325
327
|
return /*#__PURE__*/React.createElement(ListWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
326
328
|
fileId: item.id,
|
|
327
329
|
fileState: item,
|
package/dist/esm/zoomControls.js
CHANGED
|
@@ -32,20 +32,22 @@ export var ZoomControlsBase = /*#__PURE__*/function (_Component) {
|
|
|
32
32
|
_defineProperty(_assertThisInitialized(_this), "zoomIn", function () {
|
|
33
33
|
var _this$props = _this.props,
|
|
34
34
|
onChange = _this$props.onChange,
|
|
35
|
-
zoomLevel = _this$props.zoomLevel
|
|
35
|
+
zoomLevel = _this$props.zoomLevel,
|
|
36
|
+
createAnalyticsEvent = _this$props.createAnalyticsEvent;
|
|
36
37
|
if (zoomLevel.canZoomIn) {
|
|
37
38
|
var zoom = zoomLevel.zoomIn();
|
|
38
|
-
fireAnalytics(createZoomInButtonClickEvent(zoom.value),
|
|
39
|
+
fireAnalytics(createZoomInButtonClickEvent(zoom.value), createAnalyticsEvent);
|
|
39
40
|
onChange(zoom);
|
|
40
41
|
}
|
|
41
42
|
});
|
|
42
43
|
_defineProperty(_assertThisInitialized(_this), "zoomOut", function () {
|
|
43
44
|
var _this$props2 = _this.props,
|
|
44
45
|
onChange = _this$props2.onChange,
|
|
45
|
-
zoomLevel = _this$props2.zoomLevel
|
|
46
|
+
zoomLevel = _this$props2.zoomLevel,
|
|
47
|
+
createAnalyticsEvent = _this$props2.createAnalyticsEvent;
|
|
46
48
|
if (zoomLevel.canZoomOut) {
|
|
47
49
|
var zoom = zoomLevel.zoomOut();
|
|
48
|
-
fireAnalytics(createZoomOutButtonClickedEvent(zoom.value),
|
|
50
|
+
fireAnalytics(createZoomOutButtonClickedEvent(zoom.value), createAnalyticsEvent);
|
|
49
51
|
onChange(zoom);
|
|
50
52
|
}
|
|
51
53
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileState, RequestMetadata } from '@atlaskit/media-client';
|
|
2
2
|
import { FileAttributes, WithFileAttributes, FailureAttributes, WithTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import {
|
|
3
|
+
import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
4
4
|
import { PrimaryErrorReason } from '../errors';
|
|
5
5
|
import { MediaViewerEventPayload } from './events';
|
|
6
6
|
declare const componentName = "mediaViewer";
|
|
@@ -13,4 +13,4 @@ export type MediaViewerFailureAttributes = Omit<FailureAttributes, 'failReason'>
|
|
|
13
13
|
failReason: PrimaryErrorReason;
|
|
14
14
|
request?: RequestMetadata;
|
|
15
15
|
} & WithFileAttributes & WithTraceContext;
|
|
16
|
-
export declare function fireAnalytics(payload: MediaViewerEventPayload,
|
|
16
|
+
export declare function fireAnalytics(payload: MediaViewerEventPayload, createAnalyticsEvent?: CreateUIAnalyticsEvent): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import { MediaViewerExtensions } from '../components/types';
|
|
5
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
6
|
+
export type Props = {
|
|
7
|
+
readonly identifier: Identifier;
|
|
8
|
+
readonly onClose?: () => void;
|
|
9
|
+
readonly extensions?: MediaViewerExtensions;
|
|
10
|
+
readonly onSidebarButtonClick?: () => void;
|
|
11
|
+
readonly isSidebarVisible?: boolean;
|
|
12
|
+
readonly featureFlags?: MediaFeatureFlags;
|
|
13
|
+
readonly onSetArchiveSideBarVisible?: (isVisible: boolean) => void;
|
|
14
|
+
readonly isArchiveSideBarVisible?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const HeaderV2: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onSetArchiveSideBarVisible, }: Props & WrappedComponentProps) => JSX.Element;
|
|
17
|
+
declare const _default: React.FC<Props>;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileState, Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { WithShowControlMethodProp } from '@atlaskit/media-ui';
|
|
4
|
+
import { Outcome } from '../domain';
|
|
5
|
+
import { MediaViewerError } from '../errors';
|
|
6
|
+
import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
7
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
8
|
+
export type Props = Readonly<{
|
|
9
|
+
identifier: Identifier;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
previewCount: number;
|
|
12
|
+
contextId?: string;
|
|
13
|
+
featureFlags?: MediaFeatureFlags;
|
|
14
|
+
}> & WithAnalyticsEventsProps & WithShowControlMethodProp;
|
|
15
|
+
export type FileItem = FileState | 'external-image';
|
|
16
|
+
export type State = Outcome<FileItem, MediaViewerError>;
|
|
17
|
+
export declare const isExternalImageItem: (fileItem: FileItem) => fileItem is "external-image";
|
|
18
|
+
export declare const isFileStateItem: (fileItem: FileItem) => fileItem is FileState;
|
|
19
|
+
export declare const MAX_FILE_SIZE_SUPPORTED_BY_CODEVIEWER: number;
|
|
20
|
+
export declare const ItemViewerV2Base: ({ identifier, showControls, onClose, previewCount, contextId, createAnalyticsEvent, }: Props) => React.ReactElement | null;
|
|
21
|
+
export declare const ItemViewerV2: React.ForwardRefExoticComponent<Omit<Props, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { WithShowControlMethodProp } from '@atlaskit/media-ui';
|
|
4
|
+
import { MediaViewerExtensions } from '../components/types';
|
|
5
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
6
|
+
export type Props = Readonly<{
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
onNavigationChange?: (selectedItem: Identifier) => void;
|
|
9
|
+
defaultSelectedItem: Identifier;
|
|
10
|
+
items: Identifier[];
|
|
11
|
+
extensions?: MediaViewerExtensions;
|
|
12
|
+
onSidebarButtonClick?: () => void;
|
|
13
|
+
isSidebarVisible?: boolean;
|
|
14
|
+
contextId?: string;
|
|
15
|
+
featureFlags?: MediaFeatureFlags;
|
|
16
|
+
} & WithShowControlMethodProp>;
|
|
17
|
+
export type State = {
|
|
18
|
+
selectedItem: Identifier;
|
|
19
|
+
previewCount: number;
|
|
20
|
+
isArchiveSideBarVisible: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const ListV2: ({ defaultSelectedItem, onClose, showControls, extensions, onSidebarButtonClick, contextId, featureFlags, isSidebarVisible, onNavigationChange, items, }: Props) => JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
4
|
+
import { MediaViewerExtensions } from '../components/types';
|
|
5
|
+
export type Props = {
|
|
6
|
+
onClose?: () => void;
|
|
7
|
+
selectedItem?: Identifier;
|
|
8
|
+
featureFlags?: MediaFeatureFlags;
|
|
9
|
+
items: Identifier[];
|
|
10
|
+
extensions?: MediaViewerExtensions;
|
|
11
|
+
contextId?: string;
|
|
12
|
+
innerRef?: React.Ref<HTMLDivElement>;
|
|
13
|
+
};
|
|
14
|
+
export declare const MediaViewerV2: React.ComponentType<Props>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FileState, RequestMetadata } from '@atlaskit/media-client';
|
|
2
2
|
import { FileAttributes, WithFileAttributes, FailureAttributes, WithTraceContext } from '@atlaskit/media-common';
|
|
3
|
-
import {
|
|
3
|
+
import { CreateUIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
4
4
|
import { PrimaryErrorReason } from '../errors';
|
|
5
5
|
import { MediaViewerEventPayload } from './events';
|
|
6
6
|
declare const componentName = "mediaViewer";
|
|
@@ -13,4 +13,4 @@ export type MediaViewerFailureAttributes = Omit<FailureAttributes, 'failReason'>
|
|
|
13
13
|
failReason: PrimaryErrorReason;
|
|
14
14
|
request?: RequestMetadata;
|
|
15
15
|
} & WithFileAttributes & WithTraceContext;
|
|
16
|
-
export declare function fireAnalytics(payload: MediaViewerEventPayload,
|
|
16
|
+
export declare function fireAnalytics(payload: MediaViewerEventPayload, createAnalyticsEvent?: CreateUIAnalyticsEvent): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
+
import { MediaViewerExtensions } from '../components/types';
|
|
5
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
6
|
+
export type Props = {
|
|
7
|
+
readonly identifier: Identifier;
|
|
8
|
+
readonly onClose?: () => void;
|
|
9
|
+
readonly extensions?: MediaViewerExtensions;
|
|
10
|
+
readonly onSidebarButtonClick?: () => void;
|
|
11
|
+
readonly isSidebarVisible?: boolean;
|
|
12
|
+
readonly featureFlags?: MediaFeatureFlags;
|
|
13
|
+
readonly onSetArchiveSideBarVisible?: (isVisible: boolean) => void;
|
|
14
|
+
readonly isArchiveSideBarVisible?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const HeaderV2: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onSetArchiveSideBarVisible, }: Props & WrappedComponentProps) => JSX.Element;
|
|
17
|
+
declare const _default: React.FC<Props>;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FileState, Identifier } from '@atlaskit/media-client';
|
|
3
|
+
import { WithShowControlMethodProp } from '@atlaskit/media-ui';
|
|
4
|
+
import { Outcome } from '../domain';
|
|
5
|
+
import { MediaViewerError } from '../errors';
|
|
6
|
+
import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
|
|
7
|
+
import { MediaFeatureFlags } from '@atlaskit/media-common';
|
|
8
|
+
export type Props = Readonly<{
|
|
9
|
+
identifier: Identifier;
|
|
10
|
+
onClose?: () => void;
|
|
11
|
+
previewCount: number;
|
|
12
|
+
contextId?: string;
|
|
13
|
+
featureFlags?: MediaFeatureFlags;
|
|
14
|
+
}> & WithAnalyticsEventsProps & WithShowControlMethodProp;
|
|
15
|
+
export type FileItem = FileState | 'external-image';
|
|
16
|
+
export type State = Outcome<FileItem, MediaViewerError>;
|
|
17
|
+
export declare const isExternalImageItem: (fileItem: FileItem) => fileItem is "external-image";
|
|
18
|
+
export declare const isFileStateItem: (fileItem: FileItem) => fileItem is FileState;
|
|
19
|
+
export declare const MAX_FILE_SIZE_SUPPORTED_BY_CODEVIEWER: number;
|
|
20
|
+
export declare const ItemViewerV2Base: ({ identifier, showControls, onClose, previewCount, contextId, createAnalyticsEvent, }: Props) => React.ReactElement | null;
|
|
21
|
+
export declare const ItemViewerV2: React.ForwardRefExoticComponent<Omit<Props, keyof WithAnalyticsEventsProps> & React.RefAttributes<any>>;
|