@wordpress/block-library
Version:
Block library for the WordPress editor.
59 lines (58 loc) • 2.17 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
let __constants_js = require("./constants.cjs");
let ___image_constants_js = require("../image/constants.cjs");
// 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 __constants_js.LINK_DESTINATION_MEDIA_WP_CORE:
case __constants_js.LINK_DESTINATION_MEDIA: return {
href: image?.source_url || image?.url,
linkDestination: ___image_constants_js.LINK_DESTINATION_MEDIA,
lightbox: lightboxSetting?.enabled ? {
...attributes?.lightbox,
enabled: false
} : void 0
};
case __constants_js.LINK_DESTINATION_ATTACHMENT_WP_CORE:
case __constants_js.LINK_DESTINATION_ATTACHMENT: return {
href: image?.link,
linkDestination: ___image_constants_js.LINK_DESTINATION_ATTACHMENT,
lightbox: lightboxSetting?.enabled ? {
...attributes?.lightbox,
enabled: false
} : void 0
};
case __constants_js.LINK_DESTINATION_LIGHTBOX: return {
href: void 0,
lightbox: !lightboxSetting?.enabled ? {
...attributes?.lightbox,
enabled: true
} : void 0,
linkDestination: ___image_constants_js.LINK_DESTINATION_NONE
};
case __constants_js.LINK_DESTINATION_NONE: return {
href: void 0,
linkDestination: ___image_constants_js.LINK_DESTINATION_NONE,
lightbox: void 0
};
}
return {};
}
exports.getHrefAndDestination = getHrefAndDestination;
//# sourceMappingURL=utils.cjs.map