@wordpress/media-utils 5.32.0 → 5.32.1-next.47f435fc9.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 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_blob","_uploadToServer","_validateMimeType","_validateMimeTypeForUser","_validateFileSize","_uploadError","uploadMedia","wpAllowedMimeTypes","allowedTypes","additionalData","filesList","maxUploadFileSize","onError","onFileChange","signal","multiple","length","Error","__","validFiles","filesSet","setAndUpdateFiles","index","value","window","__experimentalMediaProcessing","url","revokeBlobURL","filter","attachment","mediaFile","validateMimeTypeForUser","error","validateMimeType","validateFileSize","push","createBlobURL","map","file","uploadToServer","message","String","sprintf","name","UploadError","code","cause","undefined"],"sources":["@wordpress/media-utils/src/utils/upload-media.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { createBlobURL, revokeBlobURL } from '@wordpress/blob';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tAdditionalData,\n\tAttachment,\n\tOnChangeHandler,\n\tOnErrorHandler,\n} from './types';\nimport { uploadToServer } from './upload-to-server';\nimport { validateMimeType } from './validate-mime-type';\nimport { validateMimeTypeForUser } from './validate-mime-type-for-user';\nimport { validateFileSize } from './validate-file-size';\nimport { UploadError } from './upload-error';\n\ndeclare global {\n\tinterface Window {\n\t\t__experimentalMediaProcessing?: boolean;\n\t}\n}\n\ninterface UploadMediaArgs {\n\t// Additional data to include in the request.\n\tadditionalData?: AdditionalData;\n\t// Array with the types of media that can be uploaded, if unset all types are allowed.\n\tallowedTypes?: string[];\n\t// List of files.\n\tfilesList: File[];\n\t// Maximum upload size in bytes allowed for the site.\n\tmaxUploadFileSize?: number;\n\t// Function called when an error happens.\n\tonError?: OnErrorHandler;\n\t// Function called each time a file or a temporary representation of the file is available.\n\tonFileChange?: OnChangeHandler;\n\t// List of allowed mime types and file extensions.\n\twpAllowedMimeTypes?: Record< string, string > | null;\n\t// Abort signal.\n\tsignal?: AbortSignal;\n\t// Whether to allow multiple files to be uploaded.\n\tmultiple?: boolean;\n}\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param $0 Parameters object passed to the function.\n * @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param $0.additionalData Additional data to include in the request.\n * @param $0.filesList List of files.\n * @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.\n * @param $0.onError Function called when an error happens.\n * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.\n * @param $0.signal Abort signal.\n * @param $0.multiple Whether to allow multiple files to be uploaded.\n */\nexport function uploadMedia( {\n\twpAllowedMimeTypes,\n\tallowedTypes,\n\tadditionalData = {},\n\tfilesList,\n\tmaxUploadFileSize,\n\tonError,\n\tonFileChange,\n\tsignal,\n\tmultiple = true,\n}: UploadMediaArgs ) {\n\tif ( ! multiple && filesList.length > 1 ) {\n\t\tonError?.( new Error( __( 'Only one file can be used here.' ) ) );\n\t\treturn;\n\t}\n\n\tconst validFiles = [];\n\n\tconst filesSet: Array< Partial< Attachment > | null > = [];\n\tconst setAndUpdateFiles = ( index: number, value: Attachment | null ) => {\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\tif ( filesSet[ index ]?.url ) {\n\t\t\t\trevokeBlobURL( filesSet[ index ].url );\n\t\t\t}\n\t\t}\n\t\tfilesSet[ index ] = value;\n\t\tonFileChange?.(\n\t\t\tfilesSet.filter( ( attachment ) => attachment !== null )\n\t\t);\n\t};\n\n\tfor ( const mediaFile of filesList ) {\n\t\t// Verify if user is allowed to upload this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeTypeForUser( mediaFile, wpAllowedMimeTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check if the caller (e.g. a block) supports this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeType( mediaFile, allowedTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Verify if file is greater than the maximum file upload size allowed for the site.\n\t\ttry {\n\t\t\tvalidateFileSize( mediaFile, maxUploadFileSize );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\tvalidFiles.push( mediaFile );\n\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\t// Set temporary URL to create placeholder media file, this is replaced\n\t\t\t// with final file from media gallery when upload is `done` below.\n\t\t\tfilesSet.push( { url: createBlobURL( mediaFile ) } );\n\t\t\tonFileChange?.( filesSet as Array< Partial< Attachment > > );\n\t\t}\n\t}\n\n\tvalidFiles.map( async ( file, index ) => {\n\t\ttry {\n\t\t\tconst attachment = await uploadToServer(\n\t\t\t\tfile,\n\t\t\t\tadditionalData,\n\t\t\t\tsignal\n\t\t\t);\n\t\t\tsetAndUpdateFiles( index, attachment );\n\t\t} catch ( error ) {\n\t\t\t// Reset to empty on failure.\n\t\t\tsetAndUpdateFiles( index, null );\n\n\t\t\t// @wordpress/api-fetch throws any response that isn't in the 200 range as-is.\n\t\t\tlet message: string;\n\t\t\tif (\n\t\t\t\ttypeof error === 'object' &&\n\t\t\t\terror !== null &&\n\t\t\t\t'message' in error\n\t\t\t) {\n\t\t\t\tmessage =\n\t\t\t\t\ttypeof error.message === 'string'\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: String( error.message );\n\t\t\t} else {\n\t\t\t\tmessage = sprintf(\n\t\t\t\t\t// translators: %s: file name\n\t\t\t\t\t__( 'Error while uploading file %s to the media library.' ),\n\t\t\t\t\tfile.name\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tonError?.(\n\t\t\t\tnew UploadError( {\n\t\t\t\t\tcode: 'GENERAL',\n\t\t\t\t\tmessage,\n\t\t\t\t\tfile,\n\t\t\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\t} );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAWA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,wBAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAA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IAAI,EAAE,SAAS;QACfL,OAAO;QACPF,IAAI;QACJQ,KAAK,EAAEd,KAAK,YAAYf,KAAK,GAAGe,KAAK,GAAGe;MACzC,CAAE,CACH,CAAC;IACF;EACD,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/upload-media.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\nimport { createBlobURL, revokeBlobURL } from '@wordpress/blob';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tAdditionalData,\n\tAttachment,\n\tOnChangeHandler,\n\tOnErrorHandler,\n} from './types';\nimport { uploadToServer } from './upload-to-server';\nimport { validateMimeType } from './validate-mime-type';\nimport { validateMimeTypeForUser } from './validate-mime-type-for-user';\nimport { validateFileSize } from './validate-file-size';\nimport { UploadError } from './upload-error';\n\ndeclare global {\n\tinterface Window {\n\t\t__experimentalMediaProcessing?: boolean;\n\t}\n}\n\ninterface UploadMediaArgs {\n\t// Additional data to include in the request.\n\tadditionalData?: AdditionalData;\n\t// Array with the types of media that can be uploaded, if unset all types are allowed.\n\tallowedTypes?: string[];\n\t// List of files.\n\tfilesList: File[];\n\t// Maximum upload size in bytes allowed for the site.\n\tmaxUploadFileSize?: number;\n\t// Function called when an error happens.\n\tonError?: OnErrorHandler;\n\t// Function called each time a file or a temporary representation of the file is available.\n\tonFileChange?: OnChangeHandler;\n\t// List of allowed mime types and file extensions.\n\twpAllowedMimeTypes?: Record< string, string > | null;\n\t// Abort signal.\n\tsignal?: AbortSignal;\n\t// Whether to allow multiple files to be uploaded.\n\tmultiple?: boolean;\n}\n\n/**\n * Upload a media file when the file upload button is activated\n * or when adding a file to the editor via drag & drop.\n *\n * @param $0 Parameters object passed to the function.\n * @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.\n * @param $0.additionalData Additional data to include in the request.\n * @param $0.filesList List of files.\n * @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.\n * @param $0.onError Function called when an error happens.\n * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.\n * @param $0.signal Abort signal.\n * @param $0.multiple Whether to allow multiple files to be uploaded.\n */\nexport function uploadMedia( {\n\twpAllowedMimeTypes,\n\tallowedTypes,\n\tadditionalData = {},\n\tfilesList,\n\tmaxUploadFileSize,\n\tonError,\n\tonFileChange,\n\tsignal,\n\tmultiple = true,\n}: UploadMediaArgs ) {\n\tif ( ! multiple && filesList.length > 1 ) {\n\t\tonError?.( new Error( __( 'Only one file can be used here.' ) ) );\n\t\treturn;\n\t}\n\n\tconst validFiles = [];\n\n\tconst filesSet: Array< Partial< Attachment > | null > = [];\n\tconst setAndUpdateFiles = ( index: number, value: Attachment | null ) => {\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\tif ( filesSet[ index ]?.url ) {\n\t\t\t\trevokeBlobURL( filesSet[ index ].url );\n\t\t\t}\n\t\t}\n\t\tfilesSet[ index ] = value;\n\t\tonFileChange?.(\n\t\t\tfilesSet.filter( ( attachment ) => attachment !== null )\n\t\t);\n\t};\n\n\tfor ( const mediaFile of filesList ) {\n\t\t// Verify if user is allowed to upload this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeTypeForUser( mediaFile, wpAllowedMimeTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Check if the caller (e.g. a block) supports this mime type.\n\t\t// Defer to the server when type not detected.\n\t\ttry {\n\t\t\tvalidateMimeType( mediaFile, allowedTypes );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Verify if file is greater than the maximum file upload size allowed for the site.\n\t\ttry {\n\t\t\tvalidateFileSize( mediaFile, maxUploadFileSize );\n\t\t} catch ( error: unknown ) {\n\t\t\tonError?.( error as Error );\n\t\t\tcontinue;\n\t\t}\n\n\t\tvalidFiles.push( mediaFile );\n\n\t\t// For client-side media processing, this is handled by the upload-media package.\n\t\tif ( ! window.__experimentalMediaProcessing ) {\n\t\t\t// Set temporary URL to create placeholder media file, this is replaced\n\t\t\t// with final file from media gallery when upload is `done` below.\n\t\t\tfilesSet.push( { url: createBlobURL( mediaFile ) } );\n\t\t\tonFileChange?.( filesSet as Array< Partial< Attachment > > );\n\t\t}\n\t}\n\n\tvalidFiles.map( async ( file, index ) => {\n\t\ttry {\n\t\t\tconst attachment = await uploadToServer(\n\t\t\t\tfile,\n\t\t\t\tadditionalData,\n\t\t\t\tsignal\n\t\t\t);\n\t\t\tsetAndUpdateFiles( index, attachment );\n\t\t} catch ( error ) {\n\t\t\t// Reset to empty on failure.\n\t\t\tsetAndUpdateFiles( index, null );\n\n\t\t\t// @wordpress/api-fetch throws any response that isn't in the 200 range as-is.\n\t\t\tlet message: string;\n\t\t\tif (\n\t\t\t\ttypeof error === 'object' &&\n\t\t\t\terror !== null &&\n\t\t\t\t'message' in error\n\t\t\t) {\n\t\t\t\tmessage =\n\t\t\t\t\ttypeof error.message === 'string'\n\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t: String( error.message );\n\t\t\t} else {\n\t\t\t\tmessage = sprintf(\n\t\t\t\t\t// translators: %s: file name\n\t\t\t\t\t__( 'Error while uploading file %s to the media library.' ),\n\t\t\t\t\tfile.name\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tonError?.(\n\t\t\t\tnew UploadError( {\n\t\t\t\t\tcode: 'GENERAL',\n\t\t\t\t\tmessage,\n\t\t\t\t\tfile,\n\t\t\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t\t\t} )\n\t\t\t);\n\t\t}\n\t} );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAC5B,kBAA6C;AA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,QACxB;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA,wBAAmB,OAAO,UAAW;AAAA,IACtC,SAAU,OAAQ;AAEjB,wBAAmB,OAAO,IAAK;AAG/B,UAAI;AACJ,UACC,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,OACZ;AACD,kBACC,OAAO,MAAM,YAAY,WACtB,MAAM,UACN,OAAQ,MAAM,OAAQ;AAAA,MAC3B,OAAO;AACN,sBAAU;AAAA;AAAA,cAET,gBAAI,qDAAsD;AAAA,UAC1D,KAAK;AAAA,QACN;AAAA,MACD;AAEA;AAAA,QACC,IAAI,gCAAa;AAAA,UAChB,MAAM;AAAA,UACN;AAAA,UACA;AAAA,UACA,OAAO,iBAAiB,QAAQ,QAAQ;AAAA,QACzC,CAAE;AAAA,MACH;AAAA,IACD;AAAA,EACD,CAAE;AACH;",
6
+ "names": []
7
+ }
@@ -1,34 +1,61 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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 });
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 upload_to_server_exports = {};
30
+ __export(upload_to_server_exports, {
31
+ uploadToServer: () => uploadToServer
6
32
  });
