@atlaskit/media-viewer 52.3.2 → 52.4.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/analytics/index.js +1 -1
  3. package/dist/cjs/analytics/ufoExperiences.js +1 -1
  4. package/dist/cjs/viewers/archiveSidebar/archive-sidebar-folder-entry.js +1 -1
  5. package/dist/cjs/viewers/doc-next/doc-viewer.js +201 -0
  6. package/dist/cjs/viewers/doc-next/index.js +17 -81
  7. package/dist/cjs/viewers/doc-next/passwordInput.compiled.css +11 -0
  8. package/dist/cjs/viewers/doc-next/passwordInput.js +126 -0
  9. package/dist/es2019/analytics/index.js +1 -1
  10. package/dist/es2019/analytics/ufoExperiences.js +1 -1
  11. package/dist/es2019/viewers/archiveSidebar/archive-sidebar-folder-entry.js +1 -1
  12. package/dist/es2019/viewers/doc-next/doc-viewer.js +138 -0
  13. package/dist/es2019/viewers/doc-next/index.js +12 -40
  14. package/dist/es2019/viewers/doc-next/passwordInput.compiled.css +11 -0
  15. package/dist/es2019/viewers/doc-next/passwordInput.js +112 -0
  16. package/dist/esm/analytics/index.js +1 -1
  17. package/dist/esm/analytics/ufoExperiences.js +1 -1
  18. package/dist/esm/viewers/archiveSidebar/archive-sidebar-folder-entry.js +1 -1
  19. package/dist/esm/viewers/doc-next/doc-viewer.js +192 -0
  20. package/dist/esm/viewers/doc-next/index.js +17 -79
  21. package/dist/esm/viewers/doc-next/passwordInput.compiled.css +11 -0
  22. package/dist/esm/viewers/doc-next/passwordInput.js +117 -0
  23. package/dist/types/errors.d.ts +1 -1
  24. package/dist/types/viewers/doc-next/doc-viewer.d.ts +13 -0
  25. package/dist/types/viewers/doc-next/index.d.ts +7 -5
  26. package/dist/types/viewers/doc-next/passwordInput.d.ts +11 -0
  27. package/dist/types-ts4.5/errors.d.ts +1 -1
  28. package/dist/types-ts4.5/viewers/doc-next/doc-viewer.d.ts +13 -0
  29. package/dist/types-ts4.5/viewers/doc-next/index.d.ts +7 -5
  30. package/dist/types-ts4.5/viewers/doc-next/passwordInput.d.ts +11 -0
  31. package/package.json +6 -6
  32. /package/dist/cjs/viewers/doc-next/{index.compiled.css → doc-viewer.compiled.css} +0 -0
  33. /package/dist/es2019/viewers/doc-next/{index.compiled.css → doc-viewer.compiled.css} +0 -0
  34. /package/dist/esm/viewers/doc-next/{index.compiled.css → doc-viewer.compiled.css} +0 -0
