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


Generated: Sat Jan 25 01:00:03 2020 Cross-referenced by PHPXref 0.7.1