2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
/*! This file is auto-generated */
|
|
this.wp=this.wp||{},this.wp.listReusableBlocks=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},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/@babel/runtime/helpers/esm/assertThisInitialized.js":function(e,t,n){"use strict";function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}n.d(t,"a",(function(){return r}))},"./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js":function(e,t,n){"use strict";function r(e,t,n,r,o,s,i){try{var a=e[s](i),c=a.value}catch(e){return void n(e)}a.done?t(c):Promise.resolve(c).then(r,o)}function o(e){return function(){var t=this,n=arguments;return new Promise((function(o,s){var i=e.apply(t,n);function a(e){r(i,o,s,a,c,"next",e)}function c(e){r(i,o,s,a,c,"throw",e)}a(void 0)}))}}n.d(t,"a",(function(){return o}))},"./node_modules/@babel/runtime/helpers/esm/classCallCheck.js":function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,"a",(function(){return r}))},"./node_modules/@babel/runtime/helpers/esm/createClass.js":function(e,t,n){"use strict";function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}n.d(t,"a",(function(){return o}))},"./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js":function(e,t,n){"use strict";function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}n.d(t,"a",(function(){return r}))},"./node_modules/@babel/runtime/helpers/esm/inherits.js":function(e,t,n){"use strict";n.d(t,"a",(function(){return o}));var r=n("./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js");function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&Object(r.a)(e,t)}},"./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js":function(e,t,n){"use strict";n.d(t,"a",(function(){return s}));var r=n("./node_modules/@babel/runtime/helpers/esm/typeof.js"),o=n("./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js");function s(e,t){return!t||"object"!==Object(r.a)(t)&&"function"!=typeof t?Object(o.a)(e):t}},"./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js":function(e,t,n){"use strict";function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}n.d(t,"a",(function(){return r}))},"./node_modules/@babel/runtime/helpers/esm/typeof.js":function(e,t,n){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}n.d(t,"a",(function(){return r}))},"./node_modules/@wordpress/list-reusable-blocks/build-module/index.js":function(e,t,n){"use strict";n.r(t);var r=n("@wordpress/element"),o=n("@wordpress/i18n"),s=n("@babel/runtime/regenerator"),i=n.n(s),a=n("./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js"),c=n("lodash"),u=n("@wordpress/api-fetch"),l=n.n(u);function p(e,t,n){var r=new window.Blob([t],{type:n});if(window.navigator.msSaveOrOpenBlob)window.navigator.msSaveOrOpenBlob(r,e);else{var o=document.createElement("a");o.href=URL.createObjectURL(r),o.download=e,o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o)}}function d(e){var t=new window.FileReader;return new Promise((function(n){t.onload=function(){n(t.result)},t.readAsText(e)}))}function f(){return(f=Object(a.a)(i.a.mark((function e(t){var n,r,o,s,a;return i.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,l()({path:"/wp/v2/types/wp_block"});case 2:return n=e.sent,e.next=5,l()({path:"/wp/v2/".concat(n.rest_base,"/").concat(t,"?context=edit")});case 5:r=e.sent,o=r.title.raw,s=r.content.raw,a=JSON.stringify({__file:"wp_block",title:o,content:s},null,2),p(Object(c.kebabCase)(o)+".json",a,"application/json");case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var b=function(e){return f.apply(this,arguments)},m=n("@wordpress/components"),h=n("./node_modules/@babel/runtime/helpers/esm/classCallCheck.js"),w=n("./node_modules/@babel/runtime/helpers/esm/createClass.js"),y=n("./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js"),v=n("./node_modules/@babel/runtime/helpers/esm/inherits.js"),j=n("./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js"),O=n("./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js"),_=n("@wordpress/compose");function S(){return(S=Object(a.a)(i.a.mark((function e(t){var n,r,o,s;return i.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,d(t);case 2:n=e.sent,e.prev=3,r=JSON.parse(n),e.next=10;break;case 7:throw e.prev=7,e.t0=e.catch(3),new Error("Invalid JSON file");case 10:if("wp_block"===r.__file&&r.title&&r.content&&Object(c.isString)(r.title)&&Object(c.isString)(r.content)){e.next=12;break}throw new Error("Invalid Reusable Block JSON file");case 12:return e.next=14,l()({path:"/wp/v2/types/wp_block"});case 14:return o=e.sent,e.next=17,l()({path:"/wp/v2/".concat(o.rest_base),data:{title:r.title,content:r.content,status:"publish"},method:"POST"});case 17:return s=e.sent,e.abrupt("return",s);case 19:case"end":return e.stop()}}),e,null,[[3,7]])})))).apply(this,arguments)}var g=function(e){return S.apply(this,arguments)};function k(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=Object(O.a)(e);if(t){var o=Object(O.a)(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return Object(j.a)(this,n)}}var x=function(e){Object(v.a)(n,e);var t=k(n);function n(){var e;return Object(h.a)(this,n),(e=t.apply(this,arguments)).state={isLoading:!1,error:null,file:null},e.isStillMounted=!0,e.onChangeFile=e.onChangeFile.bind(Object(y.a)(e)),e.onSubmit=e.onSubmit.bind(Object(y.a)(e)),e}return Object(w.a)(n,[{key:"componentWillUnmount",value:function(){this.isStillMounted=!1}},{key:"onChangeFile",value:function(e){this.setState({file:e.target.files[0],error:null})}},{key:"onSubmit",value:function(e){var t=this;e.preventDefault();var n=this.state.file,r=this.props.onUpload;n&&(this.setState({isLoading:!0}),g(n).then((function(e){t.isStillMounted&&(t.setState({isLoading:!1}),r(e))})).catch((function(e){if(t.isStillMounted){var n;switch(e.message){case"Invalid JSON file":n=Object(o.__)("Invalid JSON file");break;case"Invalid Reusable Block JSON file":n=Object(o.__)("Invalid Reusable Block JSON file");break;default:n=Object(o.__)("Unknown error")}t.setState({isLoading:!1,error:n})}})))}},{key:"onDismissError",value:function(){this.setState({error:null})}},{key:"render",value:function(){var e=this,t=this.props.instanceId,n=this.state,s=n.file,i=n.isLoading,a=n.error,c="list-reusable-blocks-import-form-"+t;return Object(r.createElement)("form",{className:"list-reusable-blocks-import-form",onSubmit:this.onSubmit},a&&Object(r.createElement)(m.Notice,{status:"error",onRemove:function(){return e.onDismissError()}},a),Object(r.createElement)("label",{htmlFor:c,className:"list-reusable-blocks-import-form__label"},Object(o.__)("File")),Object(r.createElement)("input",{id:c,type:"file",onChange:this.onChangeFile}),Object(r.createElement)(m.Button,{type:"submit",isBusy:i,disabled:!s||i,isSecondary:!0,className:"list-reusable-blocks-import-form__button"},Object(o._x)("Import","button label")))}}]),n}(r.Component),C=Object(_.withInstanceId)(x);var E=function(e){var t=e.onUpload;return Object(r.createElement)(m.Dropdown,{position:"bottom right",contentClassName:"list-reusable-blocks-import-dropdown__content",renderToggle:function(e){var t=e.isOpen,n=e.onToggle;return Object(r.createElement)(m.Button,{"aria-expanded":t,onClick:n,isPrimary:!0},Object(o.__)("Import from JSON"))},renderContent:function(e){var n=e.onClose;return Object(r.createElement)(C,{onUpload:Object(c.flow)(n,t)})}})};document.body.addEventListener("click",(function(e){e.target.classList.contains("wp-list-reusable-blocks__export")&&(e.preventDefault(),b(e.target.dataset.id))})),document.addEventListener("DOMContentLoaded",(function(){var e=document.querySelector(".page-title-action");if(e){var t=document.createElement("div");t.className="list-reusable-blocks__container",e.parentNode.insertBefore(t,e),Object(r.render)(Object(r.createElement)(E,{onUpload:function(){var e=document.createElement("div");e.className="notice notice-success is-dismissible",e.innerHTML="<p>".concat(Object(o.__)("Reusable block imported successfully!"),"</p>");var t=document.querySelector(".wp-header-end");t&&t.parentNode.insertBefore(e,t)}}),t)}}))},"@babel/runtime/regenerator":function(e,t){e.exports=window.regeneratorRuntime},"@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}}); |