@wordpress/media-utils 5.32.0 → 5.32.1-next.ff1cebbba.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/build/components/index.js +36 -11
  2. package/build/components/index.js.map +7 -1
  3. package/build/components/media-upload/index.js +156 -221
  4. package/build/components/media-upload/index.js.map +7 -1
  5. package/build/index.js +44 -65
  6. package/build/index.js.map +7 -1
  7. package/build/lock-unlock.js +31 -14
  8. package/build/lock-unlock.js.map +7 -1
  9. package/build/private-apis.js +31 -17
  10. package/build/private-apis.js.map +7 -1
  11. package/build/utils/flatten-form-data.js +28 -20
  12. package/build/utils/flatten-form-data.js.map +7 -1
  13. package/build/utils/get-mime-types-array.js +38 -20
  14. package/build/utils/get-mime-types-array.js.map +7 -1
  15. package/build/utils/sideload-media.js +50 -38
  16. package/build/utils/sideload-media.js.map +7 -1
  17. package/build/utils/sideload-to-server.js +53 -36
  18. package/build/utils/sideload-to-server.js.map +7 -1
  19. package/build/utils/transform-attachment.js +29 -23
  20. package/build/utils/transform-attachment.js.map +7 -1
  21. package/build/utils/types.js +16 -5
  22. package/build/utils/types.js.map +7 -1
  23. package/build/utils/upload-error.js +30 -21
  24. package/build/utils/upload-error.js.map +7 -1
  25. package/build/utils/upload-media.js +62 -71
  26. package/build/utils/upload-media.js.map +7 -1
  27. package/build/utils/upload-to-server.js +54 -27
  28. package/build/utils/upload-to-server.js.map +7 -1
  29. package/build/utils/validate-file-size.js +44 -32
  30. package/build/utils/validate-file-size.js.map +7 -1
  31. package/build/utils/validate-mime-type-for-user.js +42 -30
  32. package/build/utils/validate-mime-type-for-user.js.map +7 -1
  33. package/build/utils/validate-mime-type.js +37 -32
  34. package/build/utils/validate-mime-type.js.map +7 -1
  35. package/build-module/components/index.js +5 -2
  36. package/build-module/components/index.js.map +7 -1
  37. package/build-module/components/media-upload/index.js +137 -215
  38. package/build-module/components/media-upload/index.js.map +7 -1
  39. package/build-module/index.js +16 -8
  40. package/build-module/index.js.map +7 -1
  41. package/build-module/lock-unlock.js +8 -7
  42. package/build-module/lock-unlock.js.map +7 -1
  43. package/build-module/private-apis.js +7 -11
  44. package/build-module/private-apis.js.map +7 -1
  45. package/build-module/utils/flatten-form-data.js +7 -17
  46. package/build-module/utils/flatten-form-data.js.map +7 -1
  47. package/build-module/utils/get-mime-types-array.js +17 -17
  48. package/build-module/utils/get-mime-types-array.js.map +7 -1
  49. package/build-module/utils/sideload-media.js +28 -34
  50. package/build-module/utils/sideload-media.js.map +7 -1
  51. package/build-module/utils/sideload-to-server.js +22 -33
  52. package/build-module/utils/sideload-to-server.js.map +7 -1
  53. package/build-module/utils/transform-attachment.js +8 -20
  54. package/build-module/utils/transform-attachment.js.map +7 -1
  55. package/build-module/utils/types.js +1 -2
  56. package/build-module/utils/types.js.map +7 -1
  57. package/build-module/utils/upload-error.js +9 -17
  58. package/build-module/utils/upload-error.js.map +7 -1
  59. package/build-module/utils/upload-media.js +36 -63
  60. package/build-module/utils/upload-media.js.map +7 -1
  61. package/build-module/utils/upload-to-server.js +23 -22
  62. package/build-module/utils/upload-to-server.js.map +7 -1
  63. package/build-module/utils/validate-file-size.js +19 -25
  64. package/build-module/utils/validate-file-size.js.map +7 -1
  65. package/build-module/utils/validate-mime-type-for-user.js +18 -24
  66. package/build-module/utils/validate-mime-type-for-user.js.map +7 -1
  67. package/build-module/utils/validate-mime-type.js +14 -27
  68. package/build-module/utils/validate-mime-type.js.map +7 -1
  69. package/package.json +15 -8
