[ 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 = 465);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 1:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = window["wp"]["i18n"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 14:
  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 _objectWithoutPropertiesLoose_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(45);
 103  
 104  function _objectWithoutProperties(source, excluded) {
 105    if (source == null) return {};
 106    var target = Object(_objectWithoutPropertiesLoose_js__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  /***/ 29:
 133  /***/ (function(module, exports) {
 134  
 135  (function() { module.exports = window["wp"]["url"]; }());
 136  
 137  /***/ }),
 138  
 139  /***/ 45:
 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  /***/ 465:
 162  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 163  
 164  "use strict";
 165  // ESM COMPAT FLAG
 166  __webpack_require__.r(__webpack_exports__);
 167  
 168  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
 169  var defineProperty = __webpack_require__(5);
 170  
 171  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js
 172  var objectWithoutProperties = __webpack_require__(14);
 173  
 174  // EXTERNAL MODULE: external ["wp","i18n"]
 175  var external_wp_i18n_ = __webpack_require__(1);
 176  
 177  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
 178  
 179  
 180  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; }
 181  
 182  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; }
 183  
 184  /**
 185   * @param {string} nonce
 186   * @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
 187   */
 188  function createNonceMiddleware(nonce) {
 189    /**
 190     * @type {import('../types').APIFetchMiddleware & { nonce: string }}
 191     */
 192    var middleware = function middleware(options, next) {
 193      var _options$headers = options.headers,
 194          headers = _options$headers === void 0 ? {} : _options$headers; // If an 'X-WP-Nonce' header (or any case-insensitive variation
 195      // thereof) was specified, no need to add a nonce header.
 196  
 197      for (var headerName in headers) {
 198        if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
 199          return next(options);
 200        }
 201      }
 202  
 203      return next(_objectSpread(_objectSpread({}, options), {}, {
 204        headers: _objectSpread(_objectSpread({}, headers), {}, {
 205          'X-WP-Nonce': middleware.nonce
 206        })
 207      }));
 208    };
 209  
 210    middleware.nonce = nonce;
 211    return middleware;
 212  }
 213  
 214  /* harmony default export */ var nonce = (createNonceMiddleware);
 215  
 216  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
 217  
 218  
 219  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; }
 220  
 221  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; }
 222  
 223  /**
 224   * @type {import('../types').APIFetchMiddleware}
 225   */
 226  var namespaceAndEndpointMiddleware = function namespaceAndEndpointMiddleware(options, next) {
 227    var path = options.path;
 228    var namespaceTrimmed, endpointTrimmed;
 229  
 230    if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
 231      namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
 232      endpointTrimmed = options.endpoint.replace(/^\//, '');
 233  
 234      if (endpointTrimmed) {
 235        path = namespaceTrimmed + '/' + endpointTrimmed;
 236      } else {
 237        path = namespaceTrimmed;
 238      }
 239    }
 240  
 241    delete options.namespace;
 242    delete options.endpoint;
 243    return next(namespace_endpoint_objectSpread(namespace_endpoint_objectSpread({}, options), {}, {
 244      path: path
 245    }));
 246  };
 247  
 248  /* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
 249  
 250  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
 251  
 252  
 253  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; }
 254  
 255  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; }
 256  
 257  /**
 258   * Internal dependencies
 259   */
 260  
 261  /**
 262   * @param {string} rootURL
 263   * @return {import('../types').APIFetchMiddleware} Root URL middleware.
 264   */
 265  
 266  var root_url_createRootURLMiddleware = function createRootURLMiddleware(rootURL) {
 267    return function (options, next) {
 268      return namespace_endpoint(options, function (optionsWithPath) {
 269        var url = optionsWithPath.url;
 270        var path = optionsWithPath.path;
 271        var apiRoot;
 272  
 273        if (typeof path === 'string') {
 274          apiRoot = rootURL;
 275  
 276          if (-1 !== rootURL.indexOf('?')) {
 277            path = path.replace('?', '&');
 278          }
 279  
 280          path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is
 281          // configured to use plain permalinks.
 282  
 283          if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
 284            path = path.replace('?', '&');
 285          }
 286  
 287          url = apiRoot + path;
 288        }
 289  
 290        return next(root_url_objectSpread(root_url_objectSpread({}, optionsWithPath), {}, {
 291          url: url
 292        }));
 293      });
 294    };
 295  };
 296  
 297  /* harmony default export */ var root_url = (root_url_createRootURLMiddleware);
 298  
 299  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
 300  /**
 301   * Given a path, returns a normalized path where equal query parameter values
 302   * will be treated as identical, regardless of order they appear in the original
 303   * text.
 304   *
 305   * @param {string} path Original path.
 306   *
 307   * @return {string} Normalized path.
 308   */
 309  function getStablePath(path) {
 310    var splitted = path.split('?');
 311    var query = splitted[1];
 312    var base = splitted[0];
 313  
 314    if (!query) {
 315      return base;
 316    } // 'b=1&c=2&a=5'
 317  
 318  
 319    return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
 320    .split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
 321    .map(function (entry) {
 322      return entry.split('=');
 323    }) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
 324    .sort(function (a, b) {
 325      return a[0].localeCompare(b[0]);
 326    }) // [ 'a=5', 'b=1', 'c=2' ]
 327    .map(function (pair) {
 328      return pair.join('=');
 329    }) // 'a=5&b=1&c=2'
 330    .join('&');
 331  }
 332  /**
 333   * @param {Record<string, any>} preloadedData
 334   * @return {import('../types').APIFetchMiddleware} Preloading middleware.
 335   */
 336  
 337  function createPreloadingMiddleware(preloadedData) {
 338    var cache = Object.keys(preloadedData).reduce(function (result, path) {
 339      result[getStablePath(path)] = preloadedData[path];
 340      return result;
 341    },
 342    /** @type {Record<string, any>} */
 343    {});
 344    return function (options, next) {
 345      var _options$parse = options.parse,
 346          parse = _options$parse === void 0 ? true : _options$parse;
 347  
 348      if (typeof options.path === 'string') {
 349        var method = options.method || 'GET';
 350        var path = getStablePath(options.path);
 351  
 352        if ('GET' === method && cache[path]) {
 353          var cacheData = cache[path]; // Unsetting the cache key ensures that the data is only preloaded a single time
 354  
 355          delete cache[path];
 356          return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
 357            status: 200,
 358            statusText: 'OK',
 359            headers: cacheData.headers
 360          }));
 361        } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
 362          return Promise.resolve(parse ? cache[method][path].body : cache[method][path]);
 363        }
 364      }
 365  
 366      return next(options);
 367    };
 368  }
 369  
 370  /* harmony default export */ var preloading = (createPreloadingMiddleware);
 371  
 372  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
 373  var asyncToGenerator = __webpack_require__(48);
 374  
 375  // EXTERNAL MODULE: external "regeneratorRuntime"
 376  var external_regeneratorRuntime_ = __webpack_require__(16);
 377  var external_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_regeneratorRuntime_);
 378  
 379  // EXTERNAL MODULE: external ["wp","url"]
 380  var external_wp_url_ = __webpack_require__(29);
 381  
 382  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
 383  
 384  
 385  
 386  
 387  
 388  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; }
 389  
 390  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; }
 391  
 392  /**
 393   * WordPress dependencies
 394   */
 395  
 396  /**
 397   * Internal dependencies
 398   */
 399  
 400  
 401  /**
 402   * Apply query arguments to both URL and Path, whichever is present.
 403   *
 404   * @param {import('../types').APIFetchOptions} props
 405   * @param {Record<string, string | number>} queryArgs
 406   * @return {import('../types').APIFetchOptions} The request with the modified query args
 407   */
 408  
 409  var fetch_all_middleware_modifyQuery = function modifyQuery(_ref, queryArgs) {
 410    var path = _ref.path,
 411        url = _ref.url,
 412        options = Object(objectWithoutProperties["a" /* default */])(_ref, ["path", "url"]);
 413  
 414    return fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, options), {}, {
 415      url: url && Object(external_wp_url_["addQueryArgs"])(url, queryArgs),
 416      path: path && Object(external_wp_url_["addQueryArgs"])(path, queryArgs)
 417    });
 418  };
 419  /**
 420   * Duplicates parsing functionality from apiFetch.
 421   *
 422   * @param {Response} response
 423   * @return {Promise<any>} Parsed response json.
 424   */
 425  
 426  
 427  var parseResponse = function parseResponse(response) {
 428    return response.json ? response.json() : Promise.reject(response);
 429  };
 430  /**
 431   * @param {string | null} linkHeader
 432   * @return {{ next?: string }} The parsed link header.
 433   */
 434  
 435  
 436  var parseLinkHeader = function parseLinkHeader(linkHeader) {
 437    if (!linkHeader) {
 438      return {};
 439    }
 440  
 441    var match = linkHeader.match(/<([^>]+)>; rel="next"/);
 442    return match ? {
 443      next: match[1]
 444    } : {};
 445  };
 446  /**
 447   * @param {Response} response
 448   * @return {string | undefined} The next page URL.
 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   * @param {import('../types').APIFetchOptions} options
 460   * @return {boolean} True if the request contains an unbounded query.
 461   */
 462  
 463  
 464  var requestContainsUnboundedQuery = function requestContainsUnboundedQuery(options) {
 465    var pathIsUnbounded = !!options.path && options.path.indexOf('per_page=-1') !== -1;
 466    var urlIsUnbounded = !!options.url && options.url.indexOf('per_page=-1') !== -1;
 467    return pathIsUnbounded || urlIsUnbounded;
 468  };
 469  /**
 470   * The REST API enforces an upper limit on the per_page option. To handle large
 471   * collections, apiFetch consumers can pass `per_page=-1`; this middleware will
 472   * then recursively assemble a full response array from all available pages.
 473   *
 474   * @type {import('../types').APIFetchMiddleware}
 475   */
 476  
 477  
 478  var fetchAllMiddleware = /*#__PURE__*/function () {
 479    var _ref2 = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_regeneratorRuntime_default.a.mark(function _callee(options, next) {
 480      var response, results, nextPage, mergedResults, nextResponse, nextResults;
 481      return external_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 482        while (1) {
 483          switch (_context.prev = _context.next) {
 484            case 0:
 485              if (!(options.parse === false)) {
 486                _context.next = 2;
 487                break;
 488              }
 489  
 490              return _context.abrupt("return", next(options));
 491  
 492            case 2:
 493              if (requestContainsUnboundedQuery(options)) {
 494                _context.next = 4;
 495                break;
 496              }
 497  
 498              return _context.abrupt("return", next(options));
 499  
 500            case 4:
 501              _context.next = 6;
 502              return build_module(fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, fetch_all_middleware_modifyQuery(options, {
 503                per_page: 100
 504              })), {}, {
 505                // Ensure headers are returned for page 1.
 506                parse: false
 507              }));
 508  
 509            case 6:
 510              response = _context.sent;
 511              _context.next = 9;
 512              return parseResponse(response);
 513  
 514            case 9:
 515              results = _context.sent;
 516  
 517              if (Array.isArray(results)) {
 518                _context.next = 12;
 519                break;
 520              }
 521  
 522              return _context.abrupt("return", results);
 523  
 524            case 12:
 525              nextPage = getNextPageUrl(response);
 526  
 527              if (nextPage) {
 528                _context.next = 15;
 529                break;
 530              }
 531  
 532              return _context.abrupt("return", results);
 533  
 534            case 15:
 535              // Iteratively fetch all remaining pages until no "next" header is found.
 536              mergedResults =
 537              /** @type {any[]} */
 538              [].concat(results);
 539  
 540            case 16:
 541              if (!nextPage) {
 542                _context.next = 27;
 543                break;
 544              }
 545  
 546              _context.next = 19;
 547              return build_module(fetch_all_middleware_objectSpread(fetch_all_middleware_objectSpread({}, options), {}, {
 548                // Ensure the URL for the next page is used instead of any provided path.
 549                path: undefined,
 550                url: nextPage,
 551                // Ensure we still get headers so we can identify the next page.
 552                parse: false
 553              }));
 554  
 555            case 19:
 556              nextResponse = _context.sent;
 557              _context.next = 22;
 558              return parseResponse(nextResponse);
 559  
 560            case 22:
 561              nextResults = _context.sent;
 562              mergedResults = mergedResults.concat(nextResults);
 563              nextPage = getNextPageUrl(nextResponse);
 564              _context.next = 16;
 565              break;
 566  
 567            case 27:
 568              return _context.abrupt("return", mergedResults);
 569  
 570            case 28:
 571            case "end":
 572              return _context.stop();
 573          }
 574        }
 575      }, _callee);
 576    }));
 577  
 578    return function fetchAllMiddleware(_x, _x2) {
 579      return _ref2.apply(this, arguments);
 580    };
 581  }();
 582  
 583  /* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
 584  
 585  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
 586  
 587  
 588  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; }
 589  
 590  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; }
 591  
 592  /**
 593   * Set of HTTP methods which are eligible to be overridden.
 594   *
 595   * @type {Set<string>}
 596   */
 597  var OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
 598  /**
 599   * Default request method.
 600   *
 601   * "A request has an associated method (a method). Unless stated otherwise it
 602   * is `GET`."
 603   *
 604   * @see  https://fetch.spec.whatwg.org/#requests
 605   *
 606   * @type {string}
 607   */
 608  
 609  var DEFAULT_METHOD = 'GET';
 610  /**
 611   * API Fetch middleware which overrides the request method for HTTP v1
 612   * compatibility leveraging the REST API X-HTTP-Method-Override header.
 613   *
 614   * @type {import('../types').APIFetchMiddleware}
 615   */
 616  
 617  var httpV1Middleware = function httpV1Middleware(options, next) {
 618    var _options = options,
 619        _options$method = _options.method,
 620        method = _options$method === void 0 ? DEFAULT_METHOD : _options$method;
 621  
 622    if (OVERRIDE_METHODS.has(method.toUpperCase())) {
 623      options = http_v1_objectSpread(http_v1_objectSpread({}, options), {}, {
 624        headers: http_v1_objectSpread(http_v1_objectSpread({}, options.headers), {}, {
 625          'X-HTTP-Method-Override': method,
 626          'Content-Type': 'application/json'
 627        }),
 628        method: 'POST'
 629      });
 630    }
 631  
 632    return next(options);
 633  };
 634  
 635  /* harmony default export */ var http_v1 = (httpV1Middleware);
 636  
 637  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
 638  /**
 639   * WordPress dependencies
 640   */
 641  
 642  /**
 643   * @type {import('../types').APIFetchMiddleware}
 644   */
 645  
 646  var user_locale_userLocaleMiddleware = function userLocaleMiddleware(options, next) {
 647    if (typeof options.url === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.url, '_locale')) {
 648      options.url = Object(external_wp_url_["addQueryArgs"])(options.url, {
 649        _locale: 'user'
 650      });
 651    }
 652  
 653    if (typeof options.path === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.path, '_locale')) {
 654      options.path = Object(external_wp_url_["addQueryArgs"])(options.path, {
 655        _locale: 'user'
 656      });
 657    }
 658  
 659    return next(options);
 660  };
 661  
 662  /* harmony default export */ var user_locale = (user_locale_userLocaleMiddleware);
 663  
 664  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
 665  /**
 666   * WordPress dependencies
 667   */
 668  
 669  /**
 670   * Parses the apiFetch response.
 671   *
 672   * @param {Response} response
 673   * @param {boolean}  shouldParseResponse
 674   *
 675   * @return {Promise<any> | null | Response} Parsed response.
 676   */
 677  
 678  var response_parseResponse = function parseResponse(response) {
 679    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 680  
 681    if (shouldParseResponse) {
 682      if (response.status === 204) {
 683        return null;
 684      }
 685  
 686      return response.json ? response.json() : Promise.reject(response);
 687    }
 688  
 689    return response;
 690  };
 691  /**
 692   * Calls the `json` function on the Response, throwing an error if the response
 693   * doesn't have a json function or if parsing the json itself fails.
 694   *
 695   * @param {Response} response
 696   * @return {Promise<any>} Parsed response.
 697   */
 698  
 699  
 700  var response_parseJsonAndNormalizeError = function parseJsonAndNormalizeError(response) {
 701    var invalidJsonError = {
 702      code: 'invalid_json',
 703      message: Object(external_wp_i18n_["__"])('The response is not a valid JSON response.')
 704    };
 705  
 706    if (!response || !response.json) {
 707      throw invalidJsonError;
 708    }
 709  
 710    return response.json().catch(function () {
 711      throw invalidJsonError;
 712    });
 713  };
 714  /**
 715   * Parses the apiFetch response properly and normalize response errors.
 716   *
 717   * @param {Response} response
 718   * @param {boolean}  shouldParseResponse
 719   *
 720   * @return {Promise<any>} Parsed response.
 721   */
 722  
 723  
 724  var parseResponseAndNormalizeError = function parseResponseAndNormalizeError(response) {
 725    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 726    return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(function (res) {
 727      return parseAndThrowError(res, shouldParseResponse);
 728    });
 729  };
 730  /**
 731   * Parses a response, throwing an error if parsing the response fails.
 732   *
 733   * @param {Response} response
 734   * @param {boolean} shouldParseResponse
 735   * @return {Promise<any>} Parsed response.
 736   */
 737  
 738  function parseAndThrowError(response) {
 739    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 740  
 741    if (!shouldParseResponse) {
 742      throw response;
 743    }
 744  
 745    return response_parseJsonAndNormalizeError(response).then(function (error) {
 746      var unknownError = {
 747        code: 'unknown_error',
 748        message: Object(external_wp_i18n_["__"])('An unknown error occurred.')
 749      };
 750      throw error || unknownError;
 751    });
 752  }
 753  
 754  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
 755  
 756  
 757  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; }
 758  
 759  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; }
 760  
 761  /**
 762   * WordPress dependencies
 763   */
 764  
 765  /**
 766   * Internal dependencies
 767   */
 768  
 769  
 770  /**
 771   * Middleware handling media upload failures and retries.
 772   *
 773   * @type {import('../types').APIFetchMiddleware}
 774   */
 775  
 776  var media_upload_mediaUploadMiddleware = function mediaUploadMiddleware(options, next) {
 777    var isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
 778  
 779    if (!isMediaUploadRequest) {
 780      return next(options);
 781    }
 782  
 783    var retries = 0;
 784    var maxRetries = 5;
 785    /**
 786     * @param {string} attachmentId
 787     * @return {Promise<any>} Processed post response.
 788     */
 789  
 790    var postProcess = function postProcess(attachmentId) {
 791      retries++;
 792      return next({
 793        path: "/wp/v2/media/".concat(attachmentId, "/post-process"),
 794        method: 'POST',
 795        data: {
 796          action: 'create-image-subsizes'
 797        },
 798        parse: false
 799      }).catch(function () {
 800        if (retries < maxRetries) {
 801          return postProcess(attachmentId);
 802        }
 803  
 804        next({
 805          path: "/wp/v2/media/".concat(attachmentId, "?force=true"),
 806          method: 'DELETE'
 807        });
 808        return Promise.reject();
 809      });
 810    };
 811  
 812    return next(media_upload_objectSpread(media_upload_objectSpread({}, options), {}, {
 813      parse: false
 814    })).catch(function (response) {
 815      var attachmentId = response.headers.get('x-wp-upload-attachment-id');
 816  
 817      if (response.status >= 500 && response.status < 600 && attachmentId) {
 818        return postProcess(attachmentId).catch(function () {
 819          if (options.parse !== false) {
 820            return Promise.reject({
 821              code: 'post_process',
 822              message: Object(external_wp_i18n_["__"])('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
 823            });
 824          }
 825  
 826          return Promise.reject(response);
 827        });
 828      }
 829  
 830      return parseAndThrowError(response, options.parse);
 831    }).then(function (response) {
 832      return parseResponseAndNormalizeError(response, options.parse);
 833    });
 834  };
 835  
 836  /* harmony default export */ var media_upload = (media_upload_mediaUploadMiddleware);
 837  
 838  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
 839  
 840  
 841  
 842  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; }
 843  
 844  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; }
 845  
 846  /**
 847   * WordPress dependencies
 848   */
 849  
 850  /**
 851   * Internal dependencies
 852   */
 853  
 854  
 855  
 856  
 857  
 858  
 859  
 860  
 861  
 862  
 863  /**
 864   * Default set of header values which should be sent with every request unless
 865   * explicitly provided through apiFetch options.
 866   *
 867   * @type {Record<string, string>}
 868   */
 869  
 870  var DEFAULT_HEADERS = {
 871    // The backend uses the Accept header as a condition for considering an
 872    // incoming request as a REST request.
 873    //
 874    // See: https://core.trac.wordpress.org/ticket/44534
 875    Accept: 'application/json, */*;q=0.1'
 876  };
 877  /**
 878   * Default set of fetch option values which should be sent with every request
 879   * unless explicitly provided through apiFetch options.
 880   *
 881   * @type {Object}
 882   */
 883  
 884  var DEFAULT_OPTIONS = {
 885    credentials: 'include'
 886  };
 887  /** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */
 888  
 889  /** @typedef {import('./types').APIFetchOptions} APIFetchOptions */
 890  
 891  /**
 892   * @type {import('./types').APIFetchMiddleware[]}
 893   */
 894  
 895  var middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
 896  /**
 897   * Register a middleware
 898   *
 899   * @param {import('./types').APIFetchMiddleware} middleware
 900   */
 901  
 902  function registerMiddleware(middleware) {
 903    middlewares.unshift(middleware);
 904  }
 905  /**
 906   * Checks the status of a response, throwing the Response as an error if
 907   * it is outside the 200 range.
 908   *
 909   * @param {Response} response
 910   * @return {Response} The response if the status is in the 200 range.
 911   */
 912  
 913  
 914  var checkStatus = function checkStatus(response) {
 915    if (response.status >= 200 && response.status < 300) {
 916      return response;
 917    }
 918  
 919    throw response;
 920  };
 921  /** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/
 922  
 923  /**
 924   * @type {FetchHandler}
 925   */
 926  
 927  
 928  var build_module_defaultFetchHandler = function defaultFetchHandler(nextOptions) {
 929    var url = nextOptions.url,
 930        path = nextOptions.path,
 931        data = nextOptions.data,
 932        _nextOptions$parse = nextOptions.parse,
 933        parse = _nextOptions$parse === void 0 ? true : _nextOptions$parse,
 934        remainingOptions = Object(objectWithoutProperties["a" /* default */])(nextOptions, ["url", "path", "data", "parse"]);
 935  
 936    var body = nextOptions.body,
 937        headers = nextOptions.headers; // Merge explicitly-provided headers with default values.
 938  
 939    headers = build_module_objectSpread(build_module_objectSpread({}, DEFAULT_HEADERS), headers); // The `data` property is a shorthand for sending a JSON body.
 940  
 941    if (data) {
 942      body = JSON.stringify(data);
 943      headers['Content-Type'] = 'application/json';
 944    }
 945  
 946    var responsePromise = window.fetch( // fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed
 947    url || path || window.location.href, build_module_objectSpread(build_module_objectSpread(build_module_objectSpread({}, DEFAULT_OPTIONS), remainingOptions), {}, {
 948      body: body,
 949      headers: headers
 950    }));
 951    return responsePromise // Return early if fetch errors. If fetch error, there is most likely no
 952    // network connection. Unfortunately fetch just throws a TypeError and
 953    // the message might depend on the browser.
 954    .then(function (value) {
 955      return Promise.resolve(value).then(checkStatus).catch(function (response) {
 956        return parseAndThrowError(response, parse);
 957      }).then(function (response) {
 958        return parseResponseAndNormalizeError(response, parse);
 959      });
 960    }, function () {
 961      throw {
 962        code: 'fetch_error',
 963        message: Object(external_wp_i18n_["__"])('You are probably offline.')
 964      };
 965    });
 966  };
 967  /** @type {FetchHandler} */
 968  
 969  
 970  var fetchHandler = build_module_defaultFetchHandler;
 971  /**
 972   * Defines a custom fetch handler for making the requests that will override
 973   * the default one using window.fetch
 974   *
 975   * @param {FetchHandler} newFetchHandler The new fetch handler
 976   */
 977  
 978  function setFetchHandler(newFetchHandler) {
 979    fetchHandler = newFetchHandler;
 980  }
 981  /**
 982   * @template T
 983   * @param {import('./types').APIFetchOptions} options
 984   * @return {Promise<T>} A promise representing the request processed via the registered middlewares.
 985   */
 986  
 987  
 988  function apiFetch(options) {
 989    // creates a nested function chain that calls all middlewares and finally the `fetchHandler`,
 990    // converting `middlewares = [ m1, m2, m3 ]` into:
 991    // ```
 992    // opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) );
 993    // ```
 994    var enhancedHandler = middlewares.reduceRight(function (
 995    /** @type {FetchHandler} */
 996    next, middleware) {
 997      return function (workingOptions) {
 998        return middleware(workingOptions, next);
 999      };
1000    }, fetchHandler);
1001    return enhancedHandler(options).catch(function (error) {
1002      if (error.code !== 'rest_cookie_invalid_nonce') {
1003        return Promise.reject(error);
1004      } // If the nonce is invalid, refresh it and try again.
1005  
1006  
1007      return window // @ts-ignore
1008      .fetch(apiFetch.nonceEndpoint).then(checkStatus).then(function (data) {
1009        return data.text();
1010      }).then(function (text) {
1011        // @ts-ignore
1012        apiFetch.nonceMiddleware.nonce = text;
1013        return apiFetch(options);
1014      });
1015    });
1016  }
1017  
1018  apiFetch.use = registerMiddleware;
1019  apiFetch.setFetchHandler = setFetchHandler;
1020  apiFetch.createNonceMiddleware = nonce;
1021  apiFetch.createPreloadingMiddleware = preloading;
1022  apiFetch.createRootURLMiddleware = root_url;
1023  apiFetch.fetchAllMiddleware = fetch_all_middleware;
1024  apiFetch.mediaUploadMiddleware = media_upload;
1025  /* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
1026  
1027  
1028  /***/ }),
1029  
1030  /***/ 48:
1031  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1032  
1033  "use strict";
1034  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
1035  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1036    try {
1037      var info = gen[key](arg);
1038      var value = info.value;
1039    } catch (error) {
1040      reject(error);
1041      return;
1042    }
1043  
1044    if (info.done) {
1045      resolve(value);
1046    } else {
1047      Promise.resolve(value).then(_next, _throw);
1048    }
1049  }
1050  
1051  function _asyncToGenerator(fn) {
1052    return function () {
1053      var self = this,
1054          args = arguments;
1055      return new Promise(function (resolve, reject) {
1056        var gen = fn.apply(self, args);
1057  
1058        function _next(value) {
1059          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1060        }
1061  
1062        function _throw(err) {
1063          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1064        }
1065  
1066        _next(undefined);
1067      });
1068    };
1069  }
1070  
1071  /***/ }),
1072  
1073  /***/ 5:
1074  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1075  
1076  "use strict";
1077  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
1078  function _defineProperty(obj, key, value) {
1079    if (key in obj) {
1080      Object.defineProperty(obj, key, {
1081        value: value,
1082        enumerable: true,
1083        configurable: true,
1084        writable: true
1085      });
1086    } else {
1087      obj[key] = value;
1088    }
1089  
1090    return obj;
1091  }
1092  
1093  /***/ })
1094  
1095  /******/ })["default"];


Generated: Sat May 15 01:00:05 2021 Cross-referenced by PHPXref 0.7.1