WordPress/wp-includes/js/dist/list-reusable-blocks.min.js

2 lines
5.0 KiB
JavaScript
Raw Normal View History

/*! This file is auto-generated */
!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t);var n=window.wp.element,o=window.wp.i18n;var r=function(){return r=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},r.apply(this,arguments)};Object.create;Object.create;"function"==typeof SuppressedError&&SuppressedError;function a(e){return e.toLowerCase()}var i=[/([a-z0-9])([A-Z])/g,/([A-Z])([A-Z][a-z])/g],s=/[^A-Z0-9]+/gi;function l(e,t,n){return t instanceof RegExp?e.replace(t,n):t.reduce((function(e,t){return e.replace(t,n)}),e)}function c(e,t){return void 0===t&&(t={}),function(e,t){void 0===t&&(t={});for(var n=t.splitRegexp,o=void 0===n?i:n,r=t.stripRegexp,c=void 0===r?s:r,p=t.transform,u=void 0===p?a:p,d=t.delimiter,f=void 0===d?" ":d,m=l(l(e,o,"$1\0$2"),c,"\0"),w=0,b=m.length;"\0"===m.charAt(w);)w++;for(;"\0"===m.charAt(b-1);)b--;return m.slice(w,b).split("\0").map(u).join(f)}(e,r({delimiter:"."},t))}var p=window.wp.apiFetch,u=e.n(p);var d=async function(e){const t=await u()({path:"/wp/v2/types/wp_block"}),n=await u()({path:`/wp/v2/${t.rest_base}/${e}?context=edit`}),o=n.title.raw,a=n.content.raw,i=n.wp_pattern_sync_status,s=JSON.stringify({__file:"wp_block",title:o,content:a,syncStatus:i},null,2);var l;!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)}}((void 0===l&&(l={}),c(o,r({delimiter:"-"},l))+".json"),s,"application/json")},f=window.wp.compose,m=window.wp.components;var w=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||"string"!=typeof n.title||"string"!=typeof n.content||n.syncStatus&&"string"!=typeof n.syncStatus)throw new Error("Invalid pattern JSON file");const o=await u()({path:"/wp/v2/types/wp_block"});return await u()({path:`/wp/v2/${o.rest_base}`,data:{title:n.title,content:n.content,status:"publish",meta:"unsynced"===n.syncStatus?{wp_pattern_sync_status:n.syncStatus}:void 0},method:"POST"})};var b=(0,f.withInstanceId)((function({instanceId:e,onUpload:t}){const r="list-reusable-blocks-import-form-"+e,a=(0,n.useRef)(),[i,s]=(0,n.useState)(!1),[l,c]=(0,n.useState)(null),[p,u]=(0,n.useState)(null);return(0,n.createElement)("form",{className:"list-reusable-blocks-import-form",onSubmit:e=>{e.preventDefault(),p&&(s({isLoading:!0}),w(p).then((e=>{a&&(s(!1),t(e))})).catch((e=>{if(!a)return;let t;switch(e.message){case"Invalid JSON file":t=(0,o.__)("Invalid JSON file");break;case"Invalid pattern JSON file":t=(0,o.__)("Invalid pattern JSON file");break;default:t=(0,o.__)("Unknown error")}s(!1),c(t)})))},ref:a},l&&(0,n.createElement)(m.Notice,{status:"error",onRemove:()=>{c(null)}},l),(0,n.createElement)("label",{htmlFor:r,className:"list-reusable-blocks-import-form__label"},(0,o.__)("File")),(0,n.createElement)("input",{id:r,type:"file",onChange:e=>{u(e.target.files[0]),c(null)}}),(0,n.createElement)(m.Button,{type:"submit",isBusy:i,disabled:!p||i,variant:"secondary",className:"list-reusable-blocks-import-form__button"},(0,o._x)("Import","button label")))}));var v=function({onUpload:e}){return(0,n.createElement)(m.Dropdown,{popoverProps:{placement:"bottom-start"},contentClassName:"list-reusable-blocks-import-dropdown__content",renderToggle:(