@@ -0,0 +1,138 @@
1
+ /* doc-viewer.tsx generated by @compiled/babel-plugin v0.36.1 */
2
+ import "./doc-viewer.compiled.css";
3
+ import * as React from 'react';
4
+ import { ax, ix } from "@compiled/react/runtime";
5
+ import { useReducer } from 'react';
6
+ import { isCommonMediaClientError } from '@atlaskit/media-client';
7
+ import { DOCUMENT_SCROLL_ROOT_ID, DocumentViewer } from '@atlaskit/media-document-viewer';
8
+ import { useStaticCallback } from '@atlaskit/media-common';
9
+ import { MediaViewerError } from '../../errors';
10
+ import { ZoomControls } from '../../zoomControls';
11
+ import { ZoomLevel } from '../../domain/zoomLevel';
12
+ import { PasswordInput } from './passwordInput';
13
+ const initialState = {
14
+ isMissingPassword: false,
15
+ hasPasswordError: false,
16
+ password: '',
17
+ zoomLevel: new ZoomLevel(1.75)
18
+ };
19
+ const reducer = (state, action) => {
20
+ switch (action.type) {
21
+ case 'submit_password':
22
+ return {
23
+ ...state,
24
+ password: action.password
25
+ };
26
+ case 'set_zoom_level':
27
+ return {
28
+ ...state,
29
+ zoomLevel: action.zoomLevel
30
+ };
31
+ case 'password_validation_failed':
32
+ return {
33
+ ...state,
34
+ hasPasswordError: true
35
+ };
36
+ case 'password_validation_succeeded':
37
+ return {
38
+ ...state,
39
+ isMissingPassword: false,
40
+ hasPasswordError: false
41
+ };
42
+ case 'content_fetch_failed_password_required':
43
+ return {
44
+ ...state,
45
+ isMissingPassword: true
46
+ };
47
+ default:
48
+ return state;
49
+ }
50
+ };
51
+ const documentViewerStyles = null;
52
+ export const DocViewer = ({
53
+ mediaClient,
54
+ fileState,
55
+ collectionName,
56
+ onError,
57
+ traceContext
58
+ }) => {
59
+ const [state, dispatch] = useReducer(reducer, initialState);
60
+ const getContent = useStaticCallback(async (pageStart, pageEnd) => {
61
+ try {
62
+ return await mediaClient.mediaStore.getDocumentContent(fileState.id, {
63
+ pageStart,
64
+ pageEnd,
65
+ collectionName,
66
+ password: state.password
67
+ }, traceContext);
68
+ } catch (error) {
69
+ if (isCommonMediaClientError(error) && error.reason === 'serverEntityLocked') {
70
+ dispatch({
71
+ type: 'content_fetch_failed_password_required'
72
+ });
73
+ } else {
74
+ onError(new MediaViewerError('docviewer-content-fetch-failed', error instanceof Error ? error : undefined));
75
+ }
76
+ throw error;
77
+ }
78
+ });
79
+ const onPasswordSubmit = useStaticCallback(async data => {
80
+ dispatch({
81
+ type: 'submit_password',
82
+ password: data.password
83
+ });
84
+ try {
85
+ // checking if the password is correct currently requires content fetch but we may have a faster enpoint for this in the future
86
+ await mediaClient.mediaStore.getDocumentContent(fileState.id, {
87
+ pageStart: 0,
88
+ pageEnd: 1,
89
+ collectionName,
90
+ password: data.password
91
+ }, traceContext);
92
+ dispatch({
93
+ type: 'password_validation_succeeded'
94
+ });
95
+ } catch (error) {
96
+ if (isCommonMediaClientError(error) && error.reason === 'serverEntityLocked') {
97
+ dispatch({
98
+ type: 'password_validation_failed'
99
+ });
100
+ } else {
101
+ onError(new MediaViewerError('docviewer-content-fetch-failed', error instanceof Error ? error : undefined));
102
+ }
103
+ }
104
+ });
105
+ const getPageImageUrl = useStaticCallback(async (pageNumber, zoom) => {
106
+ const src = await mediaClient.mediaStore.getDocumentPageImage(fileState.id, {
107
+ page: pageNumber,
108
+ zoom,
109
+ collectionName,
110
+ password: state.password
111
+ }, traceContext);
112
+ return URL.createObjectURL(src);
113
+ });
114
+ const onZoomChange = useStaticCallback(newZoomLevel => {
115
+ dispatch({
116
+ type: 'set_zoom_level',
117
+ zoomLevel: newZoomLevel
118
+ });
119
+ });
120
+ if (state.isMissingPassword) {
121
+ return /*#__PURE__*/React.createElement(PasswordInput, {
122
+ onSubmit: onPasswordSubmit,
123
+ hasPasswordError: state.hasPasswordError
124
+ });
125
+ }
126
+ return /*#__PURE__*/React.createElement("div", {
127
+ id: DOCUMENT_SCROLL_ROOT_ID,
128
+ className: ax(["_1reo1wug _18m91wug _4t3i1kxc _1bsbauwl"])
129
+ }, /*#__PURE__*/React.createElement(DocumentViewer, {
130
+ getContent: getContent,
131
+ getPageImageUrl: getPageImageUrl,
132
+ zoom: state.zoomLevel.value
133
+ }), /*#__PURE__*/React.createElement(ZoomControls, {
134
+ onChange: onZoomChange,
135
+ zoomLevel: state.zoomLevel
136
+ }));
137
+ };
138
+ export default DocViewer;
@@ -1,44 +1,20 @@
1
- /* index.tsx generated by @compiled/babel-plugin v0.36.1 */
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import "./index.compiled.css";
4
- import * as React from 'react';
5
- import { ax, ix } from "@compiled/react/runtime";
6
- import { DOCUMENT_SCROLL_ROOT_ID, DocumentViewer } from '@atlaskit/media-document-viewer';
2
+ import React from 'react';
7
3
  import { Outcome } from '../../domain';