7
- exports.uploadToServer = uploadToServer;
8
- var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
9
- var _flattenFormData = require("./flatten-form-data");
10
- var _transformAttachment = require("./transform-attachment");
11
- /**
12
- * WordPress dependencies
13
- */
14
-
15
- /**
16
- * Internal dependencies
17
- */
18
-
33
+ module.exports = __toCommonJS(upload_to_server_exports);
34
+ var import_api_fetch = __toESM(require("@wordpress/api-fetch"));
35
+ var import_flatten_form_data = require("./flatten-form-data");
36
+ var import_transform_attachment = require("./transform-attachment");
19
37
  async function uploadToServer(file, additionalData = {}, signal) {
20
- // Create upload payload.
21
38
  const data = new FormData();
22
- data.append('file', file, file.name || file.type.replace('/', '.'));
39
+ data.append("file", file, file.name || file.type.replace("/", "."));
23
40
  for (const [key, value] of Object.entries(additionalData)) {
24
- (0, _flattenFormData.flattenFormData)(data, key, value);
41
+ (0, import_flatten_form_data.flattenFormData)(
42
+ data,
43
+ key,
44
+ value
45
+ );
25
46
  }
26
- return (0, _transformAttachment.transformAttachment)(await (0, _apiFetch.default)({
27
- // This allows the video block to directly get a video's poster image.
28
- path: '/wp/v2/media?_embed=wp:featuredmedia',
29
- body: data,
30
- method: 'POST',
31
- signal
32
- }));
47
+ return (0, import_transform_attachment.transformAttachment)(
48
+ await (0, import_api_fetch.default)({
49
+ // This allows the video block to directly get a video's poster image.
50
+ path: "/wp/v2/media?_embed=wp:featuredmedia",
51
+ body: data,
52
+ method: "POST",
53
+ signal
54
+ })
55
+ );
33
56
  }
