wp/wp-includes/js/dist/media-utils.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 this["wp"] = this["wp"] || {}; this["wp"]["mediaUtils"] =
     1 /******/ (function() { // webpackBootstrap
     2 /******/ (function(modules) { // webpackBootstrap
     2 /******/ 	"use strict";
     3 /******/ 	// The module cache
     3 /******/ 	// The require scope
     4 /******/ 	var installedModules = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/
     5 /******/ 	
     6 /******/ 	// The require function
     6 /************************************************************************/
     7 /******/ 	function __webpack_require__(moduleId) {
     7 /******/ 	/* webpack/runtime/compat get default export */
     8 /******/
     8 /******/ 	!function() {
     9 /******/ 		// Check if module is in cache
     9 /******/ 		// getDefaultExport function for compatibility with non-harmony modules
    10 /******/ 		if(installedModules[moduleId]) {
    10 /******/ 		__webpack_require__.n = function(module) {
    11 /******/ 			return installedModules[moduleId].exports;
    11 /******/ 			var getter = module && module.__esModule ?
    12 /******/ 		}
    12 /******/ 				function() { return module['default']; } :
    13 /******/ 		// Create a new module (and put it into the cache)
    13 /******/ 				function() { return module; };
    14 /******/ 		var module = installedModules[moduleId] = {
    14 /******/ 			__webpack_require__.d(getter, { a: getter });
    15 /******/ 			i: moduleId,
    15 /******/ 			return getter;
    16 /******/ 			l: false,
       
    17 /******/ 			exports: {}
       
    18 /******/ 		};
    16 /******/ 		};
    19 /******/
    17 /******/ 	}();
    20 /******/ 		// Execute the module function
    18 /******/ 	
    21 /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    19 /******/ 	/* webpack/runtime/define property getters */
    22 /******/
    20 /******/ 	!function() {
    23 /******/ 		// Flag the module as loaded
    21 /******/ 		// define getter functions for harmony exports
    24 /******/ 		module.l = true;
    22 /******/ 		__webpack_require__.d = function(exports, definition) {
    25 /******/
    23 /******/ 			for(var key in definition) {
    26 /******/ 		// Return the exports of the module
    24 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    27 /******/ 		return module.exports;
    25 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    28 /******/ 	}
    26 /******/ 				}
    29 /******/
    27 /******/ 			}
    30 /******/
    28 /******/ 		};
    31 /******/ 	// expose the modules object (__webpack_modules__)
    29 /******/ 	}();
    32 /******/ 	__webpack_require__.m = modules;
    30 /******/ 	
    33 /******/
    31 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    34 /******/ 	// expose the module cache
    32 /******/ 	!function() {
    35 /******/ 	__webpack_require__.c = installedModules;
    33 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    36 /******/
    34 /******/ 	}();
    37 /******/ 	// define getter function for harmony exports
    35 /******/ 	
    38 /******/ 	__webpack_require__.d = function(exports, name, getter) {
    36 /******/ 	/* webpack/runtime/make namespace object */
    39 /******/ 		if(!__webpack_require__.o(exports, name)) {
    37 /******/ 	!function() {
    40 /******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
    38 /******/ 		// define __esModule on exports
    41 /******/ 		}
    39 /******/ 		__webpack_require__.r = function(exports) {
    42 /******/ 	};
    40 /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    43 /******/
    41 /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    44 /******/ 	// define __esModule on exports
    42 /******/ 			}
    45 /******/ 	__webpack_require__.r = function(exports) {
    43 /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    46 /******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    44 /******/ 		};
    47 /******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    45 /******/ 	}();
    48 /******/ 		}
    46 /******/ 	
    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 = "Lb+8");
       
    86 /******/ })
       
    87 /************************************************************************/
    47 /************************************************************************/
    88 /******/ ({
    48 var __webpack_exports__ = {};
    89 
       
    90 /***/ "GRId":
       
    91 /***/ (function(module, exports) {
       
    92 
       
    93 (function() { module.exports = window["wp"]["element"]; }());
       
    94 
       
    95 /***/ }),
       
    96 
       
    97 /***/ "Lb+8":
       
    98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
    99 
       
   100 "use strict";
       
   101 // ESM COMPAT FLAG
    49 // ESM COMPAT FLAG
   102 __webpack_require__.r(__webpack_exports__);
    50 __webpack_require__.r(__webpack_exports__);
   103 
    51 
   104 // EXPORTS
    52 // EXPORTS
   105 __webpack_require__.d(__webpack_exports__, "MediaUpload", function() { return /* reexport */ media_upload; });
    53 __webpack_require__.d(__webpack_exports__, {
   106 __webpack_require__.d(__webpack_exports__, "uploadMedia", function() { return /* reexport */ uploadMedia; });
    54   "MediaUpload": function() { return /* reexport */ media_upload; },
   107 
    55   "uploadMedia": function() { return /* reexport */ uploadMedia; }
   108 // EXTERNAL MODULE: external "lodash"
    56 });
   109 var external_lodash_ = __webpack_require__("YLtl");
    57 
   110 
    58 ;// CONCATENATED MODULE: external "lodash"
   111 // EXTERNAL MODULE: external ["wp","element"]
    59 var external_lodash_namespaceObject = window["lodash"];
   112 var external_wp_element_ = __webpack_require__("GRId");
    60 ;// CONCATENATED MODULE: external ["wp","element"]
   113 
    61 var external_wp_element_namespaceObject = window["wp"]["element"];
   114 // EXTERNAL MODULE: external ["wp","i18n"]
    62 ;// CONCATENATED MODULE: external ["wp","i18n"]
   115 var external_wp_i18n_ = __webpack_require__("l3Sj");
    63 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
   116 
    64 ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/media-upload/index.js
   117 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/media-upload/index.js
       
   118 /**
    65 /**
   119  * External dependencies
    66  * External dependencies
   120  */
    67  */
   121 
    68 
   122 /**
    69 /**
   264         priority: 40,
   211         priority: 40,
   265         toolbar: 'main-gallery',
   212         toolbar: 'main-gallery',
   266         filterable: 'uploaded',
   213         filterable: 'uploaded',
   267         multiple: 'add',
   214         multiple: 'add',
   268         editable: false,
   215         editable: false,
   269         library: wp.media.query(Object(external_lodash_["defaults"])({
   216         library: wp.media.query((0,external_lodash_namespaceObject.defaults)({
   270           type: 'image'
   217           type: 'image'
   271         }, this.options.library))
   218         }, this.options.library))
   272       }), new wp.media.controller.EditImage({
   219       }), new wp.media.controller.EditImage({
   273         model: this.options.editImage
   220         model: this.options.editImage
   274       }), new wp.media.controller.GalleryEdit({
   221       }), new wp.media.controller.GalleryEdit({
   278         displaySettings: false,
   225         displaySettings: false,
   279         multiple: true
   226         multiple: true
   280       }), new wp.media.controller.GalleryAdd()]);
   227       }), new wp.media.controller.GalleryAdd()]);
   281     }
   228     }
   282   });
   229   });
   283 }; // the media library image object contains numerous attributes
   230 }; // The media library image object contains numerous attributes
   284 // we only need this set to display the image in the library
   231 // we only need this set to display the image in the library.
   285 
   232 
   286 
   233 
   287 const slimImageObject = img => {
   234 const slimImageObject = img => {
   288   const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
   235   const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
   289   return Object(external_lodash_["pick"])(img, attrSet);
   236   return (0,external_lodash_namespaceObject.pick)(img, attrSet);
   290 };
   237 };
   291 
   238 
   292 const getAttachmentsCollection = ids => {
   239 const getAttachmentsCollection = ids => {
   293   return wp.media.query({
   240   return wp.media.query({
   294     order: 'ASC',
   241     order: 'ASC',
   298     query: true,
   245     query: true,
   299     type: 'image'
   246     type: 'image'
   300   });
   247   });
   301 };
   248 };
   302 
   249 
   303 class media_upload_MediaUpload extends external_wp_element_["Component"] {
   250 class MediaUpload extends external_wp_element_namespaceObject.Component {
   304   constructor({
   251   constructor(_ref) {
   305     allowedTypes,
   252     let {
   306     gallery = false,
   253       allowedTypes,
   307     unstableFeaturedImageFlow = false,
   254       gallery = false,
   308     modalClass,
   255       unstableFeaturedImageFlow = false,
   309     multiple = false,
   256       modalClass,
   310     title = Object(external_wp_i18n_["__"])('Select or Upload Media')
   257       multiple = false,
   311   }) {
   258       title = (0,external_wp_i18n_namespaceObject.__)('Select or Upload Media')
       
   259     } = _ref;
   312     super(...arguments);
   260     super(...arguments);
   313     this.openModal = this.openModal.bind(this);
   261     this.openModal = this.openModal.bind(this);
   314     this.onOpen = this.onOpen.bind(this);
   262     this.onOpen = this.onOpen.bind(this);
   315     this.onSelect = this.onSelect.bind(this);
   263     this.onSelect = this.onSelect.bind(this);
   316     this.onUpdate = this.onUpdate.bind(this);
   264     this.onUpdate = this.onUpdate.bind(this);
   452 
   400 
   453   onSelect() {
   401   onSelect() {
   454     const {
   402     const {
   455       onSelect,
   403       onSelect,
   456       multiple = false
   404       multiple = false
   457     } = this.props; // Get media attachment details from the frame state
   405     } = this.props; // Get media attachment details from the frame state.
   458 
   406 
   459     const attachment = this.frame.state().get('selection').toJSON();
   407     const attachment = this.frame.state().get('selection').toJSON();
   460     onSelect(multiple ? attachment : attachment[0]);
   408     onSelect(multiple ? attachment : attachment[0]);
   461   }
   409   }
   462 
   410 
   470 
   418 
   471     if (!hasMedia) {
   419     if (!hasMedia) {
   472       return;
   420       return;
   473     }
   421     }
   474 
   422 
   475     if (!this.props.gallery) {
   423     const isGallery = this.props.gallery;
   476       const selection = this.frame.state().get('selection');
   424     const selection = this.frame.state().get('selection');
   477       Object(external_lodash_["castArray"])(this.props.value).forEach(id => {
   425 
       
   426     if (!isGallery) {
       
   427       (0,external_lodash_namespaceObject.castArray)(this.props.value).forEach(id => {
   478         selection.add(wp.media.attachment(id));
   428         selection.add(wp.media.attachment(id));
   479       });
   429       });
   480     } // load the images so they are available in the media modal.
   430     } // Load the images so they are available in the media modal.
   481 
   431 
   482 
   432 
   483     getAttachmentsCollection(Object(external_lodash_["castArray"])(this.props.value)).more();
   433     const attachments = getAttachmentsCollection((0,external_lodash_namespaceObject.castArray)(this.props.value)); // Once attachments are loaded, set the current selection.
       
   434 
       
   435     attachments.more().done(function () {
       
   436       var _attachments$models;
       
   437 
       
   438       if (isGallery && attachments !== null && attachments !== void 0 && (_attachments$models = attachments.models) !== null && _attachments$models !== void 0 && _attachments$models.length) {
       
   439         selection.add(attachments.models);
       
   440       }
       
   441     });
   484   }
   442   }
   485 
   443 
   486   onClose() {
   444   onClose() {
   487     const {
   445     const {
   488       onClose
   446       onClose
   495 
   453 
   496   updateCollection() {
   454   updateCollection() {
   497     const frameContent = this.frame.content.get();
   455     const frameContent = this.frame.content.get();
   498 
   456 
   499     if (frameContent && frameContent.collection) {
   457     if (frameContent && frameContent.collection) {
   500       const collection = frameContent.collection; // clean all attachments we have in memory.
   458       const collection = frameContent.collection; // Clean all attachments we have in memory.
   501 
   459 
   502       collection.toArray().forEach(model => model.trigger('destroy', model)); // reset has more flag, if library had small amount of items all items may have been loaded before.
   460       collection.toArray().forEach(model => model.trigger('destroy', model)); // Reset has more flag, if library had small amount of items all items may have been loaded before.
   503 
   461 
   504       collection.mirroring._hasMore = true; // request items
   462       collection.mirroring._hasMore = true; // Request items.
   505 
   463 
   506       collection.more();
   464       collection.more();
   507     }
   465     }
   508   }
   466   }
   509 
   467 
   521     });
   479     });
   522   }
   480   }
   523 
   481 
   524 }
   482 }
   525 
   483 
   526 /* harmony default export */ var media_upload = (media_upload_MediaUpload);
   484 /* harmony default export */ var media_upload = (MediaUpload);
   527 
   485 
   528 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js
   486 ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js
   529 
   487 
   530 
   488 
   531 // EXTERNAL MODULE: external ["wp","apiFetch"]
   489 ;// CONCATENATED MODULE: external ["wp","apiFetch"]
   532 var external_wp_apiFetch_ = __webpack_require__("ywyh");
   490 var external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
   533 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_);
   491 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
   534 
   492 ;// CONCATENATED MODULE: external ["wp","blob"]
   535 // EXTERNAL MODULE: external ["wp","blob"]
   493 var external_wp_blob_namespaceObject = window["wp"]["blob"];
   536 var external_wp_blob_ = __webpack_require__("xTGt");
   494 ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js
   537 
       
   538 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js
       
   539 
   495 
   540 
   496 
   541 /**
   497 /**
   542  * External dependencies
   498  * External dependencies
   543  */
   499  */
   566 function getMimeTypesArray(wpMimeTypesObject) {
   522 function getMimeTypesArray(wpMimeTypesObject) {
   567   if (!wpMimeTypesObject) {
   523   if (!wpMimeTypesObject) {
   568     return wpMimeTypesObject;
   524     return wpMimeTypesObject;
   569   }
   525   }
   570 
   526 
   571   return Object(external_lodash_["flatMap"])(wpMimeTypesObject, (mime, extensionsString) => {
   527   return (0,external_lodash_namespaceObject.flatMap)(wpMimeTypesObject, (mime, extensionsString) => {
   572     const [type] = mime.split('/');
   528     const [type] = mime.split('/');
   573     const extensions = extensionsString.split('|');
   529     const extensions = extensionsString.split('|');
   574     return [mime, ...Object(external_lodash_["map"])(extensions, extension => `${type}/${extension}`)];
   530     return [mime, ...(0,external_lodash_namespaceObject.map)(extensions, extension => `${type}/${extension}`)];
   575   });
   531   });
   576 }
   532 }
   577 /**
   533 /**
   578  *	Media Upload is used by audio, image, gallery, video, and file blocks to
   534  *	Media Upload is used by audio, image, gallery, video, and file blocks to
   579  *	handle uploading a media file when a file upload button is activated.
   535  *	handle uploading a media file when a file upload button is activated.
   580  *
   536  *
   581  *	TODO: future enhancement to add an upload indicator.
   537  *	TODO: future enhancement to add an upload indicator.
   582  *
   538  *
   583  * @param   {Object}   $0                    Parameters object passed to the function.
   539  * @param {Object}   $0                    Parameters object passed to the function.
   584  * @param   {?Array}   $0.allowedTypes       Array with the types of media that can be uploaded, if unset all types are allowed.
   540  * @param {?Array}   $0.allowedTypes       Array with the types of media that can be uploaded, if unset all types are allowed.
   585  * @param   {?Object}  $0.additionalData     Additional data to include in the request.
   541  * @param {?Object}  $0.additionalData     Additional data to include in the request.
   586  * @param   {Array}    $0.filesList          List of files.
   542  * @param {Array}    $0.filesList          List of files.
   587  * @param   {?number}  $0.maxUploadFileSize  Maximum upload size in bytes allowed for the site.
   543  * @param {?number}  $0.maxUploadFileSize  Maximum upload size in bytes allowed for the site.
   588  * @param   {Function} $0.onError            Function called when an error happens.
   544  * @param {Function} $0.onError            Function called when an error happens.
   589  * @param   {Function} $0.onFileChange       Function called each time a file or a temporary representation of the file is available.
   545  * @param {Function} $0.onFileChange       Function called each time a file or a temporary representation of the file is available.
   590  * @param   {?Object}  $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
   546  * @param {?Object}  $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
   591  */
   547  */
   592 
   548 
   593 async function uploadMedia({
   549 async function uploadMedia(_ref) {
   594   allowedTypes,
   550   let {
   595   additionalData = {},
   551     allowedTypes,
   596   filesList,
   552     additionalData = {},
   597   maxUploadFileSize,
   553     filesList,
   598   onError = external_lodash_["noop"],
   554     maxUploadFileSize,
   599   onFileChange,
   555     onError = external_lodash_namespaceObject.noop,
   600   wpAllowedMimeTypes = null
   556     onFileChange,
   601 }) {
   557     wpAllowedMimeTypes = null
   602   // Cast filesList to array
   558   } = _ref;
       
   559   // Cast filesList to array.
   603   const files = [...filesList];
   560   const files = [...filesList];
   604   const filesSet = [];
   561   const filesSet = [];
   605 
   562 
   606   const setAndUpdateFiles = (idx, value) => {
   563   const setAndUpdateFiles = (idx, value) => {
   607     Object(external_wp_blob_["revokeBlobURL"])(Object(external_lodash_["get"])(filesSet, [idx, 'url']));
   564     (0,external_wp_blob_namespaceObject.revokeBlobURL)((0,external_lodash_namespaceObject.get)(filesSet, [idx, 'url']));
   608     filesSet[idx] = value;
   565     filesSet[idx] = value;
   609     onFileChange(Object(external_lodash_["compact"])(filesSet));
   566     onFileChange((0,external_lodash_namespaceObject.compact)(filesSet));
   610   }; // Allowed type specified by consumer
   567   }; // Allowed type specified by consumer.
   611 
   568 
   612 
   569 
   613   const isAllowedType = fileType => {
   570   const isAllowedType = fileType => {
   614     if (!allowedTypes) {
   571     if (!allowedTypes) {
   615       return true;
   572       return true;
   616     }
   573     }
   617 
   574 
   618     return Object(external_lodash_["some"])(allowedTypes, allowedType => {
   575     return (0,external_lodash_namespaceObject.some)(allowedTypes, allowedType => {
   619       // If a complete mimetype is specified verify if it matches exactly the mime type of the file.
   576       // If a complete mimetype is specified verify if it matches exactly the mime type of the file.
   620       if (Object(external_lodash_["includes"])(allowedType, '/')) {
   577       if ((0,external_lodash_namespaceObject.includes)(allowedType, '/')) {
   621         return allowedType === fileType;
   578         return allowedType === fileType;
   622       } // Otherwise a general mime type is used and we should verify if the file mimetype starts with it.
   579       } // Otherwise a general mime type is used and we should verify if the file mimetype starts with it.
   623 
   580 
   624 
   581 
   625       return Object(external_lodash_["startsWith"])(fileType, `${allowedType}/`);
   582       return (0,external_lodash_namespaceObject.startsWith)(fileType, `${allowedType}/`);
   626     });
   583     });
   627   }; // Allowed types for the current WP_User
   584   }; // Allowed types for the current WP_User.
   628 
   585 
   629 
   586 
   630   const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
   587   const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
   631 
   588 
   632   const isAllowedMimeTypeForUser = fileType => {
   589   const isAllowedMimeTypeForUser = fileType => {
   633     return Object(external_lodash_["includes"])(allowedMimeTypesForUser, fileType);
   590     return (0,external_lodash_namespaceObject.includes)(allowedMimeTypesForUser, fileType);
   634   }; // Build the error message including the filename
   591   }; // Build the error message including the filename.
   635 
   592 
   636 
   593 
   637   const triggerError = error => {
   594   const triggerError = error => {
   638     error.message = [Object(external_wp_element_["createElement"])("strong", {
   595     error.message = [(0,external_wp_element_namespaceObject.createElement)("strong", {
   639       key: "filename"
   596       key: "filename"
   640     }, error.file.name), ': ', error.message];
   597     }, error.file.name), ': ', error.message];
   641     onError(error);
   598     onError(error);
   642   };
   599   };
   643 
   600 
   647     // Verify if user is allowed to upload this mime type.
   604     // Verify if user is allowed to upload this mime type.
   648     // Defer to the server when type not detected.
   605     // Defer to the server when type not detected.
   649     if (allowedMimeTypesForUser && mediaFile.type && !isAllowedMimeTypeForUser(mediaFile.type)) {
   606     if (allowedMimeTypesForUser && mediaFile.type && !isAllowedMimeTypeForUser(mediaFile.type)) {
   650       triggerError({
   607       triggerError({
   651         code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
   608         code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
   652         message: Object(external_wp_i18n_["__"])('Sorry, this file type is not permitted for security reasons.'),
   609         message: (0,external_wp_i18n_namespaceObject.__)('Sorry, you are not allowed to upload this file type.'),
   653         file: mediaFile
   610         file: mediaFile
   654       });
   611       });
   655       continue;
   612       continue;
   656     } // Check if the block supports this mime type.
   613     } // Check if the block supports this mime type.
   657     // Defer to the server when type not detected.
   614     // Defer to the server when type not detected.
   658 
   615 
   659 
   616 
   660     if (mediaFile.type && !isAllowedType(mediaFile.type)) {
   617     if (mediaFile.type && !isAllowedType(mediaFile.type)) {
   661       triggerError({
   618       triggerError({
   662         code: 'MIME_TYPE_NOT_SUPPORTED',
   619         code: 'MIME_TYPE_NOT_SUPPORTED',
   663         message: Object(external_wp_i18n_["__"])('Sorry, this file type is not supported here.'),
   620         message: (0,external_wp_i18n_namespaceObject.__)('Sorry, this file type is not supported here.'),
   664         file: mediaFile
   621         file: mediaFile
   665       });
   622       });
   666       continue;
   623       continue;
   667     } // verify if file is greater than the maximum file upload size allowed for the site.
   624     } // Verify if file is greater than the maximum file upload size allowed for the site.
   668 
   625 
   669 
   626 
   670     if (maxUploadFileSize && mediaFile.size > maxUploadFileSize) {
   627     if (maxUploadFileSize && mediaFile.size > maxUploadFileSize) {
   671       triggerError({
   628       triggerError({
   672         code: 'SIZE_ABOVE_LIMIT',
   629         code: 'SIZE_ABOVE_LIMIT',
   673         message: Object(external_wp_i18n_["__"])('This file exceeds the maximum upload size for this site.'),
   630         message: (0,external_wp_i18n_namespaceObject.__)('This file exceeds the maximum upload size for this site.'),
   674         file: mediaFile
   631         file: mediaFile
   675       });
   632       });
   676       continue;
   633       continue;
   677     } // Don't allow empty files to be uploaded.
   634     } // Don't allow empty files to be uploaded.
   678 
   635 
   679 
   636 
   680     if (mediaFile.size <= 0) {
   637     if (mediaFile.size <= 0) {
   681       triggerError({
   638       triggerError({
   682         code: 'EMPTY_FILE',
   639         code: 'EMPTY_FILE',
   683         message: Object(external_wp_i18n_["__"])('This file is empty.'),
   640         message: (0,external_wp_i18n_namespaceObject.__)('This file is empty.'),
   684         file: mediaFile
   641         file: mediaFile
   685       });
   642       });
   686       continue;
   643       continue;
   687     }
   644     }
   688 
   645 
   689     validFiles.push(mediaFile); // Set temporary URL to create placeholder media file, this is replaced
   646     validFiles.push(mediaFile); // Set temporary URL to create placeholder media file, this is replaced
   690     // with final file from media gallery when upload is `done` below
   647     // with final file from media gallery when upload is `done` below.
   691 
   648 
   692     filesSet.push({
   649     filesSet.push({
   693       url: Object(external_wp_blob_["createBlobURL"])(mediaFile)
   650       url: (0,external_wp_blob_namespaceObject.createBlobURL)(mediaFile)
   694     });
   651     });
   695     onFileChange(filesSet);
   652     onFileChange(filesSet);
   696   }
   653   }
   697 
   654 
   698   for (let idx = 0; idx < validFiles.length; ++idx) {
   655   for (let idx = 0; idx < validFiles.length; ++idx) {
   699     const mediaFile = validFiles[idx];
   656     const mediaFile = validFiles[idx];
   700 
   657 
   701     try {
   658     try {
   702       const savedMedia = await createMediaFromFile(mediaFile, additionalData);
   659       const savedMedia = await createMediaFromFile(mediaFile, additionalData);
   703       const mediaObject = { ...Object(external_lodash_["omit"])(savedMedia, ['alt_text', 'source_url']),
   660       const mediaObject = { ...(0,external_lodash_namespaceObject.omit)(savedMedia, ['alt_text', 'source_url']),
   704         alt: savedMedia.alt_text,
   661         alt: savedMedia.alt_text,
   705         caption: Object(external_lodash_["get"])(savedMedia, ['caption', 'raw'], ''),
   662         caption: (0,external_lodash_namespaceObject.get)(savedMedia, ['caption', 'raw'], ''),
   706         title: savedMedia.title.raw,
   663         title: savedMedia.title.raw,
   707         url: savedMedia.source_url
   664         url: savedMedia.source_url
   708       };
   665       };
   709       setAndUpdateFiles(idx, mediaObject);
   666       setAndUpdateFiles(idx, mediaObject);
   710     } catch (error) {
   667     } catch (error) {
   711       // Reset to empty on failure.
   668       // Reset to empty on failure.
   712       setAndUpdateFiles(idx, null);
   669       setAndUpdateFiles(idx, null);
   713       let message;
   670       let message;
   714 
   671 
   715       if (Object(external_lodash_["has"])(error, ['message'])) {
   672       if ((0,external_lodash_namespaceObject.has)(error, ['message'])) {
   716         message = Object(external_lodash_["get"])(error, ['message']);
   673         message = (0,external_lodash_namespaceObject.get)(error, ['message']);
   717       } else {
   674       } else {
   718         message = Object(external_wp_i18n_["sprintf"])( // translators: %s: file name
   675         message = (0,external_wp_i18n_namespaceObject.sprintf)( // translators: %s: file name
   719         Object(external_wp_i18n_["__"])('Error while uploading file %s to the media library.'), mediaFile.name);
   676         (0,external_wp_i18n_namespaceObject.__)('Error while uploading file %s to the media library.'), mediaFile.name);
   720       }
   677       }
   721 
   678 
   722       onError({
   679       onError({
   723         code: 'GENERAL',
   680         code: 'GENERAL',
   724         message,
   681         message,
   733  *
   690  *
   734  * @return {Promise} Media Object Promise.
   691  * @return {Promise} Media Object Promise.
   735  */
   692  */
   736 
   693 
   737 function createMediaFromFile(file, additionalData) {
   694 function createMediaFromFile(file, additionalData) {
   738   // Create upload payload
   695   // Create upload payload.
   739   const data = new window.FormData();
   696   const data = new window.FormData();
   740   data.append('file', file, file.name || file.type.replace('/', '.'));
   697   data.append('file', file, file.name || file.type.replace('/', '.'));
   741   Object(external_lodash_["forEach"])(additionalData, (value, key) => data.append(key, value));
   698   (0,external_lodash_namespaceObject.forEach)(additionalData, (value, key) => data.append(key, value));
   742   return external_wp_apiFetch_default()({
   699   return external_wp_apiFetch_default()({
   743     path: '/wp/v2/media',
   700     path: '/wp/v2/media',
   744     body: data,
   701     body: data,
   745     method: 'POST'
   702     method: 'POST'
   746   });
   703   });
   747 }
   704 }
   748 
   705 
   749 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/index.js
   706 ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/index.js
   750 
   707 
   751 
   708 
   752 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/index.js
   709 ;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/index.js
   753 
   710 
   754 
   711 
   755 
   712 
   756 
   713 (window.wp = window.wp || {}).mediaUtils = __webpack_exports__;
   757 /***/ }),
   714 /******/ })()
   758 
   715 ;
   759 /***/ "YLtl":
       
   760 /***/ (function(module, exports) {
       
   761 
       
   762 (function() { module.exports = window["lodash"]; }());
       
   763 
       
   764 /***/ }),
       
   765 
       
   766 /***/ "l3Sj":
       
   767 /***/ (function(module, exports) {
       
   768 
       
   769 (function() { module.exports = window["wp"]["i18n"]; }());
       
   770 
       
   771 /***/ }),
       
   772 
       
   773 /***/ "xTGt":
       
   774 /***/ (function(module, exports) {
       
   775 
       
   776 (function() { module.exports = window["wp"]["blob"]; }());
       
   777 
       
   778 /***/ }),
       
   779 
       
   780 /***/ "ywyh":
       
   781 /***/ (function(module, exports) {
       
   782 
       
   783 (function() { module.exports = window["wp"]["apiFetch"]; }());
       
   784 
       
   785 /***/ })
       
   786 
       
   787 /******/ });