8
4
  import { BaseViewer } from '../base-viewer';
9
- import { ZoomControls } from '../../zoomControls';
10
5
  import { ZoomLevel } from '../../domain/zoomLevel';
11
- const documentViewerStyles = null;
6
+ import { DocViewer as DocViewerComponent } from './doc-viewer';
12
7
  export class DocViewer extends BaseViewer {
13
8
  constructor(...args) {
14
9
  super(...args);
15
10
  _defineProperty(this, "isObjectUrl", false);
16
- _defineProperty(this, "getContent", async (pageStart, pageEnd) => {
17
- const src = await this.props.mediaClient.mediaStore.getDocumentContent(this.props.item.id, {
18
- pageStart,
19
- pageEnd,
20
- collectionName: this.props.collectionName
21
- });
22
- return src;
23
- });
24
- _defineProperty(this, "getPageImageUrl", async (pageNumber, zoom) => {
25
- const src = await this.props.mediaClient.mediaStore.getDocumentPageImage(this.props.item.id, {
26
- page: pageNumber,
27
- zoom,
28
- collectionName: this.props.collectionName
29
- });
30
- return URL.createObjectURL(src);
31
- });
32
- _defineProperty(this, "onZoomChange", newZoomLevel => {
33
- this.setState({
34
- zoomLevel: newZoomLevel
35
- });
36
- });
37
11
  }
38
12
  get initialState() {
39
13
  return {
40
14
  content: Outcome.pending(),
41
- zoomLevel: new ZoomLevel(1.75)
15
+ zoomLevel: new ZoomLevel(1.75),
16
+ isPasswordProtected: false,
17
+ hasPasswordError: false
42
18
  };
43
19
  }
44
20
  needsReset(propsA, propsB) {
@@ -67,16 +43,12 @@ export class DocViewer extends BaseViewer {
67
43
  }
68
44
  }
69
45
  renderSuccessful() {
70
- return /*#__PURE__*/React.createElement("div", {
71
- id: DOCUMENT_SCROLL_ROOT_ID,
72
- className: ax(["_1reo1wug _18m91wug _4t3i1kxc _1bsbauwl"])
73
- }, /*#__PURE__*/React.createElement(DocumentViewer, {
74
- getContent: this.getContent,
75
- getPageImageUrl: this.getPageImageUrl,
76
- zoom: this.state.zoomLevel.value
77
- }), /*#__PURE__*/React.createElement(ZoomControls, {
78
- onChange: this.onZoomChange,
79
- zoomLevel: this.state.zoomLevel
80
- }));
46
+ return /*#__PURE__*/React.createElement(DocViewerComponent, {
47
+ mediaClient: this.props.mediaClient,
48
+ fileState: this.props.item,
49
+ collectionName: this.props.collectionName,
50
+ onError: this.props.onError,
51
+ traceContext: this.props.traceContext
52
+ });
81
53
  }
82
54
  }
