80 /******/ // __webpack_public_path__ |
80 /******/ // __webpack_public_path__ |
81 /******/ __webpack_require__.p = ""; |
81 /******/ __webpack_require__.p = ""; |
82 /******/ |
82 /******/ |
83 /******/ |
83 /******/ |
84 /******/ // Load entry module and return exports |
84 /******/ // Load entry module and return exports |
85 /******/ return __webpack_require__(__webpack_require__.s = 460); |
85 /******/ return __webpack_require__(__webpack_require__.s = "Lb+8"); |
86 /******/ }) |
86 /******/ }) |
87 /************************************************************************/ |
87 /************************************************************************/ |
88 /******/ ({ |
88 /******/ ({ |
89 |
89 |
90 /***/ 0: |
90 /***/ "GRId": |
91 /***/ (function(module, exports) { |
91 /***/ (function(module, exports) { |
92 |
92 |
93 (function() { module.exports = this["wp"]["element"]; }()); |
93 (function() { module.exports = window["wp"]["element"]; }()); |
94 |
94 |
95 /***/ }), |
95 /***/ }), |
96 |
96 |
97 /***/ 1: |
97 /***/ "Lb+8": |
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 /***/ 460: |
|
436 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
98 /***/ (function(module, __webpack_exports__, __webpack_require__) { |
437 |
99 |
438 "use strict"; |
100 "use strict"; |
439 // ESM COMPAT FLAG |
101 // ESM COMPAT FLAG |
440 __webpack_require__.r(__webpack_exports__); |
102 __webpack_require__.r(__webpack_exports__); |
441 |
103 |
442 // EXPORTS |
104 // EXPORTS |
443 __webpack_require__.d(__webpack_exports__, "MediaUpload", function() { return /* reexport */ media_upload; }); |
105 __webpack_require__.d(__webpack_exports__, "MediaUpload", function() { return /* reexport */ media_upload; }); |
444 __webpack_require__.d(__webpack_exports__, "uploadMedia", function() { return /* reexport */ uploadMedia; }); |
106 __webpack_require__.d(__webpack_exports__, "uploadMedia", function() { return /* reexport */ uploadMedia; }); |
445 |
107 |
446 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/classCallCheck.js |
108 // EXTERNAL MODULE: external "lodash" |
447 var classCallCheck = __webpack_require__(20); |
109 var external_lodash_ = __webpack_require__("YLtl"); |
448 |
110 |
449 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/createClass.js |
111 // EXTERNAL MODULE: external ["wp","element"] |
450 var createClass = __webpack_require__(19); |
112 var external_wp_element_ = __webpack_require__("GRId"); |
451 |
113 |
452 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js |
114 // EXTERNAL MODULE: external ["wp","i18n"] |
453 var assertThisInitialized = __webpack_require__(12); |
115 var external_wp_i18n_ = __webpack_require__("l3Sj"); |
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 |
116 |
473 // 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 |
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 /** |
118 /** |
486 * External dependencies |
119 * External dependencies |
487 */ |
120 */ |
488 |
121 |
489 /** |
122 /** |
490 * WordPress dependencies |
123 * WordPress dependencies |
491 */ |
124 */ |
492 |
125 |
493 |
126 |
494 |
127 |
495 var _window = window, |
128 const { |
496 wp = _window.wp; |
129 wp |
497 var DEFAULT_EMPTY_GALLERY = []; |
130 } = window; |
|
131 const DEFAULT_EMPTY_GALLERY = []; |
498 /** |
132 /** |
499 * Prepares the Featured Image toolbars and frames. |
133 * Prepares the Featured Image toolbars and frames. |
500 * |
134 * |
501 * @return {wp.media.view.MediaFrame.Select} The default media workflow. |
135 * @return {wp.media.view.MediaFrame.Select} The default media workflow. |
502 */ |
136 */ |
503 |
137 |
504 var getFeaturedImageMediaFrame = function getFeaturedImageMediaFrame() { |
138 const getFeaturedImageMediaFrame = () => { |
505 return wp.media.view.MediaFrame.Select.extend({ |
139 return wp.media.view.MediaFrame.Select.extend({ |
506 /** |
140 /** |
507 * Enables the Set Featured Image Button. |
141 * Enables the Set Featured Image Button. |
508 * |
142 * |
509 * @param {Object} toolbar toolbar for featured image state |
143 * @param {Object} toolbar toolbar for featured image state |
510 * @return {void} |
144 * @return {void} |
511 */ |
145 */ |
512 featuredImageToolbar: function featuredImageToolbar(toolbar) { |
146 featuredImageToolbar(toolbar) { |
513 this.createSelectToolbar(toolbar, { |
147 this.createSelectToolbar(toolbar, { |
514 text: wp.media.view.l10n.setFeaturedImage, |
148 text: wp.media.view.l10n.setFeaturedImage, |
515 state: this.options.state |
149 state: this.options.state |
516 }); |
150 }); |
517 }, |
151 }, |
647 }); |
282 }); |
648 }; // the media library image object contains numerous attributes |
283 }; // the media library image object contains numerous attributes |
649 // we only need this set to display the image in the library |
284 // we only need this set to display the image in the library |
650 |
285 |
651 |
286 |
652 var media_upload_slimImageObject = function slimImageObject(img) { |
287 const slimImageObject = img => { |
653 var attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption']; |
288 const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption']; |
654 return Object(external_this_lodash_["pick"])(img, attrSet); |
289 return Object(external_lodash_["pick"])(img, attrSet); |
655 }; |
290 }; |
656 |
291 |
657 var getAttachmentsCollection = function getAttachmentsCollection(ids) { |
292 const getAttachmentsCollection = ids => { |
658 return wp.media.query({ |
293 return wp.media.query({ |
659 order: 'ASC', |
294 order: 'ASC', |
660 orderby: 'post__in', |
295 orderby: 'post__in', |
661 post__in: ids, |
296 post__in: ids, |
662 posts_per_page: -1, |
297 posts_per_page: -1, |
663 query: true, |
298 query: true, |
664 type: 'image' |
299 type: 'image' |
665 }); |
300 }); |
666 }; |
301 }; |
667 |
302 |
668 var media_upload_MediaUpload = /*#__PURE__*/function (_Component) { |
303 class media_upload_MediaUpload extends external_wp_element_["Component"] { |
669 Object(inherits["a" /* default */])(MediaUpload, _Component); |
304 constructor({ |
670 |
305 allowedTypes, |
671 var _super = _createSuper(MediaUpload); |
306 gallery = false, |
672 |
307 unstableFeaturedImageFlow = false, |
673 function MediaUpload(_ref) { |
308 modalClass, |
674 var _this; |
309 multiple = false, |
675 |
310 title = Object(external_wp_i18n_["__"])('Select or Upload Media') |
676 var allowedTypes = _ref.allowedTypes, |
311 }) { |
677 _ref$gallery = _ref.gallery, |
312 super(...arguments); |
678 gallery = _ref$gallery === void 0 ? false : _ref$gallery, |
313 this.openModal = this.openModal.bind(this); |
679 _ref$unstableFeatured = _ref.unstableFeaturedImageFlow, |
314 this.onOpen = this.onOpen.bind(this); |
680 unstableFeaturedImageFlow = _ref$unstableFeatured === void 0 ? false : _ref$unstableFeatured, |
315 this.onSelect = this.onSelect.bind(this); |
681 modalClass = _ref.modalClass, |
316 this.onUpdate = this.onUpdate.bind(this); |
682 _ref$multiple = _ref.multiple, |
317 this.onClose = this.onClose.bind(this); |
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 |
318 |
696 if (gallery) { |
319 if (gallery) { |
697 _this.buildAndSetGalleryFrame(); |
320 this.buildAndSetGalleryFrame(); |
698 } else { |
321 } else { |
699 var frameConfig = { |
322 const frameConfig = { |
700 title: title, |
323 title, |
701 multiple: multiple |
324 multiple |
702 }; |
325 }; |
703 |
326 |
704 if (!!allowedTypes) { |
327 if (!!allowedTypes) { |
705 frameConfig.library = { |
328 frameConfig.library = { |
706 type: allowedTypes |
329 type: allowedTypes |
707 }; |
330 }; |
708 } |
331 } |
709 |
332 |
710 _this.frame = wp.media(frameConfig); |
333 this.frame = wp.media(frameConfig); |
711 } |
334 } |
712 |
335 |
713 if (modalClass) { |
336 if (modalClass) { |
714 _this.frame.$el.addClass(modalClass); |
337 this.frame.$el.addClass(modalClass); |
715 } |
338 } |
716 |
339 |
717 if (unstableFeaturedImageFlow) { |
340 if (unstableFeaturedImageFlow) { |
718 _this.buildAndSetFeatureImageFrame(); |
341 this.buildAndSetFeatureImageFrame(); |
719 } |
342 } |
720 |
343 |
721 _this.initializeListeners(); |
344 this.initializeListeners(); |
722 |
345 } |
723 return _this; |
346 |
724 } |
347 initializeListeners() { |
725 |
348 // When an image is selected in the media frame... |
726 Object(createClass["a" /* default */])(MediaUpload, [{ |
349 this.frame.on('select', this.onSelect); |
727 key: "initializeListeners", |
350 this.frame.on('update', this.onUpdate); |
728 value: function initializeListeners() { |
351 this.frame.on('open', this.onOpen); |
729 // When an image is selected in the media frame... |
352 this.frame.on('close', this.onClose); |
730 this.frame.on('select', this.onSelect); |
353 } |
731 this.frame.on('update', this.onUpdate); |
354 /** |
732 this.frame.on('open', this.onOpen); |
355 * Sets the Gallery frame and initializes listeners. |
733 this.frame.on('close', this.onClose); |
356 * |
734 } |
357 * @return {void} |
735 /** |
358 */ |
736 * Sets the Gallery frame and initializes listeners. |
359 |
737 * |
360 |
738 * @return {void} |
361 buildAndSetGalleryFrame() { |
739 */ |
362 const { |
740 |
363 addToGallery = false, |
741 }, { |
364 allowedTypes, |
742 key: "buildAndSetGalleryFrame", |
365 multiple = false, |
743 value: function buildAndSetGalleryFrame() { |
366 value = DEFAULT_EMPTY_GALLERY |
744 var _this$props = this.props, |
367 } = this.props; // If the value did not changed there is no need to rebuild the frame, |
745 _this$props$addToGall = _this$props.addToGallery, |
368 // we can continue to use the existing one. |
746 addToGallery = _this$props$addToGall === void 0 ? false : _this$props$addToGall, |
369 |
747 allowedTypes = _this$props.allowedTypes, |
370 if (value === this.lastGalleryValue) { |
748 _this$props$multiple = _this$props.multiple, |
371 return; |
749 multiple = _this$props$multiple === void 0 ? false : _this$props$multiple, |
372 } |
750 _this$props$value = _this$props.value, |
373 |
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, |
374 this.lastGalleryValue = value; // If a frame already existed remove it. |
752 // we can continue to use the existing one. |
375 |
753 |
376 if (this.frame) { |
754 if (value === this.lastGalleryValue) { |
377 this.frame.remove(); |
755 return; |
378 } |
756 } |
379 |
757 |
380 let currentState; |
758 this.lastGalleryValue = value; // If a frame already existed remove it. |
381 |
759 |
382 if (addToGallery) { |
760 if (this.frame) { |
383 currentState = 'gallery-library'; |
761 this.frame.remove(); |
384 } else { |
762 } |
385 currentState = value && value.length ? 'gallery-edit' : 'gallery'; |
763 |
386 } |
764 var currentState; |
387 |
765 |
388 if (!this.GalleryDetailsMediaFrame) { |
766 if (addToGallery) { |
389 this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame(); |
767 currentState = 'gallery-library'; |
390 } |
768 } else { |
391 |
769 currentState = value && value.length ? 'gallery-edit' : 'gallery'; |
392 const attachments = getAttachmentsCollection(value); |
770 } |
393 const selection = new wp.media.model.Selection(attachments.models, { |
771 |
394 props: attachments.props.toJSON(), |
772 if (!this.GalleryDetailsMediaFrame) { |
395 multiple |
773 this.GalleryDetailsMediaFrame = media_upload_getGalleryDetailsMediaFrame(); |
396 }); |
774 } |
397 this.frame = new this.GalleryDetailsMediaFrame({ |
775 |
398 mimeType: allowedTypes, |
776 var attachments = getAttachmentsCollection(value); |
399 state: currentState, |
777 var selection = new wp.media.model.Selection(attachments.models, { |
400 multiple, |
778 props: attachments.props.toJSON(), |
401 selection, |
779 multiple: multiple |
402 editing: value && value.length ? true : false |
|
403 }); |
|
404 wp.media.frame = this.frame; |
|
405 this.initializeListeners(); |
|
406 } |
|
407 /** |
|
408 * Initializes the Media Library requirements for the featured image flow. |
|
409 * |
|
410 * @return {void} |
|
411 */ |
|
412 |
|
413 |
|
414 buildAndSetFeatureImageFrame() { |
|
415 const featuredImageFrame = getFeaturedImageMediaFrame(); |
|
416 const attachments = getAttachmentsCollection(this.props.value); |
|
417 const selection = new wp.media.model.Selection(attachments.models, { |
|
418 props: attachments.props.toJSON() |
|
419 }); |
|
420 this.frame = new featuredImageFrame({ |
|
421 mimeType: this.props.allowedTypes, |
|
422 state: 'featured-image', |
|
423 multiple: this.props.multiple, |
|
424 selection, |
|
425 editing: this.props.value ? true : false |
|
426 }); |
|
427 wp.media.frame = this.frame; |
|
428 } |
|
429 |
|
430 componentWillUnmount() { |
|
431 this.frame.remove(); |
|
432 } |
|
433 |
|
434 onUpdate(selections) { |
|
435 const { |
|
436 onSelect, |
|
437 multiple = false |
|
438 } = this.props; |
|
439 const state = this.frame.state(); |
|
440 const selectedImages = selections || state.get('selection'); |
|
441 |
|
442 if (!selectedImages || !selectedImages.models.length) { |
|
443 return; |
|
444 } |
|
445 |
|
446 if (multiple) { |
|
447 onSelect(selectedImages.models.map(model => slimImageObject(model.toJSON()))); |
|
448 } else { |
|
449 onSelect(slimImageObject(selectedImages.models[0].toJSON())); |
|
450 } |
|
451 } |
|
452 |
|
453 onSelect() { |
|
454 const { |
|
455 onSelect, |
|
456 multiple = false |
|
457 } = this.props; // Get media attachment details from the frame state |
|
458 |
|
459 const attachment = this.frame.state().get('selection').toJSON(); |
|
460 onSelect(multiple ? attachment : attachment[0]); |
|
461 } |
|
462 |
|
463 onOpen() { |
|
464 var _this$props$value; |
|
465 |
|
466 this.updateCollection(); // Handle both this.props.value being either (number[]) multiple ids |
|
467 // (for galleries) or a (number) singular id (e.g. image block). |
|
468 |
|
469 const hasMedia = Array.isArray(this.props.value) ? !!((_this$props$value = this.props.value) !== null && _this$props$value !== void 0 && _this$props$value.length) : !!this.props.value; |
|
470 |
|
471 if (!hasMedia) { |
|
472 return; |
|
473 } |
|
474 |
|
475 if (!this.props.gallery) { |
|
476 const selection = this.frame.state().get('selection'); |
|
477 Object(external_lodash_["castArray"])(this.props.value).forEach(id => { |
|
478 selection.add(wp.media.attachment(id)); |
780 }); |
479 }); |
781 this.frame = new this.GalleryDetailsMediaFrame({ |
480 } // load the images so they are available in the media modal. |
782 mimeType: allowedTypes, |
481 |
783 state: currentState, |
482 |
784 multiple: multiple, |
483 getAttachmentsCollection(Object(external_lodash_["castArray"])(this.props.value)).more(); |
785 selection: selection, |
484 } |
786 editing: value && value.length ? true : false |
485 |
787 }); |
486 onClose() { |
788 wp.media.frame = this.frame; |
487 const { |
789 this.initializeListeners(); |
488 onClose |
790 } |
489 } = this.props; |
791 /** |
490 |
792 * Initializes the Media Library requirements for the featured image flow. |
491 if (onClose) { |
793 * |
492 onClose(); |
794 * @return {void} |
493 } |
795 */ |
494 } |
796 |
495 |
797 }, { |
496 updateCollection() { |
798 key: "buildAndSetFeatureImageFrame", |
497 const frameContent = this.frame.content.get(); |
799 value: function buildAndSetFeatureImageFrame() { |
498 |
800 var featuredImageFrame = getFeaturedImageMediaFrame(); |
499 if (frameContent && frameContent.collection) { |
801 var attachments = getAttachmentsCollection(this.props.value); |
500 const collection = frameContent.collection; // clean all attachments we have in memory. |
802 var selection = new wp.media.model.Selection(attachments.models, { |
501 |
803 props: attachments.props.toJSON() |
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. |
804 }); |
503 |
805 this.frame = new featuredImageFrame({ |
504 collection.mirroring._hasMore = true; // request items |
806 mimeType: this.props.allowedTypes, |
505 |
807 state: 'featured-image', |
506 collection.more(); |
808 multiple: this.props.multiple, |
507 } |
809 selection: selection, |
508 } |
810 editing: this.props.value ? true : false |
509 |
811 }); |
510 openModal() { |
812 wp.media.frame = this.frame; |
511 if (this.props.gallery) { |
813 } |
512 this.buildAndSetGalleryFrame(); |
814 }, { |
513 } |
815 key: "componentWillUnmount", |
514 |
816 value: function componentWillUnmount() { |
515 this.frame.open(); |
817 this.frame.remove(); |
516 } |
818 } |
517 |
819 }, { |
518 render() { |
820 key: "onUpdate", |
519 return this.props.render({ |
821 value: function onUpdate(selections) { |
520 open: this.openModal |
822 var _this$props2 = this.props, |
521 }); |
823 onSelect = _this$props2.onSelect, |
522 } |
824 _this$props2$multiple = _this$props2.multiple, |
523 |
825 multiple = _this$props2$multiple === void 0 ? false : _this$props2$multiple; |
524 } |
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 |
525 |
918 /* harmony default export */ var media_upload = (media_upload_MediaUpload); |
526 /* harmony default export */ var media_upload = (media_upload_MediaUpload); |
919 |
527 |
920 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js |
528 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js |
921 |
529 |
922 |
530 |
923 // EXTERNAL MODULE: external {"this":"regeneratorRuntime"} |
531 // EXTERNAL MODULE: external ["wp","apiFetch"] |
924 var external_this_regeneratorRuntime_ = __webpack_require__(24); |
532 var external_wp_apiFetch_ = __webpack_require__("ywyh"); |
925 var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_); |
533 var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_); |
926 |
534 |
927 // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/defineProperty.js |
535 // EXTERNAL MODULE: external ["wp","blob"] |
928 var defineProperty = __webpack_require__(5); |
536 var external_wp_blob_ = __webpack_require__("xTGt"); |
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 |
537 |
946 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js |
538 // CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js |
947 |
539 |
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 |
540 |
964 /** |
541 /** |
965 * External dependencies |
542 * External dependencies |
966 */ |
543 */ |
967 |
544 |
1016 * @param {Function} $0.onError Function called when an error happens. |
588 * @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. |
589 * @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. |
590 * @param {?Object} $0.wpAllowedMimeTypes List of allowed mime types and file extensions. |
1019 */ |
591 */ |
1020 |
592 |
1021 function uploadMedia(_x) { |
593 async function uploadMedia({ |
1022 return _uploadMedia.apply(this, arguments); |
594 allowedTypes, |
|
595 additionalData = {}, |
|
596 filesList, |
|
597 maxUploadFileSize, |
|
598 onError = external_lodash_["noop"], |
|
599 onFileChange, |
|
600 wpAllowedMimeTypes = null |
|
601 }) { |
|
602 // Cast filesList to array |
|
603 const files = [...filesList]; |
|
604 const filesSet = []; |
|
605 |
|
606 const setAndUpdateFiles = (idx, value) => { |
|
607 Object(external_wp_blob_["revokeBlobURL"])(Object(external_lodash_["get"])(filesSet, [idx, 'url'])); |
|
608 filesSet[idx] = value; |
|
609 onFileChange(Object(external_lodash_["compact"])(filesSet)); |
|
610 }; // Allowed type specified by consumer |
|
611 |
|
612 |
|
613 const isAllowedType = fileType => { |
|
614 if (!allowedTypes) { |
|
615 return true; |
|
616 } |
|
617 |
|
618 return Object(external_lodash_["some"])(allowedTypes, allowedType => { |
|
619 // If a complete mimetype is specified verify if it matches exactly the mime type of the file. |
|
620 if (Object(external_lodash_["includes"])(allowedType, '/')) { |
|
621 return allowedType === fileType; |
|
622 } // Otherwise a general mime type is used and we should verify if the file mimetype starts with it. |
|
623 |
|
624 |
|
625 return Object(external_lodash_["startsWith"])(fileType, `${allowedType}/`); |
|
626 }); |
|
627 }; // Allowed types for the current WP_User |
|
628 |
|
629 |
|
630 const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes); |
|
631 |
|
632 const isAllowedMimeTypeForUser = fileType => { |
|
633 return Object(external_lodash_["includes"])(allowedMimeTypesForUser, fileType); |
|
634 }; // Build the error message including the filename |
|
635 |
|
636 |
|
637 const triggerError = error => { |
|
638 error.message = [Object(external_wp_element_["createElement"])("strong", { |
|
639 key: "filename" |
|
640 }, error.file.name), ': ', error.message]; |
|
641 onError(error); |
|
642 }; |
|
643 |
|
644 const validFiles = []; |
|
645 |
|
646 for (const mediaFile of files) { |
|
647 // Verify if user is allowed to upload this mime type. |
|
648 // Defer to the server when type not detected. |
|
649 if (allowedMimeTypesForUser && mediaFile.type && !isAllowedMimeTypeForUser(mediaFile.type)) { |
|
650 triggerError({ |
|
651 code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER', |
|
652 message: Object(external_wp_i18n_["__"])('Sorry, this file type is not permitted for security reasons.'), |
|
653 file: mediaFile |
|
654 }); |
|
655 continue; |
|
656 } // Check if the block supports this mime type. |
|
657 // Defer to the server when type not detected. |
|
658 |
|
659 |
|
660 if (mediaFile.type && !isAllowedType(mediaFile.type)) { |
|
661 triggerError({ |
|
662 code: 'MIME_TYPE_NOT_SUPPORTED', |
|
663 message: Object(external_wp_i18n_["__"])('Sorry, this file type is not supported here.'), |
|
664 file: mediaFile |
|
665 }); |
|
666 continue; |
|
667 } // verify if file is greater than the maximum file upload size allowed for the site. |
|
668 |
|
669 |
|
670 if (maxUploadFileSize && mediaFile.size > maxUploadFileSize) { |
|
671 triggerError({ |
|
672 code: 'SIZE_ABOVE_LIMIT', |
|
673 message: Object(external_wp_i18n_["__"])('This file exceeds the maximum upload size for this site.'), |
|
674 file: mediaFile |
|
675 }); |
|
676 continue; |
|
677 } // Don't allow empty files to be uploaded. |
|
678 |
|
679 |
|
680 if (mediaFile.size <= 0) { |
|
681 triggerError({ |
|
682 code: 'EMPTY_FILE', |
|
683 message: Object(external_wp_i18n_["__"])('This file is empty.'), |
|
684 file: mediaFile |
|
685 }); |
|
686 continue; |
|
687 } |
|
688 |
|
689 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 |
|
691 |
|
692 filesSet.push({ |
|
693 url: Object(external_wp_blob_["createBlobURL"])(mediaFile) |
|
694 }); |
|
695 onFileChange(filesSet); |
|
696 } |
|
697 |
|
698 for (let idx = 0; idx < validFiles.length; ++idx) { |
|
699 const mediaFile = validFiles[idx]; |
|
700 |
|
701 try { |
|
702 const savedMedia = await createMediaFromFile(mediaFile, additionalData); |
|
703 const mediaObject = { ...Object(external_lodash_["omit"])(savedMedia, ['alt_text', 'source_url']), |
|
704 alt: savedMedia.alt_text, |
|
705 caption: Object(external_lodash_["get"])(savedMedia, ['caption', 'raw'], ''), |
|
706 title: savedMedia.title.raw, |
|
707 url: savedMedia.source_url |
|
708 }; |
|
709 setAndUpdateFiles(idx, mediaObject); |
|
710 } catch (error) { |
|
711 // Reset to empty on failure. |
|
712 setAndUpdateFiles(idx, null); |
|
713 let message; |
|
714 |
|
715 if (Object(external_lodash_["has"])(error, ['message'])) { |
|
716 message = Object(external_lodash_["get"])(error, ['message']); |
|
717 } else { |
|
718 message = Object(external_wp_i18n_["sprintf"])( // translators: %s: file name |
|
719 Object(external_wp_i18n_["__"])('Error while uploading file %s to the media library.'), mediaFile.name); |
|
720 } |
|
721 |
|
722 onError({ |
|
723 code: 'GENERAL', |
|
724 message, |
|
725 file: mediaFile |
|
726 }); |
|
727 } |
|
728 } |
1023 } |
729 } |
1024 /** |
730 /** |
1025 * @param {File} file Media File to Save. |
731 * @param {File} file Media File to Save. |
1026 * @param {?Object} additionalData Additional data to include in the request. |
732 * @param {?Object} additionalData Additional data to include in the request. |
1027 * |
733 * |
1028 * @return {Promise} Media Object Promise. |
734 * @return {Promise} Media Object Promise. |
1029 */ |
735 */ |
1030 |
736 |
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) { |
737 function createMediaFromFile(file, additionalData) { |
1239 // Create upload payload |
738 // Create upload payload |
1240 var data = new window.FormData(); |
739 const data = new window.FormData(); |
1241 data.append('file', file, file.name || file.type.replace('/', '.')); |
740 data.append('file', file, file.name || file.type.replace('/', '.')); |
1242 Object(external_this_lodash_["forEach"])(additionalData, function (value, key) { |
741 Object(external_lodash_["forEach"])(additionalData, (value, key) => data.append(key, value)); |
1243 return data.append(key, value); |
742 return external_wp_apiFetch_default()({ |
1244 }); |
|
1245 return external_this_wp_apiFetch_default()({ |
|
1246 path: '/wp/v2/media', |
743 path: '/wp/v2/media', |
1247 body: data, |
744 body: data, |
1248 method: 'POST' |
745 method: 'POST' |
1249 }); |
746 }); |
1250 } |
747 } |