WordPress/wp-includes/js/dist/api-fetch.min.js

2 lines
13 KiB
JavaScript

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.apiFetch=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s="./node_modules/@wordpress/api-fetch/build-module/index.js")}({"./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js":function(e,r,t){"use strict";function n(e,r,t,n,o,c,i){try{var u=e[c](i),a=u.value}catch(e){return void t(e)}u.done?r(a):Promise.resolve(a).then(n,o)}function o(e){return function(){var r=this,t=arguments;return new Promise((function(o,c){var i=e.apply(r,t);function u(e){n(i,o,c,u,a,"next",e)}function a(e){n(i,o,c,u,a,"throw",e)}u(void 0)}))}}t.d(r,"a",(function(){return o}))},"./node_modules/@babel/runtime/helpers/esm/defineProperty.js":function(e,r,t){"use strict";function n(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}t.d(r,"a",(function(){return n}))},"./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js":function(e,r,t){"use strict";t.d(r,"a",(function(){return o}));var n=t("./node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js");function o(e,r){if(null==e)return{};var t,o,c=Object(n.a)(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)t=i[o],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(c[t]=e[t])}return c}},"./node_modules/@babel/runtime/helpers/esm/objectWithoutPropertiesLoose.js":function(e,r,t){"use strict";function n(e,r){if(null==e)return{};var t,n,o={},c=Object.keys(e);for(n=0;n<c.length;n++)t=c[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}t.d(r,"a",(function(){return n}))},"./node_modules/@wordpress/api-fetch/build-module/index.js":function(e,r,t){"use strict";t.r(r);var n=t("./node_modules/@babel/runtime/helpers/esm/defineProperty.js"),o=t("./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js"),c=t("@wordpress/i18n");function i(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function u(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?i(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):i(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var a=function(e){function r(e,t){var n=e.headers,o=void 0===n?{}:n;for(var c in o)if("x-wp-nonce"===c.toLowerCase()&&o[c]===r.nonce)return t(e);return t(u(u({},e),{},{headers:u(u({},o),{},{"X-WP-Nonce":r.nonce})}))}return r.nonce=e,r};function s(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function p(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?s(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):s(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var f=function(e,r){var t,n,o=e.path;return"string"==typeof e.namespace&&"string"==typeof e.endpoint&&(t=e.namespace.replace(/^\/|\/$/g,""),o=(n=e.endpoint.replace(/^\//,""))?t+"/"+n:t),delete e.namespace,delete e.endpoint,r(p(p({},e),{},{path:o}))};function l(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function b(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?l(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):l(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var d=function(e){return function(r,t){return f(r,(function(r){var n,o=r.url,c=r.path;return"string"==typeof c&&(n=e,-1!==e.indexOf("?")&&(c=c.replace("?","&")),c=c.replace(/^\//,""),"string"==typeof n&&-1!==n.indexOf("?")&&(c=c.replace("?","&")),o=n+c),t(b(b({},r),{},{url:o}))}))}};function O(e){var r=e.split("?"),t=r[1],n=r[0];return t?n+"?"+t.split("&").map((function(e){return e.split("=")})).sort((function(e,r){return e[0].localeCompare(r[0])})).map((function(e){return e.join("=")})).join("&"):n}var j=function(e){var r=Object.keys(e).reduce((function(r,t){return r[O(t)]=e[t],r}),{});return function(e,t){var n=e.parse,o=void 0===n||n;if("string"==typeof e.path){var c=e.method||"GET",i=O(e.path);if("GET"===c&&r[i]){var u=r[i];return delete r[i],Promise.resolve(o?u.body:new window.Response(JSON.stringify(u.body),{status:200,statusText:"OK",headers:u.headers}))}if("OPTIONS"===c&&r[c]&&r[c][i])return Promise.resolve(r[c][i])}return t(e)}},h=t("@babel/runtime/regenerator"),y=t.n(h),v=t("./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js"),m=t("@wordpress/url");function g(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function w(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?g(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):g(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var P=function(e){return e.json?e.json():Promise.reject(e)},_=function(e){return function(e){if(!e)return{};var r=e.match(/<([^>]+)>; rel="next"/);return r?{next:r[1]}:{}}(e.headers.get("link")).next},x=function(e){var r=e.path&&-1!==e.path.indexOf("per_page=-1"),t=e.url&&-1!==e.url.indexOf("per_page=-1");return r||t},D=function(){var e=Object(v.a)(y.a.mark((function e(r,t){var n,c,i,u,a,s;return y.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!1!==r.parse){e.next=2;break}return e.abrupt("return",t(r));case 2:if(x(r)){e.next=4;break}return e.abrupt("return",t(r));case 4:return e.next=6,X(w(w({},(f={per_page:100},l=void 0,b=void 0,l=(p=r).path,b=p.url,w(w({},Object(o.a)(p,["path","url"])),{},{url:b&&Object(m.addQueryArgs)(b,f),path:l&&Object(m.addQueryArgs)(l,f)}))),{},{parse:!1}));case 6:return n=e.sent,e.next=9,P(n);case 9:if(c=e.sent,Array.isArray(c)){e.next=12;break}return e.abrupt("return",c);case 12:if(i=_(n)){e.next=15;break}return e.abrupt("return",c);case 15:u=[].concat(c);case 16:if(!i){e.next=27;break}return e.next=19,X(w(w({},r),{},{path:void 0,url:i,parse:!1}));case 19:return a=e.sent,e.next=22,P(a);case 22:s=e.sent,u=u.concat(s),i=_(a),e.next=16;break;case 27:return e.abrupt("return",u);case 28:case"end":return e.stop()}var p,f,l,b}),e)})));return function(r,t){return e.apply(this,arguments)}}();function S(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function E(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?S(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):S(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var k=new Set(["PATCH","PUT","DELETE"]);var T=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return r?204===e.status?null:e.json?e.json():Promise.reject(e):e},A=function(e){var r={code:"invalid_json",message:Object(c.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw r;return e.json().catch((function(){throw r}))},M=function(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Promise.resolve(T(e,r)).catch((function(e){return C(e,r)}))};function C(e){var r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!r)throw e;return A(e).then((function(e){var r={code:"unknown_error",message:Object(c.__)("An unknown error occurred.")};throw e||r}))}function L(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function N(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?L(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):L(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var Q=function(e,r){if(!(e.path&&-1!==e.path.indexOf("/wp/v2/media")||e.url&&-1!==e.url.indexOf("/wp/v2/media")))return r(e,r);var t=0;return r(N(N({},e),{},{parse:!1})).catch((function(n){var o=n.headers.get("x-wp-upload-attachment-id");return n.status>=500&&n.status<600&&o?function e(n){return t++,r({path:"/wp/v2/media/".concat(n,"/post-process"),method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch((function(){return t<5?e(n):(r({path:"/wp/v2/media/".concat(n,"?force=true"),method:"DELETE"}),Promise.reject())}))}(o).catch((function(){return!1!==e.parse?Promise.reject({code:"post_process",message:Object(c.__)("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(n)})):C(n,e.parse)})).then((function(r){return M(r,e.parse)}))};function G(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function R(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?G(Object(t),!0).forEach((function(r){Object(n.a)(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):G(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var W={Accept:"application/json, */*;q=0.1"},U={credentials:"include"},H=[function(e,r){return"string"!=typeof e.url||Object(m.hasQueryArg)(e.url,"_locale")||(e.url=Object(m.addQueryArgs)(e.url,{_locale:"user"})),"string"!=typeof e.path||Object(m.hasQueryArg)(e.path,"_locale")||(e.path=Object(m.addQueryArgs)(e.path,{_locale:"user"})),r(e)},f,function(e,r){var t=e.method,n=void 0===t?"GET":t;return k.has(n.toUpperCase())&&(e=E(E({},e),{},{headers:E(E({},e.headers),{},{"X-HTTP-Method-Override":n,"Content-Type":"application/json"}),method:"POST"})),r(e)},D];var I=function(e){if(e.status>=200&&e.status<300)return e;throw e},J=function(e){var r=e.url,t=e.path,n=e.data,i=e.parse,u=void 0===i||i,a=Object(o.a)(e,["url","path","data","parse"]),s=e.body,p=e.headers;return p=R(R({},W),p),n&&(s=JSON.stringify(n),p["Content-Type"]="application/json"),window.fetch(r||t,R(R(R({},U),a),{},{body:s,headers:p})).then((function(e){return Promise.resolve(e).then(I).catch((function(e){return C(e,u)})).then((function(e){return M(e,u)}))}),(function(){throw{code:"fetch_error",message:Object(c.__)("You are probably offline.")}}))};function F(e){return H.reduceRight((function(e,r){return function(t){return r(t,e)}}),J)(e).catch((function(r){return"rest_cookie_invalid_nonce"!==r.code?Promise.reject(r):window.fetch(F.nonceEndpoint).then(I).then((function(e){return e.text()})).then((function(r){return F.nonceMiddleware.nonce=r,F(e)}))}))}F.use=function(e){H.unshift(e)},F.setFetchHandler=function(e){J=e},F.createNonceMiddleware=a,F.createPreloadingMiddleware=j,F.createRootURLMiddleware=d,F.fetchAllMiddleware=D,F.mediaUploadMiddleware=Q;var X=r.default=F},"@babel/runtime/regenerator":function(e,r){e.exports=window.regeneratorRuntime},"@wordpress/i18n":function(e,r){e.exports=window.wp.i18n},"@wordpress/url":function(e,r){e.exports=window.wp.url}}).default;