34
- //# sourceMappingURL=upload-to-server.js.map
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ uploadToServer
60
+ });
61
+ //# sourceMappingURL=upload-to-server.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_apiFetch","_interopRequireDefault","require","_flattenFormData","_transformAttachment","uploadToServer","file","additionalData","signal","data","FormData","append","name","type","replace","key","value","Object","entries","flattenFormData","transformAttachment","apiFetch","path","body","method"],"sources":["@wordpress/media-utils/src/utils/upload-to-server.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { flattenFormData } from './flatten-form-data';\nimport { transformAttachment } from './transform-attachment';\nimport type { CreateRestAttachment, RestAttachment } from './types';\n\nexport async function uploadToServer(\n\tfile: File,\n\tadditionalData: CreateRestAttachment = {},\n\tsignal?: AbortSignal\n) {\n\t// Create upload payload.\n\tconst data = new FormData();\n\tdata.append( 'file', file, file.name || file.type.replace( '/', '.' ) );\n\tfor ( const [ key, value ] of Object.entries( additionalData ) ) {\n\t\tflattenFormData(\n\t\t\tdata,\n\t\t\tkey,\n\t\t\tvalue as string | Record< string, string > | undefined\n\t\t);\n\t}\n\n\treturn transformAttachment(\n\t\tawait apiFetch< RestAttachment >( {\n\t\t\t// This allows the video block to directly get a video's poster image.\n\t\t\tpath: '/wp/v2/media?_embed=wp:featuredmedia',\n\t\t\tbody: data,\n\t\t\tmethod: 'POST',\n\t\t\tsignal,\n\t\t} )\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAKO,eAAeG,cAAcA,CACnCC,IAAU,EACVC,cAAoC,GAAG,CAAC,CAAC,EACzCC,MAAoB,EACnB;EACD;EACA,MAAMC,IAAI,GAAG,IAAIC,QAAQ,CAAC,CAAC;EAC3BD,IAAI,CAACE,MAAM,CAAE,MAAM,EAAEL,IAAI,EAAEA,IAAI,CAACM,IAAI,IAAIN,IAAI,CAACO,IAAI,CAACC,OAAO,CAAE,GAAG,EAAE,GAAI,CAAE,CAAC;EACvE,KAAM,MAAM,CAAEC,GAAG,EAAEC,KAAK,CAAE,IAAIC,MAAM,CAACC,OAAO,CAAEX,cAAe,CAAC,EAAG;IAChE,IAAAY,gCAAe,EACdV,IAAI,EACJM,GAAG,EACHC,KACD,CAAC;EACF;EAEA,OAAO,IAAAI,wCAAmB,EACzB,MAAM,IAAAC,iBAAQ,EAAoB;IACjC;IACAC,IAAI,EAAE,sCAAsC;IAC5CC,IAAI,EAAEd,IAAI;IACVe,MAAM,EAAE,MAAM;IACdhB;EACD,CAAE,CACH,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/upload-to-server.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { flattenFormData } from './flatten-form-data';\nimport { transformAttachment } from './transform-attachment';\nimport type { CreateRestAttachment, RestAttachment } from './types';\n\nexport async function uploadToServer(\n\tfile: File,\n\tadditionalData: CreateRestAttachment = {},\n\tsignal?: AbortSignal\n) {\n\t// Create upload payload.\n\tconst data = new FormData();\n\tdata.append( 'file', file, file.name || file.type.replace( '/', '.' ) );\n\tfor ( const [ key, value ] of Object.entries( additionalData ) ) {\n\t\tflattenFormData(\n\t\t\tdata,\n\t\t\tkey,\n\t\t\tvalue as string | Record< string, string > | undefined\n\t\t);\n\t}\n\n\treturn transformAttachment(\n\t\tawait apiFetch< RestAttachment >( {\n\t\t\t// This allows the video block to directly get a video's poster image.\n\t\t\tpath: '/wp/v2/media?_embed=wp:featuredmedia',\n\t\t\tbody: data,\n\t\t\tmethod: 'POST',\n\t\t\tsignal,\n\t\t} )\n\t);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAKrB,+BAAgC;AAChC,kCAAoC;AAGpC,eAAsB,eACrB,MACA,iBAAuC,CAAC,GACxC,QACC;AAED,QAAM,OAAO,IAAI,SAAS;AAC1B,OAAK,OAAQ,QAAQ,MAAM,KAAK,QAAQ,KAAK,KAAK,QAAS,KAAK,GAAI,CAAE;AACtE,aAAY,CAAE,KAAK,KAAM,KAAK,OAAO,QAAS,cAAe,GAAI;AAChE;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAEA,aAAO;AAAA,IACN,UAAM,iBAAAA,SAA4B;AAAA;AAAA,MAEjC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": ["apiFetch"]
7
+ }
@@ -1,44 +1,56 @@
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 validate_file_size_exports = {};
20
+ __export(validate_file_size_exports, {
21
+ validateFileSize: () => validateFileSize
5
22
  });
