@wordpress/block-library
Version:
Block library for the WordPress editor.
674 lines (673 loc) • 31.7 kB
JavaScript
;
Object.defineProperties(exports, {
__esModule: { value: true },
[Symbol.toStringTag]: { value: "Module" }
});
// \0rolldown/runtime.js
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
key = keys[i];
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: ((k) => from[k]).bind(null, key),
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod));
let clsx = require("clsx");
clsx = __toESM(clsx);
let _wordpress_components = require("@wordpress/components");
let _wordpress_block_editor = require("@wordpress/block-editor");
let _wordpress_element = require("@wordpress/element");
let _wordpress_i18n = require("@wordpress/i18n");
let _wordpress_data = require("@wordpress/data");
let _wordpress_blocks = require("@wordpress/blocks");
let _wordpress_blob = require("@wordpress/blob");
let _wordpress_notices = require("@wordpress/notices");
let _wordpress_icons = require("@wordpress/icons");
let __shared_icon_jsx = require("./shared-icon.cjs");
let __shared_js = require("./shared.cjs");
let __utils_js = require("./utils.cjs");
let ___utils_hooks_js = require("../utils/hooks.cjs");
let ___image_utils_js = require("../image/utils.cjs");
let __gallery_jsx = require("./gallery.cjs");
__gallery_jsx = __toESM(__gallery_jsx);
let __constants_js = require("./constants.cjs");
let __use_image_sizes_js = require("./use-image-sizes.cjs");
__use_image_sizes_js = __toESM(__use_image_sizes_js);
let __use_get_new_images_js = require("./use-get-new-images.cjs");
__use_get_new_images_js = __toESM(__use_get_new_images_js);
let __use_get_media_js = require("./use-get-media.cjs");
__use_get_media_js = __toESM(__use_get_media_js);
let __gallery_styles_js = require("./gallery-styles.cjs");
__gallery_styles_js = __toESM(__gallery_styles_js);
let __use_dynamic_gallery_js = require("./use-dynamic-gallery.cjs");
__use_dynamic_gallery_js = __toESM(__use_dynamic_gallery_js);
let __dynamic_gallery_jsx = require("./dynamic-gallery.cjs");
let __order_controls_tsx = require("./order-controls.cjs");
let __dynamic_source_js = require("./dynamic-source.cjs");
let __order_images_js = require("./order-images.cjs");
let __responsive_styles_js = require("./responsive-styles.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
// packages/block-library/src/gallery/edit.jsx
const LINK_OPTIONS = [
{
icon: _wordpress_icons.customLink,
label: (0, _wordpress_i18n.__)("Link images to attachment pages"),
value: __constants_js.LINK_DESTINATION_ATTACHMENT,
noticeText: (0, _wordpress_i18n.__)("Attachment Pages")
},
{
icon: _wordpress_icons.image,
label: (0, _wordpress_i18n.__)("Link images to media files"),
value: __constants_js.LINK_DESTINATION_MEDIA,
noticeText: (0, _wordpress_i18n.__)("Media Files")
},
{
icon: _wordpress_icons.fullscreen,
label: (0, _wordpress_i18n.__)("Enlarge on click"),
value: __constants_js.LINK_DESTINATION_LIGHTBOX,
noticeText: (0, _wordpress_i18n.__)("Lightbox effect"),
infoText: (0, _wordpress_i18n.__)("Scale images with a lightbox effect")
},
{
icon: _wordpress_icons.linkOff,
label: (0, _wordpress_i18n._x)("None", "Media item link option"),
value: __constants_js.LINK_DESTINATION_NONE,
noticeText: (0, _wordpress_i18n.__)("None")
}
];
const NAVIGATION_BUTTON_TYPE_OPTIONS = [
{
label: (0, _wordpress_i18n.__)("Icon"),
value: "icon"
},
{
label: (0, _wordpress_i18n.__)("Text"),
value: "text"
},
{
label: (0, _wordpress_i18n.__)("Both"),
value: "both"
}
];
const ALLOWED_MEDIA_TYPES = ["image"];
const PLACEHOLDER_TEXT = (0, _wordpress_i18n.__)("Drag and drop images, upload, or choose from your library.");
const DEFAULT_BLOCK = { name: "core/image" };
const EMPTY_ARRAY = [];
function GalleryEdit(props) {
const { setAttributes, attributes, className, clientId, isSelected, insertBlocksAfter, isContentLocked, context, __unstableLayoutClassNames: layoutClassNames } = props;
const postId = context?.postId;
const postType = context?.postType;
const blockEditingMode = (0, _wordpress_block_editor.useBlockEditingMode)();
const [lightboxSetting, defaultRatios, themeRatios, showDefaultRatios] = (0, _wordpress_block_editor.useSettings)("blocks.core/image.lightbox", "dimensions.aspectRatios.default", "dimensions.aspectRatios.theme", "dimensions.defaultAspectRatios");
const linkOptions = !lightboxSetting?.allowEditing ? LINK_OPTIONS.filter((option) => option.value !== __constants_js.LINK_DESTINATION_LIGHTBOX) : LINK_OPTIONS;
const { align, navigationButtonType, columns, imageCrop, randomOrder, linkTarget, linkTo, sizeSlug, aspectRatio, layout } = attributes;
const isFlexLayout = (0, __shared_js.isGalleryFlexLayout)(layout);
const previousLayoutRef = (0, _wordpress_element.useRef)(layout);
const { __unstableMarkNextChangeAsNotPersistent, replaceInnerBlocks, updateBlockAttributes, selectBlock } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
const { createSuccessNotice, createErrorNotice } = (0, _wordpress_data.useDispatch)(_wordpress_notices.store);
(0, _wordpress_element.useEffect)(() => {
const previousLayout = previousLayoutRef.current;
previousLayoutRef.current = layout;
if (!(0, __shared_js.isObject)(previousLayout) || !(0, __shared_js.isObject)(layout) || previousLayout.type === layout.type) return;
const nextLayout = { ...layout };
let hasPreservedGridSetting = false;
if (!Object.hasOwn(layout, "columnCount") && Number.isInteger(previousLayout.columnCount) && previousLayout.columnCount > 0) {
nextLayout.columnCount = previousLayout.columnCount;
hasPreservedGridSetting = true;
}
if (!Object.hasOwn(layout, "minimumColumnWidth") && typeof previousLayout.minimumColumnWidth === "string") {
nextLayout.minimumColumnWidth = previousLayout.minimumColumnWidth;
hasPreservedGridSetting = true;
}
if (hasPreservedGridSetting) {
previousLayoutRef.current = nextLayout;
__unstableMarkNextChangeAsNotPersistent();
setAttributes({ layout: nextLayout });
}
}, [
layout,
setAttributes,
__unstableMarkNextChangeAsNotPersistent
]);
const { getBlock, getSettings, innerBlockImages, multiGallerySelection, selectedStyleState } = (0, _wordpress_data.useSelect)((select) => {
const { getBlockName, getMultiSelectedBlockClientIds, getSettings: _getSettings, getBlock: _getBlock, getSelectedBlockStyleState } = select(_wordpress_block_editor.store);
const multiSelectedClientIds = getMultiSelectedBlockClientIds();
return {
getBlock: _getBlock,
getSettings: _getSettings,
innerBlockImages: _getBlock(clientId)?.innerBlocks ?? EMPTY_ARRAY,
multiGallerySelection: multiSelectedClientIds.length && multiSelectedClientIds.every((_clientId) => getBlockName(_clientId) === "core/gallery"),
selectedStyleState: getSelectedBlockStyleState(clientId)
};
}, [clientId]);
const isViewportStyleState = selectedStyleState?.viewport && selectedStyleState.viewport !== "default";
const viewportStyle = isViewportStyleState ? (0, __responsive_styles_js.getViewportGalleryStyle)(attributes.style, selectedStyleState.viewport) : {};
const baseColumns = (0, __responsive_styles_js.isValidGalleryColumns)(columns) ? columns : void 0;
const baseImageCrop = typeof imageCrop === "boolean" ? imageCrop : true;
const baseAspectRatio = aspectRatio || "auto";
const hasViewportColumns = isViewportStyleState && Object.hasOwn(viewportStyle, "columns") && (0, __responsive_styles_js.isValidGalleryColumns)(viewportStyle.columns);
const hasViewportImageCrop = isViewportStyleState && Object.hasOwn(viewportStyle, "imageCrop") && typeof viewportStyle.imageCrop === "boolean";
const hasViewportAspectRatio = isViewportStyleState && Object.hasOwn(viewportStyle, "aspectRatio") && typeof viewportStyle.aspectRatio === "string" && !!viewportStyle.aspectRatio;
const activeColumns = hasViewportColumns ? viewportStyle.columns : baseColumns;
const activeImageCrop = hasViewportImageCrop ? viewportStyle.imageCrop : baseImageCrop;
const activeAspectRatio = hasViewportAspectRatio ? viewportStyle.aspectRatio : baseAspectRatio;
const images = (0, _wordpress_element.useMemo)(() => innerBlockImages?.map((block) => ({
clientId: block.clientId,
id: block.attributes.id,
url: block.attributes.url,
attributes: block.attributes,
fromSavedContent: Boolean(block.originalContent)
})), [innerBlockImages]);
const imageData = (0, __use_get_media_js.default)(innerBlockImages);
const newImages = (0, __use_get_new_images_js.default)(images, imageData);
const hasImages = !!images.length;
const isDynamic = !!attributes.dynamicContent;
const [appliedSort, setAppliedSort] = (0, _wordpress_element.useState)(null);
const currentOrder = appliedSort && appliedSort.clientIds.length === innerBlockImages.length && appliedSort.clientIds.every((id, index) => innerBlockImages[index].clientId === id) ? appliedSort.order : null;
const canSortImages = (0, __order_images_js.hasSortableImages)(innerBlockImages, imageData);
const dynamic = (0, __use_dynamic_gallery_js.default)({
attributes,
setAttributes,
clientId,
postId,
postType
});
const displayedImageCount = isDynamic ? dynamic.dynamicMedia.length : images.length;
let hasLightboxImages;
if (isDynamic) hasLightboxImages = linkTo === __constants_js.LINK_DESTINATION_LIGHTBOX;
else if (lightboxSetting?.enabled) hasLightboxImages = images.filter((image) => image.attributes?.lightbox?.enabled === void 0 || image.attributes?.lightbox?.enabled === true).length > 0;
else hasLightboxImages = images.filter((image) => image.attributes.lightbox?.enabled).length > 0;
const themeOptions = themeRatios?.map(({ name, ratio }) => ({
label: name,
value: ratio
}));
const defaultOptions = defaultRatios?.map(({ name, ratio }) => ({
label: name,
value: ratio
}));
const aspectRatioOptions = [
{
label: (0, _wordpress_i18n._x)("Original", "Aspect ratio option for dimensions control"),
value: "auto"
},
...showDefaultRatios ? defaultOptions || [] : [],
...themeOptions || []
];
(0, _wordpress_element.useEffect)(() => {
newImages?.forEach((newImage) => {
__unstableMarkNextChangeAsNotPersistent();
updateBlockAttributes(newImage.clientId, {
...buildImageAttributes(newImage.attributes),
id: newImage.id,
align: void 0
});
});
}, [newImages]);
const imageSizeOptions = (0, __use_image_sizes_js.default)(isDynamic ? dynamic.dynamicMedia : imageData, isSelected, getSettings);
/**
* Determines the image attributes that should be applied to an image block
* after the gallery updates.
*
* The gallery will receive the full collection of images when a new image
* is added. As a result we need to reapply the image's original settings if
* it already existed in the gallery. If the image is in fact new, we need
* to apply the gallery's current settings to the image.
*
* @param {Object} imageAttributes Media object for the actual image.
* @return {Object} Attributes to set on the new image block.
*/
function buildImageAttributes(imageAttributes) {
const image = imageAttributes.id ? imageData.find(({ id }) => id === imageAttributes.id) : null;
let newClassName;
if (imageAttributes.className && imageAttributes.className !== "") newClassName = imageAttributes.className;
let newLinkTarget;
if (imageAttributes.linkTarget || imageAttributes.rel) newLinkTarget = {
linkTarget: imageAttributes.linkTarget,
rel: imageAttributes.rel
};
else newLinkTarget = (0, ___image_utils_js.getUpdatedLinkTargetSettings)(linkTarget, attributes);
return {
...(0, __shared_js.pickRelevantMediaFiles)(image, sizeSlug),
...(0, __utils_js.getHrefAndDestination)(image, linkTo, imageAttributes?.linkDestination),
...newLinkTarget,
className: newClassName,
sizeSlug,
caption: imageAttributes.caption.length > 0 ? imageAttributes.caption : image.caption?.raw,
alt: imageAttributes.alt || image.alt_text,
aspectRatio: aspectRatio === "auto" ? void 0 : aspectRatio,
scale: aspectRatio && aspectRatio !== "auto" ? "cover" : void 0
};
}
function isValidFileType(file) {
const mediaTypeSelector = file.type;
return ALLOWED_MEDIA_TYPES.some((mediaType) => mediaTypeSelector?.indexOf(mediaType) === 0) || file.blob;
}
function updateImages(selectedImages) {
const newFileUploads = Object.prototype.toString.call(selectedImages) === "[object FileList]";
const imageArray = newFileUploads ? Array.from(selectedImages).map((file) => {
if (!file.url) return { blob: (0, _wordpress_blob.createBlobURL)(file) };
return file;
}) : selectedImages;
if (!imageArray.every(isValidFileType)) createErrorNotice((0, _wordpress_i18n.__)("If uploading to a gallery all files need to be image formats"), {
id: "gallery-upload-invalid-file",
type: "snackbar"
});
const processedImages = imageArray.filter((file) => file.url || isValidFileType(file)).map((file) => {
if (!file.url) return { blob: file.blob || (0, _wordpress_blob.createBlobURL)(file) };
return file;
});
const newOrderMap = processedImages.reduce((result, image, index) => (result[image.id] = index, result), {});
const existingImageBlocks = !newFileUploads ? innerBlockImages.filter((block) => processedImages.find((img) => img.id === block.attributes.id)) : innerBlockImages;
const newBlocks = processedImages.filter((img) => !existingImageBlocks.find((existingImg) => img.id === existingImg.attributes.id)).map((image) => {
return (0, _wordpress_blocks.createBlock)("core/image", {
id: image.id,
blob: image.blob,
url: image.url,
caption: image.caption,
alt: image.alt
});
});
replaceInnerBlocks(clientId, existingImageBlocks.concat(newBlocks).sort((a, b) => newOrderMap[a.attributes.id] - newOrderMap[b.attributes.id]));
if (newBlocks?.length > 0) selectBlock(newBlocks[0].clientId);
}
function selectRandomOrder() {
setAttributes({ randomOrder: true });
}
function clearRandomOrderAfterEdit() {
if (randomOrder) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes({ randomOrder: false });
}
}
function sortImages(order) {
const sortedBlocks = (0, __order_images_js.sortImageBlocks)(getBlock(clientId).innerBlocks, imageData, order);
replaceInnerBlocks(clientId, sortedBlocks);
clearRandomOrderAfterEdit();
setAppliedSort({
order,
clientIds: sortedBlocks.map((block) => block.clientId)
});
}
function selectCustomOrder() {
setAttributes({ randomOrder: false });
setAppliedSort(null);
}
function changeSourceOrder({ orderby, order }) {
dynamic.setSourceOrder(orderby, order);
clearRandomOrderAfterEdit();
}
function onUploadError(message) {
createErrorNotice(message, { type: "snackbar" });
}
function setLinkTo(value) {
setAttributes({ linkTo: value });
const changedAttributes = {};
const blocks = [];
getBlock(clientId).innerBlocks.forEach((block) => {
blocks.push(block.clientId);
const image = block.attributes.id ? imageData.find(({ id }) => id === block.attributes.id) : null;
changedAttributes[block.clientId] = (0, __utils_js.getHrefAndDestination)(image, value, false, block.attributes, lightboxSetting);
});
updateBlockAttributes(blocks, changedAttributes, { uniqueByBlock: true });
const linkToText = [...linkOptions].find((linkType) => linkType.value === value);
createSuccessNotice((0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("All gallery image links updated to: %s"), linkToText.noticeText), {
id: "gallery-attributes-linkTo",
type: "snackbar"
});
}
function setGallerySettings(settings) {
if (!isViewportStyleState) {
setAttributes(settings);
return;
}
setAttributes({ style: (0, __responsive_styles_js.getUpdatedGalleryStyle)({
style: attributes.style,
viewport: selectedStyleState.viewport,
baseSettings: {
columns: baseColumns,
imageCrop: baseImageCrop,
aspectRatio: baseAspectRatio
},
settings
}) });
}
function setColumnsNumber(value) {
setGallerySettings({ columns: value });
}
function toggleImageCrop() {
setGallerySettings({ imageCrop: !activeImageCrop });
}
function toggleOpenInNewTab(openInNewTab) {
const newLinkTarget = openInNewTab ? "_blank" : void 0;
setAttributes({ linkTarget: newLinkTarget });
const changedAttributes = {};
const blocks = [];
getBlock(clientId).innerBlocks.forEach((block) => {
blocks.push(block.clientId);
changedAttributes[block.clientId] = (0, ___image_utils_js.getUpdatedLinkTargetSettings)(newLinkTarget, block.attributes);
});
updateBlockAttributes(blocks, changedAttributes, { uniqueByBlock: true });
const noticeText = openInNewTab ? (0, _wordpress_i18n.__)("All gallery images updated to open in new tab") : (0, _wordpress_i18n.__)("All gallery images updated to not open in new tab");
createSuccessNotice(noticeText, {
id: "gallery-attributes-openInNewTab",
type: "snackbar"
});
}
function updateImagesSize(newSizeSlug) {
setAttributes({ sizeSlug: newSizeSlug });
const changedAttributes = {};
const blocks = [];
getBlock(clientId).innerBlocks.forEach((block) => {
blocks.push(block.clientId);
const image = block.attributes.id ? imageData.find(({ id }) => id === block.attributes.id) : null;
changedAttributes[block.clientId] = (0, ___image_utils_js.getImageSizeAttributes)(image, newSizeSlug);
});
updateBlockAttributes(blocks, changedAttributes, { uniqueByBlock: true });
const imageSize = imageSizeOptions.find((size) => size.value === newSizeSlug);
createSuccessNotice((0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("All gallery image sizes updated to: %s"), imageSize?.label ?? newSizeSlug), {
id: "gallery-attributes-sizeSlug",
type: "snackbar"
});
}
/**
* Sets the Gallery's aspect ratio.
*
* The base value is added to the img element as an inline
* style. A viewport value is instead rendered
* from the Gallery's responsive CSS, which overrides that inline style.
*
* @param {string|undefined} value Aspect ratio to set. In a viewport state
* `'auto'` is an override that cancels the
* base ratio, while `undefined` removes the
* override so the base value applies again.
*/
function setAspectRatio(value) {
if (isViewportStyleState) setGallerySettings({ aspectRatio: value });
else {
const cleanValue = !value || value === "auto" ? void 0 : value;
setAttributes({ aspectRatio: value ?? "auto" });
const changedAttributes = {};
const blocks = [];
getBlock(clientId).innerBlocks.forEach((block) => {
blocks.push(block.clientId);
changedAttributes[block.clientId] = {
aspectRatio: cleanValue,
scale: cleanValue ? "cover" : void 0
};
});
updateBlockAttributes(blocks, changedAttributes, true);
}
const noticeValue = value ?? baseAspectRatio;
const aspectRatioText = aspectRatioOptions.find((option) => option.value === noticeValue);
const noticeText = isViewportStyleState ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Gallery images in the %1$s viewport updated to aspect ratio: %2$s"), selectedStyleState.viewport.replace("@", ""), aspectRatioText?.label || noticeValue) : (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("All gallery images updated to aspect ratio: %s"), aspectRatioText?.label || noticeValue);
createSuccessNotice(noticeText, {
id: "gallery-attributes-aspectRatio",
type: "snackbar"
});
}
(0, _wordpress_element.useEffect)(() => {
if (!linkTo) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes({ linkTo: window?.wp?.media?.view?.settings?.defaultProps?.link || __constants_js.LINK_DESTINATION_NONE });
}
}, [linkTo]);
const hasImageIds = hasImages && images.some((image) => !!image.id);
const mediaPlaceholderProps = {
addToGallery: false,
disableMediaButtons: images.some((img) => !img.id && img.url?.indexOf("blob:") === 0),
value: {}
};
const blockProps = (0, _wordpress_block_editor.useBlockProps)({ className: (0, clsx.default)(className, "has-nested-images", `wp-block-gallery-${clientId}`, isDynamic && [
layoutClassNames,
"blocks-gallery-grid",
{
[`align${align}`]: align,
[`columns-${columns}`]: isFlexLayout && columns !== void 0,
"columns-default": isFlexLayout && columns === void 0,
"is-cropped": isFlexLayout && imageCrop
}
]) });
const innerBlocksProps = (0, _wordpress_block_editor.useInnerBlocksProps)(blockProps, {
defaultBlock: DEFAULT_BLOCK,
directInsert: true,
orientation: "horizontal",
renderAppender: false,
allowedBlocks: isDynamic ? EMPTY_ARRAY : void 0
});
const dropdownMenuProps = (0, ___utils_hooks_js.useToolsPanelDropdownMenuProps)();
if (!hasImages && !isDynamic) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
...innerBlocksProps,
children: [innerBlocksProps.children, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.MediaPlaceholder, {
handleUpload: false,
icon: __shared_icon_jsx.sharedIcon,
labels: {
title: (0, _wordpress_i18n.__)("Gallery"),
instructions: PLACEHOLDER_TEXT
},
onSelect: updateImages,
allowedTypes: ALLOWED_MEDIA_TYPES,
multiple: true,
onError: onUploadError,
...mediaPlaceholderProps,
children: blockEditingMode === "default" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.Button, {
__next40pxDefaultSize: true,
variant: "secondary",
onClick: dynamic.enableDynamicMode,
children: (0, __dynamic_source_js.getDynamicSource)(__dynamic_source_js.ATTACHED_MEDIA).title
})
})]
});
const hasLinkTo = linkTo && linkTo !== "none";
const hasViewportSettings = isFlexLayout || aspectRatioOptions.length > 1;
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_block_editor.InspectorControls, {
group: isViewportStyleState && hasViewportSettings ? "style-state" : "default",
children: [!isViewportStyleState && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__dynamic_gallery_jsx.GallerySourcePanel, {
dynamic,
hasImages
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_components.__experimentalToolsPanel, {
label: (0, _wordpress_i18n.__)("Settings"),
resetAll: () => {
if (isViewportStyleState) {
setGallerySettings({
columns: void 0,
imageCrop: void 0,
aspectRatio: void 0
});
return;
}
setAttributes({
navigationButtonType: "icon",
randomOrder: false,
...isFlexLayout && {
columns: void 0,
imageCrop: true
}
});
setAspectRatio("auto");
if (isDynamic) dynamic.setSourceOrder(void 0, void 0);
if (sizeSlug !== __constants_js.DEFAULT_MEDIA_SIZE_SLUG) updateImagesSize(__constants_js.DEFAULT_MEDIA_SIZE_SLUG);
if (linkTarget) toggleOpenInNewTab(false);
},
dropdownMenuProps,
children: [
isFlexLayout && displayedImageCount > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
isShownByDefault: true,
label: (0, _wordpress_i18n.__)("Columns"),
hasValue: () => isViewportStyleState ? hasViewportColumns : !!activeColumns && activeColumns !== displayedImageCount,
onDeselect: () => setColumnsNumber(void 0),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.RangeControl, {
label: (0, _wordpress_i18n.__)("Columns"),
value: activeColumns ? activeColumns : (0, __shared_js.defaultColumnsNumber)(displayedImageCount),
onChange: setColumnsNumber,
min: 1,
max: Math.min(__constants_js.MAX_COLUMNS, displayedImageCount),
required: true
})
}),
!isViewportStyleState && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
isShownByDefault: true,
label: (0, _wordpress_i18n.__)("Order by"),
hasValue: () => !!randomOrder || isDynamic && (dynamic.sourceOrderby !== __dynamic_source_js.DEFAULT_ORDERBY || dynamic.sourceOrder !== __dynamic_source_js.DEFAULT_ORDER),
onDeselect: () => {
if (isDynamic) {
dynamic.setSourceOrder(void 0, void 0);
clearRandomOrderAfterEdit();
} else selectCustomOrder();
},
children: isDynamic ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__order_controls_tsx.SourceOrderControl, {
order: {
orderby: dynamic.sourceOrderby,
order: dynamic.sourceOrder
},
isRandom: !!randomOrder,
onChange: changeSourceOrder,
onSelectRandom: selectRandomOrder
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__order_controls_tsx.SortImagesControl, {
currentOrder,
isRandom: !!randomOrder,
canSort: canSortImages,
onSort: sortImages,
onSelectCustom: selectCustomOrder,
onSelectRandom: selectRandomOrder
})
}),
!isViewportStyleState && imageSizeOptions?.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
isShownByDefault: true,
label: (0, _wordpress_i18n.__)("Resolution"),
hasValue: () => sizeSlug !== __constants_js.DEFAULT_MEDIA_SIZE_SLUG,
onDeselect: () => updateImagesSize(__constants_js.DEFAULT_MEDIA_SIZE_SLUG),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.SelectControl, {
label: (0, _wordpress_i18n.__)("Resolution"),
help: (0, _wordpress_i18n.__)("Select the size of the source images."),
value: sizeSlug,
options: imageSizeOptions,
onChange: updateImagesSize,
hideCancelButton: true
})
}),
!isViewportStyleState && hasLinkTo && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
isShownByDefault: true,
label: (0, _wordpress_i18n.__)("Open images in new tab"),
hasValue: () => !!linkTarget,
onDeselect: () => toggleOpenInNewTab(false),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Open images in new tab"),
checked: linkTarget === "_blank",
onChange: toggleOpenInNewTab
})
}),
aspectRatioOptions.length > 1 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
hasValue: () => isViewportStyleState ? hasViewportAspectRatio : activeAspectRatio !== "auto",
label: (0, _wordpress_i18n.__)("Aspect ratio"),
onDeselect: () => setAspectRatio(isViewportStyleState ? void 0 : "auto"),
isShownByDefault: true,
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.SelectControl, {
label: (0, _wordpress_i18n.__)("Aspect ratio"),
help: (0, _wordpress_i18n.__)("Set a consistent aspect ratio for all images in the gallery."),
value: activeAspectRatio,
options: aspectRatioOptions,
onChange: setAspectRatio
})
}),
isFlexLayout && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
isShownByDefault: true,
label: (0, _wordpress_i18n.__)("Crop images to fit"),
hasValue: () => isViewportStyleState ? hasViewportImageCrop : !activeImageCrop,
onDeselect: () => setGallerySettings({ imageCrop: isViewportStyleState ? void 0 : true }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToggleControl, {
label: (0, _wordpress_i18n.__)("Crop images to fit"),
checked: activeImageCrop,
onChange: toggleImageCrop
})
}),
!isViewportStyleState && lightboxSetting?.allowEditing && hasLightboxImages && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToolsPanelItem, {
label: (0, _wordpress_i18n.__)("Navigation button type"),
isShownByDefault: true,
hasValue: () => navigationButtonType !== "icon",
onDeselect: () => setAttributes({ navigationButtonType: "icon" }),
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToggleGroupControl, {
label: (0, _wordpress_i18n.__)("Navigation button type"),
value: navigationButtonType,
onChange: (value) => setAttributes({ navigationButtonType: value }),
isBlock: true,
help: (0, _wordpress_i18n.__)("Adjust the appearance of buttons in the lightbox."),
children: NAVIGATION_BUTTON_TYPE_OPTIONS.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.__experimentalToggleGroupControlOption, {
value: option.value,
label: option.label
}, option.value))
})
})
]
})]
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "block",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ToolbarDropdownMenu, {
icon: _wordpress_icons.link,
label: (0, _wordpress_i18n.__)("Link"),
children: ({ onClose }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.MenuGroup, { children: linkOptions.map((linkItem) => {
const isOptionSelected = linkTo === linkItem.value;
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.MenuItem, {
isSelected: isOptionSelected,
className: (0, clsx.default)("components-dropdown-menu__menu-item", { "is-active": isOptionSelected }),
iconPosition: "left",
icon: linkItem.icon,
onClick: () => {
setLinkTo(linkItem.value);
onClose();
},
role: "menuitemradio",
info: linkItem.infoText,
children: linkItem.label
}, linkItem.value);
}) })
})
}),
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [!multiGallerySelection && !isDynamic && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.BlockControls, {
group: "other",
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_block_editor.MediaReplaceFlow, {
allowedTypes: ALLOWED_MEDIA_TYPES,
handleUpload: false,
onSelect: updateImages,
name: (0, _wordpress_i18n.__)("Add"),
multiple: true,
mediaIds: images.filter((image) => image.id).map((image) => image.id),
addToGallery: hasImageIds,
variant: "toolbar"
})
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__gallery_styles_js.default, {
style: attributes.style,
clientId,
isFlexLayout
})] }),
isDynamic ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__dynamic_gallery_jsx.GalleryDynamicView, {
...props,
dynamic,
blockProps,
innerBlocksProps,
multiGallerySelection
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__gallery_jsx.default, {
...props,
isContentLocked,
images,
blockProps: innerBlocksProps,
insertBlocksAfter,
multiGallerySelection
})
] });
}
exports.default = GalleryEdit;
//# sourceMappingURL=edit.cjs.map