2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => { // webpackBootstrap
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/compat get default export */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ __webpack_require__.n = (module) => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ var getter = module && module.__esModule ?
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ () => (module['default']) :
|
|
|
|
/******/ () => (module);
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ __webpack_require__.d(getter, { a: getter });
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ // define getter functions for harmony exports
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
2019-09-19 11:19:18 -04:00
|
|
|
/******/ };
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ // define __esModule on exports
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ __webpack_require__.r = (exports) => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
/******/ };
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
2019-09-19 11:19:18 -04:00
|
|
|
/************************************************************************/
|
2022-04-11 08:04:30 -04:00
|
|
|
var __webpack_exports__ = {};
|
2020-06-29 07:50:29 -04:00
|
|
|
// ESM COMPAT FLAG
|
2019-09-19 11:19:18 -04:00
|
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
|
2020-06-29 07:50:29 -04:00
|
|
|
// EXPORTS
|
2022-04-11 08:04:30 -04:00
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
2024-01-31 07:59:56 -05:00
|
|
|
MediaUpload: () => (/* reexport */ media_upload),
|
2024-09-19 21:55:35 -04:00
|
|
|
transformAttachment: () => (/* reexport */ transformAttachment),
|
|
|
|
uploadMedia: () => (/* reexport */ uploadMedia),
|
|
|
|
validateFileSize: () => (/* reexport */ validateFileSize),
|
|
|
|
validateMimeType: () => (/* reexport */ validateMimeType),
|
|
|
|
validateMimeTypeForUser: () => (/* reexport */ validateMimeTypeForUser)
|
2022-04-11 08:04:30 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: external ["wp","element"]
|
2024-01-31 07:59:56 -05:00
|
|
|
const external_wp_element_namespaceObject = window["wp"]["element"];
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: external ["wp","i18n"]
|
2024-01-31 07:59:56 -05:00
|
|
|
const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/media-upload/index.js
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const DEFAULT_EMPTY_GALLERY = [];
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2020-02-17 18:02:14 -05:00
|
|
|
/**
|
|
|
|
* Prepares the Featured Image toolbars and frames.
|
|
|
|
*
|
2023-02-07 02:04:52 -05:00
|
|
|
* @return {window.wp.media.view.MediaFrame.Select} The default media workflow.
|
2020-02-17 18:02:14 -05:00
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const getFeaturedImageMediaFrame = () => {
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2019-09-19 11:19:18 -04:00
|
|
|
return wp.media.view.MediaFrame.Select.extend({
|
|
|
|
/**
|
|
|
|
* Enables the Set Featured Image Button.
|
|
|
|
*
|
|
|
|
* @param {Object} toolbar toolbar for featured image state
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
featuredImageToolbar(toolbar) {
|
2019-09-19 11:19:18 -04:00
|
|
|
this.createSelectToolbar(toolbar, {
|
|
|
|
text: wp.media.view.l10n.setFeaturedImage,
|
|
|
|
state: this.options.state
|
|
|
|
});
|
|
|
|
},
|
2020-02-17 18:02:14 -05:00
|
|
|
/**
|
|
|
|
* Handle the edit state requirements of selected media item.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
editState() {
|
|
|
|
const selection = this.state('featured-image').get('selection');
|
|
|
|
const view = new wp.media.view.EditImage({
|
2020-02-17 18:02:14 -05:00
|
|
|
model: selection.single(),
|
|
|
|
controller: this
|
2023-09-26 10:23:26 -04:00
|
|
|
}).render();
|
2020-02-17 18:02:14 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Set the view to the EditImage frame using the selected image.
|
|
|
|
this.content.set(view);
|
2020-02-17 18:02:14 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// After bringing in the frame, load the actual editor via an ajax call.
|
2020-02-17 18:02:14 -05:00
|
|
|
view.loadEditor();
|
|
|
|
},
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* Create the default states.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
createStates: function createStates() {
|
|
|
|
this.on('toolbar:create:featured-image', this.featuredImageToolbar, this);
|
2020-02-17 18:02:14 -05:00
|
|
|
this.on('content:render:edit-image', this.editState, this);
|
|
|
|
this.states.add([new wp.media.controller.FeaturedImage(), new wp.media.controller.EditImage({
|
|
|
|
model: this.options.editImage
|
|
|
|
})]);
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
|
|
|
});
|
2020-02-17 18:02:14 -05:00
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2020-02-17 18:02:14 -05:00
|
|
|
/**
|
|
|
|
* Prepares the Gallery toolbars and frames.
|
|
|
|
*
|
2023-02-07 02:04:52 -05:00
|
|
|
* @return {window.wp.media.view.MediaFrame.Post} The default media workflow.
|
2020-02-17 18:02:14 -05:00
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const getGalleryDetailsMediaFrame = () => {
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* Custom gallery details frame.
|
|
|
|
*
|
|
|
|
* @see https://github.com/xwp/wp-core-media-widgets/blob/905edbccfc2a623b73a93dac803c5335519d7837/wp-admin/js/widgets/media-gallery-widget.js
|
|
|
|
* @class GalleryDetailsMediaFrame
|
|
|
|
* @class
|
|
|
|
*/
|
2020-02-24 19:18:15 -05:00
|
|
|
return wp.media.view.MediaFrame.Post.extend({
|
2020-02-17 18:02:14 -05:00
|
|
|
/**
|
|
|
|
* Set up gallery toolbar.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
galleryToolbar() {
|
|
|
|
const editing = this.state().get('editing');
|
2020-02-17 18:02:14 -05:00
|
|
|
this.toolbar.set(new wp.media.view.Toolbar({
|
|
|
|
controller: this,
|
|
|
|
items: {
|
|
|
|
insert: {
|
|
|
|
style: 'primary',
|
|
|
|
text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
|
|
|
|
priority: 80,
|
|
|
|
requires: {
|
|
|
|
library: true
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @fires wp.media.controller.State#update
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
click() {
|
|
|
|
const controller = this.controller,
|
2023-09-26 10:23:26 -04:00
|
|
|
state = controller.state();
|
2020-02-17 18:02:14 -05:00
|
|
|
controller.close();
|
2023-09-26 10:23:26 -04:00
|
|
|
state.trigger('update', state.get('library'));
|
2020-02-17 18:02:14 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Restore and reset the default state.
|
2020-02-17 18:02:14 -05:00
|
|
|
controller.setState(controller.options.state);
|
|
|
|
controller.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Handle the edit state requirements of selected media item.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
editState() {
|
|
|
|
const selection = this.state('gallery').get('selection');
|
|
|
|
const view = new wp.media.view.EditImage({
|
2020-02-17 18:02:14 -05:00
|
|
|
model: selection.single(),
|
|
|
|
controller: this
|
2023-09-26 10:23:26 -04:00
|
|
|
}).render();
|
2020-02-17 18:02:14 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Set the view to the EditImage frame using the selected image.
|
|
|
|
this.content.set(view);
|
2020-02-17 18:02:14 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// After bringing in the frame, load the actual editor via an ajax call.
|
2020-02-17 18:02:14 -05:00
|
|
|
view.loadEditor();
|
|
|
|
},
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* Create the default states.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
createStates: function createStates() {
|
2020-02-17 18:02:14 -05:00
|
|
|
this.on('toolbar:create:main-gallery', this.galleryToolbar, this);
|
|
|
|
this.on('content:render:edit-image', this.editState, this);
|
2019-09-19 11:19:18 -04:00
|
|
|
this.states.add([new wp.media.controller.Library({
|
|
|
|
id: 'gallery',
|
|
|
|
title: wp.media.view.l10n.createGalleryTitle,
|
|
|
|
priority: 40,
|
|
|
|
toolbar: 'main-gallery',
|
|
|
|
filterable: 'uploaded',
|
|
|
|
multiple: 'add',
|
|
|
|
editable: false,
|
2022-09-20 11:43:29 -04:00
|
|
|
library: wp.media.query({
|
|
|
|
type: 'image',
|
|
|
|
...this.options.library
|
|
|
|
})
|
2020-02-17 18:02:14 -05:00
|
|
|
}), new wp.media.controller.EditImage({
|
|
|
|
model: this.options.editImage
|
2019-09-19 11:19:18 -04:00
|
|
|
}), new wp.media.controller.GalleryEdit({
|
|
|
|
library: this.options.selection,
|
|
|
|
editing: this.options.editing,
|
|
|
|
menu: 'gallery',
|
|
|
|
displaySettings: false,
|
|
|
|
multiple: true
|
|
|
|
}), new wp.media.controller.GalleryAdd()]);
|
|
|
|
}
|
|
|
|
});
|
2023-09-26 10:23:26 -04:00
|
|
|
};
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// The media library image object contains numerous attributes
|
|
|
|
// we only need this set to display the image in the library.
|
2021-05-19 11:09:27 -04:00
|
|
|
const slimImageObject = img => {
|
|
|
|
const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
|
2022-09-20 11:43:29 -04:00
|
|
|
return attrSet.reduce((result, key) => {
|
2023-06-27 10:24:19 -04:00
|
|
|
if (img?.hasOwnProperty(key)) {
|
2022-09-20 11:43:29 -04:00
|
|
|
result[key] = img[key];
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}, {});
|
2019-09-19 11:19:18 -04:00
|
|
|
};
|
2021-05-19 11:09:27 -04:00
|
|
|
const getAttachmentsCollection = ids => {
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2019-09-19 11:19:18 -04:00
|
|
|
return wp.media.query({
|
|
|
|
order: 'ASC',
|
|
|
|
orderby: 'post__in',
|
|
|
|
post__in: ids,
|
|
|
|
posts_per_page: -1,
|
|
|
|
query: true,
|
|
|
|
type: 'image'
|
|
|
|
});
|
|
|
|
};
|
2022-04-11 08:04:30 -04:00
|
|
|
class MediaUpload extends external_wp_element_namespaceObject.Component {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
constructor() {
|
2021-05-19 11:09:27 -04:00
|
|
|
super(...arguments);
|
|
|
|
this.openModal = this.openModal.bind(this);
|
|
|
|
this.onOpen = this.onOpen.bind(this);
|
|
|
|
this.onSelect = this.onSelect.bind(this);
|
|
|
|
this.onUpdate = this.onUpdate.bind(this);
|
|
|
|
this.onClose = this.onClose.bind(this);
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
initializeListeners() {
|
|
|
|
// When an image is selected in the media frame...
|
|
|
|
this.frame.on('select', this.onSelect);
|
|
|
|
this.frame.on('update', this.onUpdate);
|
|
|
|
this.frame.on('open', this.onOpen);
|
|
|
|
this.frame.on('close', this.onClose);
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
/**
|
|
|
|
* Sets the Gallery frame and initializes listeners.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
buildAndSetGalleryFrame() {
|
|
|
|
const {
|
|
|
|
addToGallery = false,
|
|
|
|
allowedTypes,
|
|
|
|
multiple = false,
|
|
|
|
value = DEFAULT_EMPTY_GALLERY
|
2023-09-26 10:23:26 -04:00
|
|
|
} = this.props;
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// If the value did not changed there is no need to rebuild the frame,
|
|
|
|
// we can continue to use the existing one.
|
2021-05-19 11:09:27 -04:00
|
|
|
if (value === this.lastGalleryValue) {
|
|
|
|
return;
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2023-09-26 10:23:26 -04:00
|
|
|
this.lastGalleryValue = value;
|
2021-05-19 11:09:27 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// If a frame already existed remove it.
|
2021-05-19 11:09:27 -04:00
|
|
|
if (this.frame) {
|
2019-09-19 11:19:18 -04:00
|
|
|
this.frame.remove();
|
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
let currentState;
|
|
|
|
if (addToGallery) {
|
|
|
|
currentState = 'gallery-library';
|
|
|
|
} else {
|
|
|
|
currentState = value && value.length ? 'gallery-edit' : 'gallery';
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
if (!this.GalleryDetailsMediaFrame) {
|
|
|
|
this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
const attachments = getAttachmentsCollection(value);
|
|
|
|
const selection = new wp.media.model.Selection(attachments.models, {
|
|
|
|
props: attachments.props.toJSON(),
|
|
|
|
multiple
|
|
|
|
});
|
|
|
|
this.frame = new this.GalleryDetailsMediaFrame({
|
|
|
|
mimeType: allowedTypes,
|
|
|
|
state: currentState,
|
|
|
|
multiple,
|
|
|
|
selection,
|
|
|
|
editing: value && value.length ? true : false
|
|
|
|
});
|
|
|
|
wp.media.frame = this.frame;
|
|
|
|
this.initializeListeners();
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
/**
|
|
|
|
* Initializes the Media Library requirements for the featured image flow.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
buildAndSetFeatureImageFrame() {
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2024-03-12 10:08:24 -04:00
|
|
|
const {
|
|
|
|
value: featuredImageId,
|
|
|
|
multiple,
|
|
|
|
allowedTypes
|
|
|
|
} = this.props;
|
2021-05-19 11:09:27 -04:00
|
|
|
const featuredImageFrame = getFeaturedImageMediaFrame();
|
2024-03-12 10:08:24 -04:00
|
|
|
const attachments = getAttachmentsCollection(featuredImageId);
|
2021-05-19 11:09:27 -04:00
|
|
|
const selection = new wp.media.model.Selection(attachments.models, {
|
|
|
|
props: attachments.props.toJSON()
|
|
|
|
});
|
|
|
|
this.frame = new featuredImageFrame({
|
2024-03-12 10:08:24 -04:00
|
|
|
mimeType: allowedTypes,
|
2021-05-19 11:09:27 -04:00
|
|
|
state: 'featured-image',
|
2024-03-12 10:08:24 -04:00
|
|
|
multiple,
|
2021-05-19 11:09:27 -04:00
|
|
|
selection,
|
2024-03-12 10:08:24 -04:00
|
|
|
editing: featuredImageId
|
2021-05-19 11:09:27 -04:00
|
|
|
});
|
|
|
|
wp.media.frame = this.frame;
|
2024-03-12 10:08:24 -04:00
|
|
|
// In order to select the current featured image when opening
|
|
|
|
// the media library we have to set the appropriate settings.
|
|
|
|
// Currently they are set in php for the post editor, but
|
|
|
|
// not for site editor.
|
|
|
|
wp.media.view.settings.post = {
|
|
|
|
...wp.media.view.settings.post,
|
|
|
|
featuredImageId: featuredImageId || -1
|
|
|
|
};
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
componentWillUnmount() {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
this.frame?.remove();
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
onUpdate(selections) {
|
|
|
|
const {
|
|
|
|
onSelect,
|
|
|
|
multiple = false
|
|
|
|
} = this.props;
|
|
|
|
const state = this.frame.state();
|
|
|
|
const selectedImages = selections || state.get('selection');
|
|
|
|
if (!selectedImages || !selectedImages.models.length) {
|
|
|
|
return;
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
if (multiple) {
|
|
|
|
onSelect(selectedImages.models.map(model => slimImageObject(model.toJSON())));
|
|
|
|
} else {
|
|
|
|
onSelect(slimImageObject(selectedImages.models[0].toJSON()));
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
onSelect() {
|
|
|
|
const {
|
|
|
|
onSelect,
|
|
|
|
multiple = false
|
2023-09-26 10:23:26 -04:00
|
|
|
} = this.props;
|
|
|
|
// Get media attachment details from the frame state.
|
2021-05-19 11:09:27 -04:00
|
|
|
const attachment = this.frame.state().get('selection').toJSON();
|
|
|
|
onSelect(multiple ? attachment : attachment[0]);
|
|
|
|
}
|
|
|
|
onOpen() {
|
2023-02-07 02:04:52 -05:00
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
2022-09-20 11:43:29 -04:00
|
|
|
const {
|
|
|
|
value
|
|
|
|
} = this.props;
|
2023-09-26 10:23:26 -04:00
|
|
|
this.updateCollection();
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
//Handle active tab in media model on model open.
|
2022-09-20 11:43:29 -04:00
|
|
|
if (this.props.mode) {
|
|
|
|
this.frame.content.mode(this.props.mode);
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2022-09-20 11:43:29 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Handle both this.props.value being either (number[]) multiple ids
|
|
|
|
// (for galleries) or a (number) singular id (e.g. image block).
|
2023-06-27 10:24:19 -04:00
|
|
|
const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
|
2021-05-19 11:09:27 -04:00
|
|
|
if (!hasMedia) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-08 09:29:21 -05:00
|
|
|
const isGallery = this.props.gallery;
|
|
|
|
const selection = this.frame.state().get('selection');
|
2022-09-20 11:43:29 -04:00
|
|
|
const valueArray = Array.isArray(value) ? value : [value];
|
2021-11-08 09:29:21 -05:00
|
|
|
if (!isGallery) {
|
2022-09-20 11:43:29 -04:00
|
|
|
valueArray.forEach(id => {
|
2021-05-19 11:09:27 -04:00
|
|
|
selection.add(wp.media.attachment(id));
|
|
|
|
});
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2021-11-08 09:29:21 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Load the images so they are available in the media modal.
|
|
|
|
const attachments = getAttachmentsCollection(valueArray);
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Once attachments are loaded, set the current selection.
|
2021-11-08 09:29:21 -05:00
|
|
|
attachments.more().done(function () {
|
2023-06-27 10:24:19 -04:00
|
|
|
if (isGallery && attachments?.models?.length) {
|
2021-11-08 09:29:21 -05:00
|
|
|
selection.add(attachments.models);
|
|
|
|
}
|
|
|
|
});
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
onClose() {
|
|
|
|
const {
|
|
|
|
onClose
|
|
|
|
} = this.props;
|
|
|
|
if (onClose) {
|
|
|
|
onClose();
|
|
|
|
}
|
2024-09-19 21:55:35 -04:00
|
|
|
this.frame.detach();
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
updateCollection() {
|
|
|
|
const frameContent = this.frame.content.get();
|
|
|
|
if (frameContent && frameContent.collection) {
|
2023-09-26 10:23:26 -04:00
|
|
|
const collection = frameContent.collection;
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Clean all attachments we have in memory.
|
|
|
|
collection.toArray().forEach(model => model.trigger('destroy', model));
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Reset has more flag, if library had small amount of items all items may have been loaded before.
|
|
|
|
collection.mirroring._hasMore = true;
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Request items.
|
2021-05-19 11:09:27 -04:00
|
|
|
collection.more();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
openModal() {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
const {
|
|
|
|
allowedTypes,
|
|
|
|
gallery = false,
|
|
|
|
unstableFeaturedImageFlow = false,
|
|
|
|
modalClass,
|
|
|
|
multiple = false,
|
|
|
|
title = (0,external_wp_i18n_namespaceObject.__)('Select or Upload Media')
|
|
|
|
} = this.props;
|
|
|
|
const {
|
|
|
|
wp
|
|
|
|
} = window;
|
|
|
|
if (gallery) {
|
2021-05-19 11:09:27 -04:00
|
|
|
this.buildAndSetGalleryFrame();
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
} else {
|
|
|
|
const frameConfig = {
|
|
|
|
title,
|
|
|
|
multiple
|
|
|
|
};
|
|
|
|
if (!!allowedTypes) {
|
|
|
|
frameConfig.library = {
|
|
|
|
type: allowedTypes
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.frame = wp.media(frameConfig);
|
|
|
|
}
|
|
|
|
if (modalClass) {
|
|
|
|
this.frame.$el.addClass(modalClass);
|
|
|
|
}
|
|
|
|
if (unstableFeaturedImageFlow) {
|
|
|
|
this.buildAndSetFeatureImageFrame();
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
this.initializeListeners();
|
2021-05-19 11:09:27 -04:00
|
|
|
this.frame.open();
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return this.props.render({
|
|
|
|
open: this.openModal
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const media_upload = (MediaUpload);
|
2020-02-06 16:03:31 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/components/index.js
|
2020-02-06 16:03:31 -05:00
|
|
|
|
2020-06-26 09:33:47 -04:00
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
;// CONCATENATED MODULE: external ["wp","blob"]
|
|
|
|
const external_wp_blob_namespaceObject = window["wp"]["blob"];
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: external ["wp","apiFetch"]
|
2024-01-31 07:59:56 -05:00
|
|
|
const external_wp_apiFetch_namespaceObject = window["wp"]["apiFetch"];
|
2022-04-11 08:04:30 -04:00
|
|
|
var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_namespaceObject);
|
2024-09-19 21:55:35 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/flatten-form-data.js
|
|
|
|
/**
|
|
|
|
* Determines whether the passed argument appears to be a plain object.
|
|
|
|
*
|
|
|
|
* @param data The object to inspect.
|
|
|
|
*/
|
|
|
|
function isPlainObject(data) {
|
|
|
|
return data !== null && typeof data === 'object' && Object.getPrototypeOf(data) === Object.prototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively flatten data passed to form data, to allow using multi-level objects.
|
|
|
|
*
|
|
|
|
* @param {FormData} formData Form data object.
|
|
|
|
* @param {string} key Key to amend to form data object
|
|
|
|
* @param {string|Object} data Data to be amended to form data.
|
|
|
|
*/
|
|
|
|
function flattenFormData(formData, key, data) {
|
|
|
|
if (isPlainObject(data)) {
|
|
|
|
for (const [name, value] of Object.entries(data)) {
|
|
|
|
flattenFormData(formData, `${key}[${name}]`, value);
|
|
|
|
}
|
|
|
|
} else if (data !== undefined) {
|
|
|
|
formData.append(key, String(data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/transform-attachment.js
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms an attachment object from the REST API shape into the shape expected by the block editor and other consumers.
|
|
|
|
*
|
|
|
|
* @param attachment REST API attachment object.
|
|
|
|
*/
|
|
|
|
function transformAttachment(attachment) {
|
|
|
|
var _attachment$caption$r;
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
const {
|
|
|
|
alt_text,
|
|
|
|
source_url,
|
|
|
|
...savedMediaProps
|
|
|
|
} = attachment;
|
|
|
|
return {
|
|
|
|
...savedMediaProps,
|
|
|
|
alt: attachment.alt_text,
|
|
|
|
caption: (_attachment$caption$r = attachment.caption?.raw) !== null && _attachment$caption$r !== void 0 ? _attachment$caption$r : '',
|
|
|
|
title: attachment.title.raw,
|
|
|
|
url: attachment.source_url,
|
|
|
|
poster: attachment._embedded?.['wp:featuredmedia']?.[0]?.source_url || undefined
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-to-server.js
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
async function uploadToServer(file, additionalData = {}, signal) {
|
|
|
|
// Create upload payload.
|
|
|
|
const data = new FormData();
|
|
|
|
data.append('file', file, file.name || file.type.replace('/', '.'));
|
|
|
|
for (const [key, value] of Object.entries(additionalData)) {
|
|
|
|
flattenFormData(data, key, value);
|
|
|
|
}
|
|
|
|
return transformAttachment(await external_wp_apiFetch_default()({
|
|
|
|
// This allows the video block to directly get a video's poster image.
|
|
|
|
path: '/wp/v2/media?_embed=wp:featuredmedia',
|
|
|
|
body: data,
|
|
|
|
method: 'POST',
|
|
|
|
signal
|
|
|
|
}));
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-error.js
|
|
|
|
/**
|
|
|
|
* MediaError class.
|
|
|
|
*
|
|
|
|
* Small wrapper around the `Error` class
|
|
|
|
* to hold an error code and a reference to a file object.
|
|
|
|
*/
|
|
|
|
class UploadError extends Error {
|
|
|
|
constructor({
|
|
|
|
code,
|
|
|
|
message,
|
|
|
|
file,
|
|
|
|
cause
|
|
|
|
}) {
|
|
|
|
super(message, {
|
|
|
|
cause
|
|
|
|
});
|
|
|
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
|
|
this.code = code;
|
|
|
|
this.file = file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/validate-mime-type.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies if the caller (e.g. a block) supports this mime type.
|
|
|
|
*
|
|
|
|
* @param file File object.
|
|
|
|
* @param allowedTypes List of allowed mime types.
|
|
|
|
*/
|
|
|
|
function validateMimeType(file, allowedTypes) {
|
|
|
|
if (!allowedTypes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed type specified by consumer.
|
|
|
|
const isAllowedType = allowedTypes.some(allowedType => {
|
|
|
|
// If a complete mimetype is specified verify if it matches exactly the mime type of the file.
|
|
|
|
if (allowedType.includes('/')) {
|
|
|
|
return allowedType === file.type;
|
|
|
|
}
|
|
|
|
// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.
|
|
|
|
return file.type.startsWith(`${allowedType}/`);
|
|
|
|
});
|
|
|
|
if (file.type && !isAllowedType) {
|
|
|
|
throw new UploadError({
|
|
|
|
code: 'MIME_TYPE_NOT_SUPPORTED',
|
|
|
|
message: (0,external_wp_i18n_namespaceObject.sprintf)(
|
|
|
|
// translators: %s: file name.
|
|
|
|
(0,external_wp_i18n_namespaceObject.__)('%s: Sorry, this file type is not supported here.'), file.name),
|
|
|
|
file
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/get-mime-types-array.js
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
|
|
|
* Browsers may use unexpected mime types, and they differ from browser to browser.
|
|
|
|
* This function computes a flexible array of mime types from the mime type structured provided by the server.
|
|
|
|
* Converts { jpg|jpeg|jpe: "image/jpeg" } into [ "image/jpeg", "image/jpg", "image/jpeg", "image/jpe" ]
|
|
|
|
*
|
|
|
|
* @param {?Object} wpMimeTypesObject Mime type object received from the server.
|
|
|
|
* Extensions are keys separated by '|' and values are mime types associated with an extension.
|
|
|
|
*
|
2024-09-19 21:55:35 -04:00
|
|
|
* @return An array of mime types or null
|
2019-09-19 11:19:18 -04:00
|
|
|
*/
|
|
|
|
function getMimeTypesArray(wpMimeTypesObject) {
|
|
|
|
if (!wpMimeTypesObject) {
|
2024-09-19 21:55:35 -04:00
|
|
|
return null;
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2024-09-19 21:55:35 -04:00
|
|
|
return Object.entries(wpMimeTypesObject).flatMap(([extensionsString, mime]) => {
|
2021-05-19 11:09:27 -04:00
|
|
|
const [type] = mime.split('/');
|
|
|
|
const extensions = extensionsString.split('|');
|
2022-09-20 11:43:29 -04:00
|
|
|
return [mime, ...extensions.map(extension => `${type}/${extension}`)];
|
2024-09-19 21:55:35 -04:00
|
|
|
});
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/validate-mime-type-for-user.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-09-19 11:19:18 -04:00
|
|
|
/**
|
2024-09-19 21:55:35 -04:00
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies if the user is allowed to upload this mime type.
|
2019-09-19 11:19:18 -04:00
|
|
|
*
|
2024-09-19 21:55:35 -04:00
|
|
|
* @param file File object.
|
|
|
|
* @param wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
|
|
*/
|
|
|
|
function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
|
|
|
|
// Allowed types for the current WP_User.
|
|
|
|
const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
|
|
|
|
if (!allowedMimeTypesForUser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(file.type);
|
|
|
|
if (file.type && !isAllowedMimeTypeForUser) {
|
|
|
|
throw new UploadError({
|
|
|
|
code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
|
|
|
|
message: (0,external_wp_i18n_namespaceObject.sprintf)(
|
|
|
|
// translators: %s: file name.
|
|
|
|
(0,external_wp_i18n_namespaceObject.__)('%s: Sorry, you are not allowed to upload this file type.'), file.name),
|
|
|
|
file
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/validate-file-size.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifies whether the file is within the file upload size limits for the site.
|
2019-09-19 11:19:18 -04:00
|
|
|
*
|
2024-09-19 21:55:35 -04:00
|
|
|
* @param file File object.
|
|
|
|
* @param maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
2019-09-19 11:19:18 -04:00
|
|
|
*/
|
2024-09-19 21:55:35 -04:00
|
|
|
function validateFileSize(file, maxUploadFileSize) {
|
|
|
|
// Don't allow empty files to be uploaded.
|
|
|
|
if (file.size <= 0) {
|
|
|
|
throw new UploadError({
|
|
|
|
code: 'EMPTY_FILE',
|
|
|
|
message: (0,external_wp_i18n_namespaceObject.sprintf)(
|
|
|
|
// translators: %s: file name.
|
|
|
|
(0,external_wp_i18n_namespaceObject.__)('%s: This file is empty.'), file.name),
|
|
|
|
file
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (maxUploadFileSize && file.size > maxUploadFileSize) {
|
|
|
|
throw new UploadError({
|
|
|
|
code: 'SIZE_ABOVE_LIMIT',
|
|
|
|
message: (0,external_wp_i18n_namespaceObject.sprintf)(
|
|
|
|
// translators: %s: file name.
|
|
|
|
(0,external_wp_i18n_namespaceObject.__)('%s: This file exceeds the maximum upload size for this site.'), file.name),
|
|
|
|
file
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/utils/upload-media.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Upload a media file when the file upload button is activated
|
|
|
|
* or when adding a file to the editor via drag & drop.
|
|
|
|
*
|
|
|
|
* @param $0 Parameters object passed to the function.
|
|
|
|
* @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.
|
|
|
|
* @param $0.additionalData Additional data to include in the request.
|
|
|
|
* @param $0.filesList List of files.
|
|
|
|
* @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
|
|
|
|
* @param $0.onError Function called when an error happens.
|
|
|
|
* @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.
|
|
|
|
* @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
|
|
|
|
* @param $0.signal Abort signal.
|
|
|
|
*/
|
|
|
|
function uploadMedia({
|
|
|
|
wpAllowedMimeTypes,
|
2023-06-27 10:24:19 -04:00
|
|
|
allowedTypes,
|
|
|
|
additionalData = {},
|
|
|
|
filesList,
|
|
|
|
maxUploadFileSize,
|
2024-09-19 21:55:35 -04:00
|
|
|
onError,
|
2023-06-27 10:24:19 -04:00
|
|
|
onFileChange,
|
2024-09-19 21:55:35 -04:00
|
|
|
signal
|
2023-06-27 10:24:19 -04:00
|
|
|
}) {
|
2024-09-19 21:55:35 -04:00
|
|
|
const validFiles = [];
|
2021-05-19 11:09:27 -04:00
|
|
|
const filesSet = [];
|
2024-09-19 21:55:35 -04:00
|
|
|
const setAndUpdateFiles = (index, value) => {
|
|
|
|
if (filesSet[index]?.url) {
|
|
|
|
(0,external_wp_blob_namespaceObject.revokeBlobURL)(filesSet[index].url);
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
2024-09-19 21:55:35 -04:00
|
|
|
filesSet[index] = value;
|
|
|
|
onFileChange?.(filesSet.filter(attachment => attachment !== null));
|
2021-05-19 11:09:27 -04:00
|
|
|
};
|
2024-09-19 21:55:35 -04:00
|
|
|
for (const mediaFile of filesList) {
|
2021-05-19 11:09:27 -04:00
|
|
|
// Verify if user is allowed to upload this mime type.
|
|
|
|
// Defer to the server when type not detected.
|
2024-09-19 21:55:35 -04:00
|
|
|
try {
|
|
|
|
validateMimeTypeForUser(mediaFile, wpAllowedMimeTypes);
|
|
|
|
} catch (error) {
|
|
|
|
onError?.(error);
|
2021-05-19 11:09:27 -04:00
|
|
|
continue;
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
// Check if the caller (e.g. a block) supports this mime type.
|
2023-09-26 10:23:26 -04:00
|
|
|
// Defer to the server when type not detected.
|
2024-09-19 21:55:35 -04:00
|
|
|
try {
|
|
|
|
validateMimeType(mediaFile, allowedTypes);
|
|
|
|
} catch (error) {
|
|
|
|
onError?.(error);
|
2021-05-19 11:09:27 -04:00
|
|
|
continue;
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Verify if file is greater than the maximum file upload size allowed for the site.
|
2024-09-19 21:55:35 -04:00
|
|
|
try {
|
|
|
|
validateFileSize(mediaFile, maxUploadFileSize);
|
|
|
|
} catch (error) {
|
|
|
|
onError?.(error);
|
2021-05-19 11:09:27 -04:00
|
|
|
continue;
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
validFiles.push(mediaFile);
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Set temporary URL to create placeholder media file, this is replaced
|
2022-04-12 11:12:47 -04:00
|
|
|
// with final file from media gallery when upload is `done` below.
|
2021-05-19 11:09:27 -04:00
|
|
|
filesSet.push({
|
2022-04-11 08:04:30 -04:00
|
|
|
url: (0,external_wp_blob_namespaceObject.createBlobURL)(mediaFile)
|
2021-05-19 11:09:27 -04:00
|
|
|
});
|
2024-09-19 21:55:35 -04:00
|
|
|
onFileChange?.(filesSet);
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
2024-09-19 21:55:35 -04:00
|
|
|
validFiles.map(async (file, index) => {
|
2021-05-19 11:09:27 -04:00
|
|
|
try {
|
2024-09-19 21:55:35 -04:00
|
|
|
const attachment = await uploadToServer(file, additionalData, signal);
|
|
|
|
setAndUpdateFiles(index, attachment);
|
2021-05-19 11:09:27 -04:00
|
|
|
} catch (error) {
|
|
|
|
// Reset to empty on failure.
|
2024-09-19 21:55:35 -04:00
|
|
|
setAndUpdateFiles(index, null);
|
2021-05-19 11:09:27 -04:00
|
|
|
let message;
|
2024-09-19 21:55:35 -04:00
|
|
|
if (error instanceof Error) {
|
2022-09-20 11:43:29 -04:00
|
|
|
message = error.message;
|
2021-05-19 11:09:27 -04:00
|
|
|
} else {
|
2023-09-26 10:23:26 -04:00
|
|
|
message = (0,external_wp_i18n_namespaceObject.sprintf)(
|
|
|
|
// translators: %s: file name
|
2024-09-19 21:55:35 -04:00
|
|
|
(0,external_wp_i18n_namespaceObject.__)('Error while uploading file %s to the media library.'), file.name);
|
2019-09-19 11:19:18 -04:00
|
|
|
}
|
2024-09-19 21:55:35 -04:00
|
|
|
onError?.(new UploadError({
|
2021-05-19 11:09:27 -04:00
|
|
|
code: 'GENERAL',
|
|
|
|
message,
|
2024-09-19 21:55:35 -04:00
|
|
|
file,
|
|
|
|
cause: error instanceof Error ? error : undefined
|
|
|
|
}));
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
2019-09-19 11:19:18 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-09-19 21:55:35 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/media-utils/build-module/index.js
|
|
|
|
|
|
|
|
|
2021-05-20 08:20:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
(window.wp = window.wp || {}).mediaUtils = __webpack_exports__;
|
|
|
|
/******/ })()
|
|
|
|
;
|