@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.
- package/build/components/index.js +36 -11
- package/build/components/index.js.map +7 -1
- package/build/components/media-upload/index.js +156 -221
- package/build/components/media-upload/index.js.map +7 -1
- package/build/index.js +44 -65
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/private-apis.js +31 -17
- package/build/private-apis.js.map +7 -1
- package/build/utils/flatten-form-data.js +28 -20
- package/build/utils/flatten-form-data.js.map +7 -1
- package/build/utils/get-mime-types-array.js +38 -20
- package/build/utils/get-mime-types-array.js.map +7 -1
- package/build/utils/sideload-media.js +50 -38
- package/build/utils/sideload-media.js.map +7 -1
- package/build/utils/sideload-to-server.js +53 -36
- package/build/utils/sideload-to-server.js.map +7 -1
- package/build/utils/transform-attachment.js +29 -23
- package/build/utils/transform-attachment.js.map +7 -1
- package/build/utils/types.js +16 -5
- package/build/utils/types.js.map +7 -1
- package/build/utils/upload-error.js +30 -21
- package/build/utils/upload-error.js.map +7 -1
- package/build/utils/upload-media.js +62 -71
- package/build/utils/upload-media.js.map +7 -1
- package/build/utils/upload-to-server.js +54 -27
- package/build/utils/upload-to-server.js.map +7 -1
- package/build/utils/validate-file-size.js +44 -32
- package/build/utils/validate-file-size.js.map +7 -1
- package/build/utils/validate-mime-type-for-user.js +42 -30
- package/build/utils/validate-mime-type-for-user.js.map +7 -1
- package/build/utils/validate-mime-type.js +37 -32
- package/build/utils/validate-mime-type.js.map +7 -1
- package/build-module/components/index.js +5 -2
- package/build-module/components/index.js.map +7 -1
- package/build-module/components/media-upload/index.js +137 -215
- package/build-module/components/media-upload/index.js.map +7 -1
- package/build-module/index.js +16 -8
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/private-apis.js +7 -11
- package/build-module/private-apis.js.map +7 -1
- package/build-module/utils/flatten-form-data.js +7 -17
- package/build-module/utils/flatten-form-data.js.map +7 -1
- package/build-module/utils/get-mime-types-array.js +17 -17
- package/build-module/utils/get-mime-types-array.js.map +7 -1
- package/build-module/utils/sideload-media.js +28 -34
- package/build-module/utils/sideload-media.js.map +7 -1
- package/build-module/utils/sideload-to-server.js +22 -33
- package/build-module/utils/sideload-to-server.js.map +7 -1
- package/build-module/utils/transform-attachment.js +8 -20
- package/build-module/utils/transform-attachment.js.map +7 -1
- package/build-module/utils/types.js +1 -2
- package/build-module/utils/types.js.map +7 -1
- package/build-module/utils/upload-error.js +9 -17
- package/build-module/utils/upload-error.js.map +7 -1
- package/build-module/utils/upload-media.js +36 -63
- package/build-module/utils/upload-media.js.map +7 -1
- package/build-module/utils/upload-to-server.js +23 -22
- package/build-module/utils/upload-to-server.js.map +7 -1
- package/build-module/utils/validate-file-size.js +19 -25
- package/build-module/utils/validate-file-size.js.map +7 -1
- package/build-module/utils/validate-mime-type-for-user.js +18 -24
- package/build-module/utils/validate-mime-type-for-user.js.map +7 -1
- package/build-module/utils/validate-mime-type.js +14 -27
- package/build-module/utils/validate-mime-type.js.map +7 -1
- package/package.json +15 -8
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
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.
|
|
4
|
-
|
|
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
|
|
7
|
-
var
|
|
8
|
-
var
|
|
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(
|
|
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(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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(
|
|
133
|
-
this.toolbar.set(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
library: true
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
state
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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(
|
|
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(
|
|
185
|
-
this.on(
|
|
186
|
-
this.states.add([
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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:
|
|
228
|
-
orderby:
|
|
215
|
+
order: "ASC",
|
|
216
|
+
orderby: "post__in",
|
|
229
217
|
post__in: ids,
|
|
230
218
|
posts_per_page: -1,
|
|
231
219
|
query: true,
|
|
232
|
-
type:
|
|
220
|
+
type: "image"
|
|
233
221
|
});
|
|
234
222
|
};
|
|
235
|
-
class MediaUpload extends
|
|
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
|
-
|
|
246
|
-
this.frame.on(
|
|
247
|
-
this.frame.on(
|
|
248
|
-
this.frame.on(
|
|
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 =
|
|
260
|
+
currentState = "gallery-library";
|
|
282
261
|
} else {
|
|
283
|
-
currentState = value && value.length ?
|
|
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
|
-
|
|
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:
|
|
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,
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
|
501
|
-
//# sourceMappingURL=index.js.map
|
|
435
|
+
var media_upload_default = MediaUpload;
|
|
436
|
+
//# sourceMappingURL=index.js.map
|