6
- exports.validateFileSize = validateFileSize;
7
- var _i18n = require("@wordpress/i18n");
8
- var _uploadError = require("./upload-error");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
-
17
- /**
18
- * Verifies whether the file is within the file upload size limits for the site.
19
- *
20
- * @param file File object.
21
- * @param maxUploadFileSize Maximum upload size in bytes allowed for the site.
22
- */
23
+ module.exports = __toCommonJS(validate_file_size_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_upload_error = require("./upload-error");
23
26
  function validateFileSize(file, maxUploadFileSize) {
24
- // Don't allow empty files to be uploaded.
25
27
  if (file.size <= 0) {
26
- throw new _uploadError.UploadError({
27
- code: 'EMPTY_FILE',
28
- message: (0, _i18n.sprintf)(
29
- // translators: %s: file name.
30
- (0, _i18n.__)('%s: This file is empty.'), file.name),
28
+ throw new import_upload_error.UploadError({
29
+ code: "EMPTY_FILE",
30
+ message: (0, import_i18n.sprintf)(
31
+ // translators: %s: file name.
32
+ (0, import_i18n.__)("%s: This file is empty."),
33
+ file.name
34
+ ),
31
35
  file
32
36
  });
33
37
  }
34
38
  if (maxUploadFileSize && file.size > maxUploadFileSize) {
35
- throw new _uploadError.UploadError({
36
- code: 'SIZE_ABOVE_LIMIT',
37
- message: (0, _i18n.sprintf)(
38
- // translators: %s: file name.
39
- (0, _i18n.__)('%s: This file exceeds the maximum upload size for this site.'), file.name),
39
+ throw new import_upload_error.UploadError({
40
+ code: "SIZE_ABOVE_LIMIT",
41
+ message: (0, import_i18n.sprintf)(
42
+ // translators: %s: file name.
43
+ (0, import_i18n.__)(
44
+ "%s: This file exceeds the maximum upload size for this site."
45
+ ),
46
+ file.name
47
+ ),
40
48
  file
41
49
  });
42
50
  }
43
51
  }
44
- //# sourceMappingURL=validate-file-size.js.map
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ validateFileSize
55
+ });
56
+ //# sourceMappingURL=validate-file-size.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_uploadError","validateFileSize","file","maxUploadFileSize","size","UploadError","code","message","sprintf","__","name"],"sources":["@wordpress/media-utils/src/utils/validate-file-size.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies whether the file is within the file upload size limits for the site.\n *\n * @param file File object.\n * @param maxUploadFileSize Maximum upload size in bytes allowed for the site.\n */\nexport function validateFileSize( file: File, maxUploadFileSize?: number ) {\n\t// Don't allow empty files to be uploaded.\n\tif ( file.size <= 0 ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'EMPTY_FILE',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: This file is empty.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n\n\tif ( maxUploadFileSize && file.size > maxUploadFileSize ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'SIZE_ABOVE_LIMIT',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: This file exceeds the maximum upload size for this site.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAAEC,IAAU,EAAEC,iBAA0B,EAAG;EAC1E;EACA,IAAKD,IAAI,CAACE,IAAI,IAAI,CAAC,EAAG;IACrB,MAAM,IAAIC,wBAAW,CAAE;MACtBC,IAAI,EAAE,YAAY;MAClBC,OAAO,EAAE,IAAAC,aAAO;MACf;MACA,IAAAC,QAAE,EAAE,yBAA0B,CAAC,EAC/BP,IAAI,CAACQ,IACN,CAAC;MACDR;IACD,CAAE,CAAC;EACJ;EAEA,IAAKC,iBAAiB,IAAID,IAAI,CAACE,IAAI,GAAGD,iBAAiB,EAAG;IACzD,MAAM,IAAIE,wBAAW,CAAE;MACtBC,IAAI,EAAE,kBAAkB;MACxBC,OAAO,EAAE,IAAAC,aAAO;MACf;MACA,IAAAC,QAAE,EACD,8DACD,CAAC,EACDP,IAAI,CAACQ,IACN,CAAC;MACDR;IACD,CAAE,CAAC;EACJ;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/validate-file-size.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies whether the file is within the file upload size limits for the site.\n *\n * @param file File object.\n * @param maxUploadFileSize Maximum upload size in bytes allowed for the site.\n */\nexport function validateFileSize( file: File, maxUploadFileSize?: number ) {\n\t// Don't allow empty files to be uploaded.\n\tif ( file.size <= 0 ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'EMPTY_FILE',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: This file is empty.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n\n\tif ( maxUploadFileSize && file.size > maxUploadFileSize ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'SIZE_ABOVE_LIMIT',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: This file exceeds the maximum upload size for this site.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAQrB,SAAS,iBAAkB,MAAY,mBAA6B;AAE1E,MAAK,KAAK,QAAQ,GAAI;AACrB,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER,gBAAI,yBAA0B;AAAA,QAC9B,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AAEA,MAAK,qBAAqB,KAAK,OAAO,mBAAoB;AACzD,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": []
7
+ }
@@ -1,41 +1,53 @@
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 validate_mime_type_for_user_exports = {};
20
+ __export(validate_mime_type_for_user_exports, {
21
+ validateMimeTypeForUser: () => validateMimeTypeForUser
5
22
  });
6
- exports.validateMimeTypeForUser = validateMimeTypeForUser;
7
- var _i18n = require("@wordpress/i18n");
8
- var _uploadError = require("./upload-error");
9
- var _getMimeTypesArray = require("./get-mime-types-array");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /**
19
- * Verifies if the user is allowed to upload this mime type.
20
- *
21
- * @param file File object.
22
- * @param wpAllowedMimeTypes List of allowed mime types and file extensions.
23
- */
23
+ module.exports = __toCommonJS(validate_mime_type_for_user_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_upload_error = require("./upload-error");
26
+ var import_get_mime_types_array = require("./get-mime-types-array");
24
27
  function validateMimeTypeForUser(file, wpAllowedMimeTypes) {
25
- // Allowed types for the current WP_User.
26
- const allowedMimeTypesForUser = (0, _getMimeTypesArray.getMimeTypesArray)(wpAllowedMimeTypes);
28
+ const allowedMimeTypesForUser = (0, import_get_mime_types_array.getMimeTypesArray)(wpAllowedMimeTypes);
27
29
  if (!allowedMimeTypesForUser) {
28
30
  return;
29
31
  }
30
- const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(file.type);
32
+ const isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(
33
+ file.type
34
+ );
31
35
  if (file.type && !isAllowedMimeTypeForUser) {
32
- throw new _uploadError.UploadError({
33
- code: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',
34
- message: (0, _i18n.sprintf)(
35
- // translators: %s: file name.
36
- (0, _i18n.__)('%s: Sorry, you are not allowed to upload this file type.'), file.name),
36
+ throw new import_upload_error.UploadError({
37
+ code: "MIME_TYPE_NOT_ALLOWED_FOR_USER",
38
+ message: (0, import_i18n.sprintf)(
39
+ // translators: %s: file name.
40
+ (0, import_i18n.__)(
41
+ "%s: Sorry, you are not allowed to upload this file type."
42
+ ),
43
+ file.name
44
+ ),
37
45
  file
38
46
  });
39
47
  }
40
48
  }
41
- //# sourceMappingURL=validate-mime-type-for-user.js.map
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ validateMimeTypeForUser
52
+ });
53
+ //# sourceMappingURL=validate-mime-type-for-user.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_uploadError","_getMimeTypesArray","validateMimeTypeForUser","file","wpAllowedMimeTypes","allowedMimeTypesForUser","getMimeTypesArray","isAllowedMimeTypeForUser","includes","type","UploadError","code","message","sprintf","__","name"],"sources":["@wordpress/media-utils/src/utils/validate-mime-type-for-user.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\nimport { getMimeTypesArray } from './get-mime-types-array';\n\n/**\n * Verifies if the user is allowed to upload this mime type.\n *\n * @param file File object.\n * @param wpAllowedMimeTypes List of allowed mime types and file extensions.\n */\nexport function validateMimeTypeForUser(\n\tfile: File,\n\twpAllowedMimeTypes?: Record< string, string > | null\n) {\n\t// Allowed types for the current WP_User.\n\tconst allowedMimeTypesForUser = getMimeTypesArray( wpAllowedMimeTypes );\n\n\tif ( ! allowedMimeTypesForUser ) {\n\t\treturn;\n\t}\n\n\tconst isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(\n\t\tfile.type\n\t);\n\n\tif ( file.type && ! isAllowedMimeTypeForUser ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: Sorry, you are not allowed to upload this file type.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,uBAAuBA,CACtCC,IAAU,EACVC,kBAAoD,EACnD;EACD;EACA,MAAMC,uBAAuB,GAAG,IAAAC,oCAAiB,EAAEF,kBAAmB,CAAC;EAEvE,IAAK,CAAEC,uBAAuB,EAAG;IAChC;EACD;EAEA,MAAME,wBAAwB,GAAGF,uBAAuB,CAACG,QAAQ,CAChEL,IAAI,CAACM,IACN,CAAC;EAED,IAAKN,IAAI,CAACM,IAAI,IAAI,CAAEF,wBAAwB,EAAG;IAC9C,MAAM,IAAIG,wBAAW,CAAE;MACtBC,IAAI,EAAE,gCAAgC;MACtCC,OAAO,EAAE,IAAAC,aAAO;MACf;MACA,IAAAC,QAAE,EACD,0DACD,CAAC,EACDX,IAAI,CAACY,IACN,CAAC;MACDZ;IACD,CAAE,CAAC;EACJ;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/validate-mime-type-for-user.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\nimport { getMimeTypesArray } from './get-mime-types-array';\n\n/**\n * Verifies if the user is allowed to upload this mime type.\n *\n * @param file File object.\n * @param wpAllowedMimeTypes List of allowed mime types and file extensions.\n */\nexport function validateMimeTypeForUser(\n\tfile: File,\n\twpAllowedMimeTypes?: Record< string, string > | null\n) {\n\t// Allowed types for the current WP_User.\n\tconst allowedMimeTypesForUser = getMimeTypesArray( wpAllowedMimeTypes );\n\n\tif ( ! allowedMimeTypesForUser ) {\n\t\treturn;\n\t}\n\n\tconst isAllowedMimeTypeForUser = allowedMimeTypesForUser.includes(\n\t\tfile.type\n\t);\n\n\tif ( file.type && ! isAllowedMimeTypeForUser ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_ALLOWED_FOR_USER',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__(\n\t\t\t\t\t'%s: Sorry, you are not allowed to upload this file type.'\n\t\t\t\t),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAC5B,kCAAkC;AAQ3B,SAAS,wBACf,MACA,oBACC;AAED,QAAM,8BAA0B,+CAAmB,kBAAmB;AAEtE,MAAK,CAAE,yBAA0B;AAChC;AAAA,EACD;AAEA,QAAM,2BAA2B,wBAAwB;AAAA,IACxD,KAAK;AAAA,EACN;AAEA,MAAK,KAAK,QAAQ,CAAE,0BAA2B;AAC9C,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": []
7
+ }
@@ -1,47 +1,52 @@
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 validate_mime_type_exports = {};
20
+ __export(validate_mime_type_exports, {
21
+ validateMimeType: () => validateMimeType
5
22
  });
6
- exports.validateMimeType = validateMimeType;
7
- var _i18n = require("@wordpress/i18n");
8
- var _uploadError = require("./upload-error");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
-
17
- /**
18
- * Verifies if the caller (e.g. a block) supports this mime type.
19
- *
20
- * @param file File object.
21
- * @param allowedTypes List of allowed mime types.
22
- */
23
+ module.exports = __toCommonJS(validate_mime_type_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_upload_error = require("./upload-error");
23
26
  function validateMimeType(file, allowedTypes) {
24
27
  if (!allowedTypes) {
25
28
  return;
26
29
  }
27
-
28
- // Allowed type specified by consumer.
29
- const isAllowedType = allowedTypes.some(allowedType => {
30
- // If a complete mimetype is specified verify if it matches exactly the mime type of the file.
31
- if (allowedType.includes('/')) {
30
+ const isAllowedType = allowedTypes.some((allowedType) => {
31
+ if (allowedType.includes("/")) {
32
32
  return allowedType === file.type;
33
33
  }
34
- // Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.
35
34
  return file.type.startsWith(`${allowedType}/`);
36
35
  });
37
36
  if (file.type && !isAllowedType) {
38
- throw new _uploadError.UploadError({
39
- code: 'MIME_TYPE_NOT_SUPPORTED',
40
- message: (0, _i18n.sprintf)(
41
- // translators: %s: file name.
42
- (0, _i18n.__)('%s: Sorry, this file type is not supported here.'), file.name),
37
+ throw new import_upload_error.UploadError({
38
+ code: "MIME_TYPE_NOT_SUPPORTED",
39
+ message: (0, import_i18n.sprintf)(
40
+ // translators: %s: file name.
41
+ (0, import_i18n.__)("%s: Sorry, this file type is not supported here."),
42
+ file.name
43
+ ),
43
44
  file
44
45
  });
45
46
  }
46
47
  }
47
- //# sourceMappingURL=validate-mime-type.js.map
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ validateMimeType
51
+ });
52
+ //# sourceMappingURL=validate-mime-type.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_uploadError","validateMimeType","file","allowedTypes","isAllowedType","some","allowedType","includes","type","startsWith","UploadError","code","message","sprintf","__","name"],"sources":["@wordpress/media-utils/src/utils/validate-mime-type.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies if the caller (e.g. a block) supports this mime type.\n *\n * @param file File object.\n * @param allowedTypes List of allowed mime types.\n */\nexport function validateMimeType( file: File, allowedTypes?: string[] ) {\n\tif ( ! allowedTypes ) {\n\t\treturn;\n\t}\n\n\t// Allowed type specified by consumer.\n\tconst isAllowedType = allowedTypes.some( ( allowedType ) => {\n\t\t// If a complete mimetype is specified verify if it matches exactly the mime type of the file.\n\t\tif ( allowedType.includes( '/' ) ) {\n\t\t\treturn allowedType === file.type;\n\t\t}\n\t\t// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.\n\t\treturn file.type.startsWith( `${ allowedType }/` );\n\t} );\n\n\tif ( file.type && ! isAllowedType ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_SUPPORTED',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: Sorry, this file type is not supported here.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,gBAAgBA,CAAEC,IAAU,EAAEC,YAAuB,EAAG;EACvE,IAAK,CAAEA,YAAY,EAAG;IACrB;EACD;;EAEA;EACA,MAAMC,aAAa,GAAGD,YAAY,CAACE,IAAI,CAAIC,WAAW,IAAM;IAC3D;IACA,IAAKA,WAAW,CAACC,QAAQ,CAAE,GAAI,CAAC,EAAG;MAClC,OAAOD,WAAW,KAAKJ,IAAI,CAACM,IAAI;IACjC;IACA;IACA,OAAON,IAAI,CAACM,IAAI,CAACC,UAAU,CAAE,GAAIH,WAAW,GAAK,CAAC;EACnD,CAAE,CAAC;EAEH,IAAKJ,IAAI,CAACM,IAAI,IAAI,CAAEJ,aAAa,EAAG;IACnC,MAAM,IAAIM,wBAAW,CAAE;MACtBC,IAAI,EAAE,yBAAyB;MAC/BC,OAAO,EAAE,IAAAC,aAAO;MACf;MACA,IAAAC,QAAE,EAAE,kDAAmD,CAAC,EACxDZ,IAAI,CAACa,IACN,CAAC;MACDb;IACD,CAAE,CAAC;EACJ;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/validate-mime-type.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { UploadError } from './upload-error';\n\n/**\n * Verifies if the caller (e.g. a block) supports this mime type.\n *\n * @param file File object.\n * @param allowedTypes List of allowed mime types.\n */\nexport function validateMimeType( file: File, allowedTypes?: string[] ) {\n\tif ( ! allowedTypes ) {\n\t\treturn;\n\t}\n\n\t// Allowed type specified by consumer.\n\tconst isAllowedType = allowedTypes.some( ( allowedType ) => {\n\t\t// If a complete mimetype is specified verify if it matches exactly the mime type of the file.\n\t\tif ( allowedType.includes( '/' ) ) {\n\t\t\treturn allowedType === file.type;\n\t\t}\n\t\t// Otherwise a general mime type is used, and we should verify if the file mimetype starts with it.\n\t\treturn file.type.startsWith( `${ allowedType }/` );\n\t} );\n\n\tif ( file.type && ! isAllowedType ) {\n\t\tthrow new UploadError( {\n\t\t\tcode: 'MIME_TYPE_NOT_SUPPORTED',\n\t\t\tmessage: sprintf(\n\t\t\t\t// translators: %s: file name.\n\t\t\t\t__( '%s: Sorry, this file type is not supported here.' ),\n\t\t\t\tfile.name\n\t\t\t),\n\t\t\tfile,\n\t\t} );\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAK5B,0BAA4B;AAQrB,SAAS,iBAAkB,MAAY,cAA0B;AACvE,MAAK,CAAE,cAAe;AACrB;AAAA,EACD;AAGA,QAAM,gBAAgB,aAAa,KAAM,CAAE,gBAAiB;AAE3D,QAAK,YAAY,SAAU,GAAI,GAAI;AAClC,aAAO,gBAAgB,KAAK;AAAA,IAC7B;AAEA,WAAO,KAAK,KAAK,WAAY,GAAI,WAAY,GAAI;AAAA,EAClD,CAAE;AAEF,MAAK,KAAK,QAAQ,CAAE,eAAgB;AACnC,UAAM,IAAI,gCAAa;AAAA,MACtB,MAAM;AAAA,MACN,aAAS;AAAA;AAAA,YAER,gBAAI,kDAAmD;AAAA,QACvD,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": []
7
+ }
@@ -1,2 +1,5 @@
1
- export { default as MediaUpload } from './media-upload';
2
- //# sourceMappingURL=index.js.map
1
+ import { default as default2 } from "./media-upload";
2
+ export {
3
+ default2 as MediaUpload
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["default","MediaUpload"],"sources":["@wordpress/media-utils/src/components/index.js"],"sourcesContent":["export { default as MediaUpload } from './media-upload';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/components/index.js"],
4
+ "sourcesContent": ["export { default as MediaUpload } from './media-upload';\n"],
5
+ "mappings": "AAAA,SAAoB,WAAXA,gBAA8B;",
6
+ "names": ["default"]
7
+ }