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

1 line
5.3 KiB
JavaScript

this.wp=this.wp||{},this.wp.apiFetch=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=377)}({16:function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,"a",function(){return r})},2:function(e,t){!function(){e.exports=this.wp.i18n}()},22:function(e,t,n){"use strict";function r(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}n.d(t,"a",function(){return r})},25:function(e,t){!function(){e.exports=this.wp.hooks}()},37:function(e,t,n){"use strict";function r(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){return void n(e)}c.done?t(a):Promise.resolve(a).then(r,o)}function o(e){return function(){var t=this,n=arguments;return new Promise(function(o,i){var u=e.apply(t,n);function c(e){r(u,o,i,c,a,"next",e)}function a(e){r(u,o,i,c,a,"throw",e)}c(void 0)})}}n.d(t,"a",function(){return o})},377:function(e,t,n){"use strict";n.r(t);var r=n(37),o=n(9),i=n(22),u=n(2),c=n(25),a=function(e){return function(t,n){var r=e;Object(c.addAction)("heartbeat.tick","core/api-fetch/create-nonce-middleware",function(e){e["rest-nonce"]&&(r=e["rest-nonce"])});var i=t.headers||{},u=!0;for(var a in i)if(i.hasOwnProperty(a)&&"x-wp-nonce"===a.toLowerCase()){u=!1;break}return u&&(i=Object(o.a)({},i,{"X-WP-Nonce":r})),n(Object(o.a)({},t,{headers:i}))}},f=function(e,t){var n,r,i=e.path;return"string"==typeof e.namespace&&"string"==typeof e.endpoint&&(n=e.namespace.replace(/^\/|\/$/g,""),i=(r=e.endpoint.replace(/^\//,""))?n+"/"+r:n),delete e.namespace,delete e.endpoint,t(Object(o.a)({},e,{path:i}))},s=function(e){return function(t,n){return f(t,function(t){var r,i=t.url,u=t.path;return"string"==typeof u&&(r=e,-1!==e.indexOf("?")&&(u=u.replace("?","&")),u=u.replace(/^\//,""),"string"==typeof r&&-1!==r.indexOf("?")&&(u=u.replace("?","&")),i=r+u),n(Object(o.a)({},t,{url:i}))})}},p=function(e){return function(t,n){var r=t.parse,o=void 0===r||r;if("string"==typeof t.path&&o){var i=t.method||"GET",u=function(e){var t=e.split("?"),n=t[1],r=t[0];return n?r+"?"+n.split("&").map(function(e){return e.split("=")}).sort(function(e,t){return e[0].localeCompare(t[0])}).map(function(e){return e.join("=")}).join("&"):r}(t.path);if("GET"===i&&e[u])return Promise.resolve(e[u].body)}return n(t)}};var l=function(e,t){var n=Object(o.a)({},e);return n.method&&["PATCH","PUT","DELETE"].indexOf(n.method.toUpperCase())>=0&&(n.headers||(n.headers={}),n.headers["X-HTTP-Method-Override"]=n.method,n.headers["Content-Type"]="application/json",n.method="POST"),t(n,t)},d=[];function h(e){if("string"==typeof e&&e.indexOf("Cloudflare Ray ID")>=0)throw{code:"cloudflare_error"}}function b(e){var t=[function(e){var t=e.url,n=e.path,c=e.body,a=e.data,f=e.parse,s=void 0===f||f,p=Object(i.a)(e,["url","path","body","data","parse"]),l=p.headers||{};!l["Content-Type"]&&a&&(l["Content-Type"]="application/json");return window.fetch(t||n,Object(o.a)({},p,{credentials:"include",body:c||JSON.stringify(a),headers:l})).then(function(e){if(e.status>=200&&e.status<300)return e;throw e}).then(function(e){return s?e.json?e.json():Promise.reject(e):e}).catch(function(e){if(!s)throw e;var t={code:"invalid_json",message:Object(u.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw t;var n=e.clone();return e.json().catch(Object(r.a)(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.text();case 2:throw h(e.sent),t;case 5:case"end":return e.stop()}},e,this)}))).then(function(e){var t={code:"unknown_error",message:Object(u.__)("An unknown error occurred.")};throw h(e),e||t})})},l,f].concat(d);return function e(n){return t.pop()(n,e)}(e)}b.use=function(e){d.push(e)},b.createNonceMiddleware=a,b.createPreloadingMiddleware=p,b.createRootURLMiddleware=s;t.default=b},9:function(e,t,n){"use strict";n.d(t,"a",function(){return o});var r=n(16);function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(t){Object(r.a)(e,t,n[t])})}return e}}}).default;