@atlaskit/media-viewer 52.8.4 → 52.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @atlaskit/media-viewer
2
2
 
3
+ ## 52.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`6e25e8bbb01c3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/6e25e8bbb01c3) -
8
+ [ux] Adds mediaViewerExtensions prop to media-viewer/src/header and threads it through parents.
9
+ Allows callers to pass in additional buttons to the image / video preview'
10
+
11
+ ## 52.8.5
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 52.8.4
4
18
 
5
19
  ### Patch Changes
@@ -21,12 +21,14 @@ var _util = require("./viewers/codeViewer/util");
21
21
  var _errors = require("./errors");
22
22
  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); }
23
23
  var Header = exports.Header = function Header(_ref) {
24
+ var _extensions$headerAct;
24
25
  var _ref$isArchiveSideBar = _ref.isArchiveSideBarVisible,
25
26
  isArchiveSideBarVisible = _ref$isArchiveSideBar === void 0 ? false : _ref$isArchiveSideBar,
26
27
  extensions = _ref.extensions,
27
28
  isSidebarVisible = _ref.isSidebarVisible,
28
29
  onSidebarButtonClick = _ref.onSidebarButtonClick,
29
30
  identifier = _ref.identifier,
31
+ onClose = _ref.onClose,
30
32
  onSetArchiveSideBarVisible = _ref.onSetArchiveSideBarVisible,
31
33
  traceContext = _ref.traceContext;
32
34
  // States
@@ -136,7 +138,22 @@ var Header = exports.Header = function Header(_ref) {
136
138
  failed: function failed() {
137
139
  return null;
138
140
  }
139
- })), /*#__PURE__*/_react.default.createElement(_styleWrappers.RightHeader, null, (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/_react.default.createElement(_mediaUi.MediaButton, {
141
+ })), /*#__PURE__*/_react.default.createElement(_styleWrappers.RightHeader, null, extensions === null || extensions === void 0 || (_extensions$headerAct = extensions.headerActions) === null || _extensions$headerAct === void 0 ? void 0 : _extensions$headerAct.map(function (action, index) {
142
+ if (action.isVisible && !action.isVisible(identifier)) {
143
+ return null;
144
+ }
145
+ return /*#__PURE__*/_react.default.createElement(_mediaUi.MediaButton, {
146
+ key: index,
147
+ testId: "media-viewer-header-action-".concat(index),
148
+ onClick: function onClick() {
149
+ return action.onClick(identifier, {
150
+ close: onClose || function () {}
151
+ });
152
+ },
153
+ iconBefore: action.icon,
154
+ "aria-label": action.label
155
+ });
156
+ }), (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/_react.default.createElement(_mediaUi.MediaButton, {
140
157
  isSelected: isSidebarVisible,
141
158
  testId: "media-viewer-sidebar-button",
142
159
  onClick: onSidebarButtonClick,
@@ -16,9 +16,11 @@ export const Header = ({
16
16
  isSidebarVisible,
17
17
  onSidebarButtonClick,
18
18
  identifier,
19
+ onClose,
19
20
  onSetArchiveSideBarVisible,
20
21
  traceContext
21
22
  }) => {
23
+ var _extensions$headerAct;
22
24
  // States
23
25
  const [item, setItem] = useState(Outcome.pending());
24
26
 
@@ -122,7 +124,20 @@ export const Header = ({
122
124
  }, /*#__PURE__*/React.createElement(FormattedMessageWrapper, null, renderFileTypeText(item)), item.size ? ' · ' + toHumanReadableMediaSize(item.size) : ''))),
123
125
  pending: () => null,
124
126
  failed: () => null
125
- })), /*#__PURE__*/React.createElement(RightHeader, null, (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/React.createElement(MediaButton, {
127
+ })), /*#__PURE__*/React.createElement(RightHeader, null, extensions === null || extensions === void 0 ? void 0 : (_extensions$headerAct = extensions.headerActions) === null || _extensions$headerAct === void 0 ? void 0 : _extensions$headerAct.map((action, index) => {
128
+ if (action.isVisible && !action.isVisible(identifier)) {
129
+ return null;
130
+ }
131
+ return /*#__PURE__*/React.createElement(MediaButton, {
132
+ key: index,
133
+ testId: `media-viewer-header-action-${index}`,
134
+ onClick: () => action.onClick(identifier, {
135
+ close: onClose || (() => {})
136
+ }),
137
+ iconBefore: action.icon,
138
+ "aria-label": action.label
139
+ });
140
+ }), (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/React.createElement(MediaButton, {
126
141
  isSelected: isSidebarVisible,
127
142
  testId: "media-viewer-sidebar-button",
128
143
  onClick: onSidebarButtonClick,
@@ -12,12 +12,14 @@ import { MimeTypeIcon } from '@atlaskit/media-ui/mime-type-icon';
12
12
  import { getFormat } from './viewers/codeViewer/util';
13
13
  import { MediaViewerError } from './errors';
14
14
  export var Header = function Header(_ref) {
15
+ var _extensions$headerAct;
15
16
  var _ref$isArchiveSideBar = _ref.isArchiveSideBarVisible,
16
17
  isArchiveSideBarVisible = _ref$isArchiveSideBar === void 0 ? false : _ref$isArchiveSideBar,
17
18
  extensions = _ref.extensions,
18
19
  isSidebarVisible = _ref.isSidebarVisible,
19
20
  onSidebarButtonClick = _ref.onSidebarButtonClick,
20
21
  identifier = _ref.identifier,
22
+ onClose = _ref.onClose,
21
23
  onSetArchiveSideBarVisible = _ref.onSetArchiveSideBarVisible,
22
24
  traceContext = _ref.traceContext;
23
25
  // States
@@ -127,7 +129,22 @@ export var Header = function Header(_ref) {
127
129
  failed: function failed() {
128
130
  return null;
129
131
  }
130
- })), /*#__PURE__*/React.createElement(RightHeader, null, (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/React.createElement(MediaButton, {
132
+ })), /*#__PURE__*/React.createElement(RightHeader, null, extensions === null || extensions === void 0 || (_extensions$headerAct = extensions.headerActions) === null || _extensions$headerAct === void 0 ? void 0 : _extensions$headerAct.map(function (action, index) {
133
+ if (action.isVisible && !action.isVisible(identifier)) {
134
+ return null;
135
+ }
136
+ return /*#__PURE__*/React.createElement(MediaButton, {
137
+ key: index,
138
+ testId: "media-viewer-header-action-".concat(index),
139
+ onClick: function onClick() {
140
+ return action.onClick(identifier, {
141
+ close: onClose || function () {}
142
+ });
143
+ },
144
+ iconBefore: action.icon,
145
+ "aria-label": action.label
146
+ });
147
+ }), (extensions === null || extensions === void 0 ? void 0 : extensions.sidebar) && /*#__PURE__*/React.createElement(MediaButton, {
131
148
  isSelected: isSidebarVisible,
132
149
  testId: "media-viewer-sidebar-button",
133
150
  onClick: onSidebarButtonClick,
@@ -15,6 +15,17 @@ export interface MediaViewerExtensions {
15
15
  icon: ReactNode;
16
16
  renderer: (selectedIdentifier: Identifier, actions: MediaViewerExtensionsActions) => ReactNode;
17
17
  };
18
+ headerActions?: Array<{
19
+ /** Icon to display in the header button */
20
+ icon: ReactNode;
21
+ /** Label for the button (accessibility) */
22
+ label: string;
23
+ /** Called when the button is clicked. Receives the currently viewed item's identifier
24
+ * and actions (including close) to control the viewer. */
25
+ onClick: (selectedIdentifier: Identifier, actions: MediaViewerExtensionsActions) => void;
26
+ /** Optional callback to control per-item visibility. When omitted, button always shows. */
27
+ isVisible?: (selectedIdentifier: Identifier) => boolean;
28
+ }>;
18
29
  }
19
30
  export interface MediaViewerProps {
20
31
  readonly mediaClient: MediaClient;
@@ -14,6 +14,6 @@ export type Props = {
14
14
  readonly isArchiveSideBarVisible?: boolean;
15
15
  traceContext: MediaTraceContext;
16
16
  };
17
- export declare const Header: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onSetArchiveSideBarVisible, traceContext, }: Props & WrappedComponentProps) => React.JSX.Element;
17
+ export declare const Header: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onClose, onSetArchiveSideBarVisible, traceContext, }: Props & WrappedComponentProps) => React.JSX.Element;
18
18
  declare const _default: React.FC<Props>;
19
19
  export default _default;
@@ -15,6 +15,17 @@ export interface MediaViewerExtensions {
15
15
  icon: ReactNode;
16
16
  renderer: (selectedIdentifier: Identifier, actions: MediaViewerExtensionsActions) => ReactNode;
17
17
  };
18
+ headerActions?: Array<{
19
+ /** Icon to display in the header button */
20
+ icon: ReactNode;
21
+ /** Label for the button (accessibility) */
22
+ label: string;
23
+ /** Called when the button is clicked. Receives the currently viewed item's identifier
24
+ * and actions (including close) to control the viewer. */
25
+ onClick: (selectedIdentifier: Identifier, actions: MediaViewerExtensionsActions) => void;
26
+ /** Optional callback to control per-item visibility. When omitted, button always shows. */
27
+ isVisible?: (selectedIdentifier: Identifier) => boolean;
28
+ }>;
18
29
  }
19
30
  export interface MediaViewerProps {
20
31
  readonly mediaClient: MediaClient;
@@ -14,6 +14,6 @@ export type Props = {
14
14
  readonly isArchiveSideBarVisible?: boolean;
15
15
  traceContext: MediaTraceContext;
16
16
  };
17
- export declare const Header: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onSetArchiveSideBarVisible, traceContext, }: Props & WrappedComponentProps) => React.JSX.Element;
17
+ export declare const Header: ({ isArchiveSideBarVisible, extensions, isSidebarVisible, onSidebarButtonClick, identifier, onClose, onSetArchiveSideBarVisible, traceContext, }: Props & WrappedComponentProps) => React.JSX.Element;
18
18
  declare const _default: React.FC<Props>;
19
19
  export default _default;
@@ -22,7 +22,7 @@ export const NativeMediaPreview = ({
22
22
  identifier,
23
23
  mediaClient,
24
24
  onClick,
25
- }: NativeMediaViewerProps) => {
25
+ }: NativeMediaViewerProps): React.JSX.Element => {
26
26
  const [url, setUrl] = useState('dataURI' in identifier ? identifier.dataURI : '');
27
27
  const [isPreviewUnavailable, setIsPreviewUnavailable] = useState(false);
28
28
 
@@ -8,7 +8,7 @@ const centeredFormStyles = xcss({
8
8
  margin: 'auto',
9
9
  });
10
10
 
11
- export const CenteredForm = ({ children }: { children: ReactNode }) => (
11
+ export const CenteredForm = ({ children }: { children: ReactNode }): React.JSX.Element => (
12
12
  <Stack alignInline="center" alignBlock="center" grow="fill" xcss={centeredFormStyles}>
13
13
  <Box>{children}</Box>
14
14
  </Stack>
@@ -175,27 +175,52 @@ export const zipWithNestedFolderItem: FileIdentifier = {
175
175
  occurrenceKey: 'testOccurrenceKey',
176
176
  };
177
177
 
178
- export const zipItemMultipleFoldersAtRoot = {
178
+ export const zipItemMultipleFoldersAtRoot: {
179
+ occurrenceKey: string;
180
+ mediaItemType: 'file';
181
+ id: string;
182
+ collectionName?: string;
183
+ } = {
179
184
  ...zipItemMultipleFoldersAtRootId,
180
185
  occurrenceKey: 'testOccurenceKey',
181
186
  };
182
187
 
183
- export const zipItemLargeInnerFile = {
188
+ export const zipItemLargeInnerFile: {
189
+ occurrenceKey: string;
190
+ mediaItemType: 'file';
191
+ id: string;
192
+ collectionName?: string;
193
+ } = {
184
194
  ...zipItemLargeInnerFileId,
185
195
  occurrenceKey: 'testOccurrenceKey',
186
196
  };
187
197
 
188
- export const codeItem = {
198
+ export const codeItem: {
199
+ occurrenceKey: string;
200
+ mediaItemType: 'file';
201
+ id: string;
202
+ collectionName?: string;
203
+ } = {
189
204
  ...codeFileId,
190
205
  occurrenceKey: 'testOccurrenceKey',
191
206
  };
192
207
 
193
- export const emailItem = {
208
+ export const emailItem: {
209
+ occurrenceKey: string;
210
+ mediaItemType: 'file';
211
+ id: string;
212
+ collectionName?: string;
213
+ } = {
194
214
  ...emailFileId,
195
215
  occurrenceKey: 'testOccurrenceKey',
196
216
  };
197
217
 
198
- export const emailFailedItem = {
218
+ export const emailFailedItem: {
219
+ occurrenceKey: string;
220
+ mediaItemType: 'file';
221
+ id: string;
222
+ collectionName?: string;
223
+ } = {
199
224
  ...emailUnsupportedFileId,
200
225
  occurrenceKey: 'testOccurrenceKey',
201
226
  };
@@ -1,27 +1,27 @@
1
1
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
2
- import { css } from '@emotion/react';
2
+ import { css, type SerializedStyles } from '@emotion/react';
3
3
  import { token } from '@atlaskit/tokens';
4
4
 
5
5
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
6
- export const containerStyles = css({
6
+ export const containerStyles: SerializedStyles = css({
7
7
  display: 'flex',
8
8
  flexDirection: 'row',
9
9
  flexWrap: 'wrap',
10
10
  });
11
11
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
12
- export const groupStyles = css({
12
+ export const groupStyles: SerializedStyles = css({
13
13
  width: '250px',
14
14
  padding: token('space.250', '20px'),
15
15
  });
16
16
 
17
17
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
18
- export const buttonListStyles = css({
18
+ export const buttonListStyles: SerializedStyles = css({
19
19
  paddingLeft: 0,
20
20
  listStyle: 'none',
21
21
  });
22
22
 
23
23
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
24
- export const mVSidebarStyles = css({
24
+ export const mVSidebarStyles: SerializedStyles = css({
25
25
  height: 'calc(100vh - 64px)',
26
26
  padding: token('space.400', '32px'),
27
27
  overflow: 'auto',
@@ -38,7 +38,7 @@ export const mVSidebarStyles = css({
38
38
  });
39
39
 
40
40
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766
41
- export const mVSidebarHeaderStyles = css({
41
+ export const mVSidebarHeaderStyles: SerializedStyles = css({
42
42
  display: 'flex',
43
43
  width: '100%',
44
44
  justifyContent: 'space-between',
@@ -6,7 +6,7 @@ type Endpoints = Partial<Record<keyof MediaApi, number>>;
6
6
  export const delayApiResponses = (
7
7
  mediaApi: MediaApi,
8
8
  { getImage, getItems, getFileBinary }: Endpoints,
9
- ) => {
9
+ ): void => {
10
10
  const baseGetImage = mediaApi.getImage;
11
11
  mediaApi.getImage = async (...params) => {
12
12
  await sleep(getImage);
@@ -32,7 +32,7 @@ export const ToggleBox = ({
32
32
  label: string;
33
33
  centered?: boolean;
34
34
  onChange: (val: boolean) => void;
35
- }) => {
35
+ }): React.JSX.Element => {
36
36
  const [id] = useState(makeid());
37
37
 
38
38
  return (
@@ -4,12 +4,19 @@ import { type FileIdentifier } from '@atlaskit/media-client';
4
4
  import { getMediaClient } from '@atlaskit/media-client-react';
5
5
  import { type MediaClientConfig } from '@atlaskit/media-client';
6
6
 
7
- export const useSvgUploader = (config: MediaClientConfig, collectionName?: string) => {
7
+ export const useSvgUploader = (
8
+ config: MediaClientConfig,
9
+ collectionName?: string,
10
+ ): {
11
+ status: string;
12
+ identifier: FileIdentifier | undefined;
13
+ uploadFn: (event: SyntheticEvent<HTMLInputElement>) => Promise<void>;
14
+ } => {
8
15
  const mediaClient = getMediaClient(config);
9
16
  const [identifier, setIdentifier] = useState<FileIdentifier>();
10
17
  const [status, setStatus] = useState<string>('');
11
18
 
12
- const uploadFn = async (event: SyntheticEvent<HTMLInputElement>) => {
19
+ const uploadFn = async (event: SyntheticEvent<HTMLInputElement>): Promise<void> => {
13
20
  if (!event.currentTarget.files || !event.currentTarget.files.length) {
14
21
  return;
15
22
  }
@@ -1,7 +1,21 @@
1
- import { useState, useMemo } from 'react';
1
+ import { useState, useMemo, type Dispatch, type SetStateAction } from 'react';
2
2
  import { type FileIdentifier } from '@atlaskit/media-client';
3
3
 
4
- export const useSelectOptions = (identifiers: FileIdentifier[], fileKeys: string[]) => {
4
+ export const useSelectOptions = (
5
+ identifiers: FileIdentifier[],
6
+ fileKeys: string[],
7
+ ): {
8
+ options: {
9
+ label: string;
10
+ value: FileIdentifier;
11
+ }[];
12
+ defaultOption: {
13
+ label: string;
14
+ value: FileIdentifier;
15
+ };
16
+ identifier: FileIdentifier;
17
+ setIdentifier: Dispatch<SetStateAction<FileIdentifier>>;
18
+ } => {
5
19
  const defaultOption = useMemo(
6
20
  () => ({ label: fileKeys[0], value: identifiers[0] }),
7
21
  [identifiers, fileKeys],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-viewer",
3
- "version": "52.8.4",
3
+ "version": "52.9.0",
4
4
  "description": "MediaViewer is Atlassian's powerful solution for viewing files on the web. It's both powerful and extendable yet easy-to-integrate",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -54,7 +54,7 @@
54
54
  "@atlaskit/textfield": "^8.2.0",
55
55
  "@atlaskit/theme": "^22.0.0",
56
56
  "@atlaskit/tokens": "^11.1.0",
57
- "@atlaskit/tooltip": "^20.14.0",
57
+ "@atlaskit/tooltip": "^21.0.0",
58
58
  "@atlaskit/ufo": "^0.4.0",
59
59
  "@babel/runtime": "^7.0.0",
60
60
  "@codemirror/language": "6.10.8",