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

1 line
6.8 KiB
JavaScript

this.wp=this.wp||{},this.wp.apiFetch=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=316)}({1:function(e,t){!function(){e.exports=this.wp.i18n}()},15:function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,"a",function(){return n})},21:function(e,t,r){"use strict";function n(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}r.d(t,"a",function(){return n})},23:function(e,t){!function(){e.exports=this.wp.hooks}()},24:function(e,t){!function(){e.exports=this.wp.url}()},316:function(e,t,r){"use strict";r.r(t);var n=r(8),o=r(21),a=r(1),u=r(23),c=function(e){var t=e;return Object(u.addAction)("heartbeat.tick","core/api-fetch/create-nonce-middleware",function(e){e["rest-nonce"]&&(t=e["rest-nonce"])}),function(e,r){var o=e.headers||{},a=!0;for(var u in o)if(o.hasOwnProperty(u)&&"x-wp-nonce"===u.toLowerCase()){a=!1;break}return a&&(o=Object(n.a)({},o,{"X-WP-Nonce":t})),r(Object(n.a)({},e,{headers:o}))}},i=function(e,t){var r,o,a=e.path;return"string"==typeof e.namespace&&"string"==typeof e.endpoint&&(r=e.namespace.replace(/^\/|\/$/g,""),a=(o=e.endpoint.replace(/^\//,""))?r+"/"+o:r),delete e.namespace,delete e.endpoint,t(Object(n.a)({},e,{path:a}))},s=function(e){return function(t,r){return i(t,function(t){var o,a=t.url,u=t.path;return"string"==typeof u&&(o=e,-1!==e.indexOf("?")&&(u=u.replace("?","&")),u=u.replace(/^\//,""),"string"==typeof o&&-1!==o.indexOf("?")&&(u=u.replace("?","&")),a=o+u),r(Object(n.a)({},t,{url:a}))})}},f=function(e){return function(t,r){var n=t.parse,o=void 0===n||n;if("string"==typeof t.path){var a=t.method||"GET",u=function(e){var t=e.split("?"),r=t[1],n=t[0];return r?n+"?"+r.split("&").map(function(e){return e.split("=")}).sort(function(e,t){return e[0].localeCompare(t[0])}).map(function(e){return e.join("=")}).join("&"):n}(t.path);if(o&&"GET"===a&&e[u])return Promise.resolve(e[u].body);if("OPTIONS"===a&&e[a][u])return Promise.resolve(e[a][u])}return r(t)}},p=r(38),l=r(24),d=function(e,t){var r=e.path,a=e.url,u=Object(o.a)(e,["path","url"]);return Object(n.a)({},u,{url:a&&Object(l.addQueryArgs)(a,t),path:r&&Object(l.addQueryArgs)(r,t)})},b=function(e){return e.json?e.json():Promise.reject(e)},h=function(e){return function(e){if(!e)return{};var t=e.match(/<([^>]+)>; rel="next"/);return t?{next:t[1]}:{}}(e.headers.get("link")).next},O=function(e){var t=e.path&&-1!==e.path.indexOf("per_page=-1"),r=e.url&&-1!==e.url.indexOf("per_page=-1");return t||r},j=function(){var e=Object(p.a)(regeneratorRuntime.mark(function e(t,r){var o,a,u,c,i,s;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!1!==t.parse){e.next=2;break}return e.abrupt("return",r(t));case 2:if(O(t)){e.next=4;break}return e.abrupt("return",r(t));case 4:return e.next=6,r(Object(n.a)({},d(t,{per_page:100}),{parse:!1}));case 6:return o=e.sent,e.next=9,b(o);case 9:if(a=e.sent,Array.isArray(a)){e.next=12;break}return e.abrupt("return",a);case 12:if(u=h(o)){e.next=15;break}return e.abrupt("return",a);case 15:c=[].concat(a);case 16:if(!u){e.next=27;break}return e.next=19,r(Object(n.a)({},t,{path:void 0,url:u,parse:!1}));case 19:return i=e.sent,e.next=22,b(i);case 22:s=e.sent,c=c.concat(s),u=h(i),e.next=16;break;case 27:return e.abrupt("return",c);case 28:case"end":return e.stop()}},e,this)}));return function(t,r){return e.apply(this,arguments)}}(),v=new Set(["PATCH","PUT","DELETE"]),y="GET";var g=function(e,t){var r=e.method,o=void 0===r?y:r;return v.has(o.toUpperCase())&&(e=Object(n.a)({},e,{headers:Object(n.a)({},e.headers,{"X-HTTP-Method-Override":o,"Content-Type":"application/json"}),method:"POST"})),t(e,t)};var m=function(e,t){return"string"!=typeof e.url||Object(l.hasQueryArg)(e.url,"_locale")||(e.url=Object(l.addQueryArgs)(e.url,{_locale:"user"})),"string"!=typeof e.path||Object(l.hasQueryArg)(e.path,"_locale")||(e.path=Object(l.addQueryArgs)(e.path,{_locale:"user"})),t(e,t)},w={Accept:"application/json, */*;q=0.1"},x={credentials:"include"},P=[];function _(e){var t=[function(e){var t=e.url,r=e.path,u=e.data,c=e.parse,i=void 0===c||c,s=Object(o.a)(e,["url","path","data","parse"]),f=e.body,p=e.headers;p=Object(n.a)({},w,p),u&&(f=JSON.stringify(u),p["Content-Type"]="application/json");return window.fetch(t||r,Object(n.a)({},x,s,{body:f,headers:p})).then(function(e){if(e.status>=200&&e.status<300)return e;throw e}).then(function(e){return i?204===e.status?null:e.json?e.json():Promise.reject(e):e}).catch(function(e){if(!i)throw e;var t={code:"invalid_json",message:Object(a.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch(function(){throw t}).then(function(e){var t={code:"unknown_error",message:Object(a.__)("An unknown error occurred.")};throw e||t})})},j,g,i,m].concat(P).reverse();return function e(r){return function(n){return(0,t[r])(n,e(r+1))}}(0)(e)}_.use=function(e){P.push(e)},_.createNonceMiddleware=c,_.createPreloadingMiddleware=f,_.createRootURLMiddleware=s,_.fetchAllMiddleware=j;t.default=_},38:function(e,t,r){"use strict";function n(e,t,r,n,o,a,u){try{var c=e[a](u),i=c.value}catch(e){return void r(e)}c.done?t(i):Promise.resolve(i).then(n,o)}function o(e){return function(){var t=this,r=arguments;return new Promise(function(o,a){var u=e.apply(t,r);function c(e){n(u,o,a,c,i,"next",e)}function i(e){n(u,o,a,c,i,"throw",e)}c(void 0)})}}r.d(t,"a",function(){return o})},8:function(e,t,r){"use strict";r.d(t,"a",function(){return o});var n=r(15);function o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),o.forEach(function(t){Object(n.a)(e,t,r[t])})}return e}}}).default;