"use strict";(globalThis.webpackChunkcoblocks=globalThis.webpackChunkcoblocks||[]).push([[453],{4453:(e,t,l)=>{l.r(t),l.d(t,{default:()=>ee});var o=l(1609),n=l(2485),i=l.n(n),a=l(9668),c=l(8468),r=l.n(c),s=l(7723),u=l(9491),d=l(3162),m=l(4997),p=l(4715),b=l(6427),g=l(6087),k=l(7143),_=l(5556),f=l.n(_);const h=({hoveredFilter:e})=>{if(!e)return null;const t=r().cloneDeep((0,k.select)("core/block-editor").getSelectedBlock());return t.attributes.filter=e,(0,o.createElement)("div",{className:"block-editor-block-switcher__popover__preview__parent"},(0,o.createElement)("div",{className:"block-editor-block-switcher__popover__preview__container"},(0,o.createElement)(b.Popover,{className:"block-editor-block-switcher__preview__popover coblocks-image-filter-popover",focusOnMount:!1,position:"bottom right"},(0,o.createElement)("div",{className:"block-editor-block-switcher__preview coblocks__preview"},(0,o.createElement)("div",{className:"block-editor-block-switcher__preview-title"},(0,s.__)("Preview filter","coblocks")),(0,o.createElement)(p.BlockPreview,{autoHeight:!0,blocks:{...t}})))))},v=e=>{const[t,l]=(0,g.useState)(null),n=e=>{l(e)},{attributes:c,setAttributes:r}=e,{filter:u}=c,d=[{icon:(0,o.createElement)(b.Icon,{icon:a.cN3}),isActive:"none"===u,onClick:()=>{r({filter:"none"})},slug:"none",
/* translators: image style */
title:(0,s.__)("Original","coblocks")},{icon:(0,o.createElement)(b.Icon,{icon:a.vIu}),isActive:"grayscale"===u,onClick:()=>{r({filter:"grayscale"})},slug:"grayscale",
/* translators: image style */
title:(0,s.__)("Grayscale filter","coblocks")},{icon:(0,o.createElement)(b.Icon,{icon:a.mZe}),isActive:"sepia"===u,onClick:()=>{r({filter:"sepia"})},slug:"sepia",
/* translators: image style */
title:(0,s.__)("Sepia filter","coblocks")},{icon:(0,o.createElement)(b.Icon,{icon:a.UKw}),isActive:"saturation"===u,onClick:()=>{r({filter:"saturation"})},slug:"saturation",
/* translators: image style */
title:(0,s.__)("Saturation filter","coblocks")},{icon:(0,o.createElement)(b.Icon,{icon:a.GVY}),isActive:"dim"===u,onClick:()=>{r({filter:"dim"})},slug:"dim",
/* translators: image style */
title:(0,s.__)("Dim filter","coblocks")},{icon:(0,o.createElement)(b.Icon,{icon:a.u5Q}),isActive:"vintage"===u,onClick:()=>{r({filter:"vintage"})},slug:"vintage",
/* translators: image style */
title:(0,s.__)("Vintage filter","coblocks")}];return(0,o.createElement)(b.ToolbarGroup,null,(0,o.createElement)(b.DropdownMenu,{className:i()("components-coblocks-media-filter","none"!==u?"has-filter":""),icon:(0,o.createElement)(b.Icon,{icon:a.x7G}),label:(0,s.__)("Apply filter","coblocks"),noIcons:!0,popoverProps:{className:"components-coblocks-dropdown"}},(()=>(0,o.createElement)(b.MenuGroup,null,(0,o.createElement)(h,{hoveredFilter:t}),d.map((e=>(0,o.createElement)(b.MenuItem,{icon:e.icon,isSelected:u===e.slug,key:`coblocks-image-filter-${e.slug}`,label:e.title,onClick:e.onClick,onMouseEnter:()=>n(e.slug),onMouseLeave:()=>n(null),role:"menuitemradio"},e.title)))))))},E=v;v.propTypes={attributes:f().object,setAttributes:f().func};const y=e=>{const{attributes:t,innerBlocks:l}=e,{images:n}=t,i=!!n.length||!!l?.length;return(0,o.createElement)(p.BlockControls,null,i&&(0,o.createElement)(E,{...e}))};var C=l(5573);const w="function"==typeof p.__experimentalUseInnerBlocksProps?p.__experimentalUseInnerBlocksProps:p.useInnerBlocksProps,I=["core/image"],S=e=>{const{attributes:t,isSelected:l,setAttributes:n,mediaPlaceholder:a,insertBlocksAfter:c,blockProps:r,wrapperClass:u=""}=e,{align:d,caption:b,imageCrop:k,lightbox:_}=t,{children:f,...h}=w(r,{__experimentalLayout:{alignments:[],type:"default"},allowedBlocks:I,orientation:"vertical",renderAppender:!1}),[v,E]=(0,g.useState)(!1);return(0,g.useEffect)((()=>{l||E(!1)}),[l]),(0,o.createElement)("figure",{...h,className:i()(r.className,{[`align${d}`]:d,"has-lightbox":_,"is-cropped":k})},u?(0,o.createElement)(C.View,{className:i()(u)},f):{children:f},(0,o.createElement)(C.View,{className:"gallery-media-placeholder-wrapper",onClick:function(){v&&E(!1)}},a),(0,o.createElement)(B,{__unstableOnSplitAtEnd:()=>c((0,m.createBlock)("core/paragraph")),"aria-label":(0,s.__)("Gallery caption text","coblocks"),captionFocused:v,className:"blocks-gallery-caption",inlineToolbar:!0,isHidden:!l&&p.RichText.isEmpty(b),onChange:e=>n({caption:e}),onFocusCaption:function(){v||E(!0)},placeholder:(0,s.__)("Write gallery caption…","coblocks"),tagName:"figcaption",value:b}))};function B({isHidden:e,captionFocused:t,onFocusCaption:l,className:n,value:i,placeholder:a,tagName:c,captionRef:r,...s}){return e?(0,o.createElement)(b.VisuallyHidden,{as:p.RichText,...s}):(0,o.createElement)(p.RichText,{className:n,isSelected:t,onClick:l,placeholder:a,ref:r,tagName:c,value:i,...s})}const N=S;S.propTypes={attributes:f().object.isRequired,blockProps:f().object,insertBlocksAfter:f().func,isSelected:f().bool.isRequired,mediaPlaceholder:f().elementType,setAttributes:f().func,wrapperClass:f().string.isRequired},S.defaultProps={attributes:{},isSelected:!1,wrapperClass:""};var A=l(632),x=l(692);const T=[{
/* translators: abbreviation for small size */
label:(0,s.__)("S","coblocks"),tooltip:(0,s.__)("Small","coblocks"),value:1},{
/* translators: abbreviation for medium size */
label:(0,s.__)("M","coblocks"),tooltip:(0,s.__)("Medium","coblocks"),value:2},{
/* translators: abbreviation for large size */
label:(0,s.__)("L","coblocks"),tooltip:(0,s.__)("Large","coblocks"),value:3},{
/* translators: abbreviation for extra large size */
label:(0,s.__)("XL","coblocks"),tooltip:(0,s.__)("Extra Large","coblocks"),value:4}],M={label:(0,s.__)("None","coblocks"),tooltip:(0,s.__)("None","coblocks"),value:0},P={label:(0,o.createElement)(b.Icon,{icon:a.Zes}),tooltip:(0,s.__)("Custom","coblocks"),value:"custom"};class z extends g.Component{render(){const{advancedMaxValue:e,advancedMinValue:t,currentOption:l,label:n,onChange:a,options:r,showAdvancedControls:s,showIcons:u,showNoneOption:d,showCustomOption:m}=this.props;let p=r||T;return d&&(p=[M,...p]),m&&(p=[...p,P]),s&&!1!==t&&!1!==e?(0,o.createElement)(b.RangeControl,{label:n,max:e,min:t,onChange:e=>a(e),value:l}):(0,o.createElement)(b.BaseControl,{className:i()("coblocks-option-selector-control",{"is-custom":"custom"===l}),id:`coblocks-option-selector-${(0,c.kebabCase)(n)}`,label:n},(0,o.createElement)(b.PanelRow,null,(0,o.createElement)(b.ButtonGroup,{"aria-label":n},p.map((e=>(0,o.createElement)(b.Tooltip,{key:`option-${e.value}`,text:e.tooltip},(0,o.createElement)(b.Button,{"aria-label":e.tooltip,"aria-pressed":l===e.value,isPrimary:l===e.value,isSecondary:l!==e.value,onClick:()=>a(e.value)},u?e.icon:e.label)))))))}}z.propTypes={advancedMaxValue:f().number,advancedMinValue:f().number,currentOption:f().oneOfType([f().string,f().number]),label:f().string,onChange:f().func,options:f().array,showAdvancedControls:f().bool,showCustomOption:f().bool,showIcons:f().bool,showNoneOption:f().bool};const O=[{
/* translators: abbreviation for small size */
label:(0,s.__)("S","coblocks"),tooltip:(0,s.__)("Small","coblocks"),value:"small"},{
/* translators: abbreviation for medium size */
label:(0,s.__)("M","coblocks"),tooltip:(0,s.__)("Medium","coblocks"),value:"medium"},{
/* translators: abbreviation for large size */
label:(0,s.__)("L","coblocks"),tooltip:(0,s.__)("Large","coblocks"),value:"large"}],L=e=>{const{attributes:t,setAttributes:l}=e,{align:n,gutter:i,gutterCustom:a}=t,c="full"===n?10:5;return(0,g.useEffect)((()=>{a>c&&l({gutterCustom:c})}),[a,c]),(0,o.createElement)(o.Fragment,null,(0,o.createElement)(z,{currentOption:i,label:(0,s.__)("Gutter","coblocks"),onChange:e=>l({gutter:e}),options:O,showCustomOption:!0}),"custom"===i&&(0,o.createElement)(b.RangeControl,{initialValue:0,max:c,min:0,onChange:e=>l({gutterCustom:e.toString()}),step:.1,value:parseFloat(a)||0,withInputField:!0}))},R=L;L.propTypes={attributes:f().object,setAttributes:f().func};var D=l(3582);function F(e){const[t,l]=(0,g.useState)([]),o=(0,k.useSelect)((t=>{if(!e?.length)return[];const l=e.map((e=>e.attributes.id)).filter((e=>void 0!==e));if(0===l.length)return[];if(l.length>100){const e=[...l];let n=[];for(;e.length;){var o;const l=null!==(o=t(D.store).getMediaItems({include:e.splice(0,100).join(","),per_page:100}))&&void 0!==o?o:[];n=[...n,...l]}return n}return t(D.store).getMediaItems({include:l.join(","),per_page:100})||[]}),[e]);return o?.length!==t?.length||o?.some((e=>!t.find((t=>t.id===e.id))))?(l(o),o):t}const V="attachment",G="media",j="none",U=["noreferrer","noopener"],$="none",H="media",q="attachment";function W(e,t){switch(t){case H:return{href:e?.source_url||e?.url,linkDestination:G};case q:return{href:e?.link,linkDestination:V};case $:return{href:void 0,linkDestination:j}}return{}}function Y(e,{rel:t}){const l=e?"_blank":void 0;let o;return o=l||t?function(e){let t=e;return void 0===e||(0,c.isEmpty)(t)||(0,c.isEmpty)(t)||((0,c.each)(U,(e=>{const l=new RegExp("\\b"+e+"\\b","gi");t=t.replace(l,"")})),t!==e&&(t=t.trim()),(0,c.isEmpty)(t)&&(t=void 0)),t}(t):void 0,{linkTarget:l,rel:o}}const Z=[{label:(0,s.__)("Attachment Page","coblocks"),value:q},{label:(0,s.__)("Media File","coblocks"),value:H},{label:(0,s._x)("None","Media item link option"),value:$}];function J(e){const{attributes:t,clientId:l,isSelected:n,setAttributes:i}=e,{linkTarget:a,linkTo:r,sizeSlug:u,lightbox:d,gutter:m,gutterCustom:_,radius:f}=t,{updateBlockAttributes:h}=(0,k.useDispatch)(p.store),{createSuccessNotice:v}=(0,k.useDispatch)(x.store),{getBlock:E,getSettings:y}=(0,k.useSelect)((e=>({getBlock:e(p.store).getBlock,getSettings:e(p.store)?.getSettings||{}})),[]),w=F((0,k.useSelect)((e=>e(p.store).getBlock(l)?.innerBlocks),[l])),I=function(e,t,l){return(0,g.useMemo)((()=>function(){if(!e||0===e.length)return;const{imageSizes:o}=l();let n={};return t&&(n=e.reduce(((e,t)=>{if(!t.id)return e;const l=o.reduce(((e,l)=>{const o=(0,c.get)(t,["sizes",l.slug,"url"]),n=(0,c.get)(t,["media_details","sizes",l.slug,"source_url"]);return{...e,[l.slug]:o||n}}),{});return{...e,[parseInt(t.id,10)]:l}}),{})),o.filter((({slug:e})=>(0,c.some)(n,(t=>t[e])))).map((({name:e,slug:t})=>({label:e,value:t})))}()),[e,t])}(w,n,y),S=r&&"none"!==r;return(0,o.createElement)(p.InspectorControls,null,(0,o.createElement)(b.PanelBody,{title:(0,s.__)("Gallery settings","coblocks")},(0,o.createElement)(R,{...e}),"custom"!==m&&0!==_&&(0,o.createElement)(b.RangeControl,{"aria-label":(0,s.__)("Add rounded corners to the gallery items.","coblocks"),label:(0,s.__)("Rounded corners","coblocks"),max:20,min:0,onChange:e=>{i({radius:e})},step:1,value:f}),I?.length>0&&(0,o.createElement)(b.SelectControl,{hideCancelButton:!0,label:(0,s.__)("Image size","coblocks"),onChange:function(e){i({sizeSlug:e});const t={},o=[];E(l).innerBlocks.forEach((l=>{o.push(l.clientId);const n=l.attributes.id?(0,c.find)(w,{id:l.attributes.id}):null;t[l.clientId]=function(e,t){const l=(0,c.get)(e,["media_details","sizes",t,"source_url"]);return l?{height:void 0,sizeSlug:t,url:l,width:void 0}:{}}(n,e)})),h(o,t,!0);const n=I.find((t=>t.value===e));v((0,s.sprintf)(/* translators: %s: image size settings */ /* translators: %s: image size settings */
(0,s.__)("All gallery image sizes updated to: %s","coblocks"),n.label),{id:"gallery-attributes-sizeSlug",type:"snackbar"})},options:I,value:u}),g.Platform.isWeb&&!I&&(0,o.createElement)(b.BaseControl,{className:"gallery-image-sizes"},(0,o.createElement)(b.BaseControl.VisualLabel,null,(0,s.__)("Image size","coblocks")),(0,o.createElement)(C.View,{className:"gallery-image-sizes__loading"},(0,o.createElement)(b.Spinner,null),(0,s.__)("Loading options…","coblocks"))),(0,o.createElement)(b.ToggleControl,{checked:!!d,help:e=>e?(0,s.__)("Image lightbox is enabled.","coblocks"):(0,s.__)("Toggle to enable the image lightbox.","coblocks"),label:(0,s.__)("Lightbox","coblocks"),onChange:()=>i({lightbox:!d})}),(0,o.createElement)(b.SelectControl,{hideCancelButton:!0,label:(0,s.__)("Link to","coblocks"),onChange:function(e){i({linkTo:e});const t={},o=[];E(l).innerBlocks.forEach((l=>{o.push(l.clientId);const n=l.attributes.id?(0,c.find)(w,{id:l.attributes.id}):null;t[l.clientId]=W(n,e)})),h(o,t,!0);const n=[...Z].find((t=>t.value===e));v((0,s.sprintf)(/* translators: %s: image size settings */ /* translators: %s: image size settings */
(0,s.__)("All gallery image links updated to: %s","coblocks"),n.label),{id:"gallery-attributes-linkTo",type:"snackbar"})},options:Z,value:r}),S&&(0,o.createElement)(b.ToggleControl,{checked:"_blank"===a,label:(0,s.__)("Open in new tab","coblocks"),onChange:function(e){const t=e?"_blank":void 0;i({linkTarget:t});const o={},n=[];E(l).innerBlocks.forEach((e=>{n.push(e.clientId),o[e.clientId]=Y(t,e.attributes)})),h(n,o,!0);const a=e?(0,s.__)("All gallery images updated to open in new tab","coblocks"):(0,s.__)("All gallery images updated to not open in new tab","coblocks");v(a,{id:"gallery-attributes-openInNewTab",type:"snackbar"})}})))}const K=(e,t="large")=>{const l=(0,c.pick)(e,["alt","id","link","caption"]);l.url=(0,c.get)(e,["sizes",t,"url"])||(0,c.get)(e,["media_details","sizes",t,"source_url"])||e.url;const o=(0,c.get)(e,["sizes","full","url"])||(0,c.get)(e,["media_details","sizes","full","source_url"]);return o&&(l.fullUrl=o),l.alt=""!==l.alt?l.alt:(0,s.__)("Image gallery image","coblocks"),l};const Q=["image"],X=g.Platform.isNative?(0,s.__)("ADD MEDIA","coblocks"):(0,s.__)("Drag images, upload new ones or select files from your library.","coblocks"),ee=(0,u.compose)([b.withNotices])((function(e){const{setAttributes:t,attributes:l,className:n,clientId:r,noticeOperations:u,isSelected:_,noticeUI:f,insertBlocksAfter:h}=e,{filter:v,linkTarget:E,linkTo:C,sizeSlug:w,radius:I}=l,{__unstableMarkNextChangeAsNotPersistent:S,replaceBlocks:B,replaceInnerBlocks:x,updateBlockAttributes:T}=(0,k.useDispatch)(p.store),{getBlock:M,preferredStyle:P}=(0,k.useSelect)((e=>{const t=e(p.store).getSettings().__experimentalPreferredStyleVariations;return{getBlock:e(p.store).getBlock,preferredStyle:t?.value?.["core/image"]}}),[]),z=(0,k.useSelect)((e=>e(p.store).getBlock(r)?.innerBlocks),[r]),O=(0,g.useMemo)((()=>z?.map((e=>({attributes:e.attributes,clientId:e.clientId,fromSavedContent:Boolean(e.originalContent),id:e.attributes.id,url:e.attributes.url})))),[z]);(0,g.useEffect)((()=>{if(l?.images?.length&&!O?.length){const e=l?.images.map((e=>(0,m.createBlock)("core/image",{alt:e.alt,caption:e.caption?.toString(),id:parseInt(e.id),url:e.url}))),t={...l};delete t.images,delete t.gutter,delete t.gutterCustom;const o=(0,m.createBlock)("coblocks/gallery-masonry",{...t},e);B([r],o)}}),[]);const L=F(z),R=function(e,t){const[l,o]=(0,g.useState)([]);return(0,g.useMemo)((()=>function(){let n=!1;const i=l.filter((t=>e.find((e=>t.clientId===e.clientId))));let a;return i.length<l.length&&(n=!0),e.forEach((e=>{e.fromSavedContent&&!i.find((t=>t.id===e.id))&&(n=!0,i.push(e))})),!t||(a=e.filter((e=>!i.find((t=>e.clientId&&t.clientId===e.clientId))&&t?.find((t=>t.id===e.id))&&!e.fromSavedConent))),(n||a?.length>0)&&o([...i,...a]),a.length>0?a:null}()),[e,t])}(O,L);function D(e){const t=e.id?(0,c.find)(L,{id:e.id}):null;let o;return o=e.className&&""!==e.className?e.className:P?`is-style-${P}`:void 0,{...K(e,w),...W(t,C),...Y(E,l),className:o,sizeSlug:w}}function V(e){return Q.some((t=>0===e.type?.indexOf(t)))||0===e.url?.indexOf("blob:")}(0,g.useEffect)((()=>{const e={},t=[];M(r)?.innerBlocks.forEach((l=>{t.push(l.clientId),e[l.clientId]={className:"masonry-brick"}})),T(t,e,!0)}),[]),(0,g.useEffect)((()=>{R?.forEach((e=>{T(e.clientId,{...D(e.attributes),align:void 0,id:e.id})}))}),[R]),(0,g.useEffect)((()=>{"0"===l.gutterCustom&&t({radius:0})}),[l.gutterCustom]),(0,g.useEffect)((()=>{C||(S(),t({linkTo:window?.wp?.media?.view?.settings?.defaultProps?.link||$}))}),[C]);const G=!!O.length,j=G&&O.some((e=>!!e.id)),U=O.some((e=>!e.id&&0===e.url?.indexOf("blob:"))),H=(0,o.createElement)(p.MediaPlaceholder,{accept:"image/*",addToGallery:j,allowedTypes:Q,disableMediaButtons:G&&!_||U,handleUpload:!1,icon:!G&&(0,o.createElement)(b.Icon,{icon:a.J0Y}),isAppender:G,labels:{instructions:!G&&X,title:!G&&(0,s.__)("Masonry Gallery","coblocks")},multiple:!0,notices:G?void 0:f,onError:function(e){u.removeAllNotices(),u.createErrorNotice(e)},onSelect:function(e){const t="[object FileList]"===Object.prototype.toString.call(e),l=t?Array.from(e).map((e=>e.url?e:K({url:(0,d.createBlobURL)(e)}))):e;t&&!l.every(V)&&(u.removeAllNotices(),u.createErrorNotice((0,s.__)("If uploading to a gallery all files need to be image formats","coblocks"),{id:"gallery-upload-invalid-file"}));const o=l.filter((e=>e.url||V(e))).map((e=>e.url?e:K({url:(0,d.createBlobURL)(e)}))),n=o?.reduce(((e,t,l)=>(e[t.id]=l,e)),{}),i=t?z:z.filter((e=>o.find((t=>t.id===e.attributes.id)))),a=Array.from(e).reduce(((e,t)=>({...e?.mime?{}:e,[`${t.id}`]:t.caption})));i?.forEach((e=>{const t=a[e.attributes.id];e.attributes.caption!==t&&(e.attributes.caption=t)}));const p=o.filter((e=>!i.find((t=>e.id===t.attributes.id)))).map((e=>(0,m.createBlock)("core/image",{alt:e.alt,caption:e.caption,id:e.id,url:e.url})));x(r,(0,c.concat)(i,p).sort(((e,t)=>n[e.attributes.id]-n[t.attributes.id])))},value:j?O:{}}),q=(0,p.useBlockProps)({className:i()(n,{[`has-filter-${v}`]:"none"!==v,[`has-border-radius-${I}`]:I>0})});return(0,o.createElement)(o.Fragment,null,_&&(0,o.createElement)(o.Fragment,null,(0,o.createElement)(y,{...e,innerBlocks:O}),(0,o.createElement)(J,{...e})),f,(0,o.createElement)(A.A,{...l},(0,o.createElement)(N,{...e,blockProps:q,images:O,insertBlocksAfter:h,mediaPlaceholder:H,wrapperClass:"masonry-grid"})))}))}}]);