@@ -0,0 +1,11 @@
1
+ ._11c8dcr7{font:var(--ds-font-body-UNSAFE_small,normal 400 9pt/1pc ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
+ ._12nx2smr h1{font:var(--ds-font-body,normal 400 14px/20px ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
+ ._125x1366 p{color:#fd9891}
4
+ ._18u01b66{margin-left:var(--ds-space-050,4px)}
5
+ ._19pk1b66{margin-top:var(--ds-space-050,4px)}
6
+ ._19pkidpf{margin-top:0}
7
+ ._1e0c1txw{display:flex}
8
+ ._1nda9txx h1{color:#b6c2cf}
9
+ ._1twlmoej h1{font-weight:var(--ds-font-weight-bold,700)}
10
+ ._4cvr1h6o{align-items:center}
11
+ ._syaz1366{color:#fd9891}
@@ -0,0 +1,112 @@
1
+ /* passwordInput.tsx generated by @compiled/babel-plugin v0.36.1 */
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import "./passwordInput.compiled.css";
4
+ import * as React from 'react';
5
+ import { ax, ix } from "@compiled/react/runtime";
6
+ import { useEffect, useRef, useState } from 'react';
7
+ import Button from '@atlaskit/button/new';
8
+ import TextField from '@atlaskit/textfield';
9
+ import LockIcon from '@atlaskit/icon/core/migration/lock-locked--lock';
10
+ import Form, { Field } from '@atlaskit/form';
11
+ import { FormattedMessage, useIntl } from 'react-intl-next';
12
+ import { messages } from '@atlaskit/media-ui';
13
+ import { xcss, Box, Flex, Text } from '@atlaskit/primitives';
14
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
15
+ import ErrorIcon from '@atlaskit/icon/core/migration/error';
16
+ import Heading from '@atlaskit/heading';
17
+ const COLOR_SHADE = '#b6c2cf';
18
+ const ERROR_COLOR = '#FD9891';
19
+ const headingStyle = null;
20
+ const errorMessageWrapperStyle = null;
21
+ const errorMessageStyle = null;
22
+ const headerStyles = xcss({
23
+ textAlign: 'center',
24
+ marginTop: 'space.200',
25
+ marginBottom: 'space.200'
26
+ });
27
+ const inputStyle = xcss({
28
+ width: '330px'
29
+ });
30
+ const footerStyles = xcss({
31
+ marginTop: 'space.200',
32
+ display: 'flex',
33
+ justifyContent: 'center'
34
+ });
35
+ export const PasswordInput = ({
36
+ onSubmit,
37
+ hasPasswordError,
38
+ onRender
39
+ }) => {
40
+ const passwordInputRef = useRef(null);
41
+ const onRenderRef = useRef(onRender);
42
+ const [formError, setFormError] = useState(hasPasswordError);
43
+ const intl = useIntl();
44
+ useEffect(() => {
45
+ var _onRenderRef$current;
46
+ (_onRenderRef$current = onRenderRef.current) === null || _onRenderRef$current === void 0 ? void 0 : _onRenderRef$current.call(onRenderRef);
47
+ }, []);
48
+ useEffect(() => {
49
+ if (hasPasswordError) {
50
+ var _passwordInputRef$cur;
51
+ setFormError(true);
52
+ (_passwordInputRef$cur = passwordInputRef.current) === null || _passwordInputRef$cur === void 0 ? void 0 : _passwordInputRef$cur.focus();
53
+ }
54
+ }, [hasPasswordError]);
55
+ return /*#__PURE__*/React.createElement(Form, {
56
+ onSubmit: onSubmit
57
+ }, ({
58
+ formProps,
59
+ submitting
60
+ }) => /*#__PURE__*/React.createElement("form", formProps, /*#__PURE__*/React.createElement(Flex, {
61
+ justifyContent: "center"
62
+ }, /*#__PURE__*/React.createElement(LockIcon, {
63
+ label: "",
64
+ LEGACY_size: "xlarge",
65
+ color: COLOR_SHADE
66
+ })), /*#__PURE__*/React.createElement(Box, {
67
+ xcss: headerStyles
68
+ }, /*#__PURE__*/React.createElement("div", {
69
+ className: ax(["_12nx2smr _1twlmoej _1nda9txx"])
70
+ }, /*#__PURE__*/React.createElement(Heading, {
71
+ as: "h1",
72
+ size: "medium"
73
+ }, /*#__PURE__*/React.createElement(FormattedMessage, messages.password_protected_pdf)))), /*#__PURE__*/React.createElement(Field, {
74
+ "aria-required": true,
75
+ name: "password",
76
+ defaultValue: "",
77
+ isRequired: true
78
+ }, ({
79
+ fieldProps
80
+ }) => /*#__PURE__*/React.createElement(Box, {
81
+ xcss: inputStyle
82
+ }, /*#__PURE__*/React.createElement(TextField, _extends({}, fieldProps, {
83
+ type: "password",
84
+ "aria-label": intl.formatMessage(messages.password),
85
+ placeholder: intl.formatMessage(messages.enter_password),
86
+ ref: passwordInputRef,
87
+ "aria-describedby": formError ? `${fieldProps.id}-error` : undefined,
88
+ onChange: value => {
89
+ fieldProps.onChange(value);
90
+ setFormError(false);
91
+ }
92
+ })), formError && /*#__PURE__*/React.createElement("div", {
93
+ id: `${fieldProps.id}-error`,
94
+ className: ax(["_11c8dcr7 _19pk1b66 _1e0c1txw _4cvr1h6o _syaz1366 _125x1366"])
95
+ }, /*#__PURE__*/React.createElement(ErrorIcon, {
96
+ color: "currentColor",
97
+ LEGACY_size: "small",
98
+ label: "",
99
+ size: "small"
100
+ }), /*#__PURE__*/React.createElement("div", {
101
+ id: `${fieldProps.id}-errorMessage`,
102
+ className: ax(["_19pkidpf _18u01b66"])
103
+ }, /*#__PURE__*/React.createElement(Text, {
104
+ as: "p"
105
+ }, /*#__PURE__*/React.createElement(FormattedMessage, messages.incorrect_password)))))), /*#__PURE__*/React.createElement(Box, {
106
+ xcss: footerStyles
107
+ }, /*#__PURE__*/React.createElement(Button, {
108
+ appearance: "primary",
109
+ type: "submit",
110
+ isLoading: submitting
111
+ }, /*#__PURE__*/React.createElement(FormattedMessage, messages.submit)))));
112
+ };
@@ -1,7 +1,7 @@
1
1
  import { ANALYTICS_MEDIA_CHANNEL, sanitiseAnalyticsPayload } from '@atlaskit/media-common/analytics';
2
2
  var componentName = 'mediaViewer';
3
3
  var packageName = "@atlaskit/media-viewer";
4
- var packageVersion = "52.3.1";
4
+ var packageVersion = "52.3.3";
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 = "52.3.1";
8
+ var packageVersion = "52.3.3";
9
9
  var ufoExperience;
10
10
  var getExperience = function getExperience() {
11
11
  if (!ufoExperience) {
@@ -60,7 +60,7 @@ var ArchiveSidebarFolderEntryBase = /*#__PURE__*/function (_React$Component) {
60
60
  var _this$props2 = _this.props,
61
61
  shouldRenderAbuseModal = _this$props2.shouldRenderAbuseModal,
62
62
  intl = _this$props2.intl;
63
- var tooltip = intl.formatMessage(messages.download_disabled_security_policy);
63
+ var tooltip = enforceDataSecurityPolicy ? intl.formatMessage(messages.download_disabled_security_policy) : undefined;
64
64
  var downloadFn = function downloadFn() {
65
65
  return _this.downloadZipEntry(entry, root);
66
66
  };
@@ -0,0 +1,192 @@
1
+ /* doc-viewer.tsx generated by @compiled/babel-plugin v0.36.1 */
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
+ import "./doc-viewer.compiled.css";
6
+ import * as React from 'react';
7
+ import { ax, ix } from "@compiled/react/runtime";
8
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ import { useReducer } from 'react';
12
+ import { isCommonMediaClientError } from '@atlaskit/media-client';
13
+ import { DOCUMENT_SCROLL_ROOT_ID, DocumentViewer } from '@atlaskit/media-document-viewer';
14
+ import { useStaticCallback } from '@atlaskit/media-common';
15
+ import { MediaViewerError } from '../../errors';
16
+ import { ZoomControls } from '../../zoomControls';
17
+ import { ZoomLevel } from '../../domain/zoomLevel';
18
+ import { PasswordInput } from './passwordInput';
19
+ var initialState = {
20
+ isMissingPassword: false,
21
+ hasPasswordError: false,
22
+ password: '',
23
+ zoomLevel: new ZoomLevel(1.75)
24
+ };
25
+ var reducer = function reducer(state, action) {
26
+ switch (action.type) {
27
+ case 'submit_password':
28
+ return _objectSpread(_objectSpread({}, state), {}, {
29
+ password: action.password
30
+ });
31
+ case 'set_zoom_level':
32
+ return _objectSpread(_objectSpread({}, state), {}, {
33
+ zoomLevel: action.zoomLevel
34
+ });
35
+ case 'password_validation_failed':
36
+ return _objectSpread(_objectSpread({}, state), {}, {
37
+ hasPasswordError: true
38
+ });
39
+ case 'password_validation_succeeded':
40
+ return _objectSpread(_objectSpread({}, state), {}, {
41
+ isMissingPassword: false,
42
+ hasPasswordError: false
43
+ });
44
+ case 'content_fetch_failed_password_required':
45
+ return _objectSpread(_objectSpread({}, state), {}, {
46
+ isMissingPassword: true
47
+ });
48
+ default:
49
+ return state;
50
+ }
51
+ };
52
+ var documentViewerStyles = null;
53
+ export var DocViewer = function DocViewer(_ref) {
54
+ var mediaClient = _ref.mediaClient,
55
+ fileState = _ref.fileState,
56
+ collectionName = _ref.collectionName,
57
+ onError = _ref.onError,
58
+ traceContext = _ref.traceContext;
59
+ var _useReducer = useReducer(reducer, initialState),
60
+ _useReducer2 = _slicedToArray(_useReducer, 2),
61
+ state = _useReducer2[0],
62
+ dispatch = _useReducer2[1];
63
+ var getContent = useStaticCallback( /*#__PURE__*/function () {
64
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageStart, pageEnd) {
65
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
66
+ while (1) switch (_context.prev = _context.next) {
67
+ case 0:
68
+ _context.prev = 0;
69
+ _context.next = 3;
70
+ return mediaClient.mediaStore.getDocumentContent(fileState.id, {
71
+ pageStart: pageStart,
72
+ pageEnd: pageEnd,
73
+ collectionName: collectionName,
74
+ password: state.password
75
+ }, traceContext);
76
+ case 3:
77
+ return _context.abrupt("return", _context.sent);
78
+ case 6:
79
+ _context.prev = 6;
80
+ _context.t0 = _context["catch"](0);
81
+ if (isCommonMediaClientError(_context.t0) && _context.t0.reason === 'serverEntityLocked') {
82
+ dispatch({
83
+ type: 'content_fetch_failed_password_required'
84
+ });
85
+ } else {
86
+ onError(new MediaViewerError('docviewer-content-fetch-failed', _context.t0 instanceof Error ? _context.t0 : undefined));
87
+ }
88
+ throw _context.t0;
89
+ case 10:
90
+ case "end":
91
+ return _context.stop();
92
+ }
93
+ }, _callee, null, [[0, 6]]);
94
+ }));
95
+ return function (_x, _x2) {
96
+ return _ref2.apply(this, arguments);
97
+ };
98
+ }());
99
+ var onPasswordSubmit = useStaticCallback( /*#__PURE__*/function () {
100
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(data) {
101
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
102
+ while (1) switch (_context2.prev = _context2.next) {
103
+ case 0:
104
+ dispatch({
105
+ type: 'submit_password',
106
+ password: data.password
107
+ });
108
+ _context2.prev = 1;
109
+ _context2.next = 4;
110
+ return mediaClient.mediaStore.getDocumentContent(fileState.id, {
111
+ pageStart: 0,
112
+ pageEnd: 1,
113
+ collectionName: collectionName,
114
+ password: data.password
115
+ }, traceContext);
116
+ case 4:
117
+ dispatch({
118
+ type: 'password_validation_succeeded'
119
+ });
120
+ _context2.next = 10;
121
+ break;
122
+ case 7:
123
+ _context2.prev = 7;
124
+ _context2.t0 = _context2["catch"](1);
125
+ if (isCommonMediaClientError(_context2.t0) && _context2.t0.reason === 'serverEntityLocked') {
126
+ dispatch({
127
+ type: 'password_validation_failed'
128
+ });
129
+ } else {
130
+ onError(new MediaViewerError('docviewer-content-fetch-failed', _context2.t0 instanceof Error ? _context2.t0 : undefined));
131
+ }
132
+ case 10:
133
+ case "end":
134
+ return _context2.stop();
135
+ }
136
+ }, _callee2, null, [[1, 7]]);
137
+ }));
138
+ return function (_x3) {
139
+ return _ref3.apply(this, arguments);
140
+ };
141
+ }());
142
+ var getPageImageUrl = useStaticCallback( /*#__PURE__*/function () {
143
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(pageNumber, zoom) {
144
+ var src;
145
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
146
+ while (1) switch (_context3.prev = _context3.next) {
147
+ case 0:
148
+ _context3.next = 2;
149
+ return mediaClient.mediaStore.getDocumentPageImage(fileState.id, {
150
+ page: pageNumber,
151
+ zoom: zoom,
152
+ collectionName: collectionName,
153
+ password: state.password
154
+ }, traceContext);
155
+ case 2:
156
+ src = _context3.sent;
157
+ return _context3.abrupt("return", URL.createObjectURL(src));
158
+ case 4:
159
+ case "end":
160
+ return _context3.stop();
161
+ }
162
+ }, _callee3);
163
+ }));
164
+ return function (_x4, _x5) {
165
+ return _ref4.apply(this, arguments);
166
+ };
167
+ }());
168
+ var onZoomChange = useStaticCallback(function (newZoomLevel) {
169
+ dispatch({
170
+ type: 'set_zoom_level',
171
+ zoomLevel: newZoomLevel
172
+ });
173
+ });
174
+ if (state.isMissingPassword) {
175
+ return /*#__PURE__*/React.createElement(PasswordInput, {
176
+ onSubmit: onPasswordSubmit,
177
+ hasPasswordError: state.hasPasswordError
178
+ });
179
+ }
180
+ return /*#__PURE__*/React.createElement("div", {
181
+ id: DOCUMENT_SCROLL_ROOT_ID,
182
+ className: ax(["_1reo1wug _18m91wug _4t3i1kxc _1bsbauwl"])
183
+ }, /*#__PURE__*/React.createElement(DocumentViewer, {
184
+ getContent: getContent,
185
+ getPageImageUrl: getPageImageUrl,
186
+ zoom: state.zoomLevel.value
187
+ }), /*#__PURE__*/React.createElement(ZoomControls, {
188
+ onChange: onZoomChange,
189
+ zoomLevel: state.zoomLevel
190
+ }));
191
+ };
192
+ export default DocViewer;