@atlaskit/media-viewer 54.10.6 → 54.11.1
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
|
@@ -2,11 +2,16 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["analyticspayload", "onClick", "tooltip"];
|
|
4
4
|
import React, { useCallback } from 'react';
|
|
5
|
+
import { useIntl } from 'react-intl';
|
|
5
6
|
import { useAnalyticsEvents } from '@atlaskit/analytics-next/useAnalyticsEvents';
|
|
7
|
+
import DownloadIcon from '@atlaskit/icon/core/download';
|
|
6
8
|
import MediaButton from '@atlaskit/media-ui/MediaButton';
|
|
9
|
+
import { messages } from '@atlaskit/media-ui/messages';
|
|
7
10
|
import Tooltip from '@atlaskit/tooltip/Tooltip';
|
|
8
11
|
import { fireAnalytics } from './analytics/fireAnalytics';
|
|
12
|
+
import { useIsInsetViewer } from './insetViewerContext';
|
|
9
13
|
import { noop } from './noop';
|
|
14
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
10
15
|
export function DownloadButton(_ref) {
|
|
11
16
|
var analyticspayload = _ref.analyticspayload,
|
|
12
17
|
_ref$onClick = _ref.onClick,
|
|
@@ -15,11 +20,20 @@ export function DownloadButton(_ref) {
|
|
|
15
20
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
16
21
|
var _useAnalyticsEvents = useAnalyticsEvents(),
|
|
17
22
|
createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
|
|
23
|
+
var _useIntl = useIntl(),
|
|
24
|
+
formatMessage = _useIntl.formatMessage;
|
|
25
|
+
var isInsetViewer = useIsInsetViewer();
|
|
18
26
|
var onClick = useCallback(function (event, analyticsEvent) {
|
|
19
27
|
fireAnalytics(analyticspayload, createAnalyticsEvent);
|
|
20
28
|
providedOnClick(event, analyticsEvent);
|
|
21
29
|
}, [analyticspayload, providedOnClick, createAnalyticsEvent]);
|
|
22
|
-
var downloadButton = /*#__PURE__*/React.createElement(
|
|
30
|
+
var 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, {
|
|
23
37
|
onClick: onClick
|
|
24
38
|
}));
|
|
25
39
|
return tooltip ? /*#__PURE__*/React.createElement(Tooltip, {
|
|
@@ -7,7 +7,7 @@ import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
|
7
7
|
import { UFOExperience } from '@atlaskit/ufo/experience';
|
|
8
8
|
import { ExperiencePerformanceTypes, ExperienceTypes } from '@atlaskit/ufo/experience-types';
|
|
9
9
|
var packageName = "@atlaskit/media-viewer";
|
|
10
|
-
var packageVersion = "54.
|
|
10
|
+
var packageVersion = "54.11.0";
|
|
11
11
|
var ufoExperience;
|
|
12
12
|
var getExperience = function getExperience() {
|
|
13
13
|
if (!ufoExperience) {
|
package/dist/esm/content.js
CHANGED
|
@@ -11,14 +11,15 @@ import CrossIcon from '@atlaskit/icon/core/cross';
|
|
|
11
11
|
import { hideControlsClassName } from '@atlaskit/media-ui/classNames';
|
|
12
12
|
import { InactivityDetector } from '@atlaskit/media-ui/inactivityDetector';
|
|
13
13
|
import MediaButton from '@atlaskit/media-ui/MediaButton';
|
|
14
|
+
import { withInsetViewer } from './insetViewerContext';
|
|
14
15
|
import { CloseButtonWrapper, ContentWrapper } from './styleWrappers';
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
_classCallCheck(this,
|
|
18
|
-
return _callSuper(this,
|
|
16
|
+
var ContentBase = /*#__PURE__*/function (_Component) {
|
|
17
|
+
function ContentBase() {
|
|
18
|
+
_classCallCheck(this, ContentBase);
|
|
19
|
+
return _callSuper(this, ContentBase, arguments);
|
|
19
20
|
}
|
|
20
|
-
_inherits(
|
|
21
|
-
return _createClass(
|
|
21
|
+
_inherits(ContentBase, _Component);
|
|
22
|
+
return _createClass(ContentBase, [{
|
|
22
23
|
key: "render",
|
|
23
24
|
value:
|
|
24
25
|
/*
|
|
@@ -29,14 +30,18 @@ export var Content = /*#__PURE__*/function (_Component) {
|
|
|
29
30
|
var _this = this;
|
|
30
31
|
var _this$props = this.props,
|
|
31
32
|
onClose = _this$props.onClose,
|
|
32
|
-
isSidebarVisible = _this$props.isSidebarVisible
|
|
33
|
+
isSidebarVisible = _this$props.isSidebarVisible,
|
|
34
|
+
isInsetViewer = _this$props.isInsetViewer;
|
|
33
35
|
return /*#__PURE__*/React.createElement(ContentWrapper, {
|
|
34
36
|
isSidebarVisible: isSidebarVisible
|
|
35
37
|
}, /*#__PURE__*/React.createElement(InactivityDetector, null, function (triggerActivityCallback) {
|
|
36
38
|
var children = /*#__PURE__*/React.cloneElement(_this.props.children, {
|
|
37
39
|
showControls: triggerActivityCallback
|
|
38
40
|
});
|
|
39
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
41
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, !isInsetViewer &&
|
|
42
|
+
/*#__PURE__*/
|
|
43
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
44
|
+
React.createElement(CloseButtonWrapper, {
|
|
40
45
|
className: hideControlsClassName
|
|
41
46
|
}, /*#__PURE__*/React.createElement(MediaButton, {
|
|
42
47
|
testId: "media-viewer-close-button",
|
|
@@ -50,4 +55,5 @@ export var Content = /*#__PURE__*/function (_Component) {
|
|
|
50
55
|
}));
|
|
51
56
|
}
|
|
52
57
|
}]);
|
|
53
|
-
}(Component);
|
|
58
|
+
}(Component);
|
|
59
|
+
export var Content = withInsetViewer(ContentBase);
|
package/dist/esm/download.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
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 var DisabledToolbarDownloadButton = function DisabledToolbarDownloadButton() {
|
|
10
|
+
var _useIntl = useIntl(),
|
|
11
|
+
formatMessage = _useIntl.formatMessage;
|
|
12
|
+
var isInsetViewer = useIsInsetViewer();
|
|
13
|
+
if (isInsetViewer) {
|
|
14
|
+
return /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
15
|
+
isDisabled: true,
|
|
16
|
+
icon: DownloadIcon,
|
|
17
|
+
label: formatMessage(messages.download)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return /*#__PURE__*/React.createElement(MediaButton, {
|
|
21
|
+
isDisabled: true,
|
|
22
|
+
iconBefore: downloadIcon
|
|
23
|
+
});
|
|
24
|
+
};
|
package/dist/esm/header.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { FormattedMessage } from 'react-intl';
|
|
4
|
+
import CrossIcon from '@atlaskit/icon/core/cross';
|
|
4
5
|
import { isExternalImageIdentifier, isErrorFileState, toCommonMediaClientError } from '@atlaskit/media-client';
|
|
5
6
|
import { useFileState } from '@atlaskit/media-client-react/use-file-state';
|
|
6
7
|
import { useMediaClient } from '@atlaskit/media-client-react/use-media-client';
|
|
@@ -16,9 +17,11 @@ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
|
|
|
16
17
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
17
18
|
import { Outcome } from './domain/outcome';
|
|
18
19
|
import { DisabledToolbarDownloadButton } from './download';
|
|
20
|
+
import { useIsInsetViewer } from './insetViewerContext';
|
|
19
21
|
import { MediaViewerError } from './MediaViewerError';
|
|
20
22
|
import { Header as HeaderWrapper, LeftHeader, RightHeader, MetadataWrapper, MetadataSubText, MedatadataTextWrapper, MetadataIconWrapper, MetadataFileName, FormattedMessageWrapper } from './styleWrappers';
|
|
21
23
|
import { ToolbarDownloadButton } from './ToolbarDownloadButton';
|
|
24
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
22
25
|
import { getFormat } from './viewers/codeViewer/getFormat';
|
|
23
26
|
export var Header = function Header(_ref) {
|
|
24
27
|
var _extensions$headerAct;
|
|
@@ -31,7 +34,9 @@ export var Header = function Header(_ref) {
|
|
|
31
34
|
onClose = _ref.onClose,
|
|
32
35
|
onSetArchiveSideBarVisible = _ref.onSetArchiveSideBarVisible,
|
|
33
36
|
traceContext = _ref.traceContext,
|
|
34
|
-
fallbackMediaNameFetcher = _ref.fallbackMediaNameFetcher
|
|
37
|
+
fallbackMediaNameFetcher = _ref.fallbackMediaNameFetcher,
|
|
38
|
+
sidebarToggleRef = _ref.sidebarToggleRef,
|
|
39
|
+
formatMessage = _ref.intl.formatMessage;
|
|
35
40
|
// States
|
|
36
41
|
var _useState = useState(Outcome.pending()),
|
|
37
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -146,35 +151,57 @@ export var Header = function Header(_ref) {
|
|
|
146
151
|
// Defaulting to unknown again since backend has more mediaTypes than the current supported ones
|
|
147
152
|
return /*#__PURE__*/React.createElement(FormattedMessage, message || messages.unknown);
|
|
148
153
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
testId: 'media-viewer-file-type-icon',
|
|
158
|
-
mediaType: item.mediaType,
|
|
159
|
-
mimeType: item.mimeType,
|
|
160
|
-
name: item.name
|
|
161
|
-
})), /*#__PURE__*/React.createElement(MedatadataTextWrapper, null, /*#__PURE__*/React.createElement(MetadataFileName, {
|
|
162
|
-
"data-testid": "media-viewer-file-name"
|
|
163
|
-
}, item.name || fallbackMediaName || /*#__PURE__*/React.createElement(FormattedMessage, messages.unknown)), /*#__PURE__*/React.createElement(MetadataSubText, {
|
|
164
|
-
"data-testid": "media-viewer-file-metadata-text"
|
|
165
|
-
}, /*#__PURE__*/React.createElement(FormattedMessageWrapper, null, renderFileTypeText(item)), item.size ? ' · ' + toHumanReadableMediaSize(item.size) : '')));
|
|
166
|
-
},
|
|
154
|
+
var isInsetViewer = useIsInsetViewer();
|
|
155
|
+
var hideControlsClass = isInsetViewer ? undefined : hideControlsClassName;
|
|
156
|
+
var renderInsetFileName = function renderInsetFileName(name, size) {
|
|
157
|
+
return /*#__PURE__*/React.createElement(MetadataWrapper, null, /*#__PURE__*/React.createElement(MedatadataTextWrapper, null, /*#__PURE__*/React.createElement(MetadataFileName, {
|
|
158
|
+
"data-testid": "media-viewer-file-name"
|
|
159
|
+
}, name || fallbackMediaName || /*#__PURE__*/React.createElement(FormattedMessage, messages.unknown), size ? " \xB7 ".concat(toHumanReadableMediaSize(size)) : '')));
|
|
160
|
+
};
|
|
161
|
+
var downloadButton = item.match({
|
|
167
162
|
pending: function pending() {
|
|
168
|
-
return null;
|
|
163
|
+
return /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null);
|
|
169
164
|
},
|
|
170
165
|
failed: function failed() {
|
|
171
|
-
return null;
|
|
166
|
+
return /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null);
|
|
167
|
+
},
|
|
168
|
+
successful: function successful(item) {
|
|
169
|
+
return /*#__PURE__*/React.createElement(ToolbarDownloadButton, {
|
|
170
|
+
state: item,
|
|
171
|
+
identifier: identifier,
|
|
172
|
+
mediaClient: mediaClient,
|
|
173
|
+
traceContext: traceContext,
|
|
174
|
+
fallbackMediaName: fallbackMediaName
|
|
175
|
+
});
|
|
172
176
|
}
|
|
173
|
-
})
|
|
177
|
+
});
|
|
178
|
+
var sidebarToggleButton = extensions !== null && extensions !== void 0 && extensions.sidebar ? isInsetViewer ? /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
179
|
+
testId: "media-viewer-sidebar-button",
|
|
180
|
+
onClick: onSidebarButtonClick,
|
|
181
|
+
buttonRef: sidebarToggleRef,
|
|
182
|
+
iconBefore: extensions.sidebar.icon,
|
|
183
|
+
label: extensions.sidebar.label || formatMessage(messages.show_sidebar)
|
|
184
|
+
}) : /*#__PURE__*/React.createElement(MediaButton, {
|
|
185
|
+
isSelected: isSidebarVisible,
|
|
186
|
+
testId: "media-viewer-sidebar-button",
|
|
187
|
+
onClick: onSidebarButtonClick,
|
|
188
|
+
iconBefore: extensions.sidebar.icon
|
|
189
|
+
}) : null;
|
|
190
|
+
var extraHeaderActions = extensions === null || extensions === void 0 || (_extensions$headerAct = extensions.headerActions) === null || _extensions$headerAct === void 0 ? void 0 : _extensions$headerAct.map(function (action, index) {
|
|
174
191
|
if (action.isVisible && !action.isVisible(identifier)) {
|
|
175
192
|
return null;
|
|
176
193
|
}
|
|
177
|
-
return /*#__PURE__*/React.createElement(
|
|
194
|
+
return isInsetViewer ? /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
195
|
+
key: index,
|
|
196
|
+
testId: "media-viewer-header-action-".concat(index),
|
|
197
|
+
onClick: function onClick() {
|
|
198
|
+
return action.onClick(identifier, {
|
|
199
|
+
close: onClose || function () {}
|
|
200
|
+
});
|
|
201
|
+
},
|
|
202
|
+
iconBefore: action.icon,
|
|
203
|
+
label: action.label
|
|
204
|
+
}) : /*#__PURE__*/React.createElement(MediaButton, {
|
|
178
205
|
key: index,
|
|
179
206
|
testId: "media-viewer-header-action-".concat(index),
|
|
180
207
|
onClick: function onClick() {
|
|
@@ -185,26 +212,50 @@ export var Header = function Header(_ref) {
|
|
|
185
212
|
iconBefore: action.icon,
|
|
186
213
|
"aria-label": action.label
|
|
187
214
|
});
|
|
188
|
-
})
|
|
189
|
-
|
|
190
|
-
testId: "media-viewer-
|
|
191
|
-
onClick:
|
|
192
|
-
|
|
193
|
-
|
|
215
|
+
});
|
|
216
|
+
var closeButton = /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
217
|
+
testId: "media-viewer-close-button",
|
|
218
|
+
onClick: onClose,
|
|
219
|
+
icon: CrossIcon,
|
|
220
|
+
label: formatMessage(messages.close)
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
// In inset mode, download, the sidebar toggle and close move into the sidebar's own header while
|
|
224
|
+
// it's open; the consumer's extra actions always stay here.
|
|
225
|
+
var 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);
|
|
226
|
+
return /*#__PURE__*/React.createElement(HeaderWrapper, {
|
|
227
|
+
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
228
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Existing Media Viewer control visibility is class-based.
|
|
229
|
+
,
|
|
230
|
+
className: hideControlsClass !== null && hideControlsClass !== void 0 ? hideControlsClass : ''
|
|
231
|
+
}, /*#__PURE__*/React.createElement(LeftHeader, null, item.match(isInsetViewer ? {
|
|
232
|
+
successful: function successful(item) {
|
|
233
|
+
return !isErrorFileState(item) && renderInsetFileName(item.name, item.size);
|
|
234
|
+
},
|
|
194
235
|
pending: function pending() {
|
|
195
|
-
return
|
|
236
|
+
return renderInsetFileName();
|
|
196
237
|
},
|
|
197
238
|
failed: function failed() {
|
|
198
|
-
return
|
|
199
|
-
}
|
|
239
|
+
return renderInsetFileName();
|
|
240
|
+
}
|
|
241
|
+
} : {
|
|
200
242
|
successful: function successful(item) {
|
|
201
|
-
return /*#__PURE__*/React.createElement(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
243
|
+
return !isErrorFileState(item) && /*#__PURE__*/React.createElement(MetadataWrapper, null, /*#__PURE__*/React.createElement(MetadataIconWrapper, null, /*#__PURE__*/React.createElement(MimeTypeIcon, {
|
|
244
|
+
testId: 'media-viewer-file-type-icon',
|
|
245
|
+
mediaType: item.mediaType,
|
|
246
|
+
mimeType: item.mimeType,
|
|
247
|
+
name: item.name
|
|
248
|
+
})), /*#__PURE__*/React.createElement(MedatadataTextWrapper, null, /*#__PURE__*/React.createElement(MetadataFileName, {
|
|
249
|
+
"data-testid": "media-viewer-file-name"
|
|
250
|
+
}, item.name || fallbackMediaName || /*#__PURE__*/React.createElement(FormattedMessage, messages.unknown)), /*#__PURE__*/React.createElement(MetadataSubText, {
|
|
251
|
+
"data-testid": "media-viewer-file-metadata-text"
|
|
252
|
+
}, /*#__PURE__*/React.createElement(FormattedMessageWrapper, null, renderFileTypeText(item)), item.size ? ' · ' + toHumanReadableMediaSize(item.size) : '')));
|
|
253
|
+
},
|
|
254
|
+
pending: function pending() {
|
|
255
|
+
return null;
|
|
256
|
+
},
|
|
257
|
+
failed: function failed() {
|
|
258
|
+
return null;
|
|
208
259
|
}
|
|
209
|
-
})));
|
|
260
|
+
})), /*#__PURE__*/React.createElement(RightHeader, null, actionButtons));
|
|
210
261
|
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { useIntl } from 'react-intl';
|
|
4
|
+
import CrossIcon from '@atlaskit/icon/core/cross';
|
|
5
|
+
import PanelRightIcon from '@atlaskit/icon/core/panel-right';
|
|
6
|
+
import { useFileState } from '@atlaskit/media-client-react/use-file-state';
|
|
7
|
+
import { useMediaClient } from '@atlaskit/media-client-react/use-media-client';
|
|
8
|
+
import { isExternalImageIdentifier } from '@atlaskit/media-client/is-external-image-identifier';
|
|
9
|
+
import { getRandomTelemetryId } from '@atlaskit/media-common/helpers';
|
|
10
|
+
import { messages } from '@atlaskit/media-ui/messages';
|
|
11
|
+
import { DisabledToolbarDownloadButton } from './download';
|
|
12
|
+
import { InsetSidebarHeaderRow, RightHeader } from './styleWrappers';
|
|
13
|
+
import { ToolbarDownloadButton } from './ToolbarDownloadButton';
|
|
14
|
+
import { ViewerIconButton } from './viewer-icon-button';
|
|
15
|
+
// TODO: Header's download works the same way (file state, trace, fallback name). Consider
|
|
16
|
+
// refactoring so Header and the sidebar share one implementation.
|
|
17
|
+
var SidebarDownloadButton = function SidebarDownloadButton(_ref) {
|
|
18
|
+
var identifier = _ref.identifier,
|
|
19
|
+
fallbackMediaNameFetcher = _ref.fallbackMediaNameFetcher;
|
|
20
|
+
var mediaClient = useMediaClient();
|
|
21
|
+
var _ref2 = identifier,
|
|
22
|
+
id = _ref2.id,
|
|
23
|
+
collectionName = _ref2.collectionName,
|
|
24
|
+
occurrenceKey = _ref2.occurrenceKey;
|
|
25
|
+
var _useFileState = useFileState(id, {
|
|
26
|
+
collectionName: collectionName,
|
|
27
|
+
occurrenceKey: occurrenceKey
|
|
28
|
+
}),
|
|
29
|
+
fileState = _useFileState.fileState;
|
|
30
|
+
var traceContext = useRef({
|
|
31
|
+
traceId: getRandomTelemetryId()
|
|
32
|
+
});
|
|
33
|
+
var _useState = useState(),
|
|
34
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
35
|
+
fallbackMediaName = _useState2[0],
|
|
36
|
+
setFallbackMediaName = _useState2[1];
|
|
37
|
+
var fileId = fileState && fileState.status !== 'error' ? fileState.id : undefined;
|
|
38
|
+
var hasName = !!fileState && fileState.status !== 'error' && !!fileState.name;
|
|
39
|
+
useEffect(function () {
|
|
40
|
+
setFallbackMediaName(undefined);
|
|
41
|
+
if (!fileId || hasName || !fallbackMediaNameFetcher) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var isCancelled = false;
|
|
45
|
+
fallbackMediaNameFetcher(fileId).then(function (name) {
|
|
46
|
+
if (!isCancelled) {
|
|
47
|
+
setFallbackMediaName(name);
|
|
48
|
+
}
|
|
49
|
+
}, function () {
|
|
50
|
+
// Silently ignore fetch failures, as the media header does.
|
|
51
|
+
});
|
|
52
|
+
return function () {
|
|
53
|
+
isCancelled = true;
|
|
54
|
+
};
|
|
55
|
+
}, [fileId, hasName, fallbackMediaNameFetcher]);
|
|
56
|
+
if (isExternalImageIdentifier(identifier)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
if (!fileState || fileState.status === 'error') {
|
|
60
|
+
return /*#__PURE__*/React.createElement(DisabledToolbarDownloadButton, null);
|
|
61
|
+
}
|
|
62
|
+
return /*#__PURE__*/React.createElement(ToolbarDownloadButton, {
|
|
63
|
+
state: fileState,
|
|
64
|
+
identifier: identifier,
|
|
65
|
+
mediaClient: mediaClient,
|
|
66
|
+
traceContext: traceContext.current,
|
|
67
|
+
fallbackMediaName: fallbackMediaName
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
// While the sidebar is open, download, the sidebar toggle and close sit in its header.
|
|
71
|
+
export var InsetSidebarHeader = function InsetSidebarHeader(_ref3) {
|
|
72
|
+
var identifier = _ref3.identifier,
|
|
73
|
+
title = _ref3.title,
|
|
74
|
+
label = _ref3.label,
|
|
75
|
+
onHideSidebar = _ref3.onHideSidebar,
|
|
76
|
+
onClose = _ref3.onClose,
|
|
77
|
+
hideSidebarButtonRef = _ref3.hideSidebarButtonRef,
|
|
78
|
+
fallbackMediaNameFetcher = _ref3.fallbackMediaNameFetcher;
|
|
79
|
+
var _useIntl = useIntl(),
|
|
80
|
+
formatMessage = _useIntl.formatMessage;
|
|
81
|
+
return /*#__PURE__*/React.createElement(InsetSidebarHeaderRow, {
|
|
82
|
+
title: title
|
|
83
|
+
}, /*#__PURE__*/React.createElement(RightHeader, null, /*#__PURE__*/React.createElement(SidebarDownloadButton, {
|
|
84
|
+
identifier: identifier,
|
|
85
|
+
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
86
|
+
}), /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
87
|
+
testId: "media-viewer-sidebar-button",
|
|
88
|
+
onClick: onHideSidebar,
|
|
89
|
+
buttonRef: hideSidebarButtonRef,
|
|
90
|
+
isSelected: true,
|
|
91
|
+
icon: PanelRightIcon,
|
|
92
|
+
label: label || formatMessage(messages.hide_sidebar)
|
|
93
|
+
}), /*#__PURE__*/React.createElement(ViewerIconButton, {
|
|
94
|
+
testId: "media-viewer-close-button",
|
|
95
|
+
onClick: onClose,
|
|
96
|
+
icon: CrossIcon,
|
|
97
|
+
label: formatMessage(messages.close)
|
|
98
|
+
})));
|
|
99
|
+
};
|
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
3
4
|
var InsetViewerContext = /*#__PURE__*/createContext(false);
|
|
5
|
+
|
|
6
|
+
// The inset media footer element, once mounted, so controls can portal into it.
|
|
7
|
+
var MediaFooterControlsContext = /*#__PURE__*/createContext(null);
|
|
8
|
+
var SetMediaFooterControlsContext = /*#__PURE__*/createContext(function () {});
|
|
4
9
|
export var InsetViewerProvider = function InsetViewerProvider(_ref) {
|
|
5
10
|
var _ref$isInsetViewer = _ref.isInsetViewer,
|
|
6
11
|
isInsetViewer = _ref$isInsetViewer === void 0 ? false : _ref$isInsetViewer,
|
|
7
12
|
children = _ref.children;
|
|
13
|
+
var _useState = useState(null),
|
|
14
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
15
|
+
mediaFooterControls = _useState2[0],
|
|
16
|
+
setMediaFooterControls = _useState2[1];
|
|
8
17
|
return /*#__PURE__*/React.createElement(InsetViewerContext.Provider, {
|
|
9
18
|
value: isInsetViewer
|
|
10
|
-
},
|
|
19
|
+
}, /*#__PURE__*/React.createElement(SetMediaFooterControlsContext.Provider, {
|
|
20
|
+
value: setMediaFooterControls
|
|
21
|
+
}, /*#__PURE__*/React.createElement(MediaFooterControlsContext.Provider, {
|
|
22
|
+
value: mediaFooterControls
|
|
23
|
+
}, children)));
|
|
11
24
|
};
|
|
12
25
|
export var useIsInsetViewer = function useIsInsetViewer() {
|
|
13
26
|
return useContext(InsetViewerContext);
|
|
14
27
|
};
|
|
28
|
+
export var useMediaFooterControls = function useMediaFooterControls() {
|
|
29
|
+
return useContext(MediaFooterControlsContext);
|
|
30
|
+
};
|
|
31
|
+
export var useSetMediaFooterControls = function useSetMediaFooterControls() {
|
|
32
|
+
return useContext(SetMediaFooterControlsContext);
|
|
33
|
+
};
|
|
15
34
|
export var withInsetViewer = function withInsetViewer(WrappedComponent) {
|
|
16
35
|
var WithInsetViewer = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
17
36
|
var isInsetViewer = useIsInsetViewer();
|
|
@@ -22,4 +41,17 @@ export var withInsetViewer = function withInsetViewer(WrappedComponent) {
|
|
|
22
41
|
});
|
|
23
42
|
WithInsetViewer.displayName = "WithInsetViewer(".concat(WrappedComponent.displayName || WrappedComponent.name || 'Component', ")");
|
|
24
43
|
return WithInsetViewer;
|
|
44
|
+
};
|
|
45
|
+
export var withInsetViewerFooter = function withInsetViewerFooter(WrappedComponent) {
|
|
46
|
+
var WithInsetViewerFooter = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
47
|
+
var isInsetViewer = useIsInsetViewer();
|
|
48
|
+
var mediaFooterControls = useMediaFooterControls();
|
|
49
|
+
return /*#__PURE__*/React.createElement(WrappedComponent, _extends({}, props, {
|
|
50
|
+
ref: ref,
|
|
51
|
+
isInsetViewer: isInsetViewer,
|
|
52
|
+
mediaFooterControls: mediaFooterControls
|
|
53
|
+
}));
|
|
54
|
+
});
|
|
55
|
+
WithInsetViewerFooter.displayName = "WithInsetViewerFooter(".concat(WrappedComponent.displayName || WrappedComponent.name || 'Component', ")");
|
|
56
|
+
return WithInsetViewerFooter;
|
|
25
57
|
};
|
package/dist/esm/list.js
CHANGED
|
@@ -20,7 +20,9 @@ export var List = function List(_ref) {
|
|
|
20
20
|
onNavigationRequest = _ref.onNavigationRequest,
|
|
21
21
|
items = _ref.items,
|
|
22
22
|
viewerOptions = _ref.viewerOptions,
|
|
23
|
-
fallbackMediaNameFetcher = _ref.fallbackMediaNameFetcher
|
|
23
|
+
fallbackMediaNameFetcher = _ref.fallbackMediaNameFetcher,
|
|
24
|
+
onHeaderClose = _ref.onHeaderClose,
|
|
25
|
+
sidebarToggleRef = _ref.sidebarToggleRef;
|
|
24
26
|
var _useState = useState(defaultSelectedItem),
|
|
25
27
|
_useState2 = _slicedToArray(_useState, 2),
|
|
26
28
|
selectedItem = _useState2[0],
|
|
@@ -38,14 +40,15 @@ export var List = function List(_ref) {
|
|
|
38
40
|
});
|
|
39
41
|
var isInsetViewer = useIsInsetViewer();
|
|
40
42
|
var ViewerWrapper = isInsetViewer ? ItemStage : React.Fragment;
|
|
41
|
-
return /*#__PURE__*/React.createElement(ListWrapper, null,
|
|
43
|
+
return /*#__PURE__*/React.createElement(ListWrapper, null, /*#__PURE__*/React.createElement(HeaderWrapper
|
|
44
|
+
// The inset header stays visible, so it doesn't auto-hide with the other controls.
|
|
42
45
|
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-classname-prop -- Ignored via go/DSP-18766
|
|
43
46
|
, {
|
|
44
|
-
className: hideControlsClassName,
|
|
47
|
+
className: isInsetViewer ? undefined : hideControlsClassName,
|
|
45
48
|
isArchiveSideBarVisible: isArchiveSideBarVisible
|
|
46
49
|
}, /*#__PURE__*/React.createElement(Header, {
|
|
47
50
|
identifier: selectedItem,
|
|
48
|
-
onClose: onClose,
|
|
51
|
+
onClose: onHeaderClose !== null && onHeaderClose !== void 0 ? onHeaderClose : onClose,
|
|
49
52
|
extensions: extensions,
|
|
50
53
|
onSidebarButtonClick: onSidebarButtonClick,
|
|
51
54
|
isSidebarVisible: isSidebarVisible,
|
|
@@ -53,7 +56,8 @@ export var List = function List(_ref) {
|
|
|
53
56
|
featureFlags: featureFlags,
|
|
54
57
|
onSetArchiveSideBarVisible: setIsArchiveSideBarVisible,
|
|
55
58
|
traceContext: traceContext.current,
|
|
56
|
-
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
59
|
+
fallbackMediaNameFetcher: fallbackMediaNameFetcher,
|
|
60
|
+
sidebarToggleRef: sidebarToggleRef
|
|
57
61
|
})), /*#__PURE__*/React.createElement(ViewerWrapper, null, /*#__PURE__*/React.createElement(ItemViewer, {
|
|
58
62
|
identifier: selectedItem,
|
|
59
63
|
showControls: showControls,
|
package/dist/esm/media-viewer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
import React, { useState, useLayoutEffect, useRef, useCallback } from 'react';
|
|
3
|
+
import React, { useState, useEffect, useLayoutEffect, useRef, useCallback } from 'react';
|
|
4
4
|
import { start } from 'perf-marks';
|
|
5
5
|
import FocusLock from 'react-focus-lock';
|
|
6
6
|
import { IntlProvider, injectIntl } from 'react-intl';
|
|
@@ -15,9 +15,10 @@ import { createClosedEvent } from './analytics/events/ui/closed';
|
|
|
15
15
|
import { fireAnalytics } from './analytics/fireAnalytics';
|
|
16
16
|
import { mediaViewerPopupClass } from './classnames';
|
|
17
17
|
import { Content } from './content';
|
|
18
|
+
import { InsetSidebarHeader } from './inset-sidebar-header';
|
|
18
19
|
import { InsetViewerProvider } from './insetViewerContext';
|
|
19
20
|
import { List } from './list';
|
|
20
|
-
import { Blanket, BlanketCloseButton, InsetViewerLayout, InsetViewerShell, MediaColumn, MediaStage, SidebarWrapper } from './styleWrappers';
|
|
21
|
+
import { Blanket, BlanketCloseButton, InsetViewerLayout, InsetViewerShell, MediaColumn, MediaFooterBar, MediaStage, SidebarColumn, SidebarWrapper } from './styleWrappers';
|
|
21
22
|
var getIdentifierId = function getIdentifierId(identifier) {
|
|
22
23
|
return isFileIdentifier(identifier) ? identifier.id : undefined;
|
|
23
24
|
};
|
|
@@ -94,6 +95,7 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
94
95
|
start('MediaViewer.SessionDuration');
|
|
95
96
|
}, []);
|
|
96
97
|
var defaultSelectedItem = selectedItem || items[0];
|
|
98
|
+
var currentIdentifier = selectedIdentifier || defaultSelectedItem;
|
|
97
99
|
|
|
98
100
|
// Toggling the sidebar: opening is unconditional; closing goes through the
|
|
99
101
|
// optional onSidebarClose interceptor.
|
|
@@ -107,6 +109,24 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
107
109
|
}
|
|
108
110
|
}, [isSidebarVisible, requestSidebarClose, setIsSidebarVisible]);
|
|
109
111
|
|
|
112
|
+
// In inset mode the sidebar toggle is in the media header while the sidebar is closed and in the
|
|
113
|
+
// sidebar's own header while it's open, so a toggle click unmounts the focused button. Move focus
|
|
114
|
+
// to the toggle that's now showing, only after a toggle click.
|
|
115
|
+
var showSidebarButtonRef = useRef(null);
|
|
116
|
+
var hideSidebarButtonRef = useRef(null);
|
|
117
|
+
var shouldFocusSidebarToggle = useRef(false);
|
|
118
|
+
useEffect(function () {
|
|
119
|
+
if (shouldFocusSidebarToggle.current) {
|
|
120
|
+
var _current;
|
|
121
|
+
shouldFocusSidebarToggle.current = false;
|
|
122
|
+
(_current = (isSidebarVisible ? hideSidebarButtonRef : showSidebarButtonRef).current) === null || _current === void 0 || _current.focus();
|
|
123
|
+
}
|
|
124
|
+
}, [isSidebarVisible]);
|
|
125
|
+
var onInsetSidebarButtonClick = useCallback(function () {
|
|
126
|
+
shouldFocusSidebarToggle.current = true;
|
|
127
|
+
toggleSidebar();
|
|
128
|
+
}, [toggleSidebar]);
|
|
129
|
+
|
|
110
130
|
// The full modal close — used by ESC, the close button, and click-outside.
|
|
111
131
|
// Always passed through requestPreviewClose so the consumer can intercept.
|
|
112
132
|
var handlePreviewClose = useCallback(function (reason) {
|
|
@@ -122,8 +142,7 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
122
142
|
// in `items` with the current selected identifier's index. Falls back to
|
|
123
143
|
// 'next' if we can't determine direction (e.g. random jump from a list).
|
|
124
144
|
var computeNavigationDirection = useCallback(function (nextIdentifier) {
|
|
125
|
-
var
|
|
126
|
-
var currentId = current && getIdentifierId(current);
|
|
145
|
+
var currentId = currentIdentifier && getIdentifierId(currentIdentifier);
|
|
127
146
|
var nextId = getIdentifierId(nextIdentifier);
|
|
128
147
|
if (!currentId || !nextId) {
|
|
129
148
|
return 'next';
|
|
@@ -138,13 +157,12 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
138
157
|
return 'next';
|
|
139
158
|
}
|
|
140
159
|
return nextIndex < currentIndex ? 'prev' : 'next';
|
|
141
|
-
}, [items,
|
|
160
|
+
}, [items, currentIdentifier]);
|
|
142
161
|
var renderSidebar = function renderSidebar() {
|
|
143
|
-
|
|
144
|
-
if (sidebarSelectedIdentifier && isSidebarVisible && extensions !== null && extensions !== void 0 && extensions.sidebar) {
|
|
162
|
+
if (currentIdentifier && isSidebarVisible && extensions !== null && extensions !== void 0 && extensions.sidebar) {
|
|
145
163
|
return /*#__PURE__*/React.createElement(SidebarWrapper, {
|
|
146
164
|
"data-testid": "media-viewer-sidebar-content"
|
|
147
|
-
}, extensions.sidebar.renderer(
|
|
165
|
+
}, extensions.sidebar.renderer(currentIdentifier, {
|
|
148
166
|
// `close` is what the sidebar renderer calls to dismiss itself.
|
|
149
167
|
// Route it through the same interceptor so confluence's
|
|
150
168
|
// unsaved-comment guard runs here too.
|
|
@@ -186,7 +204,7 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
186
204
|
handlePreviewClose(reason);
|
|
187
205
|
}
|
|
188
206
|
}, /*#__PURE__*/React.createElement(List, {
|
|
189
|
-
defaultSelectedItem: defaultSelectedItem
|
|
207
|
+
defaultSelectedItem: defaultSelectedItem,
|
|
190
208
|
items: items
|
|
191
209
|
// Note: `onClose` here is what the prev/next list passes down for
|
|
192
210
|
// "close-the-modal" actions. Route through interceptor too.
|
|
@@ -211,13 +229,29 @@ var MediaViewerComponent = function MediaViewerComponent(_ref) {
|
|
|
211
229
|
var direction = computeNavigationDirection(identifier);
|
|
212
230
|
requestNavigation(direction, commit);
|
|
213
231
|
},
|
|
214
|
-
onSidebarButtonClick: toggleSidebar,
|
|
232
|
+
onSidebarButtonClick: isInsetViewer ? onInsetSidebarButtonClick : toggleSidebar,
|
|
215
233
|
isSidebarVisible: isSidebarVisible,
|
|
234
|
+
onHeaderClose: isInsetViewer ? function () {
|
|
235
|
+
return handlePreviewClose('button');
|
|
236
|
+
} : undefined,
|
|
237
|
+
sidebarToggleRef: isInsetViewer ? showSidebarButtonRef : undefined,
|
|
216
238
|
contextId: contextId,
|
|
217
239
|
featureFlags: featureFlags,
|
|
218
240
|
viewerOptions: viewerOptions,
|
|
219
241
|
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
220
|
-
})))
|
|
242
|
+
}))), isInsetViewer ? /*#__PURE__*/React.createElement(MediaFooterBar, null) : null), isInsetViewer ? /*#__PURE__*/React.createElement(SidebarColumn, {
|
|
243
|
+
isOpen: isSidebarVisible
|
|
244
|
+
}, currentIdentifier && extensions !== null && extensions !== void 0 && extensions.sidebar ? /*#__PURE__*/React.createElement(InsetSidebarHeader, {
|
|
245
|
+
identifier: currentIdentifier,
|
|
246
|
+
title: extensions.sidebar.title,
|
|
247
|
+
label: extensions.sidebar.label,
|
|
248
|
+
onHideSidebar: onInsetSidebarButtonClick,
|
|
249
|
+
onClose: function onClose() {
|
|
250
|
+
return handlePreviewClose('button');
|
|
251
|
+
},
|
|
252
|
+
hideSidebarButtonRef: hideSidebarButtonRef,
|
|
253
|
+
fallbackMediaNameFetcher: fallbackMediaNameFetcher
|
|
254
|
+
}) : null, renderSidebar()) : renderSidebar())))));
|
|
221
255
|
return intl ? content : /*#__PURE__*/React.createElement(IntlProvider, {
|
|
222
256
|
locale: "en"
|
|
223
257
|
}, content);
|