@@ -1,14 +1,39 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- Object.defineProperty(exports, "MediaUpload", {
8
- enumerable: true,
9
- get: function () {
10
- return _mediaUpload.default;
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
17
  }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var components_exports = {};
30
+ __export(components_exports, {
31
+ MediaUpload: () => import_media_upload.default
32
+ });
33
+ module.exports = __toCommonJS(components_exports);
34
+ var import_media_upload = __toESM(require("./media-upload"));
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ MediaUpload
12
38
  });
13
- var _mediaUpload = _interopRequireDefault(require("./media-upload"));
14
- //# sourceMappingURL=index.js.map
39
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_mediaUpload","_interopRequireDefault","require"],"sources":["@wordpress/media-utils/src/components/index.js"],"sourcesContent":["export { default as MediaUpload } from './media-upload';\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/components/index.js"],
4
+ "sourcesContent": ["export { default as MediaUpload } from './media-upload';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAuC;",
6
+ "names": []
7
+ }
@@ -1,26 +1,31 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var media_upload_exports = {};
20
+ __export(media_upload_exports, {
21
+ default: () => media_upload_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- var _i18n = require("@wordpress/i18n");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
23
+ module.exports = __toCommonJS(media_upload_exports);
24
+ var import_element = require("@wordpress/element");
25
+ var import_i18n = require("@wordpress/i18n");
13
26
  const DEFAULT_EMPTY_GALLERY = [];
14
-
15
- /**
16
- * Prepares the Featured Image toolbars and frames.
17
- *
18
- * @return {window.wp.media.view.MediaFrame.Select} The default media workflow.
19
- */
20
27
  const getFeaturedImageMediaFrame = () => {
21
- const {
22
- wp
23
- } = window;
28
+ const { wp } = window;
24
29
  return wp.media.view.MediaFrame.Select.extend({
25
30
  /**
26
31
  * Enables the Set Featured Image Button.
@@ -40,16 +45,12 @@ const getFeaturedImageMediaFrame = () => {
40
45
  * @return {void}
41
46
  */
42
47
  editState() {
43
- const selection = this.state('featured-image').get('selection');
48
+ const selection = this.state("featured-image").get("selection");
44
49
  const view = new wp.media.view.EditImage({
45
50
  model: selection.single(),
46
51
  controller: this
47
52
  }).render();
48
-
49
- // Set the view to the EditImage frame using the selected image.
50
53
  this.content.set(view);
51
-
52
- // After bringing in the frame, load the actual editor via an ajax call.
53
54
  view.loadEditor();
54
55
  },
55
56
  /**
@@ -58,28 +59,23 @@ const getFeaturedImageMediaFrame = () => {
58
59
  * @return {void}
59
60
  */
60
61
  createStates: function createStates() {
61
- this.on('toolbar:create:featured-image', this.featuredImageToolbar, this);
62
- this.on('content:render:edit-image', this.editState, this);
63
- this.states.add([new wp.media.controller.FeaturedImage(), new wp.media.controller.EditImage({
64
- model: this.options.editImage
65
- })]);
62
+ this.on(
63
+ "toolbar:create:featured-image",
64
+ this.featuredImageToolbar,
65
+ this
66
+ );
67
+ this.on("content:render:edit-image", this.editState, this);
68
+ this.states.add([
69
+ new wp.media.controller.FeaturedImage(),
70
+ new wp.media.controller.EditImage({
71
+ model: this.options.editImage
72
+ })
73
+ ]);
66
74
  }
67
75
  });
68
76
  };
69
-
70
- /**
71
- * Prepares the default frame for selecting a single media item.
72
- *
73
- * @return {window.wp.media.view.MediaFrame.Select} The default media workflow.
74
- */
75
77
  const getSingleMediaFrame = () => {
76
- const {
77
- wp
78
- } = window;
79
-
80
- // Extend the default Select frame, and use the same `createStates` method as in core,
81
- // but with the addition of `filterable: 'uploaded'` to the Library state, so that
82
- // the user can filter the media library by uploaded media.
78
+ const { wp } = window;
83
79
  return wp.media.view.MediaFrame.Select.extend({
84
80
  /**
85
81
  * Create the default states on the frame.
@@ -89,39 +85,25 @@ const getSingleMediaFrame = () => {
89
85
  if (this.options.states) {
90
86
  return;
91
87
  }
92
-
93
- // Add the default states.
94
88
  this.states.add([
95
- // Main states.
96
- new wp.media.controller.Library({
97
- library: wp.media.query(options.library),
98
- multiple: options.multiple,
99
- title: options.title,
100
- priority: 20,
101
- filterable: 'uploaded' // Allow filtering by uploaded images.
102
- }), new wp.media.controller.EditImage({
103
- model: options.editImage
104
- })]);
89
+ // Main states.
90
+ new wp.media.controller.Library({
91
+ library: wp.media.query(options.library),
92
+ multiple: options.multiple,
93
+ title: options.title,
94
+ priority: 20,
95
+ filterable: "uploaded"
96
+ // Allow filtering by uploaded images.
97
+ }),
98
+ new wp.media.controller.EditImage({
99
+ model: options.editImage
100
+ })
101
+ ]);
105
102
  }
106
103
  });
107
104
  };
108
-
109
- /**
110
- * Prepares the Gallery toolbars and frames.
111
- *
112
- * @return {window.wp.media.view.MediaFrame.Post} The default media workflow.
113
- */
114
105
  const getGalleryDetailsMediaFrame = () => {
115
- const {
116
- wp
117
- } = window;
118
- /**
119
- * Custom gallery details frame.
120
- *
121
- * @see https://github.com/xwp/wp-core-media-widgets/blob/905edbccfc2a623b73a93dac803c5335519d7837/wp-admin/js/widgets/media-gallery-widget.js
122
- * @class GalleryDetailsMediaFrame
123
- * @class
124
- */
106
+ const { wp } = window;
125
107
  return wp.media.view.MediaFrame.Post.extend({
126
108
  /**
127
109
  * Set up gallery toolbar.
@@ -129,33 +111,33 @@ const getGalleryDetailsMediaFrame = () => {
129
111
  * @return {void}
130
112
  */
131
113
  galleryToolbar() {
132
- const editing = this.state().get('editing');
133
- this.toolbar.set(new wp.media.view.Toolbar({
134
- controller: this,
135
- items: {
136
- insert: {
137
- style: 'primary',
138
- text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
139
- priority: 80,
140
- requires: {
141
- library: true
142
- },
143
- /**
144
- * @fires wp.media.controller.State#update
145
- */
146
- click() {
147
- const controller = this.controller,
148
- state = controller.state();
149
- controller.close();
150
- state.trigger('update', state.get('library'));
151
-
152
- // Restore and reset the default state.
153
- controller.setState(controller.options.state);
154
- controller.reset();
114
+ const editing = this.state().get("editing");
115
+ this.toolbar.set(
116
+ new wp.media.view.Toolbar({
117
+ controller: this,
118
+ items: {
119
+ insert: {
120
+ style: "primary",
121
+ text: editing ? wp.media.view.l10n.updateGallery : wp.media.view.l10n.insertGallery,
122
+ priority: 80,
123
+ requires: { library: true },
124
+ /**
125
+ * @fires wp.media.controller.State#update
126
+ */
127
+ click() {
128
+ const controller = this.controller, state = controller.state();
129
+ controller.close();
130
+ state.trigger(
131
+ "update",
132
+ state.get("library")
133
+ );
134
+ controller.setState(controller.options.state);
135
+ controller.reset();
136
+ }
155
137
  }
156
138
  }
157
- }
158
- }));
139
+ })
140
+ );
159
141
  },
160
142
  /**
161
143
  * Handle the edit state requirements of selected media item.
@@ -163,16 +145,12 @@ const getGalleryDetailsMediaFrame = () => {
163
145
  * @return {void}
164
146
  */
165
147
  editState() {
166
- const selection = this.state('gallery').get('selection');
148
+ const selection = this.state("gallery").get("selection");
167
149
  const view = new wp.media.view.EditImage({
168
150
  model: selection.single(),
169
151
  controller: this
170
152
  }).render();
171
-
172
- // Set the view to the EditImage frame using the selected image.
173
153
  this.content.set(view);
174
-
175
- // After bringing in the frame, load the actual editor via an ajax call.
176
154
  view.loadEditor();
177
155
  },
178
156
  /**
@@ -181,37 +159,49 @@ const getGalleryDetailsMediaFrame = () => {
181
159
  * @return {void}
182
160
  */
183
161
  createStates: function createStates() {
184
- this.on('toolbar:create:main-gallery', this.galleryToolbar, this);
185
- this.on('content:render:edit-image', this.editState, this);
186
- this.states.add([new wp.media.controller.Library({
187
- id: 'gallery',
188
- title: wp.media.view.l10n.createGalleryTitle,
189
- priority: 40,
190
- toolbar: 'main-gallery',
191
- filterable: 'uploaded',
192
- multiple: 'add',
193
- editable: false,
194
- library: wp.media.query({
195
- type: 'image',
196
- ...this.options.library
197
- })
198
- }), new wp.media.controller.EditImage({
199
- model: this.options.editImage
200
- }), new wp.media.controller.GalleryEdit({
201
- library: this.options.selection,
202
- editing: this.options.editing,
203
- menu: 'gallery',
204
- displaySettings: false,
205
- multiple: true
206
- }), new wp.media.controller.GalleryAdd()]);
162
+ this.on("toolbar:create:main-gallery", this.galleryToolbar, this);
163
+ this.on("content:render:edit-image", this.editState, this);
164
+ this.states.add([
165
+ new wp.media.controller.Library({
166
+ id: "gallery",
167
+ title: wp.media.view.l10n.createGalleryTitle,
168
+ priority: 40,
169
+ toolbar: "main-gallery",
170
+ filterable: "uploaded",
171
+ multiple: "add",
172
+ editable: false,
173
+ library: wp.media.query({
174
+ type: "image",
175
+ ...this.options.library
176
+ })
177
+ }),
178
+ new wp.media.controller.EditImage({
179
+ model: this.options.editImage
180
+ }),
181
+ new wp.media.controller.GalleryEdit({
182
+ library: this.options.selection,
183
+ editing: this.options.editing,
184
+ menu: "gallery",
185
+ displaySettings: false,
186
+ multiple: true
187
+ }),
188
+ new wp.media.controller.GalleryAdd()
189
+ ]);
207
190
  }
208
191
  });
209
192
  };
210
-
211
- // The media library image object contains numerous attributes
212
- // we only need this set to display the image in the library.
213
- const slimImageObject = img => {
214
- const attrSet = ['sizes', 'mime', 'type', 'subtype', 'id', 'url', 'alt', 'link', 'caption'];
193
+ const slimImageObject = (img) => {
194
+ const attrSet = [
195
+ "sizes",
196
+ "mime",
197
+ "type",
198
+ "subtype",
199
+ "id",
200
+ "url",
201
+ "alt",
202
+ "link",
203
+ "caption"
204
+ ];
215
205
  return attrSet.reduce((result, key) => {
216
206
  if (img?.hasOwnProperty(key)) {
217
207
  result[key] = img[key];
@@ -219,20 +209,18 @@ const slimImageObject = img => {
219
209
  return result;
220
210
  }, {});
221
211
  };
222
- const getAttachmentsCollection = ids => {
223
- const {
224
- wp
225
- } = window;
212
+ const getAttachmentsCollection = (ids) => {
213
+ const { wp } = window;
226
214
  return wp.media.query({
227
- order: 'ASC',
228
- orderby: 'post__in',
215
+ order: "ASC",
216
+ orderby: "post__in",
229
217
  post__in: ids,
230
218
  posts_per_page: -1,
231
219
  query: true,
232
- type: 'image'
220
+ type: "image"
233
221
  });
234
222
  };
235
- class MediaUpload extends _element.Component {
223
+ class MediaUpload extends import_element.Component {
236
224
  constructor() {
237
225
  super(...arguments);
238
226
  this.openModal = this.openModal.bind(this);
@@ -242,13 +230,11 @@ class MediaUpload extends _element.Component {
242
230
  this.onClose = this.onClose.bind(this);
243
231
  }
244
232
  initializeListeners() {
245
- // When an image is selected in the media frame...
246
- this.frame.on('select', this.onSelect);
247
- this.frame.on('update', this.onUpdate);
248
- this.frame.on('open', this.onOpen);
249
- this.frame.on('close', this.onClose);
233
+ this.frame.on("select", this.onSelect);
234
+ this.frame.on("update", this.onUpdate);
235
+ this.frame.on("open", this.onOpen);
236
+ this.frame.on("close", this.onClose);
250
237
  }
251
-
252
238
  /**
253
239
  * Sets the Gallery frame and initializes listeners.
254
240
  *
@@ -261,26 +247,19 @@ class MediaUpload extends _element.Component {
261
247
  multiple = false,
262
248
  value = DEFAULT_EMPTY_GALLERY
263
249
  } = this.props;
264
-
265
- // If the value did not changed there is no need to rebuild the frame,
266
- // we can continue to use the existing one.
267
250
  if (value === this.lastGalleryValue) {
268
251
  return;
269
252
  }
270
- const {
271
- wp
272
- } = window;
253
+ const { wp } = window;
273
254
  this.lastGalleryValue = value;
274
-
275
- // If a frame already existed remove it.
276
255
  if (this.frame) {
277
256
  this.frame.remove();
278
257
  }
279
258
  let currentState;
280
259
  if (addToGallery) {
281
- currentState = 'gallery-library';
260
+ currentState = "gallery-library";
282
261
  } else {
283
- currentState = value && value.length ? 'gallery-edit' : 'gallery';
262
+ currentState = value && value.length ? "gallery-edit" : "gallery";
284
263
  }
285
264
  if (!this.GalleryDetailsMediaFrame) {
286
265
  this.GalleryDetailsMediaFrame = getGalleryDetailsMediaFrame();
@@ -300,21 +279,14 @@ class MediaUpload extends _element.Component {
300
279
  wp.media.frame = this.frame;
301
280
  this.initializeListeners();
302
281
  }
303
-
304
282
  /**
305
283
  * Initializes the Media Library requirements for the featured image flow.
306
284
  *
307
285
  * @return {void}
308
286
  */
309
287
  buildAndSetFeatureImageFrame() {
310
- const {
311
- wp
312
- } = window;
313
- const {
314
- value: featuredImageId,
315
- multiple,
316
- allowedTypes
317
- } = this.props;
288
+ const { wp } = window;
289
+ const { value: featuredImageId, multiple, allowedTypes } = this.props;
318
290
  const featuredImageFrame = getFeaturedImageMediaFrame();
319
291
  const attachments = getAttachmentsCollection(featuredImageId);
320
292
  const selection = new wp.media.model.Selection(attachments.models, {
@@ -322,35 +294,28 @@ class MediaUpload extends _element.Component {
322
294
  });
323
295
  this.frame = new featuredImageFrame({
324
296
  mimeType: allowedTypes,
325
- state: 'featured-image',
297
+ state: "featured-image",
326
298
  multiple,
327
299
  selection,
328
300
  editing: featuredImageId
329
301
  });
330
302
  wp.media.frame = this.frame;
331
- // In order to select the current featured image when opening
332
- // the media library we have to set the appropriate settings.
333
- // Currently they are set in php for the post editor, but
334
- // not for site editor.
335
303
  wp.media.view.settings.post = {
336
304
  ...wp.media.view.settings.post,
337
305
  featuredImageId: featuredImageId || -1
338
306
  };
339
307
  }
340
-
341
308
  /**
342
309
  * Initializes the Media Library requirements for the single image flow.
343
310
  *
344
311
  * @return {void}
345
312
  */
346
313
  buildAndSetSingleMediaFrame() {
347
- const {
348
- wp
349
- } = window;
314
+ const { wp } = window;
350
315
  const {
351
316
  allowedTypes,
352
317
  multiple = false,
353
- title = (0, _i18n.__)('Select or Upload Media'),
318
+ title = (0, import_i18n.__)("Select or Upload Media"),
354
319
  value
355
320
  } = this.props;
356
321
  const frameConfig = {
@@ -358,12 +323,8 @@ class MediaUpload extends _element.Component {
358
323
  multiple
359
324
  };
360
325
  if (!!allowedTypes) {
361
- frameConfig.library = {
362
- type: allowedTypes
363
- };
326
+ frameConfig.library = { type: allowedTypes };
364
327
  }
365
-
366
- // If a frame already exists, remove it.
367
328
  if (this.frame) {
368
329
  this.frame.remove();
369
330
  }
@@ -384,73 +345,55 @@ class MediaUpload extends _element.Component {
384
345
  this.frame?.remove();
385
346
  }
386
347
  onUpdate(selections) {
387
- const {
388
- onSelect,
389
- multiple = false
390
- } = this.props;
348
+ const { onSelect, multiple = false } = this.props;
391
349
  const state = this.frame.state();
392
- const selectedImages = selections || state.get('selection');
350
+ const selectedImages = selections || state.get("selection");
393
351
  if (!selectedImages || !selectedImages.models.length) {
394
352
  return;
395
353
  }
396
354
  if (multiple) {
397
- onSelect(selectedImages.models.map(model => slimImageObject(model.toJSON())));
355
+ onSelect(
356
+ selectedImages.models.map(
357
+ (model) => slimImageObject(model.toJSON())
358
+ )
359
+ );
398
360
  } else {
399
361
  onSelect(slimImageObject(selectedImages.models[0].toJSON()));
400
362
  }
401
363
  }
402
364
  onSelect() {
403
- const {
404
- onSelect,
405
- multiple = false
406
- } = this.props;
407
- // Get media attachment details from the frame state.
408
- const attachment = this.frame.state().get('selection').toJSON();
365
+ const { onSelect, multiple = false } = this.props;
366
+ const attachment = this.frame.state().get("selection").toJSON();
409
367
  onSelect(multiple ? attachment : attachment[0]);
410
368
  }
411
369
  onOpen() {
412
- const {
413
- wp
414
- } = window;
415
- const {
416
- value
417
- } = this.props;
370
+ const { wp } = window;
371
+ const { value } = this.props;
418
372
  this.updateCollection();
419
-
420
- //Handle active tab in media model on model open.
421
373
  if (this.props.mode) {
422
374
  this.frame.content.mode(this.props.mode);
423
375
  }
424
-
425
- // Handle both this.props.value being either (number[]) multiple ids
426
- // (for galleries) or a (number) singular id (e.g. image block).
427
376
  const hasMedia = Array.isArray(value) ? !!value?.length : !!value;
428
377
  if (!hasMedia) {
429
378
  return;
430
379
  }
431
380
  const isGallery = this.props.gallery;
432
- const selection = this.frame.state().get('selection');
381
+ const selection = this.frame.state().get("selection");
433
382
  const valueArray = Array.isArray(value) ? value : [value];
434
383
  if (!isGallery) {
435
- valueArray.forEach(id => {
384
+ valueArray.forEach((id) => {
436
385
  selection.add(wp.media.attachment(id));
437
386
  });
438
387
  }
439
-
440
- // Load the images so they are available in the media modal.
441
388
  const attachments = getAttachmentsCollection(valueArray);
442
-
443
- // Once attachments are loaded, set the current selection.
444
- attachments.more().done(function () {
389
+ attachments.more().done(function() {
445
390
  if (isGallery && attachments?.models?.length) {
446
391
  selection.add(attachments.models);
447
392
  }
448
393
  });
449
394
  }
450
395
  onClose() {
451
- const {
452
- onClose
453
- } = this.props;
396
+ const { onClose } = this.props;
454
397
  if (onClose) {
455
398
  onClose();
456
399
  }
@@ -460,14 +403,8 @@ class MediaUpload extends _element.Component {
460
403
  const frameContent = this.frame.content.get();
461
404
  if (frameContent && frameContent.collection) {
462
405
  const collection = frameContent.collection;
463
-
464
- // Clean all attachments we have in memory.
465
- collection.toArray().forEach(model => model.trigger('destroy', model));
466
-
467
- // Reset has more flag, if library had small amount of items all items may have been loaded before.
406
+ collection.toArray().forEach((model) => model.trigger("destroy", model));
468
407
  collection.mirroring._hasMore = true;
469
-
470
- // Request items.
471
408
  collection.more();
472
409
  }
473
410
  }
@@ -492,10 +429,8 @@ class MediaUpload extends _element.Component {
492
429
  this.frame.open();
493
430
  }
494
431
  render() {
495
- return this.props.render({
496
- open: this.openModal
497
- });
432
+ return this.props.render({ open: this.openModal });
498
433
  }
499
434
  }
500
- var _default = exports.default = MediaUpload;
501
- //# sourceMappingURL=index.js.map
435
+ var media_upload_default = MediaUpload;
436
+ //# sourceMappingURL=index.js.map