[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> media-utils.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["mediaUtils"] =
   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 = 461);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 0:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["wp"]["element"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 1:
  98  /***/ (function(module, exports) {
  99  
 100  (function() { module.exports = this["wp"]["i18n"]; }());
 101  
 102  /***/ }),
 103  
 104  /***/ 12:
 105  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 106  
 107  "use strict";
 108  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _assertThisInitialized; });
 109  function _assertThisInitialized(self) {
 110    if (self === void 0) {
 111      throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
 112    }
 113  
 114    return self;
 115  }
 116  
 117  /***/ }),
 118  
 119  /***/ 14:
 120  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 121  
 122  "use strict";
 123  
 124  // EXPORTS
 125  __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _slicedToArray; });
 126  
 127  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithHoles.js
 128  var arrayWithHoles = __webpack_require__(38);
 129  
 130  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArrayLimit.js
 131  function _iterableToArrayLimit(arr, i) {
 132    if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
 133    var _arr = [];
 134    var _n = true;
 135    var _d = false;
 136    var _e = undefined;
 137  
 138    try {
 139      for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
 140        _arr.push(_s.value);
 141  
 142        if (i && _arr.length === i) break;
 143      }
 144    } catch (err) {
 145      _d = true;
 146      _e = err;
 147    } finally {
 148      try {
 149        if (!_n && _i["return"] != null) _i["return"]();
 150      } finally {
 151        if (_d) throw _e;
 152      }
 153    }
 154  
 155    return _arr;
 156  }
 157  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
 158  var unsupportedIterableToArray = __webpack_require__(29);
 159  
 160  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableRest.js
 161  var nonIterableRest = __webpack_require__(39);
 162  
 163  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js
 164  
 165  
 166  
 167  
 168  function _slicedToArray(arr, i) {
 169    return Object(arrayWithHoles["a" /* default */])(arr) || _iterableToArrayLimit(arr, i) || Object(unsupportedIterableToArray["a" /* default */])(arr, i) || Object(nonIterableRest["a" /* default */])();
 170  }
 171  
 172  /***/ }),
 173  
 174  /***/ 16:
 175  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 176  
 177  "use strict";
 178  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _getPrototypeOf; });
 179  function _getPrototypeOf(o) {
 180    _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
 181      return o.__proto__ || Object.getPrototypeOf(o);
 182    };
 183    return _getPrototypeOf(o);
 184  }
 185  
 186  /***/ }),
 187  
 188  /***/ 18:
 189  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 190  
 191  "use strict";
 192  
 193  // EXPORTS
 194  __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _toConsumableArray; });
 195  
 196  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js
 197  var arrayLikeToArray = __webpack_require__(26);
 198  
 199  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/arrayWithoutHoles.js
 200  
 201  function _arrayWithoutHoles(arr) {
 202    if (Array.isArray(arr)) return Object(arrayLikeToArray["a" /* default */])(arr);
 203  }
 204  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/iterableToArray.js
 205  var iterableToArray = __webpack_require__(35);
 206  
 207  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js
 208  var unsupportedIterableToArray = __webpack_require__(29);
 209  
 210  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/nonIterableSpread.js
 211  function _nonIterableSpread() {
 212    throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
 213  }
 214  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js
 215  
 216  
 217  
 218  
 219  function _toConsumableArray(arr) {
 220    return _arrayWithoutHoles(arr) || Object(iterableToArray["a" /* default */])(arr) || Object(unsupportedIterableToArray["a" /* default */])(arr) || _nonIterableSpread();
 221  }
 222  
 223  /***/ }),
 224  
 225  /***/ 19:
 226  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 227  
 228  "use strict";
 229  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _createClass; });
 230  function _defineProperties(target, props) {
 231    for (var i = 0; i < props.length; i++) {
 232      var descriptor = props[i];
 233      descriptor.enumerable = descriptor.enumerable || false;
 234      descriptor.configurable = true;
 235      if ("value" in descriptor) descriptor.writable = true;
 236      Object.defineProperty(target, descriptor.key, descriptor);
 237    }
 238  }
 239  
 240  function _createClass(Constructor, protoProps, staticProps) {
 241    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
 242    if (staticProps) _defineProperties(Constructor, staticProps);
 243    return Constructor;
 244  }
 245  
 246  /***/ }),
 247  
 248  /***/ 2:
 249  /***/ (function(module, exports) {
 250  
 251  (function() { module.exports = this["lodash"]; }());
 252  
 253  /***/ }),
 254  
 255  /***/ 20:
 256  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 257  
 258  "use strict";
 259  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _classCallCheck; });
 260  function _classCallCheck(instance, Constructor) {
 261    if (!(instance instanceof Constructor)) {
 262      throw new TypeError("Cannot call a class as a function");
 263    }
 264  }
 265  
 266  /***/ }),
 267  
 268  /***/ 22:
 269  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 270  
 271  "use strict";
 272  
 273  // EXPORTS
 274  __webpack_require__.d(__webpack_exports__, "a", function() { return /* binding */ _inherits; });
 275  
 276  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js
 277  function _setPrototypeOf(o, p) {
 278    _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
 279      o.__proto__ = p;
 280      return o;
 281    };
 282  
 283    return _setPrototypeOf(o, p);
 284  }
 285  // CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js
 286  
 287  function _inherits(subClass, superClass) {
 288    if (typeof superClass !== "function" && superClass !== null) {
 289      throw new TypeError("Super expression must either be null or a function");
 290    }
 291  
 292    subClass.prototype = Object.create(superClass && superClass.prototype, {
 293      constructor: {
 294        value: subClass,
 295        writable: true,
 296        configurable: true
 297      }
 298    });
 299    if (superClass) _setPrototypeOf(subClass, superClass);
 300  }
 301  
 302  /***/ }),
 303  
 304  /***/ 23:
 305  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 306  
 307  "use strict";
 308  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _possibleConstructorReturn; });
 309  /* harmony import */ var _helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(40);
 310  /* harmony import */ var _assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
 311  
 312  
 313  function _possibleConstructorReturn(self, call) {
 314    if (call && (Object(_helpers_esm_typeof__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(call) === "object" || typeof call === "function")) {
 315      return call;
 316    }
 317  
 318    return Object(_assertThisInitialized__WEBPACK_IMPORTED_MODULE_1__[/* default */ "a"])(self);
 319  }
 320  
 321  /***/ }),
 322  
 323  /***/ 24:
 324  /***/ (function(module, exports) {
 325  
 326  (function() { module.exports = this["regeneratorRuntime"]; }());
 327  
 328  /***/ }),
 329  
 330  /***/ 26:
 331  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 332  
 333  "use strict";
 334  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayLikeToArray; });
 335  function _arrayLikeToArray(arr, len) {
 336    if (len == null || len > arr.length) len = arr.length;
 337  
 338    for (var i = 0, arr2 = new Array(len); i < len; i++) {
 339      arr2[i] = arr[i];
 340    }
 341  
 342    return arr2;
 343  }
 344  
 345  /***/ }),
 346  
 347  /***/ 29:
 348  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 349  
 350  "use strict";
 351  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _unsupportedIterableToArray; });
 352  /* harmony import */ var _arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26);
 353  
 354  function _unsupportedIterableToArray(o, minLen) {
 355    if (!o) return;
 356    if (typeof o === "string") return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen);
 357    var n = Object.prototype.toString.call(o).slice(8, -1);
 358    if (n === "Object" && o.constructor) n = o.constructor.name;
 359    if (n === "Map" || n === "Set") return Array.from(o);
 360    if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Object(_arrayLikeToArray__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(o, minLen);
 361  }
 362  
 363  /***/ }),
 364  
 365  /***/ 35:
 366  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 367  
 368  "use strict";
 369  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _iterableToArray; });
 370  function _iterableToArray(iter) {
 371    if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
 372  }
 373  
 374  /***/ }),
 375  
 376  /***/ 38:
 377  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 378  
 379  "use strict";
 380  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _arrayWithHoles; });
 381  function _arrayWithHoles(arr) {
 382    if (Array.isArray(arr)) return arr;
 383  }
 384  
 385  /***/ }),
 386  
 387  /***/ 39:
 388  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 389  
 390  "use strict";
 391  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _nonIterableRest; });
 392  function _nonIterableRest() {
 393    throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
 394  }
 395  
 396  /***/ }),
 397  
 398  /***/ 40:
 399  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 400  
 401  "use strict";
 402  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _typeof; });
 403  function _typeof(obj) {
 404    "@babel/helpers - typeof";
 405  
 406    if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
 407      _typeof = function _typeof(obj) {
 408        return typeof obj;
 409      };
 410    } else {
 411      _typeof = function _typeof(obj) {
 412        return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
 413      };
 414    }
 415  
 416    return _typeof(obj);
 417  }
 418  
 419  /***/ }),
 420  
 421  /***/ 44:
 422  /***/ (function(module, exports) {
 423  
 424  (function() { module.exports = this["wp"]["blob"]; }());
 425  
 426  /***/ }),
 427  
 428  /***/ 45:
 429  /***/ (function(module, exports) {
 430  
 431  (function() { module.exports = this["wp"]["apiFetch"]; }());
 432  
 433  /***/ }),
 434  
 435  /***/ 461:
 436  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 437  
 438  "use strict";
 439  // ESM COMPAT FLAG
 440  __webpack_require__.r(__webpack_exports__);
 441  
 442  // EXPORTS
 443  __webpack_require__.d(__webpack_exports__, "MediaUpload", function() { return /* reexport */ media_upload; });
 444  __webpack_require__.d(__webpack_exports__, "uploadMedia", function() { return /* reexport */ uploadMedia; });
 445  
 446  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js
 447  var classCallCheck = __webpack_require__(20);
 448  
 449  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/createClass.js
 450  var createClass = __webpack_require__(19);
 451  
 452  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js
 453  var assertThisInitialized = __webpack_require__(12);
 454  
 455  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js
 456  var possibleConstructorReturn = __webpack_require__(23);
 457  
 458  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js
 459  var getPrototypeOf = __webpack_require__(16);
 460  
 461  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/inherits.js + 1 modules
 462  var inherits = __webpack_require__(22);
 463  
 464  // EXTERNAL MODULE: external {"this":"lodash"}
 465  var external_this_lodash_ = __webpack_require__(2);
 466  
 467  // EXTERNAL MODULE: external {"this":["wp","element"]}
 468  var external_this_wp_element_ = __webpack_require__(0);
 469  
 470  // EXTERNAL MODULE: external {"this":["wp","i18n"]}
 471  var external_this_wp_i18n_ = __webpack_require__(1);
 472  
 473  // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/media-upload/index.js
 474  
 475  
 476  
 477  
 478  
 479  
 480  
 481  function _createSuper(Derived) { return function () { var Super = Object(getPrototypeOf["a" /* default */])(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = Object(getPrototypeOf["a" /* default */])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return Object(possibleConstructorReturn["a" /* default */])(this, result); }; }
 482  
 483  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
 484  
 485  /**
 486   * External dependencies
 487   */
 488  
 489  /**
 490   * WordPress dependencies
 491   */
 492  
 493  
 494  
 495  var _window = window,
 496      wp = _window.wp;
 497  var DEFAULT_EMPTY_GALLERY = [];
 498  /**
 499   * Prepares the Featured Image toolbars and frames.
 500   *
 501   * @return {wp.media.view.MediaFrame.Select} The default media workflow.
 502   */
 503  
 504  var getFeaturedImageMediaFrame = function getFeaturedImageMediaFrame() {
 505    return wp.media.view.MediaFrame.Select.extend({
 506      /**
 507       * Enables the Set Featured Image Button.
 508       *
 509       * @param {Object} toolbar toolbar for featured image state
 510       * @return {void}
 511       */
 512      featuredImageToolbar: function featuredImageToolbar(toolbar) {
 513        this.createSelectToolbar(toolbar, {
 514          text: wp.media.view.l10n.setFeaturedImage,
 515          state: this.options.state
 516        });
 517      },
 518  
 519      /**
 520       * Handle the edit state requirements of selected media item.
 521       *
 522       * @return {void}
 523       */
 524      editState: function editState() {
 525        var selection = this.state('featured-image').get('selection');
 526        var view = new wp.media.view.EditImage({
 527          model: selection.single(),
 528          controller: this
 529        }).render(); // Set the view to the EditImage frame using the selected image.
 530  
 531        this.content.set(view); // After bringing in the frame, load the actual editor via an ajax call.
 532  
 533        view.loadEditor();
 534      },
 535  
 536      /**
 537       * Create the default states.
 538       *
 539       * @return {void}
 540       */
 541      createStates: function createStates() {
 542        this.on('toolbar:create:featured-image', this.featuredImageToolbar, this);
 543        this.on('content:render:edit-image', this.editState, this);
 544        this.states.add([new wp.media.controller.FeaturedImage(), new wp.media.controller.EditImage({
 545          model: this.options.editImage
 546        })]);
 547      }
 548    });
 549  };
 550  /**
 551   * Prepares the Gallery toolbars and frames.
 552   *
 553   * @return {wp.media.view.MediaFrame.Post} The default media workflow.
 554   */
 555  
 556  
 557  var media_upload_getGalleryDetailsMediaFrame = function getGalleryDetailsMediaFrame() {
 558    /**
 559     * Custom gallery details frame.
 560     *
 561     * @see https://github.com/xwp/wp-core-media-widgets/blob/905edbccfc2a623b73a93dac803c5335519d7837/wp-admin/js/widgets/media-gallery-widget.js
 562     * @class GalleryDetailsMediaFrame
 563     * @class
 564     */
 565    return wp.media.view.MediaFrame.Post.extend({
 566      /**
 567       * Set up gallery toolbar.
 568       *
 569       * @return {void}
 570       */
 571      galleryToolbar: function galleryToolbar() {
 572        var editing = this.state().get('editing');
 573        this.toolbar.set(new wp.media.view.Toolbar({
 574          controller: this,
 575          items: {
 576            insert: {
 577              style: 'primary',
 578              text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
 579              priority: 80,
 580              requires: {
 581                library: true
 582              },
 583  
 584              /**
 585               * @fires wp.media.controller.State#update
 586               */
 587              click: function click() {
 588                var controller = this.controller,
 589                    state = controller.state();
 590                controller.close();
 591                state.trigger('update', state.get('library')); // Restore and reset the default state.
 592  
 593                controller.setState(controller.options.state);
 594                controller.reset();
 595              }
 596            }
 597          }
 598        }));
 599      },
 600  
 601      /**
 602       * Handle the edit state requirements of selected media item.
 603       *
 604       * @return {void}
 605       */
 606      editState: function editState() {
 607        var selection = this.state('gallery').get('selection');
 608        var view = new wp.media.view.EditImage({
 609          model: selection.single(),
 610          controller: this
 611        }).render(); // Set the view to the EditImage frame using the selected image.
 612  
 613        this.content.set(view); // After bringing in the frame, load the actual editor via an ajax call.
 614  
 615        view.loadEditor();
 616      },
 617  
 618      /**
 619       * Create the default states.
 620       *
 621       * @return {void}
 622       */
 623      createStates: function createStates() {
 624        this.on('toolbar:create:main-gallery', this.galleryToolbar, this);
 625        this.on('content:render:edit-image', this.editState, this);
 626        this.states.add([new wp.media.controller.Library({
 627          id: 'gallery',
 628          title: wp.media.view.l10n.createGalleryTitle,
 629          priority: 40,
 630          toolbar: 'main-gallery',
 631          filterable: 'uploaded',
 632          multiple: 'add',
 633          editable: false,
 634          library: wp.media.query(Object(external_this_lodash_["defaults"])({
 635            type: 'image'
 636          }, this.options.library))
 637        }), new wp.media.controller.EditImage({
 638          model: this.options.editImage
 639        }), new wp.media.controller.GalleryEdit({
 640          library: this.options.selection,
 641          editing: this.options.editing,
 642          menu: 'gallery',
 643          displaySettings: false,
 644          multiple: true
 645        }), new wp.media.controller.GalleryAdd()]);
 646      }
 647    });
 648  }; // the media library image object contains numerous attributes
 649  // we only need this set to display the image in the library
 650  
 651  
 652  var media_upload_slimImageObject = function slimImageObject(img) {
 653    var attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
 654    return Object(external_this_lodash_["pick"])(img, attrSet);
 655  };
 656  
 657  var getAttachmentsCollection = function getAttachmentsCollection(ids) {
 658    return wp.media.query({
 659      order: 'ASC',
 660      orderby: 'post__in',
 661      post__in: ids,
 662      posts_per_page: -1,
 663      query: true,
 664      type: 'image'
 665    });
 666  };
 667  
 668  var media_upload_MediaUpload = /*#__PURE__*/function (_Component) {
 669    Object(inherits["a" /* default */])(MediaUpload, _Component);
 670  
 671    var _super = _createSuper(MediaUpload);
 672  
 673    function MediaUpload(_ref) {
 674      var _this;
 675  
 676      var allowedTypes = _ref.allowedTypes,
 677          _ref$gallery = _ref.gallery,
 678          gallery = _ref$gallery === void 0 ? false : _ref$gallery,
 679          _ref$unstableFeatured = _ref.unstableFeaturedImageFlow,
 680          unstableFeaturedImageFlow = _ref$unstableFeatured === void 0 ? false : _ref$unstableFeatured,
 681          modalClass = _ref.modalClass,
 682          _ref$multiple = _ref.multiple,
 683          multiple = _ref$multiple === void 0 ? false : _ref$multiple,
 684          _ref$title = _ref.title,
 685          title = _ref$title === void 0 ? Object(external_this_wp_i18n_["__"])('Select or Upload Media') : _ref$title;
 686  
 687      Object(classCallCheck["a" /* default */])(this, MediaUpload);
 688  
 689      _this = _super.apply(this, arguments);
 690      _this.openModal = _this.openModal.bind(Object(assertThisInitialized["a" /* default */])(_this));
 691      _this.onOpen = _this.onOpen.bind(Object(assertThisInitialized["a" /* default */])(_this));
 692      _this.onSelect = _this.onSelect.bind(Object(assertThisInitialized["a" /* default */])(_this));
 693      _this.onUpdate = _this.onUpdate.bind(Object(assertThisInitialized["a" /* default */])(_this));
 694      _this.onClose = _this.onClose.bind(Object(assertThisInitialized["a" /* default */])(_this));
 695  
 696      if (gallery) {
 697        _this.buildAndSetGalleryFrame();
 698      } else {
 699        var frameConfig = {
 700          title: title,
 701          multiple: multiple
 702        };
 703  
 704        if (!!allowedTypes) {
 705          frameConfig.library = {
 706            type: allowedTypes
 707          };
 708        }
 709  
 710        _this.frame = wp.media(frameConfig);
 711      }
 712  
 713      if (modalClass) {
 714        _this.frame.$el.addClass(modalClass);
 715      }
 716  
 717      if (unstableFeaturedImageFlow) {
 718        _this.buildAndSetFeatureImageFrame();
 719      }
 720  
 721      _this.initializeListeners();
 722  
 723      return _this;
 724    }
 725  
 726    Object(createClass["a" /* default */])(MediaUpload, [{
 727      key: "initializeListeners",
 728      value: function initializeListeners() {
 729        // When an image is selected in the media frame...
 730        this.frame.on('select', this.onSelect);
 731        this.frame.on('update', this.onUpdate);
 732        this.frame.on('open', this.onOpen);
 733        this.frame.on('close', this.onClose);
 734      }
 735      /**
 736       * Sets the Gallery frame and initializes listeners.
 737       *
 738       * @return {void}
 739       */
 740  
 741    }, {
 742      key: "buildAndSetGalleryFrame",
 743      value: function buildAndSetGalleryFrame() {
 744        var _this$props = this.props,
 745            _this$props$addToGall = _this$props.addToGallery,
 746            addToGallery = _this$props$addToGall === void 0 ? false : _this$props$addToGall,
 747            allowedTypes = _this$props.allowedTypes,
 748            _this$props$multiple = _this$props.multiple,
 749            multiple = _this$props$multiple === void 0 ? false : _this$props$multiple,
 750            _this$props$value = _this$props.value,
 751            value = _this$props$value === void 0 ? DEFAULT_EMPTY_GALLERY : _this$props$value; // If the value did not changed there is no need to rebuild the frame,
 752        // we can continue to use the existing one.
 753  
 754        if (value === this.lastGalleryValue) {
 755          return;
 756        }
 757  
 758        this.lastGalleryValue = value; // If a frame already existed remove it.
 759  
 760        if (this.frame) {
 761          this.frame.remove();
 762        }
 763  
 764        var currentState;
 765  
 766        if (addToGallery) {
 767          currentState = 'gallery-library';
 768        } else {
 769          currentState = value && value.length ? 'gallery-edit' : 'gallery';
 770        }
 771  
 772        if (!this.GalleryDetailsMediaFrame) {
 773          this.GalleryDetailsMediaFrame = media_upload_getGalleryDetailsMediaFrame();
 774        }
 775  
 776        var attachments = getAttachmentsCollection(value);
 777        var selection = new wp.media.model.Selection(attachments.models, {
 778          props: attachments.props.toJSON(),
 779          multiple: multiple
 780        });
 781        this.frame = new this.GalleryDetailsMediaFrame({
 782          mimeType: allowedTypes,
 783          state: currentState,
 784          multiple: multiple,
 785          selection: selection,
 786          editing: value && value.length ? true : false
 787        });
 788        wp.media.frame = this.frame;
 789        this.initializeListeners();
 790      }
 791      /**
 792       * Initializes the Media Library requirements for the featured image flow.
 793       *
 794       * @return {void}
 795       */
 796  
 797    }, {
 798      key: "buildAndSetFeatureImageFrame",
 799      value: function buildAndSetFeatureImageFrame() {
 800        var featuredImageFrame = getFeaturedImageMediaFrame();
 801        var attachments = getAttachmentsCollection(this.props.value);
 802        var selection = new wp.media.model.Selection(attachments.models, {
 803          props: attachments.props.toJSON()
 804        });
 805        this.frame = new featuredImageFrame({
 806          mimeType: this.props.allowedTypes,
 807          state: 'featured-image',
 808          multiple: this.props.multiple,
 809          selection: selection,
 810          editing: this.props.value ? true : false
 811        });
 812        wp.media.frame = this.frame;
 813      }
 814    }, {
 815      key: "componentWillUnmount",
 816      value: function componentWillUnmount() {
 817        this.frame.remove();
 818      }
 819    }, {
 820      key: "onUpdate",
 821      value: function onUpdate(selections) {
 822        var _this$props2 = this.props,
 823            onSelect = _this$props2.onSelect,
 824            _this$props2$multiple = _this$props2.multiple,
 825            multiple = _this$props2$multiple === void 0 ? false : _this$props2$multiple;
 826        var state = this.frame.state();
 827        var selectedImages = selections || state.get('selection');
 828  
 829        if (!selectedImages || !selectedImages.models.length) {
 830          return;
 831        }
 832  
 833        if (multiple) {
 834          onSelect(selectedImages.models.map(function (model) {
 835            return media_upload_slimImageObject(model.toJSON());
 836          }));
 837        } else {
 838          onSelect(media_upload_slimImageObject(selectedImages.models[0].toJSON()));
 839        }
 840      }
 841    }, {
 842      key: "onSelect",
 843      value: function onSelect() {
 844        var _this$props3 = this.props,
 845            onSelect = _this$props3.onSelect,
 846            _this$props3$multiple = _this$props3.multiple,
 847            multiple = _this$props3$multiple === void 0 ? false : _this$props3$multiple; // Get media attachment details from the frame state
 848  
 849        var attachment = this.frame.state().get('selection').toJSON();
 850        onSelect(multiple ? attachment : attachment[0]);
 851      }
 852    }, {
 853      key: "onOpen",
 854      value: function onOpen() {
 855        this.updateCollection();
 856  
 857        if (!this.props.value) {
 858          return;
 859        }
 860  
 861        if (!this.props.gallery) {
 862          var selection = this.frame.state().get('selection');
 863          Object(external_this_lodash_["castArray"])(this.props.value).forEach(function (id) {
 864            selection.add(wp.media.attachment(id));
 865          });
 866        } // load the images so they are available in the media modal.
 867  
 868  
 869        getAttachmentsCollection(Object(external_this_lodash_["castArray"])(this.props.value)).more();
 870      }
 871    }, {
 872      key: "onClose",
 873      value: function onClose() {
 874        var onClose = this.props.onClose;
 875  
 876        if (onClose) {
 877          onClose();
 878        }
 879      }
 880    }, {
 881      key: "updateCollection",
 882      value: function updateCollection() {
 883        var frameContent = this.frame.content.get();
 884  
 885        if (frameContent && frameContent.collection) {
 886          var collection = frameContent.collection; // clean all attachments we have in memory.
 887  
 888          collection.toArray().forEach(function (model) {
 889            return model.trigger('destroy', model);
 890          }); // reset has more flag, if library had small amount of items all items may have been loaded before.
 891  
 892          collection.mirroring._hasMore = true; // request items
 893  
 894          collection.more();
 895        }
 896      }
 897    }, {
 898      key: "openModal",
 899      value: function openModal() {
 900        if (this.props.gallery) {
 901          this.buildAndSetGalleryFrame();
 902        }
 903  
 904        this.frame.open();
 905      }
 906    }, {
 907      key: "render",
 908      value: function render() {
 909        return this.props.render({
 910          open: this.openModal
 911        });
 912      }
 913    }]);
 914  
 915    return MediaUpload;
 916  }(external_this_wp_element_["Component"]);
 917  
 918  /* harmony default export */ var media_upload = (media_upload_MediaUpload);
 919  
 920  // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js
 921  
 922  
 923  // EXTERNAL MODULE: external {"this":"regeneratorRuntime"}
 924  var external_this_regeneratorRuntime_ = __webpack_require__(24);
 925  var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_);
 926  
 927  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js
 928  var defineProperty = __webpack_require__(5);
 929  
 930  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
 931  var asyncToGenerator = __webpack_require__(50);
 932  
 933  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/toConsumableArray.js + 2 modules
 934  var toConsumableArray = __webpack_require__(18);
 935  
 936  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/slicedToArray.js + 1 modules
 937  var slicedToArray = __webpack_require__(14);
 938  
 939  // EXTERNAL MODULE: external {"this":["wp","apiFetch"]}
 940  var external_this_wp_apiFetch_ = __webpack_require__(45);
 941  var external_this_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_this_wp_apiFetch_);
 942  
 943  // EXTERNAL MODULE: external {"this":["wp","blob"]}
 944  var external_this_wp_blob_ = __webpack_require__(44);
 945  
 946  // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js
 947  
 948  
 949  
 950  
 951  
 952  
 953  
 954  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; }
 955  
 956  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; }
 957  
 958  function _createForOfIteratorHelper(o) { if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (o = _unsupportedIterableToArray(o))) { var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var it, normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
 959  
 960  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
 961  
 962  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
 963  
 964  /**
 965   * External dependencies
 966   */
 967  
 968  /**
 969   * WordPress dependencies
 970   */
 971  
 972  
 973  
 974  
 975  /**
 976   * Browsers may use unexpected mime types, and they differ from browser to browser.
 977   * This function computes a flexible array of mime types from the mime type structured provided by the server.
 978   * Converts { jpg|jpeg|jpe: "image/jpeg" } into [ "image/jpeg", "image/jpg", "image/jpeg", "image/jpe" ]
 979   * The computation of this array instead of directly using the object,
 980   * solves the problem in chrome where mp3 files have audio/mp3 as mime type instead of audio/mpeg.
 981   * https://bugs.chromium.org/p/chromium/issues/detail?id=227004
 982   *
 983   * @param {?Object} wpMimeTypesObject Mime type object received from the server.
 984   *                                    Extensions are keys separated by '|' and values are mime types associated with an extension.
 985   *
 986   * @return {?Array} An array of mime types or the parameter passed if it was "falsy".
 987   */
 988  
 989  function getMimeTypesArray(wpMimeTypesObject) {
 990    if (!wpMimeTypesObject) {
 991      return wpMimeTypesObject;
 992    }
 993  
 994    return Object(external_this_lodash_["flatMap"])(wpMimeTypesObject, function (mime, extensionsString) {
 995      var _mime$split = mime.split('/'),
 996          _mime$split2 = Object(slicedToArray["a" /* default */])(_mime$split, 1),
 997          type = _mime$split2[0];
 998  
 999      var extensions = extensionsString.split('|');
1000      return [mime].concat(Object(toConsumableArray["a" /* default */])(Object(external_this_lodash_["map"])(extensions, function (extension) {
1001        return "".concat(type, "/").concat(extension);
1002      })));
1003    });
1004  }
1005  /**
1006   *    Media Upload is used by audio, image, gallery, video, and file blocks to
1007   *    handle uploading a media file when a file upload button is activated.
1008   *
1009   *    TODO: future enhancement to add an upload indicator.
1010   *
1011   * @param   {Object}   $0                    Parameters object passed to the function.
1012   * @param   {?Array}   $0.allowedTypes       Array with the types of media that can be uploaded, if unset all types are allowed.
1013   * @param   {?Object}  $0.additionalData     Additional data to include in the request.
1014   * @param   {Array}    $0.filesList          List of files.
1015   * @param   {?number}  $0.maxUploadFileSize  Maximum upload size in bytes allowed for the site.
1016   * @param   {Function} $0.onError            Function called when an error happens.
1017   * @param   {Function} $0.onFileChange       Function called each time a file or a temporary representation of the file is available.
1018   * @param   {?Object}  $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
1019   */
1020  
1021  function uploadMedia(_x) {
1022    return _uploadMedia.apply(this, arguments);
1023  }
1024  /**
1025   * @param {File}    file           Media File to Save.
1026   * @param {?Object} additionalData Additional data to include in the request.
1027   *
1028   * @return {Promise} Media Object Promise.
1029   */
1030  
1031  function _uploadMedia() {
1032    _uploadMedia = Object(asyncToGenerator["a" /* default */])( /*#__PURE__*/external_this_regeneratorRuntime_default.a.mark(function _callee(_ref) {
1033      var allowedTypes, _ref$additionalData, additionalData, filesList, maxUploadFileSize, _ref$onError, onError, onFileChange, _ref$wpAllowedMimeTyp, wpAllowedMimeTypes, files, filesSet, setAndUpdateFiles, isAllowedType, allowedMimeTypesForUser, isAllowedMimeTypeForUser, triggerError, validFiles, _iterator, _step, _mediaFile, idx, mediaFile, savedMedia, mediaObject, message;
1034  
1035      return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
1036        while (1) {
1037          switch (_context.prev = _context.next) {
1038            case 0:
1039              allowedTypes = _ref.allowedTypes, _ref$additionalData = _ref.additionalData, additionalData = _ref$additionalData === void 0 ? {} : _ref$additionalData, filesList = _ref.filesList, maxUploadFileSize = _ref.maxUploadFileSize, _ref$onError = _ref.onError, onError = _ref$onError === void 0 ? external_this_lodash_["noop"] : _ref$onError, onFileChange = _ref.onFileChange, _ref$wpAllowedMimeTyp = _ref.wpAllowedMimeTypes, wpAllowedMimeTypes = _ref$wpAllowedMimeTyp === void 0 ? null : _ref$wpAllowedMimeTyp;
1040              // Cast filesList to array
1041              files = Object(toConsumableArray["a" /* default */])(filesList);
1042              filesSet = [];
1043  
1044              setAndUpdateFiles = function setAndUpdateFiles(idx, value) {
1045                Object(external_this_wp_blob_["revokeBlobURL"])(Object(external_this_lodash_["get"])(filesSet, [idx, 'url']));
1046                filesSet[idx] = value;
1047                onFileChange(Object(external_this_lodash_["compact"])(filesSet));
1048              }; // Allowed type specified by consumer
1049  
1050  
1051              isAllowedType = function isAllowedType(fileType) {
1052                if (!allowedTypes) {
1053                  return true;
1054                }
1055  
1056                return Object(external_this_lodash_["some"])(allowedTypes, function (allowedType) {
1057                  // If a complete mimetype is specified verify if it matches exactly the mime type of the file.
1058                  if (Object(external_this_lodash_["includes"])(allowedType, '/')) {
1059                    return allowedType === fileType;
1060                  } // Otherwise a general mime type is used and we should verify if the file mimetype starts with it.
1061  
1062  
1063                  return Object(external_this_lodash_["startsWith"])(fileType, "".concat(allowedType, "/"));
1064                });
1065              }; // Allowed types for the current WP_User
1066  
1067  
1068              allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
1069  
1070              isAllowedMimeTypeForUser = function isAllowedMimeTypeForUser(fileType) {
1071                return Object(external_this_lodash_["includes"])(allowedMimeTypesForUser, fileType);
1072              }; // Build the error message including the filename
1073  
1074  
1075              triggerError = function triggerError(error) {
1076                error.message = [Object(external_this_wp_element_["createElement"])("strong", {
1077                  key: "filename"
1078                }, error.file.name), ': ', error.message];
1079                onError(error);
1080              };
1081  
1082              validFiles = [];
1083              _iterator = _createForOfIteratorHelper(files);
1084              _context.prev = 10;
1085  
1086              _iterator.s();
1087  
1088            case 12:
1089              if ((_step = _iterator.n()).done) {
1090                _context.next = 31;
1091                break;
1092              }
1093  
1094              _mediaFile = _step.value;
1095  
1096              if (!(allowedMimeTypesForUser && _mediaFile.type && !isAllowedMimeTypeForUser(_mediaFile.type))) {
1097                _context.next = 17;
1098                break;
1099              }
1100  
1101              triggerError({
1102                code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
1103                message: Object(external_this_wp_i18n_["__"])('Sorry, this file type is not permitted for security reasons.'),
1104                file: _mediaFile
1105              });
1106              return _context.abrupt("continue", 29);
1107  
1108            case 17:
1109              if (!(_mediaFile.type && !isAllowedType(_mediaFile.type))) {
1110                _context.next = 20;
1111                break;
1112              }
1113  
1114              triggerError({
1115                code: 'MIME_TYPE_NOT_SUPPORTED',
1116                message: Object(external_this_wp_i18n_["__"])('Sorry, this file type is not supported here.'),
1117                file: _mediaFile
1118              });
1119              return _context.abrupt("continue", 29);
1120  
1121            case 20:
1122              if (!(maxUploadFileSize && _mediaFile.size > maxUploadFileSize)) {
1123                _context.next = 23;
1124                break;
1125              }
1126  
1127              triggerError({
1128                code: 'SIZE_ABOVE_LIMIT',
1129                message: Object(external_this_wp_i18n_["__"])('This file exceeds the maximum upload size for this site.'),
1130                file: _mediaFile
1131              });
1132              return _context.abrupt("continue", 29);
1133  
1134            case 23:
1135              if (!(_mediaFile.size <= 0)) {
1136                _context.next = 26;
1137                break;
1138              }
1139  
1140              triggerError({
1141                code: 'EMPTY_FILE',
1142                message: Object(external_this_wp_i18n_["__"])('This file is empty.'),
1143                file: _mediaFile
1144              });
1145              return _context.abrupt("continue", 29);
1146  
1147            case 26:
1148              validFiles.push(_mediaFile); // Set temporary URL to create placeholder media file, this is replaced
1149              // with final file from media gallery when upload is `done` below
1150  
1151              filesSet.push({
1152                url: Object(external_this_wp_blob_["createBlobURL"])(_mediaFile)
1153              });
1154              onFileChange(filesSet);
1155  
1156            case 29:
1157              _context.next = 12;
1158              break;
1159  
1160            case 31:
1161              _context.next = 36;
1162              break;
1163  
1164            case 33:
1165              _context.prev = 33;
1166              _context.t0 = _context["catch"](10);
1167  
1168              _iterator.e(_context.t0);
1169  
1170            case 36:
1171              _context.prev = 36;
1172  
1173              _iterator.f();
1174  
1175              return _context.finish(36);
1176  
1177            case 39:
1178              idx = 0;
1179  
1180            case 40:
1181              if (!(idx < validFiles.length)) {
1182                _context.next = 59;
1183                break;
1184              }
1185  
1186              mediaFile = validFiles[idx];
1187              _context.prev = 42;
1188              _context.next = 45;
1189              return createMediaFromFile(mediaFile, additionalData);
1190  
1191            case 45:
1192              savedMedia = _context.sent;
1193              mediaObject = _objectSpread({}, Object(external_this_lodash_["omit"])(savedMedia, ['alt_text', 'source_url']), {
1194                alt: savedMedia.alt_text,
1195                caption: Object(external_this_lodash_["get"])(savedMedia, ['caption', 'raw'], ''),
1196                title: savedMedia.title.raw,
1197                url: savedMedia.source_url
1198              });
1199              setAndUpdateFiles(idx, mediaObject);
1200              _context.next = 56;
1201              break;
1202  
1203            case 50:
1204              _context.prev = 50;
1205              _context.t1 = _context["catch"](42);
1206              // Reset to empty on failure.
1207              setAndUpdateFiles(idx, null);
1208              message = void 0;
1209  
1210              if (Object(external_this_lodash_["has"])(_context.t1, ['message'])) {
1211                message = Object(external_this_lodash_["get"])(_context.t1, ['message']);
1212              } else {
1213                message = Object(external_this_wp_i18n_["sprintf"])( // translators: %s: file name
1214                Object(external_this_wp_i18n_["__"])('Error while uploading file %s to the media library.'), mediaFile.name);
1215              }
1216  
1217              onError({
1218                code: 'GENERAL',
1219                message: message,
1220                file: mediaFile
1221              });
1222  
1223            case 56:
1224              ++idx;
1225              _context.next = 40;
1226              break;
1227  
1228            case 59:
1229            case "end":
1230              return _context.stop();
1231          }
1232        }
1233      }, _callee, null, [[10, 33, 36, 39], [42, 50]]);
1234    }));
1235    return _uploadMedia.apply(this, arguments);
1236  }
1237  
1238  function createMediaFromFile(file, additionalData) {
1239    // Create upload payload
1240    var data = new window.FormData();
1241    data.append('file', file, file.name || file.type.replace('/', '.'));
1242    Object(external_this_lodash_["forEach"])(additionalData, function (value, key) {
1243      return data.append(key, value);
1244    });
1245    return external_this_wp_apiFetch_default()({
1246      path: '/wp/v2/media',
1247      body: data,
1248      method: 'POST'
1249    });
1250  }
1251  
1252  // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/index.js
1253  
1254  
1255  // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/index.js
1256  
1257  
1258  
1259  
1260  /***/ }),
1261  
1262  /***/ 5:
1263  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1264  
1265  "use strict";
1266  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
1267  function _defineProperty(obj, key, value) {
1268    if (key in obj) {
1269      Object.defineProperty(obj, key, {
1270        value: value,
1271        enumerable: true,
1272        configurable: true,
1273        writable: true
1274      });
1275    } else {
1276      obj[key] = value;
1277    }
1278  
1279    return obj;
1280  }
1281  
1282  /***/ }),
1283  
1284  /***/ 50:
1285  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1286  
1287  "use strict";
1288  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
1289  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1290    try {
1291      var info = gen[key](arg);
1292      var value = info.value;
1293    } catch (error) {
1294      reject(error);
1295      return;
1296    }
1297  
1298    if (info.done) {
1299      resolve(value);
1300    } else {
1301      Promise.resolve(value).then(_next, _throw);
1302    }
1303  }
1304  
1305  function _asyncToGenerator(fn) {
1306    return function () {
1307      var self = this,
1308          args = arguments;
1309      return new Promise(function (resolve, reject) {
1310        var gen = fn.apply(self, args);
1311  
1312        function _next(value) {
1313          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1314        }
1315  
1316        function _throw(err) {
1317          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1318        }
1319  
1320        _next(undefined);
1321      });
1322    };
1323  }
1324  
1325  /***/ })
1326  
1327  /******/ });


Generated: Thu Oct 1 01:00:03 2020 Cross-referenced by PHPXref 0.7.1