-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathblock-editor.js
More file actions
2 lines (2 loc) · 4.9 KB
/
block-editor.js
File metadata and controls
2 lines (2 loc) · 4.9 KB
1
2
(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.apiFetch;var r=e.n(t);const o=window.wp.i18n,i=window.wp.data,a=window.wp.components,n=window.ReactJSXRuntime,s={_init(){"undefined"!=typeof CLD_VIDEO_PLAYER&&wp.hooks.addFilter("blocks.registerBlockType","Cloudinary/Media/Video",function(e,t){return"core/video"===t&&("off"!==CLD_VIDEO_PLAYER.video_autoplay_mode&&(e.attributes.autoplay.default=!0),"on"===CLD_VIDEO_PLAYER.video_loop&&(e.attributes.loop.default=!0),"off"===CLD_VIDEO_PLAYER.video_controls&&(e.attributes.controls.default=!1)),e})}};s._init();wp.hooks.addFilter("blocks.registerBlockType","cloudinary/addAttributes",function(e,t){return"core/image"!==t&&"core/video"!==t||(e.attributes||(e.attributes={}),e.attributes.overwrite_transformations={type:"boolean"},e.attributes.transformations={type:"boolean"}),e});const l=e=>{const{attributes:{overwrite_transformations:t},setAttributes:r}=e;return(0,n.jsx)(a.PanelBody,{title:(0,o.__)("Transformations","cloudinary"),children:(0,n.jsx)(a.ToggleControl,{label:(0,o.__)("Overwrite Global Transformations","cloudinary"),checked:t,onChange:e=>{r({overwrite_transformations:e})},__nextHasNoMarginBottom:!0})})};let d=e=>{const{setAttributes:t,media:r}=e,{InspectorControls:o}=wp.editor;return r&&r.transformations&&t({transformations:!0}),(0,n.jsx)(o,{children:(0,n.jsx)(l,{...e})})};d=(0,i.withSelect)((e,t)=>({...t,media:t.attributes.id?e("core").getMedia(t.attributes.id):null}))(d);wp.hooks.addFilter("editor.BlockEdit","cloudinary/filterEdit",e=>t=>{const{name:r}=t,o="core/image"===r||"core/video"===r;return(0,n.jsxs)(n.Fragment,{children:[o?(0,n.jsx)(d,{...t}):null,(0,n.jsx)(e,{...t})]})},20);let c=e=>(0,n.jsx)(n.Fragment,{children:e.modalClass&&(0,n.jsx)(a.ToggleControl,{label:(0,o.__)("Overwrite Cloudinary Global Transformations","cloudinary"),checked:e.overwrite_featured_transformations,onChange:t=>e.setOverwrite(t),className:"cloudinary-overwrite-transformations",__nextHasNoMarginBottom:!0})});c=(0,i.withSelect)(e=>({overwrite_featured_transformations:e("core/editor")?.getEditedPostAttribute("meta")._cloudinary_featured_overwrite??!1}))(c),c=(0,i.withDispatch)(e=>({setOverwrite:t=>{e("core/editor").editPost({meta:{_cloudinary_featured_overwrite:t}})}}))(c);const u=e=>class extends e{render(){return(0,n.jsxs)(n.Fragment,{children:[super.render(),!!this.props.value&&(0,n.jsx)(c,{...this.props})]})}},m={_init(){wp.hooks.addFilter("editor.MediaUpload","cloudinary/filter-featured-image",u)}};m._init();const h={wrapper:null,query:{per_page:-1,orderby:"name",order:"asc",_fields:"id,name,parent",context:"view"},available:{},taxonomies:null,fetchWait:null,_init(){if(this.wrapper=document.getElementById("cld-tax-items"),!this.wrapper)return;const{getTaxonomies:e}=(0,i.select)("core");this.fetchWait=setInterval(()=>{this.taxonomies=e(),this.taxonomies&&(clearInterval(this.fetchWait),this._init_listeners())},1e3)},_init_listeners(){this.taxonomies.forEach(e=>{e.rest_base&&e.visibility.public&&(0,i.subscribe)(()=>{const t=e.slug,r=e.hierarchical,{isResolving:o}=(0,i.select)("core/data"),a=["taxonomy",t,this.query];this.available[t]=null,r&&(this.available[t]=(0,i.select)("core").getEntityRecords("taxonomy",t,this.query)),o("core","getEntityRecords",a)||this.event(e)})})},event(e){const t=(0,i.select)("core/editor").getEditedPostAttribute(e.rest_base);if(!t)return;const r=[...t],o=Array.from(this.wrapper.querySelectorAll(`[data-item*="${e.slug}"]`));[...r].forEach(t=>{const r=this.wrapper.querySelector(`[data-item="${e.slug}:${t}"]`);o.splice(o.indexOf(r),1),null===r&&this.createItem(this.getItem(e,t))}),o.forEach(e=>{e.parentNode.removeChild(e)})},createItem(e){if(!e||!e.id)return;const t=document.createElement("li"),r=document.createElement("span"),o=document.createElement("input"),i=document.createTextNode(e.name);t.classList.add("cld-tax-order-list-item"),t.dataset.item=`${e.taxonomy}:${e.id}`,o.classList.add("cld-tax-order-list-item-input"),o.type="hidden",o.name="cld_tax_order[]",o.value=`${e.taxonomy}:${e.id}`,r.className="dashicons dashicons-menu cld-tax-order-list-item-handle",t.appendChild(r),t.appendChild(o),t.appendChild(i),this.wrapper.appendChild(t)},getItem(e,t){let r={};if(null===this.available[e.slug])r=(0,i.select)("core").getEntityRecord("taxonomy",e.slug,t);else for(const o of this.available[e.slug])if(o.id===t){r=o,r.taxonomy=e.slug;break}return r}};window.addEventListener("load",()=>h._init());window.$=window.jQuery,r().use((e,t)=>{if("cors"===e.mode)return t(e);if(e.url)try{const r=new URL(e.url,location.href);if(r.protocol!==location.protocol||r.hostname!==location.hostname||r.port!==location.port)return t(e)}catch{return t(e)}return e.headers||(e.headers={}),e.headers["x-cld-fetch-from-editor"]="true",t(e)})})();
//# sourceMappingURL=block-editor.js.map