@atlaskit/media-viewer 52.8.5 → 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,13 @@
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
+
3
11
  ## 52.8.5
4
12
 
5
13
  ### 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;
@@ -176,50 +176,50 @@ export const zipWithNestedFolderItem: FileIdentifier = {
176
176
  };
177
177
 
178
178
  export const zipItemMultipleFoldersAtRoot: {
179
- occurrenceKey: string;
180
- mediaItemType: "file";
181
- id: string;
182
- collectionName?: string;
179
+ occurrenceKey: string;
180
+ mediaItemType: 'file';
181
+ id: string;
182
+ collectionName?: string;
183
183
  } = {
184
184
  ...zipItemMultipleFoldersAtRootId,
185
185
  occurrenceKey: 'testOccurenceKey',
186
186
  };
187
187
 
188
188
  export const zipItemLargeInnerFile: {
189
- occurrenceKey: string;
190
- mediaItemType: "file";
191
- id: string;
192
- collectionName?: string;
189
+ occurrenceKey: string;
190
+ mediaItemType: 'file';
191
+ id: string;
192
+ collectionName?: string;
193
193
  } = {
194
194
  ...zipItemLargeInnerFileId,
195
195
  occurrenceKey: 'testOccurrenceKey',
196
196
  };
197
197
 
198
198
  export const codeItem: {
199
- occurrenceKey: string;
200
- mediaItemType: "file";
201
- id: string;
202
- collectionName?: string;
199
+ occurrenceKey: string;
200
+ mediaItemType: 'file';
201
+ id: string;
202
+ collectionName?: string;
203
203
  } = {
204
204
  ...codeFileId,
205
205
  occurrenceKey: 'testOccurrenceKey',
206
206
  };
207
207
 
208
208
  export const emailItem: {
209
- occurrenceKey: string;
210
- mediaItemType: "file";
211
- id: string;
212
- collectionName?: string;
209
+ occurrenceKey: string;
210
+ mediaItemType: 'file';
211
+ id: string;
212
+ collectionName?: string;
213
213
  } = {
214
214
  ...emailFileId,
215
215
  occurrenceKey: 'testOccurrenceKey',
216
216
  };
217
217
 
218
218
  export const emailFailedItem: {
219
- occurrenceKey: string;
220
- mediaItemType: "file";
221
- id: string;
222
- collectionName?: string;
219
+ occurrenceKey: string;
220
+ mediaItemType: 'file';
221
+ id: string;
222
+ collectionName?: string;
223
223
  } = {
224
224
  ...emailUnsupportedFileId,
225
225
  occurrenceKey: 'testOccurrenceKey',
@@ -4,10 +4,13 @@ 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): {
8
- status: string;
9
- identifier: FileIdentifier | undefined;
10
- uploadFn: (event: SyntheticEvent<HTMLInputElement>) => Promise<void>;
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>;
11
14
  } => {
12
15
  const mediaClient = getMediaClient(config);
13
16
  const [identifier, setIdentifier] = useState<FileIdentifier>();
@@ -1,14 +1,20 @@
1
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[]): {
5
- options: {
6
- label: string;
7
- value: FileIdentifier;
8
- }[]; defaultOption: {
9
- label: string;
10
- value: FileIdentifier;
11
- }; identifier: FileIdentifier; setIdentifier: Dispatch<SetStateAction<FileIdentifier>>;
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>>;
12
18
  } => {
13
19
  const defaultOption = useMemo(
14
20
  () => ({ label: fileKeys[0], value: identifiers[0] }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-viewer",
3
- "version": "52.8.5",
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/"