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