@atlaskit/media-viewer 48.2.14 → 48.3.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 +16 -0
- package/dist/cjs/analytics/events/screen/passwordPdf.js +14 -0
- package/dist/cjs/analytics/events/screen/pdfPasswordInput.js +14 -0
- package/dist/cjs/analytics/index.js +1 -1
- package/dist/cjs/analytics/ufoExperiences.js +1 -1
- package/dist/cjs/domain/outcome.js +5 -22
- package/dist/cjs/item-viewer.js +23 -17
- package/dist/cjs/media-viewer.js +2 -1
- package/dist/cjs/navigation.js +4 -2
- package/dist/cjs/v2/item-viewer-v2.js +10 -10
- package/dist/cjs/viewers/doc/index.js +50 -67
- package/dist/cjs/viewers/doc/pdfPasswordInput.js +100 -0
- package/dist/cjs/viewers/doc/pdfRenderer.js +114 -21
- package/dist/cjs/viewers/image/index.js +17 -17
- package/dist/es2019/analytics/events/screen/passwordPdf.js +6 -0
- package/dist/es2019/analytics/events/screen/pdfPasswordInput.js +6 -0
- package/dist/es2019/analytics/index.js +1 -1
- package/dist/es2019/analytics/ufoExperiences.js +1 -1
- package/dist/es2019/domain/outcome.js +5 -18
- package/dist/es2019/item-viewer.js +14 -9
- package/dist/es2019/media-viewer.js +2 -1
- package/dist/es2019/navigation.js +4 -2
- package/dist/es2019/v2/item-viewer-v2.js +10 -10
- package/dist/es2019/viewers/doc/index.js +20 -17
- package/dist/es2019/viewers/doc/pdfPasswordInput.js +85 -0
- package/dist/es2019/viewers/doc/pdfRenderer.js +98 -75
- package/dist/es2019/viewers/image/index.js +4 -4
- package/dist/esm/analytics/events/screen/passwordPdf.js +8 -0
- package/dist/esm/analytics/events/screen/pdfPasswordInput.js +8 -0
- package/dist/esm/analytics/index.js +1 -1
- package/dist/esm/analytics/ufoExperiences.js +1 -1
- package/dist/esm/domain/outcome.js +5 -22
- package/dist/esm/item-viewer.js +23 -17
- package/dist/esm/media-viewer.js +2 -1
- package/dist/esm/navigation.js +4 -2
- package/dist/esm/v2/item-viewer-v2.js +10 -10
- package/dist/esm/viewers/doc/index.js +50 -62
- package/dist/esm/viewers/doc/pdfPasswordInput.js +90 -0
- package/dist/esm/viewers/doc/pdfRenderer.js +115 -22
- package/dist/esm/viewers/image/index.js +18 -18
- package/dist/types/analytics/events/index.d.ts +3 -1
- package/dist/types/analytics/events/screen/passwordPdf.d.ts +3 -0
- package/dist/types/analytics/events/screen/pdfPasswordInput.d.ts +3 -0
- package/dist/types/domain/outcome.d.ts +5 -6
- package/dist/types/viewers/doc/index.d.ts +0 -3
- package/dist/types/viewers/doc/pdfPasswordInput.d.ts +11 -0
- package/dist/types/viewers/doc/pdfRenderer.d.ts +4 -3
- package/dist/types-ts4.5/analytics/events/index.d.ts +3 -1
- package/dist/types-ts4.5/analytics/events/screen/passwordPdf.d.ts +3 -0
- package/dist/types-ts4.5/analytics/events/screen/pdfPasswordInput.d.ts +3 -0
- package/dist/types-ts4.5/domain/outcome.d.ts +5 -6
- package/dist/types-ts4.5/viewers/doc/index.d.ts +0 -3
- package/dist/types-ts4.5/viewers/doc/pdfPasswordInput.d.ts +11 -0
- package/dist/types-ts4.5/viewers/doc/pdfRenderer.d.ts +4 -3
- package/package.json +16 -7
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import LoadingButton from '@atlaskit/button/loading-button';
|
|
4
|
+
import TextField from '@atlaskit/textfield';
|
|
5
|
+
import LockIcon from '@atlaskit/icon/glyph/lock';
|
|
6
|
+
import Form, { ErrorMessage, Field } from '@atlaskit/form';
|
|
7
|
+
import { FormattedMessage, useIntl } from 'react-intl-next';
|
|
8
|
+
import { messages } from '@atlaskit/media-ui';
|
|
9
|
+
import Heading from '@atlaskit/heading';
|
|
10
|
+
import { xcss, Box, Flex } from '@atlaskit/primitives';
|
|
11
|
+
const headerStyles = xcss({
|
|
12
|
+
textAlign: 'center',
|
|
13
|
+
marginTop: 'space.300',
|
|
14
|
+
marginBottom: 'space.100'
|
|
15
|
+
});
|
|
16
|
+
const inputStyle = xcss({
|
|
17
|
+
width: '330px'
|
|
18
|
+
});
|
|
19
|
+
const footerStyles = xcss({
|
|
20
|
+
marginTop: 'space.200',
|
|
21
|
+
display: 'flex',
|
|
22
|
+
justifyContent: 'center'
|
|
23
|
+
});
|
|
24
|
+
export const PDFPasswordInput = ({
|
|
25
|
+
onSubmit,
|
|
26
|
+
hasPasswordError,
|
|
27
|
+
onRender
|
|
28
|
+
}) => {
|
|
29
|
+
const passwordInputRef = useRef(null);
|
|
30
|
+
const onRenderRef = useRef(onRender);
|
|
31
|
+
const [formError, setFormError] = useState(hasPasswordError);
|
|
32
|
+
const intl = useIntl();
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
var _onRenderRef$current;
|
|
35
|
+
(_onRenderRef$current = onRenderRef.current) === null || _onRenderRef$current === void 0 ? void 0 : _onRenderRef$current.call(onRenderRef);
|
|
36
|
+
}, []);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (hasPasswordError) {
|
|
39
|
+
var _passwordInputRef$cur;
|
|
40
|
+
setFormError(true);
|
|
41
|
+
(_passwordInputRef$cur = passwordInputRef.current) === null || _passwordInputRef$cur === void 0 ? void 0 : _passwordInputRef$cur.focus();
|
|
42
|
+
}
|
|
43
|
+
}, [hasPasswordError]);
|
|
44
|
+
return /*#__PURE__*/React.createElement(Form, {
|
|
45
|
+
onSubmit: onSubmit
|
|
46
|
+
}, ({
|
|
47
|
+
formProps,
|
|
48
|
+
submitting
|
|
49
|
+
}) => /*#__PURE__*/React.createElement("form", formProps, /*#__PURE__*/React.createElement(Flex, {
|
|
50
|
+
justifyContent: "center",
|
|
51
|
+
"aria-hidden": true
|
|
52
|
+
}, /*#__PURE__*/React.createElement(LockIcon, {
|
|
53
|
+
label: "forbidden-lock-icon",
|
|
54
|
+
size: "xlarge",
|
|
55
|
+
primaryColor: "var(--ds-text, #c7d1db)"
|
|
56
|
+
})), /*#__PURE__*/React.createElement(Box, {
|
|
57
|
+
xcss: headerStyles
|
|
58
|
+
}, /*#__PURE__*/React.createElement(Heading, {
|
|
59
|
+
as: "h1",
|
|
60
|
+
level: "h200"
|
|
61
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, messages.password_protected_pdf))), /*#__PURE__*/React.createElement(Field, {
|
|
62
|
+
"aria-required": true,
|
|
63
|
+
name: "password",
|
|
64
|
+
label: "Password",
|
|
65
|
+
isRequired: true
|
|
66
|
+
}, ({
|
|
67
|
+
fieldProps
|
|
68
|
+
}) => /*#__PURE__*/React.createElement(Box, {
|
|
69
|
+
xcss: inputStyle
|
|
70
|
+
}, /*#__PURE__*/React.createElement(TextField, _extends({}, fieldProps, {
|
|
71
|
+
type: "password",
|
|
72
|
+
placeholder: intl.formatMessage(messages.enter_password),
|
|
73
|
+
ref: passwordInputRef,
|
|
74
|
+
onChange: value => {
|
|
75
|
+
fieldProps.onChange(value);
|
|
76
|
+
setFormError(false);
|
|
77
|
+
}
|
|
78
|
+
})), formError && /*#__PURE__*/React.createElement(ErrorMessage, null, /*#__PURE__*/React.createElement(FormattedMessage, messages.incorrect_password)))), /*#__PURE__*/React.createElement(Box, {
|
|
79
|
+
xcss: footerStyles
|
|
80
|
+
}, /*#__PURE__*/React.createElement(LoadingButton, {
|
|
81
|
+
appearance: "primary",
|
|
82
|
+
type: "submit",
|
|
83
|
+
isLoading: submitting
|
|
84
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, messages.submit)))));
|
|
85
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { PDFViewer, EventBus, PDFLinkService, NullL10n } from 'pdfjs-dist/legacy/web/pdf_viewer';
|
|
3
|
-
import { getDocument, GlobalWorkerOptions, CMapCompressionType } from 'pdfjs-dist/legacy/build/pdf';
|
|
3
|
+
import { getDocument, GlobalWorkerOptions, CMapCompressionType, PasswordResponses } from 'pdfjs-dist/legacy/build/pdf';
|
|
4
|
+
import { withAnalyticsEvents } from '@atlaskit/analytics-next';
|
|
4
5
|
import { cmap } from './cmaps';
|
|
5
6
|
import { css, Global } from '@emotion/react';
|
|
6
7
|
import { ZoomControls } from '../../zoomControls';
|
|
@@ -13,79 +14,69 @@ import { ZoomLevel } from '../../domain/zoomLevel';
|
|
|
13
14
|
import { processError } from './processError';
|
|
14
15
|
import { pdfJs } from './pdfJs';
|
|
15
16
|
import { extractCompressedBase64 } from './extractCompressedBase64';
|
|
17
|
+
import { PDFPasswordInput } from './pdfPasswordInput';
|
|
18
|
+
import { fireAnalytics } from '../../analytics';
|
|
19
|
+
import { createPdfPasswordInputScreenEvent } from '../../analytics/events/screen/pdfPasswordInput';
|
|
20
|
+
import { createPasswordPdfScreenEvent } from '../../analytics/events/screen/passwordPdf';
|
|
16
21
|
export const pdfViewerClassName = 'pdfViewer';
|
|
17
22
|
|
|
18
23
|
// Styles are partially copied from https://github.com/mozilla/pdfjs-dist/blob/v2.9.359/web/pdf_viewer.css
|
|
19
24
|
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
20
25
|
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage/preview */
|
|
21
|
-
const globalStyles = css
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
font-size: 1em;
|
|
73
|
-
top: 0;
|
|
74
|
-
left: 0;
|
|
75
|
-
width: 100%;
|
|
76
|
-
height: 100%;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
.annotationLayer .linkAnnotation > a:hover,
|
|
80
|
-
.annotationLayer .buttonWidgetAnnotation.pushButton > a:hover {
|
|
81
|
-
opacity: 0.2;
|
|
82
|
-
background: rgba(255, 255, 0, 1);
|
|
83
|
-
box-shadow: 0 2px 10px rgba(255, 255, 0, 1);
|
|
26
|
+
const globalStyles = css({
|
|
27
|
+
[`.${pdfViewerClassName}`]: {
|
|
28
|
+
marginTop: "var(--ds-space-800, 64px)",
|
|
29
|
+
marginBottom: "var(--ds-space-800, 64px)",
|
|
30
|
+
'.page': {
|
|
31
|
+
margin: `1px auto ${"var(--ds-space-negative-100, -8px)"} auto`,
|
|
32
|
+
border: '9px solid transparent',
|
|
33
|
+
position: 'relative'
|
|
34
|
+
},
|
|
35
|
+
'.canvasWrapper': {
|
|
36
|
+
overflow: 'hidden'
|
|
37
|
+
},
|
|
38
|
+
'.textLayer': {
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
left: 0,
|
|
41
|
+
top: 0,
|
|
42
|
+
right: 0,
|
|
43
|
+
bottom: 0,
|
|
44
|
+
overflow: 'hidden',
|
|
45
|
+
opacity: 0.2,
|
|
46
|
+
lineHeight: 1
|
|
47
|
+
},
|
|
48
|
+
'.textLayer span, .textLayer br': {
|
|
49
|
+
color: 'transparent',
|
|
50
|
+
position: 'absolute',
|
|
51
|
+
whiteSpace: 'pre',
|
|
52
|
+
cursor: 'text',
|
|
53
|
+
transformOrigin: '0% 0%'
|
|
54
|
+
},
|
|
55
|
+
'.textLayer ::-moz-selection': {
|
|
56
|
+
background: 'rgba(0, 0, 255, 1)'
|
|
57
|
+
},
|
|
58
|
+
'.textLayer ::selection': {
|
|
59
|
+
background: 'rgba(0, 0, 255, 1)'
|
|
60
|
+
},
|
|
61
|
+
'.annotationLayer section': {
|
|
62
|
+
position: 'absolute',
|
|
63
|
+
textAlign: 'initial'
|
|
64
|
+
},
|
|
65
|
+
'.annotationLayer .linkAnnotation > a, .annotationLayer .buttonWidgetAnnotation.pushButton > a': {
|
|
66
|
+
position: 'absolute',
|
|
67
|
+
fontSize: '1em',
|
|
68
|
+
top: 0,
|
|
69
|
+
left: 0,
|
|
70
|
+
width: '100%',
|
|
71
|
+
height: '100%'
|
|
72
|
+
},
|
|
73
|
+
'.annotationLayer .linkAnnotation > a:hover, .annotationLayer .buttonWidgetAnnotation.pushButton > a:hover': {
|
|
74
|
+
opacity: 0.2,
|
|
75
|
+
background: 'rgba(255, 255, 0, 1)',
|
|
76
|
+
boxShadow: '0 2px 10px rgba(255, 255, 0, 1)'
|
|
84
77
|
}
|
|
85
78
|
}
|
|
86
|
-
|
|
87
|
-
/* eslint-enable @atlaskit/design-system/ensure-design-token-usage/preview */
|
|
88
|
-
/* eslint-disable @atlaskit/design-system/ensure-design-token-usage */
|
|
79
|
+
});
|
|
89
80
|
class CmapFacotry {
|
|
90
81
|
constructor() {}
|
|
91
82
|
async fetch({
|
|
@@ -102,21 +93,26 @@ class CmapFacotry {
|
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
95
|
let defaultWorkerUrl = '';
|
|
105
|
-
|
|
96
|
+
const PDFRendererBase = ({
|
|
106
97
|
src,
|
|
107
98
|
onClose,
|
|
108
99
|
onSuccess,
|
|
109
100
|
onError,
|
|
110
101
|
workerUrl,
|
|
111
|
-
item
|
|
102
|
+
item,
|
|
103
|
+
createAnalyticsEvent
|
|
112
104
|
}) => {
|
|
113
105
|
const [zoomLevel, setZoomLevel] = useState(new ZoomLevel(1));
|
|
114
106
|
const [docOutcome, setDocOutcome] = useState(Outcome.pending());
|
|
107
|
+
const isPasswordPdfRef = useRef(false);
|
|
108
|
+
const [passwordProtected, setPasswordProtected] = useState(false);
|
|
109
|
+
const [hasPasswordError, setHasPasswordError] = useState(false);
|
|
115
110
|
const pdfWrapperRef = useRef();
|
|
116
111
|
const docRef = useRef();
|
|
117
112
|
const pdfViewerRef = useRef();
|
|
118
113
|
const onSuccessRef = useRef(onSuccess);
|
|
119
114
|
onSuccessRef.current = onSuccess;
|
|
115
|
+
const updatePasswordRef = useRef(undefined);
|
|
120
116
|
const onErrorRef = useRef(onError);
|
|
121
117
|
onErrorRef.current = onError;
|
|
122
118
|
useEffect(() => {
|
|
@@ -128,10 +124,20 @@ export const PDFRenderer = ({
|
|
|
128
124
|
defaultWorkerUrl = URL.createObjectURL(blob);
|
|
129
125
|
}
|
|
130
126
|
GlobalWorkerOptions.workerSrc = workerUrl !== null && workerUrl !== void 0 ? workerUrl : defaultWorkerUrl;
|
|
131
|
-
|
|
127
|
+
const getDocumentTask = getDocument({
|
|
132
128
|
url: src,
|
|
133
129
|
CMapReaderFactory: CmapFacotry
|
|
134
|
-
})
|
|
130
|
+
});
|
|
131
|
+
getDocumentTask.onPassword = (updatePassword, e) => {
|
|
132
|
+
updatePasswordRef.current = updatePassword;
|
|
133
|
+
if (e === PasswordResponses.NEED_PASSWORD) {
|
|
134
|
+
isPasswordPdfRef.current = true;
|
|
135
|
+
setPasswordProtected(true);
|
|
136
|
+
} else {
|
|
137
|
+
setHasPasswordError(true);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
docRef.current = await getDocumentTask.promise;
|
|
135
141
|
isSubscribed && setDocOutcome(Outcome.successful(docRef.current));
|
|
136
142
|
} catch (error) {
|
|
137
143
|
const pdfError = processError(error);
|
|
@@ -167,10 +173,13 @@ export const PDFRenderer = ({
|
|
|
167
173
|
pdfViewerRef.current.setDocument(docRef.current);
|
|
168
174
|
pdfLinkService.setDocument(docRef.current, null);
|
|
169
175
|
pdfViewerRef.current.firstPagePromise.then(scaleToFit);
|
|
176
|
+
if (isPasswordPdfRef.current) {
|
|
177
|
+
fireAnalytics(createPasswordPdfScreenEvent(), createAnalyticsEvent);
|
|
178
|
+
}
|
|
170
179
|
if (onSuccessRef.current) {
|
|
171
180
|
onSuccessRef.current();
|
|
172
181
|
}
|
|
173
|
-
}, [docOutcome]);
|
|
182
|
+
}, [createAnalyticsEvent, docOutcome]);
|
|
174
183
|
const savePdfElement = el => {
|
|
175
184
|
pdfWrapperRef.current = el;
|
|
176
185
|
};
|
|
@@ -185,13 +194,25 @@ export const PDFRenderer = ({
|
|
|
185
194
|
}
|
|
186
195
|
};
|
|
187
196
|
return docOutcome.match({
|
|
188
|
-
pending: () => /*#__PURE__*/React.createElement(
|
|
197
|
+
pending: () => passwordProtected ? /*#__PURE__*/React.createElement(PDFPasswordInput, {
|
|
198
|
+
onRender: () => fireAnalytics(createPdfPasswordInputScreenEvent(), createAnalyticsEvent),
|
|
199
|
+
onSubmit: data => {
|
|
200
|
+
var _updatePasswordRef$cu;
|
|
201
|
+
// Reset hasPasswordError on each submission
|
|
202
|
+
hasPasswordError && setHasPasswordError(false);
|
|
203
|
+
(_updatePasswordRef$cu = updatePasswordRef.current) === null || _updatePasswordRef$cu === void 0 ? void 0 : _updatePasswordRef$cu.call(updatePasswordRef, data.password);
|
|
204
|
+
},
|
|
205
|
+
hasPasswordError: hasPasswordError
|
|
206
|
+
}) : /*#__PURE__*/React.createElement(Spinner, null),
|
|
189
207
|
successful: () => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Global, {
|
|
190
208
|
styles: globalStyles
|
|
191
209
|
}), /*#__PURE__*/React.createElement(PDFWrapper, {
|
|
192
210
|
"data-testid": "media-viewer-pdf-content",
|
|
193
211
|
ref: savePdfElement
|
|
194
|
-
},
|
|
212
|
+
},
|
|
213
|
+
/*#__PURE__*/
|
|
214
|
+
// eslint-disable-next-line @atlaskit/design-system/prefer-primitives
|
|
215
|
+
React.createElement("div", {
|
|
195
216
|
className: pdfViewerClassName,
|
|
196
217
|
onClick: closeOnDirectClick(onClose)
|
|
197
218
|
}), /*#__PURE__*/React.createElement(ZoomControls, {
|
|
@@ -207,4 +228,6 @@ export const PDFRenderer = ({
|
|
|
207
228
|
});
|
|
208
229
|
}
|
|
209
230
|
});
|
|
210
|
-
};
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const PDFRenderer = withAnalyticsEvents()(PDFRendererBase);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { isImageRepresentationReady, isErrorFileState, addFileAttrsToUrl } from '@atlaskit/media-client';
|
|
4
4
|
import { isImageMimeTypeSupportedByBrowser } from '@atlaskit/media-common';
|
|
5
5
|
import { getOrientation } from '@atlaskit/media-ui';
|
|
6
6
|
import { Outcome } from '../../domain';
|
|
@@ -41,6 +41,7 @@ export class ImageViewer extends BaseViewer {
|
|
|
41
41
|
if (fileState.status === 'error') {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
|
|
44
45
|
try {
|
|
45
46
|
let orientation = 1;
|
|
46
47
|
let objectUrl;
|
|
@@ -63,12 +64,11 @@ export class ImageViewer extends BaseViewer {
|
|
|
63
64
|
}
|
|
64
65
|
} else if (isImageRepresentationReady(fileState)) {
|
|
65
66
|
const item = processedFileStateToMediaItem(fileState);
|
|
66
|
-
const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined;
|
|
67
67
|
const response = mediaClient.getImage(item.details.id, {
|
|
68
68
|
collection: collectionName,
|
|
69
69
|
mode: 'fit'
|
|
70
70
|
}, controller, true, traceContext);
|
|
71
|
-
this.cancelImageFetch = () => controller
|
|
71
|
+
this.cancelImageFetch = () => controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
72
72
|
objectUrl = URL.createObjectURL(await response);
|
|
73
73
|
} else {
|
|
74
74
|
this.setState({
|
|
@@ -90,7 +90,7 @@ export class ImageViewer extends BaseViewer {
|
|
|
90
90
|
});
|
|
91
91
|
} catch (err) {
|
|
92
92
|
// TODO : properly handle aborted requests (MS-2843)
|
|
93
|
-
if (!
|
|
93
|
+
if (!(controller !== null && controller !== void 0 && controller.signal.aborted)) {
|
|
94
94
|
const imgError = new MediaViewerError('imageviewer-fetch-url', err instanceof Error ? err : undefined);
|
|
95
95
|
this.setState({
|
|
96
96
|
content: Outcome.failed(imgError)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ANALYTICS_MEDIA_CHANNEL } from '@atlaskit/media-common';
|
|
2
2
|
var componentName = 'mediaViewer';
|
|
3
3
|
var packageName = "@atlaskit/media-viewer";
|
|
4
|
-
var packageVersion = "48.
|
|
4
|
+
var packageVersion = "48.3.0";
|
|
5
5
|
export { packageName, packageVersion, componentName, componentName as component };
|
|
6
6
|
export function getFileAttributes(fileState) {
|
|
7
7
|
if (!fileState) {
|
|
@@ -5,7 +5,7 @@ import { UFOExperience, ExperiencePerformanceTypes, ExperienceTypes } from '@atl
|
|
|
5
5
|
import { getMediaEnvironment, getMediaRegion } from '@atlaskit/media-client';
|
|
6
6
|
import { getFeatureFlagKeysAllProducts } from '@atlaskit/media-common';
|
|
7
7
|
var packageName = "@atlaskit/media-viewer";
|
|
8
|
-
var packageVersion = "48.
|
|
8
|
+
var packageVersion = "48.3.0";
|
|
9
9
|
var ufoExperience;
|
|
10
10
|
var getExperience = function getExperience() {
|
|
11
11
|
if (!ufoExperience) {
|
|
@@ -13,7 +13,7 @@ export var Outcome = /*#__PURE__*/function () {
|
|
|
13
13
|
}, {
|
|
14
14
|
key: "data",
|
|
15
15
|
get: function get() {
|
|
16
|
-
if (this.state.status === 'SUCCESSFUL') {
|
|
16
|
+
if (this.state.status === 'SUCCESSFUL' || this.state.status === 'FAILED') {
|
|
17
17
|
return this.state.data;
|
|
18
18
|
} else {
|
|
19
19
|
return;
|
|
@@ -61,25 +61,7 @@ export var Outcome = /*#__PURE__*/function () {
|
|
|
61
61
|
case 'PENDING':
|
|
62
62
|
return pending();
|
|
63
63
|
case 'FAILED':
|
|
64
|
-
return failed(this.state.err);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: "mapSuccessful",
|
|
69
|
-
value: function mapSuccessful(map) {
|
|
70
|
-
if (this.state.status === 'SUCCESSFUL') {
|
|
71
|
-
return Outcome.successful(map(this.state.data));
|
|
72
|
-
} else {
|
|
73
|
-
return new Outcome(this.state);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}, {
|
|
77
|
-
key: "mapFailed",
|
|
78
|
-
value: function mapFailed(map) {
|
|
79
|
-
if (this.state.status === 'FAILED') {
|
|
80
|
-
return Outcome.failed(map(this.state.err));
|
|
81
|
-
} else {
|
|
82
|
-
return new Outcome(this.state);
|
|
64
|
+
return failed(this.state.err, this.state.data);
|
|
83
65
|
}
|
|
84
66
|
}
|
|
85
67
|
}], [{
|
|
@@ -99,10 +81,11 @@ export var Outcome = /*#__PURE__*/function () {
|
|
|
99
81
|
}
|
|
100
82
|
}, {
|
|
101
83
|
key: "failed",
|
|
102
|
-
value: function failed(err) {
|
|
84
|
+
value: function failed(err, data) {
|
|
103
85
|
return new Outcome({
|
|
104
86
|
status: 'FAILED',
|
|
105
|
-
err: err
|
|
87
|
+
err: err,
|
|
88
|
+
data: data
|
|
106
89
|
});
|
|
107
90
|
}
|
|
108
91
|
}]);
|
package/dist/esm/item-viewer.js
CHANGED
|
@@ -11,6 +11,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import Loadable from 'react-loadable';
|
|
13
13
|
import { isExternalImageIdentifier, isFileIdentifier } from '@atlaskit/media-client';
|
|
14
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { FormattedMessage } from 'react-intl-next';
|
|
15
16
|
import { messages } from '@atlaskit/media-ui';
|
|
16
17
|
import { isCodeViewerItem } from '@atlaskit/media-ui/codeViewer';
|
|
@@ -125,9 +126,9 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
125
126
|
}
|
|
126
127
|
});
|
|
127
128
|
});
|
|
128
|
-
_defineProperty(_assertThisInitialized(_this), "onLoadFail", function (mediaViewerError) {
|
|
129
|
+
_defineProperty(_assertThisInitialized(_this), "onLoadFail", function (mediaViewerError, data) {
|
|
129
130
|
_this.safeSetState({
|
|
130
|
-
item: Outcome.failed(mediaViewerError)
|
|
131
|
+
item: Outcome.failed(mediaViewerError, data)
|
|
131
132
|
});
|
|
132
133
|
});
|
|
133
134
|
_defineProperty(_assertThisInitialized(_this), "onExternalImgSuccess", function () {
|
|
@@ -178,6 +179,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
178
179
|
}, {
|
|
179
180
|
key: "renderItem",
|
|
180
181
|
value: function renderItem(fileState) {
|
|
182
|
+
var _this2 = this;
|
|
181
183
|
var _this$props = this.props,
|
|
182
184
|
mediaClient = _this$props.mediaClient,
|
|
183
185
|
identifier = _this$props.identifier,
|
|
@@ -227,7 +229,9 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
227
229
|
case 'doc':
|
|
228
230
|
return /*#__PURE__*/React.createElement(DocViewer, _extends({
|
|
229
231
|
onSuccess: this.onSuccess,
|
|
230
|
-
onError:
|
|
232
|
+
onError: function onError(err) {
|
|
233
|
+
_this2.onLoadFail(err, fileState);
|
|
234
|
+
}
|
|
231
235
|
}, viewerProps));
|
|
232
236
|
case 'archive':
|
|
233
237
|
return /*#__PURE__*/React.createElement(ArchiveViewerLoader, _extends({
|
|
@@ -271,7 +275,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
271
275
|
}, {
|
|
272
276
|
key: "render",
|
|
273
277
|
value: function render() {
|
|
274
|
-
var
|
|
278
|
+
var _this3 = this;
|
|
275
279
|
var item = this.state.item;
|
|
276
280
|
var identifier = this.props.identifier;
|
|
277
281
|
return item.match({
|
|
@@ -282,29 +286,31 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
282
286
|
dataURI = _ref.dataURI;
|
|
283
287
|
return /*#__PURE__*/React.createElement(InteractiveImg, {
|
|
284
288
|
src: dataURI,
|
|
285
|
-
onLoad:
|
|
286
|
-
onError:
|
|
289
|
+
onLoad: _this3.onExternalImgSuccess,
|
|
290
|
+
onError: _this3.onExternalImgError
|
|
287
291
|
});
|
|
288
292
|
} else {
|
|
289
293
|
// render a FileState fetched through media-client
|
|
290
|
-
|
|
291
|
-
switch (fileState.status) {
|
|
294
|
+
switch (fileItem.status) {
|
|
292
295
|
case 'processed':
|
|
293
296
|
case 'uploading':
|
|
294
297
|
case 'processing':
|
|
295
|
-
return
|
|
298
|
+
return _this3.renderItem(fileItem);
|
|
296
299
|
case 'failed-processing':
|
|
297
|
-
|
|
300
|
+
if (getBooleanFF('platform.corex.password-protected-pdf_ht8re') && fileItem.mediaType === 'doc' && fileItem.mimeType === 'application/pdf') {
|
|
301
|
+
return _this3.renderItem(fileItem);
|
|
302
|
+
}
|
|
303
|
+
return _this3.renderError(new MediaViewerError('itemviewer-file-failed-processing-status'), fileItem);
|
|
298
304
|
case 'error':
|
|
299
|
-
return
|
|
305
|
+
return _this3.renderError(new MediaViewerError('itemviewer-file-error-status'), fileItem);
|
|
300
306
|
}
|
|
301
307
|
}
|
|
302
308
|
},
|
|
303
309
|
pending: function pending() {
|
|
304
310
|
return /*#__PURE__*/React.createElement(Spinner, null);
|
|
305
311
|
},
|
|
306
|
-
failed: function failed(error) {
|
|
307
|
-
return
|
|
312
|
+
failed: function failed(error, data) {
|
|
313
|
+
return _this3.renderError(error, data);
|
|
308
314
|
}
|
|
309
315
|
});
|
|
310
316
|
}
|
|
@@ -338,7 +344,7 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
338
344
|
}, {
|
|
339
345
|
key: "init",
|
|
340
346
|
value: function init(props) {
|
|
341
|
-
var
|
|
347
|
+
var _this4 = this;
|
|
342
348
|
var mediaClient = props.mediaClient,
|
|
343
349
|
identifier = props.identifier,
|
|
344
350
|
createAnalyticsEvent = props.createAnalyticsEvent;
|
|
@@ -358,13 +364,13 @@ export var ItemViewerBase = /*#__PURE__*/function (_React$Component) {
|
|
|
358
364
|
collectionName: identifier.collectionName
|
|
359
365
|
}).subscribe({
|
|
360
366
|
next: function next(file) {
|
|
361
|
-
|
|
362
|
-
|
|
367
|
+
_this4.updateFileStateFlag(file);
|
|
368
|
+
_this4.safeSetState({
|
|
363
369
|
item: Outcome.successful(file)
|
|
364
370
|
});
|
|
365
371
|
},
|
|
366
372
|
error: function error(_error) {
|
|
367
|
-
|
|
373
|
+
_this4.safeSetState({
|
|
368
374
|
item: Outcome.failed(new MediaViewerError('itemviewer-fetch-metadata', _error))
|
|
369
375
|
});
|
|
370
376
|
}
|
package/dist/esm/media-viewer.js
CHANGED
|
@@ -116,7 +116,8 @@ export var MediaViewerComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
116
116
|
className: mediaViewerPopupClass
|
|
117
117
|
}, /*#__PURE__*/React.createElement(Shortcut, {
|
|
118
118
|
code: 'Escape',
|
|
119
|
-
handler: this.onShortcutClosed
|
|
119
|
+
handler: this.onShortcutClosed,
|
|
120
|
+
eventType: 'keyup'
|
|
120
121
|
}), /*#__PURE__*/React.createElement(Content, {
|
|
121
122
|
isSidebarVisible: isSidebarVisible,
|
|
122
123
|
onClose: this.onContentClose
|
package/dist/esm/navigation.js
CHANGED
|
@@ -77,7 +77,8 @@ export var NavigationBase = /*#__PURE__*/function (_Component) {
|
|
|
77
77
|
className: hideControlsClassName
|
|
78
78
|
}, /*#__PURE__*/React.createElement(Shortcut, {
|
|
79
79
|
code: 'ArrowLeft',
|
|
80
|
-
handler: prev('keyboard')
|
|
80
|
+
handler: prev('keyboard'),
|
|
81
|
+
eventType: 'keyup'
|
|
81
82
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
82
83
|
testId: prevNavButtonId,
|
|
83
84
|
onClick: prev('mouse'),
|
|
@@ -95,7 +96,8 @@ export var NavigationBase = /*#__PURE__*/function (_Component) {
|
|
|
95
96
|
className: hideControlsClassName
|
|
96
97
|
}, /*#__PURE__*/React.createElement(Shortcut, {
|
|
97
98
|
code: 'ArrowRight',
|
|
98
|
-
handler: next('keyboard')
|
|
99
|
+
handler: next('keyboard'),
|
|
100
|
+
eventType: 'keyup'
|
|
99
101
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
100
102
|
testId: nextNavButtonId,
|
|
101
103
|
onClick: next('mouse'),
|