@atlaskit/media-viewer 54.10.5 → 54.11.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/AGENTS.md +15 -1
- package/CHANGELOG.md +32 -0
- package/dist/cjs/DownloadButton.js +15 -1
- package/dist/cjs/analytics/ufoExperiences.js +1 -1
- package/dist/cjs/content.js +15 -9
- package/dist/cjs/download.js +21 -4
- package/dist/cjs/header.js +91 -40
- package/dist/cjs/inset-sidebar-header.js +108 -0
- package/dist/cjs/insetViewerContext.js +34 -2
- package/dist/cjs/list.js +9 -5
- package/dist/cjs/media-viewer.js +43 -9
- package/dist/cjs/styleWrappers.compiled.css +32 -3
- package/dist/cjs/styleWrappers.js +205 -135
- package/dist/cjs/viewer-icon-button.js +38 -0
- package/dist/cjs/zoomControls.js +59 -5
- package/dist/es2019/DownloadButton.js +16 -1
- package/dist/es2019/analytics/ufoExperiences.js +1 -1
- package/dist/es2019/content.js +10 -4
- package/dist/es2019/download.js +22 -4
- package/dist/es2019/header.js +76 -33
- package/dist/es2019/inset-sidebar-header.js +100 -0
- package/dist/es2019/insetViewerContext.js +30 -4
- package/dist/es2019/list.js +9 -5
- package/dist/es2019/media-viewer.js +41 -11
- package/dist/es2019/styleWrappers.compiled.css +32 -3
- package/dist/es2019/styleWrappers.js +117 -32
- package/dist/es2019/viewer-icon-button.js +26 -0
- package/dist/es2019/zoomControls.js +57 -2
- package/dist/esm/DownloadButton.js +15 -1
- package/dist/esm/analytics/ufoExperiences.js +1 -1
- package/dist/esm/content.js +15 -9
- package/dist/esm/download.js +21 -4
- package/dist/esm/header.js +91 -40
- package/dist/esm/inset-sidebar-header.js +99 -0
- package/dist/esm/insetViewerContext.js +34 -2
- package/dist/esm/list.js +9 -5
- package/dist/esm/media-viewer.js +45 -11
- package/dist/esm/styleWrappers.compiled.css +32 -3
- package/dist/esm/styleWrappers.js +205 -135
- package/dist/esm/viewer-icon-button.js +31 -0
- package/dist/esm/zoomControls.js +59 -5
- package/dist/types/content.d.ts +2 -4
- package/dist/types/download.d.ts +1 -1
- package/dist/types/header.d.ts +3 -1
- package/dist/types/inset-sidebar-header.d.ts +13 -0
- package/dist/types/insetViewerContext.d.ts +6 -0
- package/dist/types/list.d.ts +4 -2
- package/dist/types/styleWrappers.d.ts +10 -1
- package/dist/types/viewer-icon-button.d.ts +18 -0
- package/dist/types/zoomControls.d.ts +6 -3
- package/package.json +8 -6
package/dist/cjs/zoomControls.js
CHANGED
|
@@ -13,17 +13,25 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
13
13
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
14
14
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
15
|
var _react = _interopRequireWildcard(require("react"));
|
|
16
|
+
var _reactDom = require("react-dom");
|
|
16
17
|
var _reactIntl = require("react-intl");
|
|
17
18
|
var _withAnalyticsEvents = _interopRequireDefault(require("@atlaskit/analytics-next/withAnalyticsEvents"));
|
|
19
|
+
var _button = _interopRequireDefault(require("@atlaskit/button/default/button"));
|
|
20
|
+
var _add = _interopRequireDefault(require("@atlaskit/icon/core/add"));
|
|
21
|
+
var _minus = _interopRequireDefault(require("@atlaskit/icon/core/minus"));
|
|
18
22
|
var _zoomIn = _interopRequireDefault(require("@atlaskit/icon/core/zoom-in"));
|
|
19
23
|
var _zoomOut = _interopRequireDefault(require("@atlaskit/icon/core/zoom-out"));
|
|
20
24
|
var _classNames = require("@atlaskit/media-ui/classNames");
|
|
21
25
|
var _MediaButton = _interopRequireDefault(require("@atlaskit/media-ui/MediaButton"));
|
|
22
26
|
var _messages = require("@atlaskit/media-ui/messages");
|
|
27
|
+
var _Tooltip = _interopRequireDefault(require("@atlaskit/tooltip/Tooltip"));
|
|
23
28
|
var _zoomInButtonClicked = require("./analytics/events/ui/zoomInButtonClicked");
|
|
24
29
|
var _zoomOutButtonClicked = require("./analytics/events/ui/zoomOutButtonClicked");
|
|
25
30
|
var _fireAnalytics = require("./analytics/fireAnalytics");
|
|
31
|
+
var _zoomLevel = require("./domain/zoomLevel");
|
|
32
|
+
var _insetViewerContext = require("./insetViewerContext");
|
|
26
33
|
var _styleWrappers = require("./styleWrappers");
|
|
34
|
+
var _viewerIconButton = require("./viewer-icon-button");
|
|
27
35
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
28
36
|
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
|
|
29
37
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
@@ -57,16 +65,60 @@ var ZoomControlsBase = exports.ZoomControlsBase = /*#__PURE__*/function (_Compon
|
|
|
57
65
|
onChange(zoom);
|
|
58
66
|
}
|
|
59
67
|
});
|
|
68
|
+
(0, _defineProperty2.default)(_this, "zoomToFit", function () {
|
|
69
|
+
var _this$props3 = _this.props,
|
|
70
|
+
onResetZoom = _this$props3.onResetZoom,
|
|
71
|
+
onChange = _this$props3.onChange,
|
|
72
|
+
zoomLevel = _this$props3.zoomLevel;
|
|
73
|
+
if (onResetZoom) {
|
|
74
|
+
onResetZoom();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
onChange(new _zoomLevel.ZoomLevel(zoomLevel.initialValue));
|
|
78
|
+
});
|
|
60
79
|
return _this;
|
|
61
80
|
}
|
|
62
81
|
(0, _inherits2.default)(ZoomControlsBase, _Component);
|
|
63
82
|
return (0, _createClass2.default)(ZoomControlsBase, [{
|
|
64
83
|
key: "render",
|
|
65
84
|
value: function render() {
|
|
66
|
-
var _this$
|
|
67
|
-
zoomLevel = _this$
|
|
68
|
-
formatMessage = _this$
|
|
69
|
-
children = _this$
|
|
85
|
+
var _this$props4 = this.props,
|
|
86
|
+
zoomLevel = _this$props4.zoomLevel,
|
|
87
|
+
formatMessage = _this$props4.intl.formatMessage,
|
|
88
|
+
children = _this$props4.children,
|
|
89
|
+
isInsetViewer = _this$props4.isInsetViewer,
|
|
90
|
+
mediaFooterControls = _this$props4.mediaFooterControls;
|
|
91
|
+
if (isInsetViewer) {
|
|
92
|
+
if (!mediaFooterControls) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
var zoomPercentage = "".concat(Math.round(zoomLevel.value * 100), "%");
|
|
96
|
+
return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomWrapper, null, /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomCenterControls, null, /*#__PURE__*/_react.default.createElement(_viewerIconButton.ViewerIconButton, {
|
|
97
|
+
isDisabled: !zoomLevel.canZoomOut,
|
|
98
|
+
onClick: this.zoomOut,
|
|
99
|
+
icon: _minus.default,
|
|
100
|
+
label: formatMessage(_messages.messages.zoom_out)
|
|
101
|
+
}), /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
|
|
102
|
+
content: formatMessage(_messages.messages.zoom_to_fit),
|
|
103
|
+
position: "top",
|
|
104
|
+
tag: "span"
|
|
105
|
+
}, /*#__PURE__*/_react.default.createElement(_button.default, {
|
|
106
|
+
appearance: "subtle"
|
|
107
|
+
// Names the current zoom as well, since the label replaces the visible percentage.
|
|
108
|
+
,
|
|
109
|
+
"aria-label": formatMessage(_messages.messages.zoom_to_fit_with_level, {
|
|
110
|
+
zoomLevel: zoomPercentage
|
|
111
|
+
}),
|
|
112
|
+
onClick: this.zoomToFit,
|
|
113
|
+
spacing: "default",
|
|
114
|
+
testId: "zoom-level-indicator"
|
|
115
|
+
}, zoomPercentage)), /*#__PURE__*/_react.default.createElement(_viewerIconButton.ViewerIconButton, {
|
|
116
|
+
isDisabled: !zoomLevel.canZoomIn,
|
|
117
|
+
onClick: this.zoomIn,
|
|
118
|
+
icon: _add.default,
|
|
119
|
+
label: formatMessage(_messages.messages.zoom_in)
|
|
120
|
+
})), children ? /*#__PURE__*/_react.default.createElement(_styleWrappers.ZoomRightControls, null, children) : null), mediaFooterControls);
|
|
121
|
+
}
|
|
70
122
|
return (
|
|
71
123
|
/*#__PURE__*/
|
|
72
124
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
@@ -93,4 +145,6 @@ var ZoomControlsBase = exports.ZoomControlsBase = /*#__PURE__*/function (_Compon
|
|
|
93
145
|
}
|
|
94
146
|
}]);
|
|
95
147
|
}(_react.Component); // @ts-ignore: [PIT-1685] Fails in post-office due to backwards incompatibility issue with React 18
|
|
96
|
-
var ZoomControls = exports.ZoomControls = (0, _withAnalyticsEvents.default)({})((0, _reactIntl.injectIntl)(ZoomControlsBase)
|
|
148
|
+
var ZoomControls = exports.ZoomControls = (0, _withAnalyticsEvents.default)({})((0, _reactIntl.injectIntl)((0, _insetViewerContext.withInsetViewerFooter)(ZoomControlsBase), {
|
|
149
|
+
forwardRef: true
|
|
150
|
+
}));
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
3
4
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next/useAnalyticsEvents';
|
|
5
|
+
import DownloadIcon from '@atlaskit/icon/core/download';
|
|
4
6
|
import MediaButton from '@atlaskit/media-ui/MediaButton';
|
|
7
|
+
import { messages } from '@atlaskit/media-ui/messages';
|
|
5
8
|
import Tooltip from '@atlaskit/tooltip/Tooltip';
|
|
6
9
|
import { fireAnalytics } from './analytics/fireAnalytics';
|
|
10
|
+
import { useIsInsetViewer } from './insetViewerContext';
|
|
7
11
|
import { noop } from './noop';
|
|
12
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
8
13
|
export function DownloadButton({
|
|
9
14
|
analyticspayload,
|
|
10
15
|
onClick: providedOnClick = noop,
|
|
@@ -14,11 +19,21 @@ export function DownloadButton({
|
|
|
14
19
|
const {
|
|
15
20
|
createAnalyticsEvent
|
|
16
21
|
} = useAnalyticsEvents();
|
|
22
|
+
const {
|
|
23
|
+
formatMessage
|
|
24
|
+
} = useIntl();
|
|
25
|
+
const isInsetViewer = useIsInsetViewer();
|
|
17
26
|
const onClick = useCallback((event, analyticsEvent) => {
|
|
18
27
|
fireAnalytics(analyticspayload, createAnalyticsEvent);
|
|
19
28
|
providedOnClick(event, analyticsEvent);
|
|
20
29
|
}, [analyticspayload, providedOnClick, createAnalyticsEvent]);
|
|
21
|
-
const downloadButton = /*#__PURE__*/React.createElement(
|
|
30
|
+
const downloadButton = isInsetViewer ? /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
31
|
+
testId: rest.testId,
|
|
32
|
+
isDisabled: rest.isDisabled,
|
|
33
|
+
icon: DownloadIcon,
|
|
34
|
+
label: formatMessage(messages.download),
|
|
35
|
+
onClick: onClick
|
|
36
|
+
}) : /*#__PURE__*/React.createElement(MediaButton, _extends({}, rest, {
|
|
22
37
|
onClick: onClick
|
|
23
38
|
}));
|
|
24
39
|
return tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
|
|
@@ -4,7 +4,7 @@ import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
|
4
4
|
import { UFOExperience } from '@atlaskit/ufo/experience';
|
|
5
5
|
import { ExperiencePerformanceTypes, ExperienceTypes } from '@atlaskit/ufo/experience-types';
|
|
6
6
|
const packageName = "@atlaskit/media-viewer";
|
|
7
|
-
const packageVersion = "54.10.
|
|
7
|
+
const packageVersion = "54.10.6";
|
|
8
8
|
let ufoExperience;
|
|
9
9
|
const getExperience = () => {
|
|
10
10
|
if (!ufoExperience) {
|
package/dist/es2019/content.js
CHANGED
|
@@ -4,8 +4,9 @@ import CrossIcon from '@atlaskit/icon/core/cross';
|
|
|
4
4
|
import { hideControlsClassName } from '@atlaskit/media-ui/classNames';
|
|
5
5
|
import { InactivityDetector } from '@atlaskit/media-ui/inactivityDetector';
|
|
6
6
|
import MediaButton from '@atlaskit/media-ui/MediaButton';
|
|
7
|
+
import { withInsetViewer } from './insetViewerContext';
|
|
7
8
|
import { CloseButtonWrapper, ContentWrapper } from './styleWrappers';
|
|
8
|
-
|
|
9
|
+
class ContentBase extends Component {
|
|
9
10
|
/*
|
|
10
11
|
* Here we get called by InactivityDetector and given a function we
|
|
11
12
|
* pass down as "showControls" to out children.
|
|
@@ -13,7 +14,8 @@ export class Content extends Component {
|
|
|
13
14
|
render() {
|
|
14
15
|
const {
|
|
15
16
|
onClose,
|
|
16
|
-
isSidebarVisible
|
|
17
|
+
isSidebarVisible,
|
|
18
|
+
isInsetViewer
|
|
17
19
|
} = this.props;
|
|
18
20
|
return /*#__PURE__*/React.createElement(ContentWrapper, {
|
|
19
21
|
isSidebarVisible: isSidebarVisible
|
|
@@ -21,7 +23,10 @@ export class Content extends Component {
|
|
|
21
23
|
const children = /*#__PURE__*/React.cloneElement(this.props.children, {
|
|
22
24
|
showControls: triggerActivityCallback
|
|
23
25
|
});
|
|
24
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
26
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, !isInsetViewer &&
|
|
27
|
+
/*#__PURE__*/
|
|
28
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
29
|
+
React.createElement(CloseButtonWrapper, {
|
|
25
30
|
className: hideControlsClassName
|
|
26
31
|
}, /*#__PURE__*/React.createElement(MediaButton, {
|
|
27
32
|
testId: "media-viewer-close-button",
|
|
@@ -34,4 +39,5 @@ export class Content extends Component {
|
|
|
34
39
|
})), children);
|
|
35
40
|
}));
|
|
36
41
|
}
|
|
37
|
-
}
|
|
42
|
+
}
|
|
43
|
+
export const Content = withInsetViewer(ContentBase);
|
package/dist/es2019/download.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import DownloadIcon from '@atlaskit/icon/core/download';
|
|
2
4
|
import MediaButton from '@atlaskit/media-ui/MediaButton';
|
|
5
|
+
import { messages } from '@atlaskit/media-ui/messages';
|
|
3
6
|
import { downloadIcon } from './downloadIcon';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { useIsInsetViewer } from './insetViewerContext';
|
|
8
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
9
|
+
export const DisabledToolbarDownloadButton = () => {
|
|
10
|
+
const {
|
|
11
|
+
formatMessage
|
|
12
|
+
} = useIntl();
|
|
13
|
+
const isInsetViewer = useIsInsetViewer();
|
|
14
|
+
if (isInsetViewer) {
|
|
15
|
+
return /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
16
|
+
isDisabled: true,
|
|
17
|
+
icon: DownloadIcon,
|
|
18
|
+
label: formatMessage(messages.download)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return /*#__PURE__*/React.createElement(MediaButton, {
|
|
22
|
+
isDisabled: true,
|
|
23
|
+
iconBefore: downloadIcon
|
|
24
|
+
});
|
|
25
|
+
};
|
package/dist/es2019/header.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { FormattedMessage } from 'react-intl';
|
|
3
|
+
import CrossIcon from '@atlaskit/icon/core/cross';
|
|
3
4
|
import { isExternalImageIdentifier, isErrorFileState, toCommonMediaClientError } from '@atlaskit/media-client';
|
|
4
5
|
import { useFileState } from '@atlaskit/media-client-react/use-file-state';
|
|
5
6
|
import { useMediaClient } from '@atlaskit/media-client-react/use-media-client';
|
|
@@ -15,9 +16,11 @@ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
|
|
|
15
16
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
16
17
|
import { Outcome } from './domain/outcome';
|
|
17
18
|
import { DisabledToolbarDownloadButton } from './download';
|
|
19
|
+
import { useIsInsetViewer } from './insetViewerContext';
|
|
18
20
|
import { MediaViewerError } from './MediaViewerError';
|
|
19
21
|
import { Header as HeaderWrapper, LeftHeader, RightHeader, MetadataWrapper, MetadataSubText, MedatadataTextWrapper, MetadataIconWrapper, MetadataFileName, FormattedMessageWrapper } from './styleWrappers';
|
|
20
22
|
import { ToolbarDownloadButton } from './ToolbarDownloadButton';
|
|
23
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
21
24
|
import { getFormat } from './viewers/codeViewer/getFormat';
|
|
22
25
|
export const Header = ({
|
|
23
26
|
isArchiveSideBarVisible = false,
|
|
@@ -28,7 +31,11 @@ export const Header = ({
|
|
|
28
31
|
onClose,
|
|
29
32
|
onSetArchiveSideBarVisible,
|
|
30
33
|
traceContext,
|
|
31
|
-
fallbackMediaNameFetcher
|
|
34
|
+
fallbackMediaNameFetcher,
|
|
35
|
+
sidebarToggleRef,
|
|
36
|
+
intl: {
|
|
37
|
+
formatMessage
|
|
38
|
+
}
|
|
32
39
|
}) => {
|
|
33
40
|
var _extensions$headerAct;
|
|
34
41
|
// States
|
|
@@ -144,12 +151,76 @@ export const Header = ({
|
|
|
144
151
|
// Defaulting to unknown again since backend has more mediaTypes than the current supported ones
|
|
145
152
|
return /*#__PURE__*/React.createElement(FormattedMessage, message || messages.unknown);
|
|
146
153
|
};
|
|
154
|
+
const isInsetViewer = useIsInsetViewer();
|
|
155
|
+
const hideControlsClass = isInsetViewer ? undefined : hideControlsClassName;
|
|
156
|
+
const renderInsetFileName = (name, size) => /*#__PURE__*/React.createElement(MetadataWrapper, null, /*#__PURE__*/React.createElement(MedatadataTextWrapper, null, /*#__PURE__*/React.createElement(MetadataFileName, {
|
|
157
|
+
"data-testid": "media-viewer-file-name"
|
|
158
|
+
}, name || fallbackMediaName || /*#__PURE__*/React.createElement(FormattedMessage, messages.unknown), size ? ` · ${toHumanReadableMediaSize(size)}` : '')));
|
|
159
|
+
const downloadButton = item.match({
|
|
160
|
+
pending: () => /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null),
|
|
161
|
+
failed: () => /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null),
|
|
162
|
+
successful: item => /*#__PURE__*/React.createElement(ToolbarDownloadButton, {
|
|
163
|
+
state: item,
|
|
164
|
+
identifier: identifier,
|
|
165
|
+
mediaClient: mediaClient,
|
|
166
|
+
traceContext: traceContext,
|
|
167
|
+
fallbackMediaName: fallbackMediaName
|
|
168
|
+
})
|
|
169
|
+
});
|
|
170
|
+
const sidebarToggleButton = extensions !== null && extensions !== void 0 && extensions.sidebar ? isInsetViewer ? /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
171
|
+
testId: "media-viewer-sidebar-button",
|
|
172
|
+
onClick: onSidebarButtonClick,
|
|
173
|
+
buttonRef: sidebarToggleRef,
|
|
174
|
+
iconBefore: extensions.sidebar.icon,
|
|
175
|
+
label: extensions.sidebar.label || formatMessage(messages.show_sidebar)
|
|
176
|
+
}) : /*#__PURE__*/React.createElement(MediaButton, {
|
|
177
|
+
isSelected: isSidebarVisible,
|
|
178
|
+
testId: "media-viewer-sidebar-button",
|
|
179
|
+
onClick: onSidebarButtonClick,
|
|
180
|
+
iconBefore: extensions.sidebar.icon
|
|
181
|
+
}) : null;
|
|
182
|
+
const extraHeaderActions = extensions === null || extensions === void 0 ? void 0 : (_extensions$headerAct = extensions.headerActions) === null || _extensions$headerAct === void 0 ? void 0 : _extensions$headerAct.map((action, index) => {
|
|
183
|
+
if (action.isVisible && !action.isVisible(identifier)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return isInsetViewer ? /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
187
|
+
key: index,
|
|
188
|
+
testId: `media-viewer-header-action-${index}`,
|
|
189
|
+
onClick: () => action.onClick(identifier, {
|
|
190
|
+
close: onClose || (() => {})
|
|
191
|
+
}),
|
|
192
|
+
iconBefore: action.icon,
|
|
193
|
+
label: action.label
|
|
194
|
+
}) : /*#__PURE__*/React.createElement(MediaButton, {
|
|
195
|
+
key: index,
|
|
196
|
+
testId: `media-viewer-header-action-${index}`,
|
|
197
|
+
onClick: () => action.onClick(identifier, {
|
|
198
|
+
close: onClose || (() => {})
|
|
199
|
+
}),
|
|
200
|
+
iconBefore: action.icon,
|
|
201
|
+
"aria-label": action.label
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
const closeButton = /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
205
|
+
testId: "media-viewer-close-button",
|
|
206
|
+
onClick: onClose,
|
|
207
|
+
icon: CrossIcon,
|
|
208
|
+
label: formatMessage(messages.close)
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// In inset mode, download, the sidebar toggle and close move into the sidebar's own header while
|
|
212
|
+
// it's open; the consumer's extra actions always stay here.
|
|
213
|
+
const actionButtons = isInsetViewer ? /*#__PURE__*/React.createElement(React.Fragment, null, extraHeaderActions, isSidebarVisible ? null : /*#__PURE__*/React.createElement(React.Fragment, null, downloadButton, sidebarToggleButton, closeButton)) : /*#__PURE__*/React.createElement(React.Fragment, null, extraHeaderActions, sidebarToggleButton, downloadButton);
|
|
147
214
|
return /*#__PURE__*/React.createElement(HeaderWrapper, {
|
|
148
215
|
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
149
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop --
|
|
216
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Existing Media Viewer control visibility is class-based.
|
|
150
217
|
,
|
|
151
|
-
className:
|
|
152
|
-
}, /*#__PURE__*/React.createElement(LeftHeader, null, item.match({
|
|
218
|
+
className: hideControlsClass !== null && hideControlsClass !== void 0 ? hideControlsClass : ''
|
|
219
|
+
}, /*#__PURE__*/React.createElement(LeftHeader, null, item.match(isInsetViewer ? {
|
|
220
|
+
successful: item => !isErrorFileState(item) && renderInsetFileName(item.name, item.size),
|
|
221
|
+
pending: () => renderInsetFileName(),
|
|
222
|
+
failed: () => renderInsetFileName()
|
|
223
|
+
} : {
|
|
153
224
|
successful: item => !isErrorFileState(item) && /*#__PURE__*/React.createElement(MetadataWrapper, null, /*#__PURE__*/React.createElement(MetadataIconWrapper, null, /*#__PURE__*/React.createElement(MimeTypeIcon, {
|
|
154
225
|
testId: 'media-viewer-file-type-icon',
|
|
155
226
|
mediaType: item.mediaType,
|
|
@@ -162,33 +233,5 @@ export const Header = ({
|
|
|
162
233
|
}, /*#__PURE__*/React.createElement(FormattedMessageWrapper, null, renderFileTypeText(item)), item.size ? ' · ' + toHumanReadableMediaSize(item.size) : ''))),
|
|
163
234
|
pending: () => null,
|
|
164
235
|
failed: () => null
|
|
165
|
-
})), /*#__PURE__*/React.createElement(RightHeader, null,
|
|
166
|
-
if (action.isVisible && !action.isVisible(identifier)) {
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
return /*#__PURE__*/React.createElement(MediaButton, {
|
|
170
|
-
key: index,
|
|
171
|
-
testId: `media-viewer-header-action-${index}`,
|
|
172
|
-
onClick: () => action.onClick(identifier, {
|
|
173
|
-
close: onClose || (() => {})
|
|
174
|
-
}),
|
|
175
|
-
iconBefore: action.icon,
|
|
176
|
-
"aria-label": action.label
|
|
177
|
-
});
|
|
178
|
-
}), (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/React.createElement(MediaButton, {
|
|
179
|
-
isSelected: isSidebarVisible,
|
|
180
|
-
testId: "media-viewer-sidebar-button",
|
|
181
|
-
onClick: onSidebarButtonClick,
|
|
182
|
-
iconBefore: extensions.sidebar.icon
|
|
183
|
-
}), item.match({
|
|
184
|
-
pending: () => DisabledToolbarDownloadButton,
|
|
185
|
-
failed: () => DisabledToolbarDownloadButton,
|
|
186
|
-
successful: item => /*#__PURE__*/React.createElement(ToolbarDownloadButton, {
|
|
187
|
-
state: item,
|
|
188
|
-
identifier: identifier,
|
|
189
|
-
mediaClient: mediaClient,
|
|
190
|
-
traceContext: traceContext,
|
|
191
|
-
fallbackMediaName: fallbackMediaName
|
|
192
|
-
})
|
|
193
|
-
})));
|
|
236
|
+
})), /*#__PURE__*/React.createElement(RightHeader, null, actionButtons));
|
|
194
237
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import CrossIcon from '@atlaskit/icon/core/cross';
|
|
4
|
+
import PanelRightIcon from '@atlaskit/icon/core/panel-right';
|
|
5
|
+
import { useFileState } from '@atlaskit/media-client-react/use-file-state';
|
|
6
|
+
import { useMediaClient } from '@atlaskit/media-client-react/use-media-client';
|
|
7
|
+
import { isExternalImageIdentifier } from '@atlaskit/media-client/is-external-image-identifier';
|
|
8
|
+
import { getRandomTelemetryId } from '@atlaskit/media-common/helpers';
|
|
9
|
+
import { messages } from '@atlaskit/media-ui/messages';
|
|
10
|
+
import { DisabledToolbarDownloadButton } from './download';
|
|
11
|
+
import { InsetSidebarHeaderRow, RightHeader } from './styleWrappers';
|
|
12
|
+
import { ToolbarDownloadButton } from './ToolbarDownloadButton';
|
|
13
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
14
|
+
// TODO: Header's download works the same way (file state, trace, fallback name). Consider
|
|
15
|
+
// refactoring so Header and the sidebar share one implementation.
|
|
16
|
+
const SidebarDownloadButton = ({
|
|
17
|
+
identifier,
|
|
18
|
+
fallbackMediaNameFetcher
|
|
19
|
+
}) => {
|
|
20
|
+
const mediaClient = useMediaClient();
|
|
21
|
+
const {
|
|
22
|
+
id,
|
|
23
|
+
collectionName,
|
|
24
|
+
occurrenceKey
|
|
25
|
+
} = identifier;
|
|
26
|
+
const {
|
|
27
|
+
fileState
|
|
28
|
+
} = useFileState(id, {
|
|
29
|
+
collectionName,
|
|
30
|
+
occurrenceKey
|
|
31
|
+
});
|
|
32
|
+
const traceContext = useRef({
|
|
33
|
+
traceId: getRandomTelemetryId()
|
|
34
|
+
});
|
|
35
|
+
const [fallbackMediaName, setFallbackMediaName] = useState();
|
|
36
|
+
const fileId = fileState && fileState.status !== 'error' ? fileState.id : undefined;
|
|
37
|
+
const hasName = !!fileState && fileState.status !== 'error' && !!fileState.name;
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
setFallbackMediaName(undefined);
|
|
40
|
+
if (!fileId || hasName || !fallbackMediaNameFetcher) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
let isCancelled = false;
|
|
44
|
+
fallbackMediaNameFetcher(fileId).then(name => {
|
|
45
|
+
if (!isCancelled) {
|
|
46
|
+
setFallbackMediaName(name);
|
|
47
|
+
}
|
|
48
|
+
}, () => {
|
|
49
|
+
// Silently ignore fetch failures, as the media header does.
|
|
50
|
+
});
|
|
51
|
+
return () => {
|
|
52
|
+
isCancelled = true;
|
|
53
|
+
};
|
|
54
|
+
}, [fileId, hasName, fallbackMediaNameFetcher]);
|
|
55
|
+
if (isExternalImageIdentifier(identifier)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!fileState || fileState.status === 'error') {
|
|
59
|
+
return /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null);
|
|
60
|
+
}
|
|
61
|
+
return /*#__PURE__*/React.createElement(ToolbarDownloadButton, {
|
|
62
|
+
state: fileState,
|
|
63
|
+
identifier: identifier,
|
|
64
|
+
mediaClient: mediaClient,
|
|
65
|
+
traceContext: traceContext.current,
|
|
66
|
+
fallbackMediaName: fallbackMediaName
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
// While the sidebar is open, download, the sidebar toggle and close sit in its header.
|
|
70
|
+
export const InsetSidebarHeader = ({
|
|
71
|
+
identifier,
|
|
72
|
+
title,
|
|
73
|
+
label,
|
|
74
|
+
onHideSidebar,
|
|
75
|
+
onClose,
|
|
76
|
+
hideSidebarButtonRef,
|
|
77
|
+
fallbackMediaNameFetcher
|
|
78
|
+
}) => {
|
|
79
|
+
const {
|
|
80
|
+
formatMessage
|
|
81
|
+
} = useIntl();
|
|
82
|
+
return /*#__PURE__*/React.createElement(InsetSidebarHeaderRow, {
|
|
83
|
+
title: title
|
|
84
|
+
}, /*#__PURE__*/React.createElement(RightHeader, null, /*#__PURE__*/React.createElement(SidebarDownloadButton, {
|
|
85
|
+
identifier: identifier,
|
|
86
|
+
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
87
|
+
}), /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
88
|
+
testId: "media-viewer-sidebar-button",
|
|
89
|
+
onClick: onHideSidebar,
|
|
90
|
+
buttonRef: hideSidebarButtonRef,
|
|
91
|
+
isSelected: true,
|
|
92
|
+
icon: PanelRightIcon,
|
|
93
|
+
label: label || formatMessage(messages.hide_sidebar)
|
|
94
|
+
}), /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
95
|
+
testId: "media-viewer-close-button",
|
|
96
|
+
onClick: onClose,
|
|
97
|
+
icon: CrossIcon,
|
|
98
|
+
label: formatMessage(messages.close)
|
|
99
|
+
})));
|
|
100
|
+
};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React, { createContext, useContext } from 'react';
|
|
2
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
3
3
|
const InsetViewerContext = /*#__PURE__*/createContext(false);
|
|
4
|
+
|
|
5
|
+
// The inset media footer element, once mounted, so controls can portal into it.
|
|
6
|
+
const MediaFooterControlsContext = /*#__PURE__*/createContext(null);
|
|
7
|
+
const SetMediaFooterControlsContext = /*#__PURE__*/createContext(() => {});
|
|
4
8
|
export const InsetViewerProvider = ({
|
|
5
9
|
isInsetViewer = false,
|
|
6
10
|
children
|
|
7
|
-
}) =>
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
}) => {
|
|
12
|
+
const [mediaFooterControls, setMediaFooterControls] = useState(null);
|
|
13
|
+
return /*#__PURE__*/React.createElement(InsetViewerContext.Provider, {
|
|
14
|
+
value: isInsetViewer
|
|
15
|
+
}, /*#__PURE__*/React.createElement(SetMediaFooterControlsContext.Provider, {
|
|
16
|
+
value: setMediaFooterControls
|
|
17
|
+
}, /*#__PURE__*/React.createElement(MediaFooterControlsContext.Provider, {
|
|
18
|
+
value: mediaFooterControls
|
|
19
|
+
}, children)));
|
|
20
|
+
};
|
|
10
21
|
export const useIsInsetViewer = () => useContext(InsetViewerContext);
|
|
22
|
+
export const useMediaFooterControls = () => useContext(MediaFooterControlsContext);
|
|
23
|
+
export const useSetMediaFooterControls = () => useContext(SetMediaFooterControlsContext);
|
|
11
24
|
export const withInsetViewer = WrappedComponent => {
|
|
12
25
|
const WithInsetViewer = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
13
26
|
const isInsetViewer = useIsInsetViewer();
|
|
@@ -18,4 +31,17 @@ export const withInsetViewer = WrappedComponent => {
|
|
|
18
31
|
});
|
|
19
32
|
WithInsetViewer.displayName = `WithInsetViewer(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
20
33
|
return WithInsetViewer;
|
|
34
|
+
};
|
|
35
|
+
export const withInsetViewerFooter = WrappedComponent => {
|
|
36
|
+
const WithInsetViewerFooter = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
37
|
+
const isInsetViewer = useIsInsetViewer();
|
|
38
|
+
const mediaFooterControls = useMediaFooterControls();
|
|
39
|
+
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
40
|
+
ref: ref,
|
|
41
|
+
isInsetViewer: isInsetViewer,
|
|
42
|
+
mediaFooterControls: mediaFooterControls
|
|
43
|
+
}));
|
|
44
|
+
});
|
|
45
|
+
WithInsetViewerFooter.displayName = `WithInsetViewerFooter(${WrappedComponent.displayName || WrappedComponent.name || 'Component'})`;
|
|
46
|
+
return WithInsetViewerFooter;
|
|
21
47
|
};
|
package/dist/es2019/list.js
CHANGED
|
@@ -19,7 +19,9 @@ export const List = ({
|
|
|
19
19
|
onNavigationRequest,
|
|
20
20
|
items,
|
|
21
21
|
viewerOptions,
|
|
22
|
-
fallbackMediaNameFetcher
|
|
22
|
+
fallbackMediaNameFetcher,
|
|
23
|
+
onHeaderClose,
|
|
24
|
+
sidebarToggleRef
|
|
23
25
|
}) => {
|
|
24
26
|
const [selectedItem, setSelectedItem] = useState(defaultSelectedItem);
|
|
25
27
|
const [previewCount, setPreviewCount] = useState(0);
|
|
@@ -29,14 +31,15 @@ export const List = ({
|
|
|
29
31
|
});
|
|
30
32
|
const isInsetViewer = useIsInsetViewer();
|
|
31
33
|
const ViewerWrapper = isInsetViewer ? ItemStage : React.Fragment;
|
|
32
|
-
return /*#__PURE__*/React.createElement(ListWrapper, null,
|
|
34
|
+
return /*#__PURE__*/React.createElement(ListWrapper, null, /*#__PURE__*/React.createElement(HeaderWrapper
|
|
35
|
+
// The inset header stays visible, so it doesn't auto-hide with the other controls.
|
|
33
36
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
34
37
|
, {
|
|
35
|
-
className: hideControlsClassName,
|
|
38
|
+
className: isInsetViewer ? undefined : hideControlsClassName,
|
|
36
39
|
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
37
40
|
}, /*#__PURE__*/React.createElement(Header, {
|
|
38
41
|
identifier: selectedItem,
|
|
39
|
-
onClose: onClose,
|
|
42
|
+
onClose: onHeaderClose !== null && onHeaderClose !== void 0 ? onHeaderClose : onClose,
|
|
40
43
|
extensions: extensions,
|
|
41
44
|
onSidebarButtonClick: onSidebarButtonClick,
|
|
42
45
|
isSidebarVisible: isSidebarVisible,
|
|
@@ -44,7 +47,8 @@ export const List = ({
|
|
|
44
47
|
featureFlags: featureFlags,
|
|
45
48
|
onSetArchiveSideBarVisible: setIsArchiveSideBarVisible,
|
|
46
49
|
traceContext: traceContext.current,
|
|
47
|
-
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
50
|
+
fallbackMediaNameFetcher: fallbackMediaNameFetcher,
|
|
51
|
+
sidebarToggleRef: sidebarToggleRef
|
|
48
52
|
})), /*#__PURE__*/React.createElement(ViewerWrapper, null, /*#__PURE__*/React.createElement(ItemViewer, {
|
|
49
53
|
identifier: selectedItem,
|
|
50
54
|
showControls: showControls,
|