WordPress/wp-includes/js/dist/list-reusable-blocks.min.js
gziolo 6e4458c935 Build: Use hashed/deterministic moduleIDs in webpack config
Props peterwilsoncc, desrosj.
Fixes #53192.


Built from https://develop.svn.wordpress.org/trunk@50940


git-svn-id: http://core.svn.wordpress.org/trunk@50549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-20 12:20:04 +00:00

2 lines
5.4 KiB
JavaScript

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.listReusableBlocks=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="./node_modules/@wordpress/list-reusable-blocks/build-module/index.js")}({"./node_modules/@wordpress/list-reusable-blocks/build-module/index.js":function(e,t,n){"use strict";n.r(t);var o=n("@wordpress/element"),r=n("@wordpress/i18n"),s=n("lodash"),i=n("@wordpress/api-fetch"),l=n.n(i);var a=async function(e){const t=await l()({path:"/wp/v2/types/wp_block"}),n=await l()({path:`/wp/v2/${t.rest_base}/${e}?context=edit`}),o=n.title.raw,r=n.content.raw,i=JSON.stringify({__file:"wp_block",title:o,content:r},null,2);!function(e,t,n){const o=new window.Blob([t],{type:n});if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(o,e);else{const t=document.createElement("a");t.href=URL.createObjectURL(o),t.download=e,t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t)}}(Object(s.kebabCase)(o)+".json",i,"application/json")},c=n("@wordpress/components"),d=n("@wordpress/compose");var u=async function(e){const t=await function(e){const t=new window.FileReader;return new Promise(n=>{t.onload=()=>{n(t.result)},t.readAsText(e)})}(e);let n;try{n=JSON.parse(t)}catch(e){throw new Error("Invalid JSON file")}if(!("wp_block"===n.__file&&n.title&&n.content&&Object(s.isString)(n.title)&&Object(s.isString)(n.content)))throw new Error("Invalid Reusable block JSON file");const o=await l()({path:"/wp/v2/types/wp_block"});return await l()({path:"/wp/v2/"+o.rest_base,data:{title:n.title,content:n.content,status:"publish"},method:"POST"})};class p extends o.Component{constructor(){super(...arguments),this.state={isLoading:!1,error:null,file:null},this.isStillMounted=!0,this.onChangeFile=this.onChangeFile.bind(this),this.onSubmit=this.onSubmit.bind(this)}componentWillUnmount(){this.isStillMounted=!1}onChangeFile(e){this.setState({file:e.target.files[0],error:null})}onSubmit(e){e.preventDefault();const{file:t}=this.state,{onUpload:n}=this.props;t&&(this.setState({isLoading:!0}),u(t).then(e=>{this.isStillMounted&&(this.setState({isLoading:!1}),n(e))}).catch(e=>{if(!this.isStillMounted)return;let t;switch(e.message){case"Invalid JSON file":t=Object(r.__)("Invalid JSON file");break;case"Invalid Reusable block JSON file":t=Object(r.__)("Invalid Reusable block JSON file");break;default:t=Object(r.__)("Unknown error")}this.setState({isLoading:!1,error:t})}))}onDismissError(){this.setState({error:null})}render(){const{instanceId:e}=this.props,{file:t,isLoading:n,error:s}=this.state,i="list-reusable-blocks-import-form-"+e;return Object(o.createElement)("form",{className:"list-reusable-blocks-import-form",onSubmit:this.onSubmit},s&&Object(o.createElement)(c.Notice,{status:"error",onRemove:()=>this.onDismissError()},s),Object(o.createElement)("label",{htmlFor:i,className:"list-reusable-blocks-import-form__label"},Object(r.__)("File")),Object(o.createElement)("input",{id:i,type:"file",onChange:this.onChangeFile}),Object(o.createElement)(c.Button,{type:"submit",isBusy:n,disabled:!t||n,isSecondary:!0,className:"list-reusable-blocks-import-form__button"},Object(r._x)("Import","button label")))}}var b=Object(d.withInstanceId)(p);var m=function({onUpload:e}){return Object(o.createElement)(c.Dropdown,{position:"bottom right",contentClassName:"list-reusable-blocks-import-dropdown__content",renderToggle:({isOpen:e,onToggle:t})=>Object(o.createElement)(c.Button,{"aria-expanded":e,onClick:t,isPrimary:!0},Object(r.__)("Import from JSON")),renderContent:({onClose:t})=>Object(o.createElement)(b,{onUpload:Object(s.flow)(t,e)})})};document.body.addEventListener("click",e=>{e.target.classList.contains("wp-list-reusable-blocks__export")&&(e.preventDefault(),a(e.target.dataset.id))}),document.addEventListener("DOMContentLoaded",()=>{const e=document.querySelector(".page-title-action");if(!e)return;const t=document.createElement("div");t.className="list-reusable-blocks__container",e.parentNode.insertBefore(t,e),Object(o.render)(Object(o.createElement)(m,{onUpload:()=>{const e=document.createElement("div");e.className="notice notice-success is-dismissible",e.innerHTML=`<p>${Object(r.__)("Reusable block imported successfully!")}</p>`;const t=document.querySelector(".wp-header-end");t&&t.parentNode.insertBefore(e,t)}}),t)})},"@wordpress/api-fetch":function(e,t){e.exports=window.wp.apiFetch},"@wordpress/components":function(e,t){e.exports=window.wp.components},"@wordpress/compose":function(e,t){e.exports=window.wp.compose},"@wordpress/element":function(e,t){e.exports=window.wp.element},"@wordpress/i18n":function(e,t){e.exports=window.wp.i18n},lodash:function(e,t){e.exports=window.lodash}});