UNPKG

@wordpress/block-library

Version:
54 lines (53 loc) • 2.16 kB
import { LINK_DESTINATION_ATTACHMENT, LINK_DESTINATION_ATTACHMENT_WP_CORE, LINK_DESTINATION_LIGHTBOX, LINK_DESTINATION_MEDIA, LINK_DESTINATION_MEDIA_WP_CORE, LINK_DESTINATION_NONE } from "./constants.mjs"; import { LINK_DESTINATION_ATTACHMENT as LINK_DESTINATION_ATTACHMENT$1, LINK_DESTINATION_MEDIA as LINK_DESTINATION_MEDIA$1, LINK_DESTINATION_NONE as LINK_DESTINATION_NONE$1 } from "../image/constants.mjs"; // packages/block-library/src/gallery/utils.js /** * Determines new href and linkDestination values for an Image block from the * supplied Gallery link destination, or falls back to the Image blocks link. * * @param {Object} image Gallery image. * @param {string} galleryDestination Gallery's selected link destination. * @param {Object} imageDestination Image block link destination attribute. * @param {Object} attributes Block attributes. * @param {Object} lightboxSetting Lightbox setting. * * @return {Object} New attributes to assign to image block. */ function getHrefAndDestination(image, galleryDestination, imageDestination, attributes, lightboxSetting) { switch (imageDestination ? imageDestination : galleryDestination) { case LINK_DESTINATION_MEDIA_WP_CORE: case LINK_DESTINATION_MEDIA: return { href: image?.source_url || image?.url, linkDestination: LINK_DESTINATION_MEDIA$1, lightbox: lightboxSetting?.enabled ? { ...attributes?.lightbox, enabled: false } : void 0 }; case LINK_DESTINATION_ATTACHMENT_WP_CORE: case LINK_DESTINATION_ATTACHMENT: return { href: image?.link, linkDestination: LINK_DESTINATION_ATTACHMENT$1, lightbox: lightboxSetting?.enabled ? { ...attributes?.lightbox, enabled: false } : void 0 }; case LINK_DESTINATION_LIGHTBOX: return { href: void 0, lightbox: !lightboxSetting?.enabled ? { ...attributes?.lightbox, enabled: true } : void 0, linkDestination: LINK_DESTINATION_NONE$1 }; case LINK_DESTINATION_NONE: return { href: void 0, linkDestination: LINK_DESTINATION_NONE$1, lightbox: void 0 }; } return {}; } export { getHrefAndDestination }; //# sourceMappingURL=utils.mjs.map