[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> api-fetch.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["apiFetch"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  26  /******/         // Return the exports of the module
  27  /******/         return module.exports;
  28  /******/     }
  29  /******/
  30  /******/
  31  /******/     // expose the modules object (__webpack_modules__)
  32  /******/     __webpack_require__.m = modules;
  33  /******/
  34  /******/     // expose the module cache
  35  /******/     __webpack_require__.c = installedModules;
  36  /******/
  37  /******/     // define getter function for harmony exports
  38  /******/     __webpack_require__.d = function(exports, name, getter) {
  39  /******/         if(!__webpack_require__.o(exports, name)) {
  40  /******/             Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41  /******/         }
  42  /******/     };
  43  /******/
  44  /******/     // define __esModule on exports
  45  /******/     __webpack_require__.r = function(exports) {
  46  /******/         if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47  /******/             Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48  /******/         }
  49  /******/         Object.defineProperty(exports, '__esModule', { value: true });
  50  /******/     };
  51  /******/
  52  /******/     // create a fake namespace object
  53  /******/     // mode & 1: value is a module id, require it
  54  /******/     // mode & 2: merge all properties of value into the ns
  55  /******/     // mode & 4: return value when already ns object
  56  /******/     // mode & 8|1: behave like require
  57  /******/     __webpack_require__.t = function(value, mode) {
  58  /******/         if(mode & 1) value = __webpack_require__(value);
  59  /******/         if(mode & 8) return value;
  60  /******/         if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61  /******/         var ns = Object.create(null);
  62  /******/         __webpack_require__.r(ns);
  63  /******/         Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64  /******/         if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65  /******/         return ns;
  66  /******/     };
  67  /******/
  68  /******/     // getDefaultExport function for compatibility with non-harmony modules
  69  /******/     __webpack_require__.n = function(module) {
  70  /******/         var getter = module && module.__esModule ?
  71  /******/ 			function getDefault() { return module['default']; } :
  72  /******/ 			function getModuleExports() { return module; };
  73  /******/         __webpack_require__.d(getter, 'a', getter);
  74  /******/         return getter;
  75  /******/     };
  76  /******/
  77  /******/     // Object.prototype.hasOwnProperty.call
  78  /******/     __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79  /******/
  80  /******/     // __webpack_public_path__
  81  /******/     __webpack_require__.p = "";
  82  /******/
  83  /******/
  84  /******/     // Load entry module and return exports
  85  /******/     return __webpack_require__(__webpack_require__.s = 470);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 1:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = window["wp"]["i18n"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 13:
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutProperties; });
 102  /* harmony import */ var _babel_runtime_helpers_esm_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(44);
 103  
 104  function _objectWithoutProperties(source, excluded) {
 105    if (source == null) return {};
 106    var target = Object(_babel_runtime_helpers_esm_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(source, excluded);
 107    var key, i;
 108  
 109    if (Object.getOwnPropertySymbols) {
 110      var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
 111  
 112      for (i = 0; i < sourceSymbolKeys.length; i++) {
 113        key = sourceSymbolKeys[i];
 114        if (excluded.indexOf(key) >= 0) continue;
 115        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
 116        target[key] = source[key];
 117      }
 118    }
 119  
 120    return target;
 121  }
 122  
 123  /***/ }),
 124  
 125  /***/ 16:
 126  /***/ (function(module, exports) {
 127  
 128  (function() { module.exports = window["regeneratorRuntime"]; }());
 129  
 130  /***/ }),
 131  
 132  /***/ 32:
 133  /***/ (function(module, exports) {
 134  
 135  (function() { module.exports = window["wp"]["url"]; }());
 136  
 137  /***/ }),
 138  
 139  /***/ 44:
 140  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 141  
 142  "use strict";
 143  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutPropertiesLoose; });
 144  function _objectWithoutPropertiesLoose(source, excluded) {
 145    if (source == null) return {};
 146    var target = {};
 147    var sourceKeys = Object.keys(source);
 148    var key, i;
 149  
 150    for (i = 0; i < sourceKeys.length; i++) {
 151      key = sourceKeys[i];
 152      if (excluded.indexOf(key) >= 0) continue;
 153      target[key] = source[key];
 154    }
 155  
 156    return target;
 157  }
 158  
 159  /***/ }),
 160  
 161  /***/ 47:
 162  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 163  
 164  "use strict";
 165  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
 166  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
 167    try {
 168      var info = gen[key](arg);
 169      var value = info.value;
 170    } catch (error) {
 171      reject(error);
 172      return;
 173    }
 174  
 175    if (info.done) {
 176      resolve(value);
 177    } else {
 178      Promise.resolve(value).then(_next, _throw);
 179    }
 180  }
 181  
 182  function _asyncToGenerator(fn) {
 183    return function () {
 184      var self = this,
 185          args = arguments;
 186      return new Promise(function (resolve, reject) {
 187        var gen = fn.apply(self, args);
 188  
 189        function _next(value) {
 190          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
 191        }
 192  
 193        function _throw(err) {
 194          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
 195        }
 196  
 197        _next(undefined);
 198      });
 199    };
 200  }
 201  
 202  /***/ }),
 203  
 204  /***/ 470:
 205  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 206  
 207  "use strict";
 208  // ESM COMPAT FLAG
 209  __webpack_require__.r(__webpack_exports__);
 210  
 211  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
 212  var defineProperty = __webpack_require__(5);
 213  
 214  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js
 215  var objectWithoutProperties = __webpack_require__(13);
 216  
 217  // EXTERNAL MODULE: external ["wp","i18n"]
 218  var external_wp_i18n_ = __webpack_require__(1);
 219  
 220  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
 221  
 222  
 223  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 224  
 225  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 226  
 227  function createNonceMiddleware(nonce) {
 228    function middleware(options, next) {
 229      var _options$headers = options.headers,
 230          headers = _options$headers === void 0 ? {} : _options$headers; // If an 'X-WP-Nonce' header (or any case-insensitive variation
 231      // thereof) was specified, no need to add a nonce header.
 232  
 233      for (var headerName in headers) {
 234        if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
 235          return next(options);
 236        }
 237      }
 238  
 239      return next(_objectSpread(_objectSpread({}, options), {}, {
 240        headers: _objectSpread(_objectSpread({}, headers), {}, {
 241          'X-WP-Nonce': middleware.nonce
 242        })
 243      }));
 244    }
 245  
 246    middleware.nonce = nonce;
 247    return middleware;
 248  }
 249  
 250  /* harmony default export */ var nonce = (createNonceMiddleware);
 251  
 252  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
 253  
 254  
 255  function namespace_endpoint_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 256  
 257  function namespace_endpoint_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { namespace_endpoint_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { namespace_endpoint_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 258  
 259  var namespaceAndEndpointMiddleware = function namespaceAndEndpointMiddleware(options, next) {
 260    var path = options.path;
 261    var namespaceTrimmed, endpointTrimmed;
 262  
 263    if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
 264      namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
 265      endpointTrimmed = options.endpoint.replace(/^\//, '');
 266  
 267      if (endpointTrimmed) {
 268        path = namespaceTrimmed + '/' + endpointTrimmed;
 269      } else {
 270        path = namespaceTrimmed;
 271      }
 272    }
 273  
 274    delete options.namespace;
 275    delete options.endpoint;
 276    return next(namespace_endpoint_objectSpread(namespace_endpoint_objectSpread({}, options), {}, {
 277      path: path
 278    }));
 279  };
 280  
 281  /* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
 282  
 283  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
 284  
 285  
 286  function root_url_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 287  
 288  function root_url_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { root_url_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { root_url_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 289  
 290  /**
 291   * Internal dependencies
 292   */
 293  
 294  
 295  var root_url_createRootURLMiddleware = function createRootURLMiddleware(rootURL) {
 296    return function (options, next) {
 297      return namespace_endpoint(options, function (optionsWithPath) {
 298        var url = optionsWithPath.url;
 299        var path = optionsWithPath.path;
 300        var apiRoot;
 301  
 302        if (typeof path === 'string') {
 303          apiRoot = rootURL;
 304  
 305          if (-1 !== rootURL.indexOf('?')) {
 306            path = path.replace('?', '&');
 307          }
 308  
 309          path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is
 310          // configured to use plain permalinks.
 311  
 312          if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
 313            path = path.replace('?', '&');
 314          }
 315  
 316          url = apiRoot + path;
 317        }
 318  
 319        return next(root_url_objectSpread(root_url_objectSpread({}, optionsWithPath), {}, {
 320          url: url
 321        }));
 322      });
 323    };
 324  };
 325  
 326  /* harmony default export */ var root_url = (root_url_createRootURLMiddleware);
 327  
 328  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
 329  /**
 330   * Given a path, returns a normalized path where equal query parameter values
 331   * will be treated as identical, regardless of order they appear in the original
 332   * text.
 333   *
 334   * @param {string} path Original path.
 335   *
 336   * @return {string} Normalized path.
 337   */
 338  function getStablePath(path) {
 339    var splitted = path.split('?');
 340    var query = splitted[1];
 341    var base = splitted[0];
 342  
 343    if (!query) {
 344      return base;
 345    } // 'b=1&c=2&a=5'
 346  
 347  
 348    return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
 349    .split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
 350    .map(function (entry) {
 351      return entry.split('=');
 352    }) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
 353    .sort(function (a, b) {
 354      return a[0].localeCompare(b[0]);
 355    }) // [ 'a=5', 'b=1', 'c=2' ]
 356    .map(function (pair) {
 357      return pair.join('=');
 358    }) // 'a=5&b=1&c=2'
 359    .join('&');
 360  }
 361  
 362  function createPreloadingMiddleware(preloadedData) {
 363    var cache = Object.keys(preloadedData).reduce(function (result, path) {
 364      result[getStablePath(path)] = preloadedData[path];
 365      return result;
 366    }, {});
 367    return function (options, next) {
 368      var _options$parse = options.parse,
 369          parse = _options$parse === void 0 ? true : _options$parse;
 370  
 371      if (typeof options.path === 'string') {
 372        var method = options.method || 'GET';
 373        var path = getStablePath(options.path);
 374  
 375        if ('GET' === method && cache[path]) {
 376          var cacheData = cache[path]; // Unsetting the cache key ensures that the data is only preloaded a single time
 377  
 378          delete cache[path];
 379          return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
 380            status: 200,
 381            statusText: 'OK',
 382            headers: cacheData.headers
 383          }));
 384        } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
 385          return Promise.resolve(cache[method][path]);
 386        }
 387      }
 388  
 389      return next(options);
 390    };
 391  }
 392  
 393  /* harmony default export */ var preloading = (createPreloadingMiddleware);
 394  
 395  // EXTERNAL MODULE: external "regeneratorRuntime"
 396  var external_regeneratorRuntime_ = __webpack_require__(16);
 397  var external_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_regeneratorRuntime_);
 398  
 399  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
 400  var asyncToGenerator = __webpack_require__(47);
 401  
 402  // EXTERNAL MODULE: external ["wp","url"]
 403  var external_wp_url_ = __webpack_require__(32);
 404  
 405  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
 406  
 407  
 408  
 409  
 410  
 411  function fetch_all_middleware_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 412  
 413  function fetch_all_middleware_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { fetch_all_middleware_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { fetch_all_middleware_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 414  
 415  /**
 416   * WordPress dependencies
 417   */
 418  
 419  /**
 420   * Internal dependencies
 421   */
 422  
 423   // Apply query arguments to both URL and Path, whichever is present.
 424  
 425  var fetch_all_middleware_modifyQuery = function modifyQuery(_ref, queryArgs) {
 426    var path = _ref.path,
 427        url = _ref.url,
 428        options = Object(objectWithoutProperties["a" /* default */])(_ref, ["path", "url"]);
 429  
 430    return fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, options), {}, {
 431      url: url && Object(external_wp_url_["addQueryArgs"])(url, queryArgs),
 432      path: path && Object(external_wp_url_["addQueryArgs"])(path, queryArgs)
 433    });
 434  }; // Duplicates parsing functionality from apiFetch.
 435  
 436  
 437  var parseResponse = function parseResponse(response) {
 438    return response.json ? response.json() : Promise.reject(response);
 439  };
 440  
 441  var parseLinkHeader = function parseLinkHeader(linkHeader) {
 442    if (!linkHeader) {
 443      return {};
 444    }
 445  
 446    var match = linkHeader.match(/<([^>]+)>; rel="next"/);
 447    return match ? {
 448      next: match[1]
 449    } : {};
 450  };
 451  
 452  var getNextPageUrl = function getNextPageUrl(response) {
 453    var _parseLinkHeader = parseLinkHeader(response.headers.get('link')),
 454        next = _parseLinkHeader.next;
 455  
 456    return next;
 457  };
 458  
 459  var requestContainsUnboundedQuery = function requestContainsUnboundedQuery(options) {
 460    var pathIsUnbounded = options.path && options.path.indexOf('per_page=-1') !== -1;
 461    var urlIsUnbounded = options.url && options.url.indexOf('per_page=-1') !== -1;
 462    return pathIsUnbounded || urlIsUnbounded;
 463  }; // The REST API enforces an upper limit on the per_page option. To handle large
 464  // collections, apiFetch consumers can pass `per_page=-1`; this middleware will
 465  // then recursively assemble a full response array from all available pages.
 466  
 467  
 468  var fetchAllMiddleware = /*#__PURE__*/function () {
 469    var _ref2 = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_regeneratorRuntime_default.a.mark(function _callee(options, next) {
 470      var response, results, nextPage, mergedResults, nextResponse, nextResults;
 471      return external_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 472        while (1) {
 473          switch (_context.prev = _context.next) {
 474            case 0:
 475              if (!(options.parse === false)) {
 476                _context.next = 2;
 477                break;
 478              }
 479  
 480              return _context.abrupt("return", next(options));
 481  
 482            case 2:
 483              if (requestContainsUnboundedQuery(options)) {
 484                _context.next = 4;
 485                break;
 486              }
 487  
 488              return _context.abrupt("return", next(options));
 489  
 490            case 4:
 491              _context.next = 6;
 492              return build_module(fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, fetch_all_middleware_modifyQuery(options, {
 493                per_page: 100
 494              })), {}, {
 495                // Ensure headers are returned for page 1.
 496                parse: false
 497              }));
 498  
 499            case 6:
 500              response = _context.sent;
 501              _context.next = 9;
 502              return parseResponse(response);
 503  
 504            case 9:
 505              results = _context.sent;
 506  
 507              if (Array.isArray(results)) {
 508                _context.next = 12;
 509                break;
 510              }
 511  
 512              return _context.abrupt("return", results);
 513  
 514            case 12:
 515              nextPage = getNextPageUrl(response);
 516  
 517              if (nextPage) {
 518                _context.next = 15;
 519                break;
 520              }
 521  
 522              return _context.abrupt("return", results);
 523  
 524            case 15:
 525              // Iteratively fetch all remaining pages until no "next" header is found.
 526              mergedResults = [].concat(results);
 527  
 528            case 16:
 529              if (!nextPage) {
 530                _context.next = 27;
 531                break;
 532              }
 533  
 534              _context.next = 19;
 535              return build_module(fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, options), {}, {
 536                // Ensure the URL for the next page is used instead of any provided path.
 537                path: undefined,
 538                url: nextPage,
 539                // Ensure we still get headers so we can identify the next page.
 540                parse: false
 541              }));
 542  
 543            case 19:
 544              nextResponse = _context.sent;
 545              _context.next = 22;
 546              return parseResponse(nextResponse);
 547  
 548            case 22:
 549              nextResults = _context.sent;
 550              mergedResults = mergedResults.concat(nextResults);
 551              nextPage = getNextPageUrl(nextResponse);
 552              _context.next = 16;
 553              break;
 554  
 555            case 27:
 556              return _context.abrupt("return", mergedResults);
 557  
 558            case 28:
 559            case "end":
 560              return _context.stop();
 561          }
 562        }
 563      }, _callee);
 564    }));
 565  
 566    return function fetchAllMiddleware(_x, _x2) {
 567      return _ref2.apply(this, arguments);
 568    };
 569  }();
 570  
 571  /* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
 572  
 573  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
 574  
 575  
 576  function http_v1_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 577  
 578  function http_v1_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { http_v1_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { http_v1_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 579  
 580  /**
 581   * Set of HTTP methods which are eligible to be overridden.
 582   *
 583   * @type {Set}
 584   */
 585  var OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
 586  /**
 587   * Default request method.
 588   *
 589   * "A request has an associated method (a method). Unless stated otherwise it
 590   * is `GET`."
 591   *
 592   * @see  https://fetch.spec.whatwg.org/#requests
 593   *
 594   * @type {string}
 595   */
 596  
 597  var DEFAULT_METHOD = 'GET';
 598  /**
 599   * API Fetch middleware which overrides the request method for HTTP v1
 600   * compatibility leveraging the REST API X-HTTP-Method-Override header.
 601   *
 602   * @param {Object}   options Fetch options.
 603   * @param {Function} next    [description]
 604   *
 605   * @return {*} The evaluated result of the remaining middleware chain.
 606   */
 607  
 608  function httpV1Middleware(options, next) {
 609    var _options = options,
 610        _options$method = _options.method,
 611        method = _options$method === void 0 ? DEFAULT_METHOD : _options$method;
 612  
 613    if (OVERRIDE_METHODS.has(method.toUpperCase())) {
 614      options = http_v1_objectSpread(http_v1_objectSpread({}, options), {}, {
 615        headers: http_v1_objectSpread(http_v1_objectSpread({}, options.headers), {}, {
 616          'X-HTTP-Method-Override': method,
 617          'Content-Type': 'application/json'
 618        }),
 619        method: 'POST'
 620      });
 621    }
 622  
 623    return next(options);
 624  }
 625  
 626  /* harmony default export */ var http_v1 = (httpV1Middleware);
 627  
 628  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
 629  /**
 630   * WordPress dependencies
 631   */
 632  
 633  
 634  function userLocaleMiddleware(options, next) {
 635    if (typeof options.url === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.url, '_locale')) {
 636      options.url = Object(external_wp_url_["addQueryArgs"])(options.url, {
 637        _locale: 'user'
 638      });
 639    }
 640  
 641    if (typeof options.path === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.path, '_locale')) {
 642      options.path = Object(external_wp_url_["addQueryArgs"])(options.path, {
 643        _locale: 'user'
 644      });
 645    }
 646  
 647    return next(options);
 648  }
 649  
 650  /* harmony default export */ var user_locale = (userLocaleMiddleware);
 651  
 652  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
 653  /**
 654   * WordPress dependencies
 655   */
 656  
 657  /**
 658   * Parses the apiFetch response.
 659   *
 660   * @param {Response} response
 661   * @param {boolean}  shouldParseResponse
 662   *
 663   * @return {Promise} Parsed response
 664   */
 665  
 666  var response_parseResponse = function parseResponse(response) {
 667    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 668  
 669    if (shouldParseResponse) {
 670      if (response.status === 204) {
 671        return null;
 672      }
 673  
 674      return response.json ? response.json() : Promise.reject(response);
 675    }
 676  
 677    return response;
 678  };
 679  
 680  var response_parseJsonAndNormalizeError = function parseJsonAndNormalizeError(response) {
 681    var invalidJsonError = {
 682      code: 'invalid_json',
 683      message: Object(external_wp_i18n_["__"])('The response is not a valid JSON response.')
 684    };
 685  
 686    if (!response || !response.json) {
 687      throw invalidJsonError;
 688    }
 689  
 690    return response.json().catch(function () {
 691      throw invalidJsonError;
 692    });
 693  };
 694  /**
 695   * Parses the apiFetch response properly and normalize response errors.
 696   *
 697   * @param {Response} response
 698   * @param {boolean}  shouldParseResponse
 699   *
 700   * @return {Promise} Parsed response.
 701   */
 702  
 703  
 704  var parseResponseAndNormalizeError = function parseResponseAndNormalizeError(response) {
 705    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 706    return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(function (res) {
 707      return parseAndThrowError(res, shouldParseResponse);
 708    });
 709  };
 710  function parseAndThrowError(response) {
 711    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 712  
 713    if (!shouldParseResponse) {
 714      throw response;
 715    }
 716  
 717    return response_parseJsonAndNormalizeError(response).then(function (error) {
 718      var unknownError = {
 719        code: 'unknown_error',
 720        message: Object(external_wp_i18n_["__"])('An unknown error occurred.')
 721      };
 722      throw error || unknownError;
 723    });
 724  }
 725  
 726  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
 727  
 728  
 729  function media_upload_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 730  
 731  function media_upload_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { media_upload_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { media_upload_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 732  
 733  /**
 734   * WordPress dependencies
 735   */
 736  
 737  /**
 738   * Internal dependencies
 739   */
 740  
 741  
 742  /**
 743   * Middleware handling media upload failures and retries.
 744   *
 745   * @param {Object}   options Fetch options.
 746   * @param {Function} next    [description]
 747   *
 748   * @return {*} The evaluated result of the remaining middleware chain.
 749   */
 750  
 751  function mediaUploadMiddleware(options, next) {
 752    var isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
 753  
 754    if (!isMediaUploadRequest) {
 755      return next(options, next);
 756    }
 757  
 758    var retries = 0;
 759    var maxRetries = 5;
 760  
 761    var postProcess = function postProcess(attachmentId) {
 762      retries++;
 763      return next({
 764        path: "/wp/v2/media/".concat(attachmentId, "/post-process"),
 765        method: 'POST',
 766        data: {
 767          action: 'create-image-subsizes'
 768        },
 769        parse: false
 770      }).catch(function () {
 771        if (retries < maxRetries) {
 772          return postProcess(attachmentId);
 773        }
 774  
 775        next({
 776          path: "/wp/v2/media/".concat(attachmentId, "?force=true"),
 777          method: 'DELETE'
 778        });
 779        return Promise.reject();
 780      });
 781    };
 782  
 783    return next(media_upload_objectSpread(media_upload_objectSpread({}, options), {}, {
 784      parse: false
 785    })).catch(function (response) {
 786      var attachmentId = response.headers.get('x-wp-upload-attachment-id');
 787  
 788      if (response.status >= 500 && response.status < 600 && attachmentId) {
 789        return postProcess(attachmentId).catch(function () {
 790          if (options.parse !== false) {
 791            return Promise.reject({
 792              code: 'post_process',
 793              message: Object(external_wp_i18n_["__"])('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
 794            });
 795          }
 796  
 797          return Promise.reject(response);
 798        });
 799      }
 800  
 801      return parseAndThrowError(response, options.parse);
 802    }).then(function (response) {
 803      return parseResponseAndNormalizeError(response, options.parse);
 804    });
 805  }
 806  
 807  /* harmony default export */ var media_upload = (mediaUploadMiddleware);
 808  
 809  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
 810  
 811  
 812  
 813  function build_module_ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
 814  
 815  function build_module_objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { build_module_ownKeys(Object(source), true).forEach(function (key) { Object(defineProperty["a" /* default */])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { build_module_ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
 816  
 817  /**
 818   * WordPress dependencies
 819   */
 820  
 821  /**
 822   * Internal dependencies
 823   */
 824  
 825  
 826  
 827  
 828  
 829  
 830  
 831  
 832  
 833  
 834  /**
 835   * Default set of header values which should be sent with every request unless
 836   * explicitly provided through apiFetch options.
 837   *
 838   * @type {Object}
 839   */
 840  
 841  var DEFAULT_HEADERS = {
 842    // The backend uses the Accept header as a condition for considering an
 843    // incoming request as a REST request.
 844    //
 845    // See: https://core.trac.wordpress.org/ticket/44534
 846    Accept: 'application/json, */*;q=0.1'
 847  };
 848  /**
 849   * Default set of fetch option values which should be sent with every request
 850   * unless explicitly provided through apiFetch options.
 851   *
 852   * @type {Object}
 853   */
 854  
 855  var DEFAULT_OPTIONS = {
 856    credentials: 'include'
 857  };
 858  var middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
 859  
 860  function registerMiddleware(middleware) {
 861    middlewares.unshift(middleware);
 862  }
 863  
 864  var checkStatus = function checkStatus(response) {
 865    if (response.status >= 200 && response.status < 300) {
 866      return response;
 867    }
 868  
 869    throw response;
 870  };
 871  
 872  var build_module_defaultFetchHandler = function defaultFetchHandler(nextOptions) {
 873    var url = nextOptions.url,
 874        path = nextOptions.path,
 875        data = nextOptions.data,
 876        _nextOptions$parse = nextOptions.parse,
 877        parse = _nextOptions$parse === void 0 ? true : _nextOptions$parse,
 878        remainingOptions = Object(objectWithoutProperties["a" /* default */])(nextOptions, ["url", "path", "data", "parse"]);
 879  
 880    var body = nextOptions.body,
 881        headers = nextOptions.headers; // Merge explicitly-provided headers with default values.
 882  
 883    headers = build_module_objectSpread(build_module_objectSpread({}, DEFAULT_HEADERS), headers); // The `data` property is a shorthand for sending a JSON body.
 884  
 885    if (data) {
 886      body = JSON.stringify(data);
 887      headers['Content-Type'] = 'application/json';
 888    }
 889  
 890    var responsePromise = window.fetch(url || path, build_module_objectSpread(build_module_objectSpread(build_module_objectSpread({}, DEFAULT_OPTIONS), remainingOptions), {}, {
 891      body: body,
 892      headers: headers
 893    }));
 894    return responsePromise // Return early if fetch errors. If fetch error, there is most likely no
 895    // network connection. Unfortunately fetch just throws a TypeError and
 896    // the message might depend on the browser.
 897    .then(function (value) {
 898      return Promise.resolve(value).then(checkStatus).catch(function (response) {
 899        return parseAndThrowError(response, parse);
 900      }).then(function (response) {
 901        return parseResponseAndNormalizeError(response, parse);
 902      });
 903    }, function () {
 904      throw {
 905        code: 'fetch_error',
 906        message: Object(external_wp_i18n_["__"])('You are probably offline.')
 907      };
 908    });
 909  };
 910  
 911  var fetchHandler = build_module_defaultFetchHandler;
 912  /**
 913   * Defines a custom fetch handler for making the requests that will override
 914   * the default one using window.fetch
 915   *
 916   * @param {Function} newFetchHandler The new fetch handler
 917   */
 918  
 919  function setFetchHandler(newFetchHandler) {
 920    fetchHandler = newFetchHandler;
 921  }
 922  
 923  function apiFetch(options) {
 924    // creates a nested function chain that calls all middlewares and finally the `fetchHandler`,
 925    // converting `middlewares = [ m1, m2, m3 ]` into:
 926    // ```
 927    // opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) );
 928    // ```
 929    var enhancedHandler = middlewares.reduceRight(function (next, middleware) {
 930      return function (workingOptions) {
 931        return middleware(workingOptions, next);
 932      };
 933    }, fetchHandler);
 934    return enhancedHandler(options).catch(function (error) {
 935      if (error.code !== 'rest_cookie_invalid_nonce') {
 936        return Promise.reject(error);
 937      } // If the nonce is invalid, refresh it and try again.
 938  
 939  
 940      return window.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(function (data) {
 941        return data.text();
 942      }).then(function (text) {
 943        apiFetch.nonceMiddleware.nonce = text;
 944        return apiFetch(options);
 945      });
 946    });
 947  }
 948  
 949  apiFetch.use = registerMiddleware;
 950  apiFetch.setFetchHandler = setFetchHandler;
 951  apiFetch.createNonceMiddleware = nonce;
 952  apiFetch.createPreloadingMiddleware = preloading;
 953  apiFetch.createRootURLMiddleware = root_url;
 954  apiFetch.fetchAllMiddleware = fetch_all_middleware;
 955  apiFetch.mediaUploadMiddleware = media_upload;
 956  /* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
 957  
 958  
 959  /***/ }),
 960  
 961  /***/ 5:
 962  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 963  
 964  "use strict";
 965  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
 966  function _defineProperty(obj, key, value) {
 967    if (key in obj) {
 968      Object.defineProperty(obj, key, {
 969        value: value,
 970        enumerable: true,
 971        configurable: true,
 972        writable: true
 973      });
 974    } else {
 975      obj[key] = value;
 976    }
 977  
 978    return obj;
 979  }
 980  
 981  /***/ })
 982  
 983  /******/ })["default"];


Generated: Thu Mar 4 01:00:04 2021 Cross-referenced by PHPXref 0.7.1