@wordpress/media-utils 5.37.0 → 5.37.1-next.79a2f3cdd.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/CHANGELOG.md +0 -2
- package/LICENSE.md +1 -1
- package/build/components/{index.js → index.cjs} +3 -3
- package/build/components/{index.js.map → index.cjs.map} +1 -1
- package/build/components/media-upload/{index.js → index.cjs} +1 -1
- package/build/components/media-upload-modal/{index.js → index.cjs} +13 -8
- package/build/components/media-upload-modal/index.cjs.map +7 -0
- package/build/{index.js → index.cjs} +9 -9
- package/build/{index.js.map → index.cjs.map} +1 -1
- package/build/{lock-unlock.js → lock-unlock.cjs} +1 -1
- package/build/{private-apis.js → private-apis.cjs} +4 -4
- package/build/utils/{flatten-form-data.js → flatten-form-data.cjs} +1 -1
- package/build/utils/{get-mime-types-array.js → get-mime-types-array.cjs} +1 -1
- package/build/utils/{sideload-media.js → sideload-media.cjs} +3 -3
- package/build/utils/{sideload-to-server.js → sideload-to-server.cjs} +3 -3
- package/build/utils/{transform-attachment.js → transform-attachment.cjs} +1 -1
- package/build/utils/{types.js → types.cjs} +1 -1
- package/build/utils/{upload-error.js → upload-error.cjs} +1 -1
- package/build/utils/{upload-media.js → upload-media.cjs} +6 -6
- package/build/utils/{upload-to-server.js → upload-to-server.cjs} +3 -3
- package/build/utils/{validate-file-size.js → validate-file-size.cjs} +2 -2
- package/build/utils/{validate-mime-type-for-user.js → validate-mime-type-for-user.cjs} +3 -3
- package/build/utils/{validate-mime-type.js → validate-mime-type.cjs} +2 -2
- package/build-module/components/index.mjs +6 -0
- package/build-module/components/{index.js.map → index.mjs.map} +1 -1
- package/build-module/components/media-upload/{index.js → index.mjs} +1 -1
- package/build-module/components/media-upload-modal/{index.js → index.mjs} +13 -8
- package/build-module/components/media-upload-modal/index.mjs.map +7 -0
- package/build-module/index.mjs +17 -0
- package/build-module/{lock-unlock.js → lock-unlock.mjs} +1 -1
- package/build-module/{private-apis.js → private-apis.mjs} +4 -4
- package/build-module/utils/{flatten-form-data.js → flatten-form-data.mjs} +1 -1
- package/build-module/utils/{get-mime-types-array.js → get-mime-types-array.mjs} +1 -1
- package/build-module/utils/{sideload-media.js → sideload-media.mjs} +3 -3
- package/build-module/utils/{sideload-to-server.js → sideload-to-server.mjs} +3 -3
- package/build-module/utils/{transform-attachment.js → transform-attachment.mjs} +1 -1
- package/build-module/utils/types.mjs +1 -0
- package/build-module/utils/{upload-error.js → upload-error.mjs} +1 -1
- package/build-module/utils/{upload-media.js → upload-media.mjs} +6 -6
- package/build-module/utils/{upload-to-server.js → upload-to-server.mjs} +3 -3
- package/build-module/utils/{validate-file-size.js → validate-file-size.mjs} +2 -2
- package/build-module/utils/{validate-mime-type-for-user.js → validate-mime-type-for-user.mjs} +3 -3
- package/build-module/utils/{validate-mime-type.js → validate-mime-type.mjs} +2 -2
- package/build-style/style-rtl.css +64 -0
- package/build-style/style.css +64 -0
- package/build-types/components/index.d.ts +1 -1
- package/build-types/components/index.d.ts.map +1 -1
- package/build-types/components/media-upload-modal/index.d.ts.map +1 -1
- package/package.json +25 -17
- package/src/components/media-upload-modal/index.tsx +11 -6
- package/src/components/media-upload-modal/style.scss +23 -0
- package/src/style.scss +1 -0
- package/build/components/media-upload-modal/index.js.map +0 -7
- package/build-module/components/index.js +0 -6
- package/build-module/components/media-upload-modal/index.js.map +0 -7
- package/build-module/index.js +0 -17
- package/build-module/utils/types.js +0 -1
- package/tsconfig.json +0 -21
- package/tsconfig.tsbuildinfo +0 -1
- /package/build/components/media-upload/{index.js.map → index.cjs.map} +0 -0
- /package/build/{lock-unlock.js.map → lock-unlock.cjs.map} +0 -0
- /package/build/{private-apis.js.map → private-apis.cjs.map} +0 -0
- /package/build/utils/{flatten-form-data.js.map → flatten-form-data.cjs.map} +0 -0
- /package/build/utils/{get-mime-types-array.js.map → get-mime-types-array.cjs.map} +0 -0
- /package/build/utils/{sideload-media.js.map → sideload-media.cjs.map} +0 -0
- /package/build/utils/{sideload-to-server.js.map → sideload-to-server.cjs.map} +0 -0
- /package/build/utils/{transform-attachment.js.map → transform-attachment.cjs.map} +0 -0
- /package/build/utils/{types.js.map → types.cjs.map} +0 -0
- /package/build/utils/{upload-error.js.map → upload-error.cjs.map} +0 -0
- /package/build/utils/{upload-media.js.map → upload-media.cjs.map} +0 -0
- /package/build/utils/{upload-to-server.js.map → upload-to-server.cjs.map} +0 -0
- /package/build/utils/{validate-file-size.js.map → validate-file-size.cjs.map} +0 -0
- /package/build/utils/{validate-mime-type-for-user.js.map → validate-mime-type-for-user.cjs.map} +0 -0
- /package/build/utils/{validate-mime-type.js.map → validate-mime-type.cjs.map} +0 -0
- /package/build-module/components/media-upload/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/{index.js.map → index.mjs.map} +0 -0
- /package/build-module/{lock-unlock.js.map → lock-unlock.mjs.map} +0 -0
- /package/build-module/{private-apis.js.map → private-apis.mjs.map} +0 -0
- /package/build-module/utils/{flatten-form-data.js.map → flatten-form-data.mjs.map} +0 -0
- /package/build-module/utils/{get-mime-types-array.js.map → get-mime-types-array.mjs.map} +0 -0
- /package/build-module/utils/{sideload-media.js.map → sideload-media.mjs.map} +0 -0
- /package/build-module/utils/{sideload-to-server.js.map → sideload-to-server.mjs.map} +0 -0
- /package/build-module/utils/{transform-attachment.js.map → transform-attachment.mjs.map} +0 -0
- /package/build-module/utils/{types.js.map → types.mjs.map} +0 -0
- /package/build-module/utils/{upload-error.js.map → upload-error.mjs.map} +0 -0
- /package/build-module/utils/{upload-media.js.map → upload-media.mjs.map} +0 -0
- /package/build-module/utils/{upload-to-server.js.map → upload-to-server.mjs.map} +0 -0
- /package/build-module/utils/{validate-file-size.js.map → validate-file-size.mjs.map} +0 -0
- /package/build-module/utils/{validate-mime-type-for-user.js.map → validate-mime-type-for-user.mjs.map} +0 -0
- /package/build-module/utils/{validate-mime-type.js.map → validate-mime-type.mjs.map} +0 -0
- /package/src/components/{index.js → index.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// packages/media-utils/src/utils/upload-media.ts
|
|
2
2
|
import { __, sprintf } from "@wordpress/i18n";
|
|
3
3
|
import { createBlobURL, revokeBlobURL } from "@wordpress/blob";
|
|
4
|
-
import { uploadToServer } from "./upload-to-server";
|
|
5
|
-
import { validateMimeType } from "./validate-mime-type";
|
|
6
|
-
import { validateMimeTypeForUser } from "./validate-mime-type-for-user";
|
|
7
|
-
import { validateFileSize } from "./validate-file-size";
|
|
8
|
-
import { UploadError } from "./upload-error";
|
|
4
|
+
import { uploadToServer } from "./upload-to-server.mjs";
|
|
5
|
+
import { validateMimeType } from "./validate-mime-type.mjs";
|
|
6
|
+
import { validateMimeTypeForUser } from "./validate-mime-type-for-user.mjs";
|
|
7
|
+
import { validateFileSize } from "./validate-file-size.mjs";
|
|
8
|
+
import { UploadError } from "./upload-error.mjs";
|
|
9
9
|
function uploadMedia({
|
|
10
10
|
wpAllowedMimeTypes,
|
|
11
11
|
allowedTypes,
|
|
@@ -93,4 +93,4 @@ function uploadMedia({
|
|
|
93
93
|
export {
|
|
94
94
|
uploadMedia
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=upload-media.
|
|
96
|
+
//# sourceMappingURL=upload-media.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/media-utils/src/utils/upload-to-server.ts
|
|
2
2
|
import apiFetch from "@wordpress/api-fetch";
|
|
3
|
-
import { flattenFormData } from "./flatten-form-data";
|
|
4
|
-
import { transformAttachment } from "./transform-attachment";
|
|
3
|
+
import { flattenFormData } from "./flatten-form-data.mjs";
|
|
4
|
+
import { transformAttachment } from "./transform-attachment.mjs";
|
|
5
5
|
async function uploadToServer(file, additionalData = {}, signal) {
|
|
6
6
|
const data = new FormData();
|
|
7
7
|
data.append("file", file, file.name || file.type.replace("/", "."));
|
|
@@ -25,4 +25,4 @@ async function uploadToServer(file, additionalData = {}, signal) {
|
|
|
25
25
|
export {
|
|
26
26
|
uploadToServer
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=upload-to-server.
|
|
28
|
+
//# sourceMappingURL=upload-to-server.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/media-utils/src/utils/validate-file-size.ts
|
|
2
2
|
import { __, sprintf } from "@wordpress/i18n";
|
|
3
|
-
import { UploadError } from "./upload-error";
|
|
3
|
+
import { UploadError } from "./upload-error.mjs";
|
|
4
4
|
function validateFileSize(file, maxUploadFileSize) {
|
|
5
5
|
if (file.size <= 0) {
|
|
6
6
|
throw new UploadError({
|
|
@@ -30,4 +30,4 @@ function validateFileSize(file, maxUploadFileSize) {
|
|
|
30
30
|
export {
|
|
31
31
|
validateFileSize
|
|
32
32
|
};
|
|
33
|
-
//# sourceMappingURL=validate-file-size.
|
|
33
|
+
//# sourceMappingURL=validate-file-size.mjs.map
|
package/build-module/utils/{validate-mime-type-for-user.js → validate-mime-type-for-user.mjs}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/media-utils/src/utils/validate-mime-type-for-user.ts
|
|
2
2
|
import { __, sprintf } from "@wordpress/i18n";
|
|
3
|
-
import { UploadError } from "./upload-error";
|
|
4
|
-
import { getMimeTypesArray } from "./get-mime-types-array";
|
|
3
|
+
import { UploadError } from "./upload-error.mjs";
|
|
4
|
+
import { getMimeTypesArray } from "./get-mime-types-array.mjs";
|
|
5
5
|
function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
|
|
6
6
|
const allowedMimeTypesForUser = getMimeTypesArray(wpAllowedMimeTypes);
|
|
7
7
|
if (!allowedMimeTypesForUser) {
|
|
@@ -27,4 +27,4 @@ function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
|
|
|
27
27
|
export {
|
|
28
28
|
validateMimeTypeForUser
|
|
29
29
|
};
|
|
30
|
-
//# sourceMappingURL=validate-mime-type-for-user.
|
|
30
|
+
//# sourceMappingURL=validate-mime-type-for-user.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// packages/media-utils/src/utils/validate-mime-type.ts
|
|
2
2
|
import { __, sprintf } from "@wordpress/i18n";
|
|
3
|
-
import { UploadError } from "./upload-error";
|
|
3
|
+
import { UploadError } from "./upload-error.mjs";
|
|
4
4
|
function validateMimeType(file, allowedTypes) {
|
|
5
5
|
if (!allowedTypes) {
|
|
6
6
|
return;
|
|
@@ -26,4 +26,4 @@ function validateMimeType(file, allowedTypes) {
|
|
|
26
26
|
export {
|
|
27
27
|
validateMimeType
|
|
28
28
|
};
|
|
29
|
-
//# sourceMappingURL=validate-mime-type.
|
|
29
|
+
//# sourceMappingURL=validate-mime-type.mjs.map
|
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
/**
|
|
84
84
|
* Reset the WP Admin page styles for Gutenberg-like pages.
|
|
85
85
|
*/
|
|
86
|
+
/**
|
|
87
|
+
* Creates a checkerboard pattern background to indicate transparency.
|
|
88
|
+
* @param {String} $size - The size of the squares in the checkerboard pattern. Default is 12px.
|
|
89
|
+
*/
|
|
86
90
|
.dataviews-media-field__media-thumbnail {
|
|
87
91
|
display: flex;
|
|
88
92
|
align-items: center;
|
|
@@ -129,4 +133,64 @@
|
|
|
129
133
|
.dataviews-media-field__media-thumbnail__filename__truncate {
|
|
130
134
|
display: none !important;
|
|
131
135
|
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* SCSS Variables.
|
|
139
|
+
*
|
|
140
|
+
* Please use variables from this sheet to ensure consistency across the UI.
|
|
141
|
+
* Don't add to this sheet unless you're pretty sure the value will be reused in many places.
|
|
142
|
+
* For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Colors
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Fonts & basic variables.
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Typography
|
|
152
|
+
*/
|
|
153
|
+
/**
|
|
154
|
+
* Grid System.
|
|
155
|
+
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* Radius scale.
|
|
159
|
+
*/
|
|
160
|
+
/**
|
|
161
|
+
* Elevation scale.
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* Dimensions.
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* Mobile specific styles
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* Editor styles.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Block & Editor UI.
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* Block paddings.
|
|
177
|
+
*/
|
|
178
|
+
/**
|
|
179
|
+
* React Native specific.
|
|
180
|
+
* These variables do not appear to be used anywhere else.
|
|
181
|
+
*/
|
|
182
|
+
.media-upload-modal .components-modal__header {
|
|
183
|
+
padding-bottom: 8px;
|
|
184
|
+
}
|
|
185
|
+
.media-upload-modal .components-modal__frame.is-full-screen .components-modal__content {
|
|
186
|
+
margin-bottom: 16px;
|
|
187
|
+
}
|
|
188
|
+
.media-upload-modal .components-modal__content {
|
|
189
|
+
padding: 0;
|
|
190
|
+
}
|
|
191
|
+
.media-upload-modal .dataviews-picker-wrapper > .dataviews__view-actions {
|
|
192
|
+
padding-top: 8px;
|
|
193
|
+
}
|
|
194
|
+
.media-upload-modal .dataviews-footer {
|
|
195
|
+
padding-bottom: 8px;
|
|
132
196
|
}
|
package/build-style/style.css
CHANGED
|
@@ -83,6 +83,10 @@
|
|
|
83
83
|
/**
|
|
84
84
|
* Reset the WP Admin page styles for Gutenberg-like pages.
|
|
85
85
|
*/
|
|
86
|
+
/**
|
|
87
|
+
* Creates a checkerboard pattern background to indicate transparency.
|
|
88
|
+
* @param {String} $size - The size of the squares in the checkerboard pattern. Default is 12px.
|
|
89
|
+
*/
|
|
86
90
|
.dataviews-media-field__media-thumbnail {
|
|
87
91
|
display: flex;
|
|
88
92
|
align-items: center;
|
|
@@ -129,4 +133,64 @@
|
|
|
129
133
|
.dataviews-media-field__media-thumbnail__filename__truncate {
|
|
130
134
|
display: none !important;
|
|
131
135
|
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* SCSS Variables.
|
|
139
|
+
*
|
|
140
|
+
* Please use variables from this sheet to ensure consistency across the UI.
|
|
141
|
+
* Don't add to this sheet unless you're pretty sure the value will be reused in many places.
|
|
142
|
+
* For example, don't add rules to this sheet that affect block visuals. It's purely for UI.
|
|
143
|
+
*/
|
|
144
|
+
/**
|
|
145
|
+
* Colors
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Fonts & basic variables.
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Typography
|
|
152
|
+
*/
|
|
153
|
+
/**
|
|
154
|
+
* Grid System.
|
|
155
|
+
* https://make.wordpress.org/design/2019/10/31/proposal-a-consistent-spacing-system-for-wordpress/
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* Radius scale.
|
|
159
|
+
*/
|
|
160
|
+
/**
|
|
161
|
+
* Elevation scale.
|
|
162
|
+
*/
|
|
163
|
+
/**
|
|
164
|
+
* Dimensions.
|
|
165
|
+
*/
|
|
166
|
+
/**
|
|
167
|
+
* Mobile specific styles
|
|
168
|
+
*/
|
|
169
|
+
/**
|
|
170
|
+
* Editor styles.
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Block & Editor UI.
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* Block paddings.
|
|
177
|
+
*/
|
|
178
|
+
/**
|
|
179
|
+
* React Native specific.
|
|
180
|
+
* These variables do not appear to be used anywhere else.
|
|
181
|
+
*/
|
|
182
|
+
.media-upload-modal .components-modal__header {
|
|
183
|
+
padding-bottom: 8px;
|
|
184
|
+
}
|
|
185
|
+
.media-upload-modal .components-modal__frame.is-full-screen .components-modal__content {
|
|
186
|
+
margin-bottom: 16px;
|
|
187
|
+
}
|
|
188
|
+
.media-upload-modal .components-modal__content {
|
|
189
|
+
padding: 0;
|
|
190
|
+
}
|
|
191
|
+
.media-upload-modal .dataviews-picker-wrapper > .dataviews__view-actions {
|
|
192
|
+
padding-top: 8px;
|
|
193
|
+
}
|
|
194
|
+
.media-upload-modal .dataviews-footer {
|
|
195
|
+
padding-bottom: 8px;
|
|
132
196
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as MediaUpload } from
|
|
1
|
+
export { default as MediaUpload } from './media-upload';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-upload-modal/index.tsx"],"names":[],"mappings":"AAyBA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AAWpE,UAAU,qBAAqB;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE1B;;;OAGG;IACH,QAAQ,EAAE,CAAE,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,KAAM,IAAI,CAAC;IAEvD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAE,IAAI,EAAE;QAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,SAAS,EAAE,IAAI,EAAE,CAAC;QAClB,YAAY,CAAC,EAAE,CAAE,WAAW,EAAE,OAAO,CAAE,UAAU,CAAE,EAAE,KAAM,IAAI,CAAC;QAChE,OAAO,CAAC,EAAE,CAAE,KAAK,EAAE,KAAK,KAAM,IAAI,CAAC;QACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;KACnB,KAAM,IAAI,CAAC;IAEZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAE,EACjC,YAA0B,EAC1B,QAAgB,EAChB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,KAA4B,EAC5B,MAAM,EACN,aAAoB,EACpB,UAAU,EACV,MAAa,EACb,WAAkC,GAClC,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-upload-modal/index.tsx"],"names":[],"mappings":"AAyBA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AAWpE,UAAU,qBAAqB;IAC9B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE1B;;;OAGG;IACH,QAAQ,EAAE,CAAE,KAAK,EAAE,UAAU,GAAG,UAAU,EAAE,KAAM,IAAI,CAAC;IAEvD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAErB;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAE,IAAI,EAAE;QAClB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,SAAS,EAAE,IAAI,EAAE,CAAC;QAClB,YAAY,CAAC,EAAE,CAAE,WAAW,EAAE,OAAO,CAAE,UAAU,CAAE,EAAE,KAAM,IAAI,CAAC;QAChE,OAAO,CAAC,EAAE,CAAE,KAAK,EAAE,KAAK,KAAM,IAAI,CAAC;QACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;KACnB,KAAM,IAAI,CAAC;IAEZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAE,EACjC,YAA0B,EAC1B,QAAgB,EAChB,KAAK,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,KAA4B,EAC5B,MAAM,EACN,aAAoB,EACpB,UAAU,EACV,MAAa,EACb,WAAkC,GAClC,EAAE,qBAAqB,sCA2QvB;AAED,eAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/media-utils",
|
|
3
|
-
"version": "5.37.0",
|
|
3
|
+
"version": "5.37.1-next.79a2f3cdd.0",
|
|
4
4
|
"description": "WordPress Media Upload Utils.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -23,13 +23,21 @@
|
|
|
23
23
|
"node": ">=18.12.0",
|
|
24
24
|
"npm": ">=8.19.2"
|
|
25
25
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
26
|
+
"files": [
|
|
27
|
+
"src",
|
|
28
|
+
"build",
|
|
29
|
+
"build-module",
|
|
30
|
+
"build-style",
|
|
31
|
+
"build-types",
|
|
32
|
+
"*.md"
|
|
33
|
+
],
|
|
34
|
+
"main": "build/index.cjs",
|
|
35
|
+
"module": "build-module/index.mjs",
|
|
28
36
|
"exports": {
|
|
29
37
|
".": {
|
|
30
38
|
"types": "./build-types/index.d.ts",
|
|
31
|
-
"import": "./build-module/index.
|
|
32
|
-
"require": "./build/index.
|
|
39
|
+
"import": "./build-module/index.mjs",
|
|
40
|
+
"require": "./build/index.cjs"
|
|
33
41
|
},
|
|
34
42
|
"./package.json": "./package.json"
|
|
35
43
|
},
|
|
@@ -39,17 +47,17 @@
|
|
|
39
47
|
"build-style/**"
|
|
40
48
|
],
|
|
41
49
|
"dependencies": {
|
|
42
|
-
"@wordpress/api-fetch": "^7.37.0",
|
|
43
|
-
"@wordpress/blob": "^4.37.0",
|
|
44
|
-
"@wordpress/components": "^
|
|
45
|
-
"@wordpress/core-data": "^7.37.0",
|
|
46
|
-
"@wordpress/data": "^10.37.0",
|
|
47
|
-
"@wordpress/dataviews": "^11.1.0",
|
|
48
|
-
"@wordpress/element": "^6.37.0",
|
|
49
|
-
"@wordpress/i18n": "^6.10.0",
|
|
50
|
-
"@wordpress/icons": "^11.4.0",
|
|
51
|
-
"@wordpress/media-fields": "^0.2.0",
|
|
52
|
-
"@wordpress/private-apis": "^1.37.0"
|
|
50
|
+
"@wordpress/api-fetch": "^7.37.1-next.79a2f3cdd.0",
|
|
51
|
+
"@wordpress/blob": "^4.37.1-next.79a2f3cdd.0",
|
|
52
|
+
"@wordpress/components": "^32.0.1-next.79a2f3cdd.0",
|
|
53
|
+
"@wordpress/core-data": "^7.37.1-next.79a2f3cdd.0",
|
|
54
|
+
"@wordpress/data": "^10.37.1-next.79a2f3cdd.0",
|
|
55
|
+
"@wordpress/dataviews": "^11.2.1-next.79a2f3cdd.0",
|
|
56
|
+
"@wordpress/element": "^6.37.1-next.79a2f3cdd.0",
|
|
57
|
+
"@wordpress/i18n": "^6.10.1-next.79a2f3cdd.0",
|
|
58
|
+
"@wordpress/icons": "^11.4.1-next.79a2f3cdd.0",
|
|
59
|
+
"@wordpress/media-fields": "^0.2.1-next.79a2f3cdd.0",
|
|
60
|
+
"@wordpress/private-apis": "^1.37.1-next.79a2f3cdd.0"
|
|
53
61
|
},
|
|
54
62
|
"peerDependencies": {
|
|
55
63
|
"react": "^18.0.0"
|
|
@@ -57,5 +65,5 @@
|
|
|
57
65
|
"publishConfig": {
|
|
58
66
|
"access": "public"
|
|
59
67
|
},
|
|
60
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "6a324496a37d9a333a11d4d7fe5fb93b8152a5ba"
|
|
61
69
|
}
|
|
@@ -222,6 +222,12 @@ export function MediaUploadModal( {
|
|
|
222
222
|
|
|
223
223
|
const fields: Field< RestAttachment >[] = useMemo(
|
|
224
224
|
() => [
|
|
225
|
+
// Media field definitions from @wordpress/media-fields
|
|
226
|
+
// Cast is safe because RestAttachment has the same properties as Attachment
|
|
227
|
+
{
|
|
228
|
+
...( mediaThumbnailField as Field< RestAttachment > ),
|
|
229
|
+
enableHiding: false, // Within the modal, the thumbnail should always be shown.
|
|
230
|
+
},
|
|
225
231
|
{
|
|
226
232
|
id: 'title',
|
|
227
233
|
type: 'text' as const,
|
|
@@ -231,9 +237,6 @@ export function MediaUploadModal( {
|
|
|
231
237
|
return titleValue || __( '(no title)' );
|
|
232
238
|
},
|
|
233
239
|
},
|
|
234
|
-
// Media field definitions from @wordpress/media-fields
|
|
235
|
-
// Cast is safe because RestAttachment has the same properties as Attachment
|
|
236
|
-
mediaThumbnailField as Field< RestAttachment >,
|
|
237
240
|
altTextField as Field< RestAttachment >,
|
|
238
241
|
captionField as Field< RestAttachment >,
|
|
239
242
|
descriptionField as Field< RestAttachment >,
|
|
@@ -264,15 +267,16 @@ export function MediaUploadModal( {
|
|
|
264
267
|
|
|
265
268
|
const selectedPosts = await resolveSelect(
|
|
266
269
|
coreStore
|
|
267
|
-
).getEntityRecords(
|
|
270
|
+
).getEntityRecords< RestAttachment >(
|
|
268
271
|
'postType',
|
|
269
272
|
'attachment',
|
|
270
273
|
selectedPostsQuery
|
|
271
274
|
);
|
|
272
275
|
|
|
273
276
|
// Transform the selected posts to the expected Attachment format
|
|
274
|
-
const transformedPosts =
|
|
275
|
-
|
|
277
|
+
const transformedPosts = ( selectedPosts ?? [] )
|
|
278
|
+
.map( transformAttachment )
|
|
279
|
+
.filter( Boolean );
|
|
276
280
|
|
|
277
281
|
const selectedItems = multiple
|
|
278
282
|
? transformedPosts
|
|
@@ -346,6 +350,7 @@ export function MediaUploadModal( {
|
|
|
346
350
|
onRequestClose={ handleModalClose }
|
|
347
351
|
isDismissible={ isDismissible }
|
|
348
352
|
className={ modalClass }
|
|
353
|
+
overlayClassName="media-upload-modal"
|
|
349
354
|
size="fill"
|
|
350
355
|
headerActions={
|
|
351
356
|
<FormFileUpload
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
|
|
3
|
+
.media-upload-modal {
|
|
4
|
+
.components-modal__header {
|
|
5
|
+
padding-bottom: $grid-unit-10;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.components-modal__frame.is-full-screen .components-modal__content {
|
|
9
|
+
margin-bottom: $grid-unit-20;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.components-modal__content {
|
|
13
|
+
padding: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.dataviews-picker-wrapper > .dataviews__view-actions {
|
|
17
|
+
padding-top: $grid-unit-10;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.dataviews-footer {
|
|
21
|
+
padding-bottom: $grid-unit-10;
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/style.scss
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-upload-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useCallback, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tprivateApis as coreDataPrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { resolveSelect } from '@wordpress/data';\nimport { Modal, DropZone, FormFileUpload, Button } from '@wordpress/components';\nimport { upload as uploadIcon } from '@wordpress/icons';\nimport { DataViewsPicker } from '@wordpress/dataviews';\nimport type { View, Field, ActionButton } from '@wordpress/dataviews';\nimport {\n\taltTextField,\n\tcaptionField,\n\tdescriptionField,\n\tfilenameField,\n\tfilesizeField,\n\tmediaDimensionsField,\n\tmediaThumbnailField,\n\tmimeTypeField,\n} from '@wordpress/media-fields';\n\n/**\n * Internal dependencies\n */\nimport type { Attachment, RestAttachment } from '../../utils/types';\nimport { transformAttachment } from '../../utils/transform-attachment';\nimport { uploadMedia } from '../../utils/upload-media';\nimport { unlock } from '../../lock-unlock';\n\nconst { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );\n\n// Layout constants - matching the picker layout types\nconst LAYOUT_PICKER_GRID = 'pickerGrid';\nconst LAYOUT_PICKER_TABLE = 'pickerTable';\n\ninterface MediaUploadModalProps {\n\t/**\n\t * Array of allowed media types.\n\t * @default ['image']\n\t */\n\tallowedTypes?: string[];\n\n\t/**\n\t * Whether multiple files can be selected.\n\t * @default false\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * The currently selected media item(s).\n\t * Can be a single ID number or array of IDs for multiple selection.\n\t */\n\tvalue?: number | number[];\n\n\t/**\n\t * Function called when media is selected.\n\t * Receives single attachment object or array of attachments.\n\t */\n\tonSelect: ( media: Attachment | Attachment[] ) => void;\n\n\t/**\n\t * Function called when the modal is closed without selection.\n\t */\n\tonClose?: () => void;\n\n\t/**\n\t * Function to handle media uploads.\n\t * If not provided, drag and drop will be disabled.\n\t */\n\tonUpload?: ( args: {\n\t\tallowedTypes?: string[];\n\t\tfilesList: File[];\n\t\tonFileChange?: ( attachments: Partial< Attachment >[] ) => void;\n\t\tonError?: ( error: Error ) => void;\n\t\tmultiple?: boolean;\n\t} ) => void;\n\n\t/**\n\t * Title for the modal.\n\t * @default 'Select Media'\n\t */\n\ttitle?: string;\n\n\t/**\n\t * Whether the modal is open.\n\t */\n\tisOpen: boolean;\n\n\t/**\n\t * Whether the modal can be closed by clicking outside or pressing escape.\n\t * @default true\n\t */\n\tisDismissible?: boolean;\n\n\t/**\n\t * Additional CSS class for the modal.\n\t */\n\tmodalClass?: string;\n\n\t/**\n\t * Whether to show a search input.\n\t * @default true\n\t */\n\tsearch?: boolean;\n\n\t/**\n\t * Label for the search input.\n\t */\n\tsearchLabel?: string;\n}\n\n/**\n * MediaUploadModal component that uses Modal and DataViewsPicker for media selection.\n *\n * This is a modern functional component alternative to the legacy MediaUpload class component.\n * It provides a cleaner API and better integration with the WordPress block editor.\n *\n * @param props Component props\n * @param props.allowedTypes Array of allowed media types\n * @param props.multiple Whether multiple files can be selected\n * @param props.value Currently selected media item(s)\n * @param props.onSelect Function called when media is selected\n * @param props.onClose Function called when modal is closed\n * @param props.onUpload Function to handle media uploads\n * @param props.title Title for the modal\n * @param props.isOpen Whether the modal is open\n * @param props.isDismissible Whether modal can be dismissed\n * @param props.modalClass Additional CSS class for modal\n * @param props.search Whether to show search input\n * @param props.searchLabel Label for search input\n * @return JSX element or null\n */\nexport function MediaUploadModal( {\n\tallowedTypes = [ 'image' ],\n\tmultiple = false,\n\tvalue,\n\tonSelect,\n\tonClose,\n\tonUpload,\n\ttitle = __( 'Select Media' ),\n\tisOpen,\n\tisDismissible = true,\n\tmodalClass,\n\tsearch = true,\n\tsearchLabel = __( 'Search media' ),\n}: MediaUploadModalProps ) {\n\tconst [ selection, setSelection ] = useState< string[] >( () => {\n\t\tif ( ! value ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn Array.isArray( value )\n\t\t\t? value.map( String )\n\t\t\t: [ String( value ) ];\n\t} );\n\n\t// DataViews configuration - allow view updates\n\tconst [ view, setView ] = useState< View >( () => ( {\n\t\ttype: LAYOUT_PICKER_GRID,\n\t\tfields: [],\n\t\tshowTitle: false,\n\t\ttitleField: 'title',\n\t\tmediaField: 'media_thumbnail',\n\t\tsearch: '',\n\t\tpage: 1,\n\t\tperPage: 20,\n\t\tfilters: [],\n\t} ) );\n\n\t// Build query args based on view properties, similar to PostList\n\tconst queryArgs = useMemo( () => {\n\t\tconst filters: Record< string, any > = {};\n\n\t\tview.filters?.forEach( ( filter ) => {\n\t\t\t// Handle media type filters\n\t\t\tif ( filter.field === 'media_type' ) {\n\t\t\t\tfilters.media_type = filter.value;\n\t\t\t}\n\t\t\t// Handle author filters\n\t\t\tif ( filter.field === 'author' ) {\n\t\t\t\tfilters.author = filter.value;\n\t\t\t}\n\t\t\t// Handle date filters\n\t\t\tif ( filter.field === 'date' ) {\n\t\t\t\tfilters.after = filter.value?.after;\n\t\t\t\tfilters.before = filter.value?.before;\n\t\t\t}\n\t\t\t// Handle mime type filters\n\t\t\tif ( filter.field === 'mime_type' ) {\n\t\t\t\tfilters.mime_type = filter.value;\n\t\t\t}\n\t\t} );\n\n\t\t// Base media type on allowedTypes if no filter is set\n\t\tif ( ! filters.media_type ) {\n\t\t\tfilters.media_type = allowedTypes.includes( '*' )\n\t\t\t\t? undefined\n\t\t\t\t: allowedTypes;\n\t\t}\n\n\t\treturn {\n\t\t\tper_page: view.perPage || 20,\n\t\t\tpage: view.page || 1,\n\t\t\tstatus: 'inherit',\n\t\t\torder: view.sort?.direction,\n\t\t\torderby: view.sort?.field,\n\t\t\tsearch: view.search,\n\t\t\t...filters,\n\t\t};\n\t}, [ view, allowedTypes ] );\n\n\t// Fetch all media attachments using WordPress core data with permissions\n\tconst {\n\t\trecords: mediaRecords,\n\t\tisResolving: isLoading,\n\t\ttotalItems,\n\t\ttotalPages,\n\t} = useEntityRecordsWithPermissions( 'postType', 'attachment', queryArgs );\n\n\tconst fields: Field< RestAttachment >[] = useMemo(\n\t\t() => [\n\t\t\t{\n\t\t\t\tid: 'title',\n\t\t\t\ttype: 'text' as const,\n\t\t\t\tlabel: __( 'Title' ),\n\t\t\t\tgetValue: ( { item }: { item: RestAttachment } ) => {\n\t\t\t\t\tconst titleValue = item.title.raw || item.title.rendered;\n\t\t\t\t\treturn titleValue || __( '(no title)' );\n\t\t\t\t},\n\t\t\t},\n\t\t\t// Media field definitions from @wordpress/media-fields\n\t\t\t// Cast is safe because RestAttachment has the same properties as Attachment\n\t\t\tmediaThumbnailField as Field< RestAttachment >,\n\t\t\taltTextField as Field< RestAttachment >,\n\t\t\tcaptionField as Field< RestAttachment >,\n\t\t\tdescriptionField as Field< RestAttachment >,\n\t\t\tfilenameField as Field< RestAttachment >,\n\t\t\tfilesizeField as Field< RestAttachment >,\n\t\t\tmediaDimensionsField as Field< RestAttachment >,\n\t\t\tmimeTypeField as Field< RestAttachment >,\n\t\t],\n\t\t[]\n\t);\n\n\tconst actions: ActionButton< RestAttachment >[] = useMemo(\n\t\t() => [\n\t\t\t{\n\t\t\t\tid: 'select',\n\t\t\t\tlabel: multiple ? __( 'Select' ) : __( 'Select' ),\n\t\t\t\tisPrimary: true,\n\t\t\t\tsupportsBulk: multiple,\n\t\t\t\tasync callback() {\n\t\t\t\t\tif ( selection.length === 0 ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectedPostsQuery = {\n\t\t\t\t\t\tinclude: selection,\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst selectedPosts = await resolveSelect(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tselectedPostsQuery\n\t\t\t\t\t);\n\n\t\t\t\t\t// Transform the selected posts to the expected Attachment format\n\t\t\t\t\tconst transformedPosts =\n\t\t\t\t\t\tselectedPosts?.map( transformAttachment );\n\n\t\t\t\t\tconst selectedItems = multiple\n\t\t\t\t\t\t? transformedPosts\n\t\t\t\t\t\t: transformedPosts?.[ 0 ];\n\n\t\t\t\t\tonSelect( selectedItems );\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t[ multiple, onSelect, selection ]\n\t);\n\n\tconst handleModalClose = useCallback( () => {\n\t\tonClose?.();\n\t}, [ onClose ] );\n\n\t// Use onUpload if provided, otherwise fall back to uploadMedia\n\tconst handleUpload = onUpload || uploadMedia;\n\n\tconst handleFileSelect = useCallback(\n\t\t( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\t\tconst files = event.target.files;\n\t\t\tif ( files && files.length > 0 ) {\n\t\t\t\tconst filesArray = Array.from( files );\n\t\t\t\thandleUpload( {\n\t\t\t\t\tallowedTypes,\n\t\t\t\t\tfilesList: filesArray,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ allowedTypes, handleUpload ]\n\t);\n\n\tconst paginationInfo = useMemo(\n\t\t() => ( {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t} ),\n\t\t[ totalItems, totalPages ]\n\t);\n\n\tconst defaultLayouts = useMemo(\n\t\t() => ( {\n\t\t\t[ LAYOUT_PICKER_GRID ]: {\n\t\t\t\tfields: [],\n\t\t\t\tshowTitle: false,\n\t\t\t},\n\t\t\t[ LAYOUT_PICKER_TABLE ]: {\n\t\t\t\tfields: [ 'filename', 'filesize', 'media_dimensions' ],\n\t\t\t\tshowTitle: true,\n\t\t\t},\n\t\t} ),\n\t\t[]\n\t);\n\n\t// Build accept attribute from allowedTypes\n\tconst acceptTypes = useMemo( () => {\n\t\tif ( allowedTypes.includes( '*' ) ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn allowedTypes.join( ',' );\n\t}, [ allowedTypes ] );\n\n\tif ( ! isOpen ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ title }\n\t\t\tonRequestClose={ handleModalClose }\n\t\t\tisDismissible={ isDismissible }\n\t\t\tclassName={ modalClass }\n\t\t\tsize=\"fill\"\n\t\t\theaderActions={\n\t\t\t\t<FormFileUpload\n\t\t\t\t\taccept={ acceptTypes }\n\t\t\t\t\tmultiple\n\t\t\t\t\tonChange={ handleFileSelect }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trender={ ( { openFileDialog } ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\ticon={ uploadIcon }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Upload media' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t}\n\t\t>\n\t\t\t<DropZone\n\t\t\t\tonFilesDrop={ ( files ) => {\n\t\t\t\t\tlet filteredFiles = files;\n\t\t\t\t\t// Filter files by allowed types if specified\n\t\t\t\t\tif ( allowedTypes && ! allowedTypes.includes( '*' ) ) {\n\t\t\t\t\t\tfilteredFiles = files.filter( ( file ) =>\n\t\t\t\t\t\t\tallowedTypes.some( ( allowedType ) => {\n\t\t\t\t\t\t\t\t// Check if the file type matches the allowed MIME type\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\tfile.type === allowedType ||\n\t\t\t\t\t\t\t\t\tfile.type.startsWith(\n\t\t\t\t\t\t\t\t\t\tallowedType.replace( '*', '' )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( filteredFiles.length > 0 ) {\n\t\t\t\t\t\thandleUpload( {\n\t\t\t\t\t\t\tallowedTypes,\n\t\t\t\t\t\t\tfilesList: filteredFiles,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tlabel={ __( 'Drop files to upload' ) }\n\t\t\t/>\n\t\t\t<DataViewsPicker\n\t\t\t\tdata={ mediaRecords || [] }\n\t\t\t\tfields={ fields }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ setView }\n\t\t\t\tactions={ actions }\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ setSelection }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\tgetItemId={ ( item: RestAttachment ) => String( item.id ) }\n\t\t\t\tsearch={ search }\n\t\t\t\tsearchLabel={ searchLabel }\n\t\t\t\titemListLabel={ __( 'Media items' ) }\n\t\t\t/>\n\t\t</Modal>\n\t);\n}\n\nexport default MediaUploadModal;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAC/C,kBAAmB;AACnB,uBAGO;AACP,kBAA8B;AAC9B,wBAAwD;AACxD,mBAAqC;AACrC,uBAAgC;AAEhC,0BASO;AAMP,kCAAoC;AACpC,0BAA4B;AAC5B,yBAAuB;AAwTrB;AAtTF,IAAM,EAAE,gCAAgC,QAAI,2BAAQ,iBAAAA,WAAoB;AAGxE,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAmGrB,SAAS,iBAAkB;AAAA,EACjC,eAAe,CAAE,OAAQ;AAAA,EACzB,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAQ,gBAAI,cAAe;AAAA,EAC3B;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,EACT,kBAAc,gBAAI,cAAe;AA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AAA,MAEF;AAAA,MAGD;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,aAAc,CAAE,UAAW;AAC1B,kBAAI,gBAAgB;AAEpB,kBAAK,gBAAgB,CAAE,aAAa,SAAU,GAAI,GAAI;AACrD,gCAAgB,MAAM;AAAA,kBAAQ,CAAE,SAC/B,aAAa,KAAM,CAAE,gBAAiB;AAErC,2BACC,KAAK,SAAS,eACd,KAAK,KAAK;AAAA,sBACT,YAAY,QAAS,KAAK,EAAG;AAAA,oBAC9B;AAAA,kBAEF,CAAE;AAAA,gBACH;AAAA,cACD;AACA,kBAAK,cAAc,SAAS,GAAI;AAC/B,6BAAc;AAAA,kBACb;AAAA,kBACA,WAAW;AAAA,gBACZ,CAAE;AAAA,cACH;AAAA,YACD;AAAA,YACA,WAAQ,gBAAI,sBAAuB;AAAA;AAAA,QACpC;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,MAAO,gBAAgB,CAAC;AAAA,YACxB;AAAA,YACA;AAAA,YACA,cAAe;AAAA,YACf;AAAA,YACA;AAAA,YACA,mBAAoB;AAAA,YACpB;AAAA,YACA;AAAA,YACA;AAAA,YACA,WAAY,CAAE,SAA0B,OAAQ,KAAK,EAAG;AAAA,YACxD;AAAA,YACA;AAAA,YACA,mBAAgB,gBAAI,aAAc;AAAA;AAAA,QACnC;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
|
-
"names": ["coreDataPrivateApis", "coreStore", "uploadIcon"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/media-upload-modal/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useCallback, useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tprivateApis as coreDataPrivateApis,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { resolveSelect } from '@wordpress/data';\nimport { Modal, DropZone, FormFileUpload, Button } from '@wordpress/components';\nimport { upload as uploadIcon } from '@wordpress/icons';\nimport { DataViewsPicker } from '@wordpress/dataviews';\nimport type { View, Field, ActionButton } from '@wordpress/dataviews';\nimport {\n\taltTextField,\n\tcaptionField,\n\tdescriptionField,\n\tfilenameField,\n\tfilesizeField,\n\tmediaDimensionsField,\n\tmediaThumbnailField,\n\tmimeTypeField,\n} from '@wordpress/media-fields';\n\n/**\n * Internal dependencies\n */\nimport type { Attachment, RestAttachment } from '../../utils/types';\nimport { transformAttachment } from '../../utils/transform-attachment';\nimport { uploadMedia } from '../../utils/upload-media';\nimport { unlock } from '../../lock-unlock';\n\nconst { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );\n\n// Layout constants - matching the picker layout types\nconst LAYOUT_PICKER_GRID = 'pickerGrid';\nconst LAYOUT_PICKER_TABLE = 'pickerTable';\n\ninterface MediaUploadModalProps {\n\t/**\n\t * Array of allowed media types.\n\t * @default ['image']\n\t */\n\tallowedTypes?: string[];\n\n\t/**\n\t * Whether multiple files can be selected.\n\t * @default false\n\t */\n\tmultiple?: boolean;\n\n\t/**\n\t * The currently selected media item(s).\n\t * Can be a single ID number or array of IDs for multiple selection.\n\t */\n\tvalue?: number | number[];\n\n\t/**\n\t * Function called when media is selected.\n\t * Receives single attachment object or array of attachments.\n\t */\n\tonSelect: ( media: Attachment | Attachment[] ) => void;\n\n\t/**\n\t * Function called when the modal is closed without selection.\n\t */\n\tonClose?: () => void;\n\n\t/**\n\t * Function to handle media uploads.\n\t * If not provided, drag and drop will be disabled.\n\t */\n\tonUpload?: ( args: {\n\t\tallowedTypes?: string[];\n\t\tfilesList: File[];\n\t\tonFileChange?: ( attachments: Partial< Attachment >[] ) => void;\n\t\tonError?: ( error: Error ) => void;\n\t\tmultiple?: boolean;\n\t} ) => void;\n\n\t/**\n\t * Title for the modal.\n\t * @default 'Select Media'\n\t */\n\ttitle?: string;\n\n\t/**\n\t * Whether the modal is open.\n\t */\n\tisOpen: boolean;\n\n\t/**\n\t * Whether the modal can be closed by clicking outside or pressing escape.\n\t * @default true\n\t */\n\tisDismissible?: boolean;\n\n\t/**\n\t * Additional CSS class for the modal.\n\t */\n\tmodalClass?: string;\n\n\t/**\n\t * Whether to show a search input.\n\t * @default true\n\t */\n\tsearch?: boolean;\n\n\t/**\n\t * Label for the search input.\n\t */\n\tsearchLabel?: string;\n}\n\n/**\n * MediaUploadModal component that uses Modal and DataViewsPicker for media selection.\n *\n * This is a modern functional component alternative to the legacy MediaUpload class component.\n * It provides a cleaner API and better integration with the WordPress block editor.\n *\n * @param props Component props\n * @param props.allowedTypes Array of allowed media types\n * @param props.multiple Whether multiple files can be selected\n * @param props.value Currently selected media item(s)\n * @param props.onSelect Function called when media is selected\n * @param props.onClose Function called when modal is closed\n * @param props.onUpload Function to handle media uploads\n * @param props.title Title for the modal\n * @param props.isOpen Whether the modal is open\n * @param props.isDismissible Whether modal can be dismissed\n * @param props.modalClass Additional CSS class for modal\n * @param props.search Whether to show search input\n * @param props.searchLabel Label for search input\n * @return JSX element or null\n */\nexport function MediaUploadModal( {\n\tallowedTypes = [ 'image' ],\n\tmultiple = false,\n\tvalue,\n\tonSelect,\n\tonClose,\n\tonUpload,\n\ttitle = __( 'Select Media' ),\n\tisOpen,\n\tisDismissible = true,\n\tmodalClass,\n\tsearch = true,\n\tsearchLabel = __( 'Search media' ),\n}: MediaUploadModalProps ) {\n\tconst [ selection, setSelection ] = useState< string[] >( () => {\n\t\tif ( ! value ) {\n\t\t\treturn [];\n\t\t}\n\t\treturn Array.isArray( value )\n\t\t\t? value.map( String )\n\t\t\t: [ String( value ) ];\n\t} );\n\n\t// DataViews configuration - allow view updates\n\tconst [ view, setView ] = useState< View >( () => ( {\n\t\ttype: LAYOUT_PICKER_GRID,\n\t\tfields: [],\n\t\tshowTitle: false,\n\t\ttitleField: 'title',\n\t\tmediaField: 'media_thumbnail',\n\t\tsearch: '',\n\t\tpage: 1,\n\t\tperPage: 20,\n\t\tfilters: [],\n\t} ) );\n\n\t// Build query args based on view properties, similar to PostList\n\tconst queryArgs = useMemo( () => {\n\t\tconst filters: Record< string, any > = {};\n\n\t\tview.filters?.forEach( ( filter ) => {\n\t\t\t// Handle media type filters\n\t\t\tif ( filter.field === 'media_type' ) {\n\t\t\t\tfilters.media_type = filter.value;\n\t\t\t}\n\t\t\t// Handle author filters\n\t\t\tif ( filter.field === 'author' ) {\n\t\t\t\tfilters.author = filter.value;\n\t\t\t}\n\t\t\t// Handle date filters\n\t\t\tif ( filter.field === 'date' ) {\n\t\t\t\tfilters.after = filter.value?.after;\n\t\t\t\tfilters.before = filter.value?.before;\n\t\t\t}\n\t\t\t// Handle mime type filters\n\t\t\tif ( filter.field === 'mime_type' ) {\n\t\t\t\tfilters.mime_type = filter.value;\n\t\t\t}\n\t\t} );\n\n\t\t// Base media type on allowedTypes if no filter is set\n\t\tif ( ! filters.media_type ) {\n\t\t\tfilters.media_type = allowedTypes.includes( '*' )\n\t\t\t\t? undefined\n\t\t\t\t: allowedTypes;\n\t\t}\n\n\t\treturn {\n\t\t\tper_page: view.perPage || 20,\n\t\t\tpage: view.page || 1,\n\t\t\tstatus: 'inherit',\n\t\t\torder: view.sort?.direction,\n\t\t\torderby: view.sort?.field,\n\t\t\tsearch: view.search,\n\t\t\t...filters,\n\t\t};\n\t}, [ view, allowedTypes ] );\n\n\t// Fetch all media attachments using WordPress core data with permissions\n\tconst {\n\t\trecords: mediaRecords,\n\t\tisResolving: isLoading,\n\t\ttotalItems,\n\t\ttotalPages,\n\t} = useEntityRecordsWithPermissions( 'postType', 'attachment', queryArgs );\n\n\tconst fields: Field< RestAttachment >[] = useMemo(\n\t\t() => [\n\t\t\t{\n\t\t\t\tid: 'title',\n\t\t\t\ttype: 'text' as const,\n\t\t\t\tlabel: __( 'Title' ),\n\t\t\t\tgetValue: ( { item }: { item: RestAttachment } ) => {\n\t\t\t\t\tconst titleValue = item.title.raw || item.title.rendered;\n\t\t\t\t\treturn titleValue || __( '(no title)' );\n\t\t\t\t},\n\t\t\t},\n\t\t\t// Media field definitions from @wordpress/media-fields\n\t\t\t// Cast is safe because RestAttachment has the same properties as Attachment\n\t\t\tmediaThumbnailField as Field< RestAttachment >,\n\t\t\taltTextField as Field< RestAttachment >,\n\t\t\tcaptionField as Field< RestAttachment >,\n\t\t\tdescriptionField as Field< RestAttachment >,\n\t\t\tfilenameField as Field< RestAttachment >,\n\t\t\tfilesizeField as Field< RestAttachment >,\n\t\t\tmediaDimensionsField as Field< RestAttachment >,\n\t\t\tmimeTypeField as Field< RestAttachment >,\n\t\t],\n\t\t[]\n\t);\n\n\tconst actions: ActionButton< RestAttachment >[] = useMemo(\n\t\t() => [\n\t\t\t{\n\t\t\t\tid: 'select',\n\t\t\t\tlabel: multiple ? __( 'Select' ) : __( 'Select' ),\n\t\t\t\tisPrimary: true,\n\t\t\t\tsupportsBulk: multiple,\n\t\t\t\tasync callback() {\n\t\t\t\t\tif ( selection.length === 0 ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst selectedPostsQuery = {\n\t\t\t\t\t\tinclude: selection,\n\t\t\t\t\t\tper_page: -1,\n\t\t\t\t\t};\n\n\t\t\t\t\tconst selectedPosts = await resolveSelect(\n\t\t\t\t\t\tcoreStore\n\t\t\t\t\t).getEntityRecords(\n\t\t\t\t\t\t'postType',\n\t\t\t\t\t\t'attachment',\n\t\t\t\t\t\tselectedPostsQuery\n\t\t\t\t\t);\n\n\t\t\t\t\t// Transform the selected posts to the expected Attachment format\n\t\t\t\t\tconst transformedPosts =\n\t\t\t\t\t\tselectedPosts?.map( transformAttachment );\n\n\t\t\t\t\tconst selectedItems = multiple\n\t\t\t\t\t\t? transformedPosts\n\t\t\t\t\t\t: transformedPosts?.[ 0 ];\n\n\t\t\t\t\tonSelect( selectedItems );\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\t[ multiple, onSelect, selection ]\n\t);\n\n\tconst handleModalClose = useCallback( () => {\n\t\tonClose?.();\n\t}, [ onClose ] );\n\n\t// Use onUpload if provided, otherwise fall back to uploadMedia\n\tconst handleUpload = onUpload || uploadMedia;\n\n\tconst handleFileSelect = useCallback(\n\t\t( event: React.ChangeEvent< HTMLInputElement > ) => {\n\t\t\tconst files = event.target.files;\n\t\t\tif ( files && files.length > 0 ) {\n\t\t\t\tconst filesArray = Array.from( files );\n\t\t\t\thandleUpload( {\n\t\t\t\t\tallowedTypes,\n\t\t\t\t\tfilesList: filesArray,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ allowedTypes, handleUpload ]\n\t);\n\n\tconst paginationInfo = useMemo(\n\t\t() => ( {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t} ),\n\t\t[ totalItems, totalPages ]\n\t);\n\n\tconst defaultLayouts = useMemo(\n\t\t() => ( {\n\t\t\t[ LAYOUT_PICKER_GRID ]: {\n\t\t\t\tfields: [],\n\t\t\t\tshowTitle: false,\n\t\t\t},\n\t\t\t[ LAYOUT_PICKER_TABLE ]: {\n\t\t\t\tfields: [ 'filename', 'filesize', 'media_dimensions' ],\n\t\t\t\tshowTitle: true,\n\t\t\t},\n\t\t} ),\n\t\t[]\n\t);\n\n\t// Build accept attribute from allowedTypes\n\tconst acceptTypes = useMemo( () => {\n\t\tif ( allowedTypes.includes( '*' ) ) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn allowedTypes.join( ',' );\n\t}, [ allowedTypes ] );\n\n\tif ( ! isOpen ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ title }\n\t\t\tonRequestClose={ handleModalClose }\n\t\t\tisDismissible={ isDismissible }\n\t\t\tclassName={ modalClass }\n\t\t\tsize=\"fill\"\n\t\t\theaderActions={\n\t\t\t\t<FormFileUpload\n\t\t\t\t\taccept={ acceptTypes }\n\t\t\t\t\tmultiple\n\t\t\t\t\tonChange={ handleFileSelect }\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trender={ ( { openFileDialog } ) => (\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tonClick={ openFileDialog }\n\t\t\t\t\t\t\ticon={ uploadIcon }\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Upload media' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t}\n\t\t>\n\t\t\t<DropZone\n\t\t\t\tonFilesDrop={ ( files ) => {\n\t\t\t\t\tlet filteredFiles = files;\n\t\t\t\t\t// Filter files by allowed types if specified\n\t\t\t\t\tif ( allowedTypes && ! allowedTypes.includes( '*' ) ) {\n\t\t\t\t\t\tfilteredFiles = files.filter( ( file ) =>\n\t\t\t\t\t\t\tallowedTypes.some( ( allowedType ) => {\n\t\t\t\t\t\t\t\t// Check if the file type matches the allowed MIME type\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\tfile.type === allowedType ||\n\t\t\t\t\t\t\t\t\tfile.type.startsWith(\n\t\t\t\t\t\t\t\t\t\tallowedType.replace( '*', '' )\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif ( filteredFiles.length > 0 ) {\n\t\t\t\t\t\thandleUpload( {\n\t\t\t\t\t\t\tallowedTypes,\n\t\t\t\t\t\t\tfilesList: filteredFiles,\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} }\n\t\t\t\tlabel={ __( 'Drop files to upload' ) }\n\t\t\t/>\n\t\t\t<DataViewsPicker\n\t\t\t\tdata={ mediaRecords || [] }\n\t\t\t\tfields={ fields }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ setView }\n\t\t\t\tactions={ actions }\n\t\t\t\tselection={ selection }\n\t\t\t\tonChangeSelection={ setSelection }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t\tdefaultLayouts={ defaultLayouts }\n\t\t\t\tgetItemId={ ( item: RestAttachment ) => String( item.id ) }\n\t\t\t\tsearch={ search }\n\t\t\t\tsearchLabel={ searchLabel }\n\t\t\t\titemListLabel={ __( 'Media items' ) }\n\t\t\t/>\n\t\t</Modal>\n\t);\n}\n\nexport default MediaUploadModal;\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU,aAAa,eAAe;AAC/C,SAAS,UAAU;AACnB;AAAA,EACC,eAAe;AAAA,EACf,SAAS;AAAA,OACH;AACP,SAAS,qBAAqB;AAC9B,SAAS,OAAO,UAAU,gBAAgB,cAAc;AACxD,SAAS,UAAU,kBAAkB;AACrC,SAAS,uBAAuB;AAEhC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAMP,SAAS,2BAA2B;AACpC,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AAwTrB,SAaI,KAbJ;AAtTF,IAAM,EAAE,gCAAgC,IAAI,OAAQ,mBAAoB;AAGxE,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAmGrB,SAAS,iBAAkB;AAAA,EACjC,eAAe,CAAE,OAAQ;AAAA,EACzB,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,GAAI,cAAe;AAAA,EAC3B;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA,SAAS;AAAA,EACT,cAAc,GAAI,cAAe;AAClC,GAA2B;AAC1B,QAAM,CAAE,WAAW,YAAa,IAAI,SAAsB,MAAM;AAC/D,QAAK,CAAE,OAAQ;AACd,aAAO,CAAC;AAAA,IACT;AACA,WAAO,MAAM,QAAS,KAAM,IACzB,MAAM,IAAK,MAAO,IAClB,CAAE,OAAQ,KAAM,CAAE;AAAA,EACtB,CAAE;AAGF,QAAM,CAAE,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AAAA,sBACT,YAAY,QAAS,KAAK,EAAG;AAAA,oBAC9B;AAAA,kBAEF,CAAE;AAAA,gBACH;AAAA,cACD;AACA,kBAAK,cAAc,SAAS,GAAI;AAC/B,6BAAc;AAAA,kBACb;AAAA,kBACA,WAAW;AAAA,gBACZ,CAAE;AAAA,cACH;AAAA,YACD;AAAA,YACA,OAAQ,GAAI,sBAAuB;AAAA;AAAA,QACpC;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACA,MAAO,gBAAgB,CAAC;AAAA,YACxB;AAAA,YACA;AAAA,YACA,cAAe;AAAA,YACf;AAAA,YACA;AAAA,YACA,mBAAoB;AAAA,YACpB;AAAA,YACA;AAAA,YACA;AAAA,YACA,WAAY,CAAE,SAA0B,OAAQ,KAAK,EAAG;AAAA,YACxD;AAAA,YACA;AAAA,YACA,eAAgB,GAAI,aAAc;AAAA;AAAA,QACnC;AAAA;AAAA;AAAA,EACD;AAEF;AAEA,IAAO,6BAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
package/build-module/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// packages/media-utils/src/index.ts
|
|
2
|
-
export * from "./components";
|
|
3
|
-
import { uploadMedia } from "./utils/upload-media";
|
|
4
|
-
import { transformAttachment } from "./utils/transform-attachment";
|
|
5
|
-
import { validateFileSize } from "./utils/validate-file-size";
|
|
6
|
-
import { validateMimeType } from "./utils/validate-mime-type";
|
|
7
|
-
import { validateMimeTypeForUser } from "./utils/validate-mime-type-for-user";
|
|
8
|
-
import { privateApis } from "./private-apis";
|
|
9
|
-
export {
|
|
10
|
-
privateApis,
|
|
11
|
-
transformAttachment,
|
|
12
|
-
uploadMedia,
|
|
13
|
-
validateFileSize,
|
|
14
|
-
validateMimeType,
|
|
15
|
-
validateMimeTypeForUser
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
-
"extends": "../../tsconfig.base.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"types": [ "gutenberg-env" ],
|
|
6
|
-
"checkJs": false
|
|
7
|
-
},
|
|
8
|
-
"references": [
|
|
9
|
-
{ "path": "../api-fetch" },
|
|
10
|
-
{ "path": "../blob" },
|
|
11
|
-
{ "path": "../components" },
|
|
12
|
-
{ "path": "../core-data" },
|
|
13
|
-
{ "path": "../data" },
|
|
14
|
-
{ "path": "../dataviews" },
|
|
15
|
-
{ "path": "../element" },
|
|
16
|
-
{ "path": "../i18n" },
|
|
17
|
-
{ "path": "../icons" },
|
|
18
|
-
{ "path": "../media-fields" },
|
|
19
|
-
{ "path": "../private-apis" }
|
|
20
|
-
]
|
|
21
|
-
}
|