@atlaskit/editor-plugin-media
Version:
Media plugin for @atlaskit/editor-core
24 lines (23 loc) • 1.45 kB
JavaScript
import { isFileIdentifier } from '@atlaskit/media-client/is-file-identifier';
import { UNSAFE_expValNoExposure } from '@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure';
import { getIdentifier } from './media-common';
// Tells the consumer which item the viewer opened on, or that it closed, before the viewer renders.
// media-card does the same for the viewers it opens, and Media Viewer reports navigation.
export const reportMediaViewerItem = (extensions, media) => {
var _extensions$onSelecte2;
if (!UNSAFE_expValNoExposure('cc_comments_media_viewer_sidebar', 'isEnabled', false)) {
return;
}
// No media means the viewer closed.
if (!media) {
var _extensions$onSelecte;
extensions === null || extensions === void 0 ? void 0 : (_extensions$onSelecte = extensions.onSelectedItemChange) === null || _extensions$onSelecte === void 0 ? void 0 : _extensions$onSelecte.call(extensions, null);
return;
}
const identifier = getIdentifier(media);
// Include the placement, so a file placed more than once can be told apart.
extensions === null || extensions === void 0 ? void 0 : (_extensions$onSelecte2 = extensions.onSelectedItemChange) === null || _extensions$onSelecte2 === void 0 ? void 0 : _extensions$onSelecte2.call(extensions, isFileIdentifier(identifier) && 'occurrenceKey' in media && media.occurrenceKey ? {
...identifier,
occurrenceKey: media.occurrenceKey
} : identifier);
};