@wordpress/media-utils 5.34.0 → 5.35.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 (76) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/index.js +2 -0
  3. package/build/components/index.js.map +1 -1
  4. package/build/components/media-upload/index.js +10 -8
  5. package/build/components/media-upload/index.js.map +1 -1
  6. package/build/components/media-upload-modal/index.js +49 -8
  7. package/build/components/media-upload-modal/index.js.map +3 -3
  8. package/build/index.js +2 -0
  9. package/build/index.js.map +1 -1
  10. package/build/lock-unlock.js +3 -1
  11. package/build/lock-unlock.js.map +1 -1
  12. package/build/private-apis.js +3 -1
  13. package/build/private-apis.js.map +1 -1
  14. package/build/utils/flatten-form-data.js +2 -0
  15. package/build/utils/flatten-form-data.js.map +1 -1
  16. package/build/utils/get-mime-types-array.js +2 -0
  17. package/build/utils/get-mime-types-array.js.map +1 -1
  18. package/build/utils/sideload-media.js +3 -1
  19. package/build/utils/sideload-media.js.map +1 -1
  20. package/build/utils/sideload-to-server.js +2 -0
  21. package/build/utils/sideload-to-server.js.map +1 -1
  22. package/build/utils/transform-attachment.js +2 -0
  23. package/build/utils/transform-attachment.js.map +1 -1
  24. package/build/utils/types.js +2 -0
  25. package/build/utils/types.js.map +1 -1
  26. package/build/utils/upload-error.js +4 -2
  27. package/build/utils/upload-error.js.map +1 -1
  28. package/build/utils/upload-media.js +2 -0
  29. package/build/utils/upload-media.js.map +1 -1
  30. package/build/utils/upload-to-server.js +2 -0
  31. package/build/utils/upload-to-server.js.map +1 -1
  32. package/build/utils/validate-file-size.js +2 -0
  33. package/build/utils/validate-file-size.js.map +1 -1
  34. package/build/utils/validate-mime-type-for-user.js +2 -0
  35. package/build/utils/validate-mime-type-for-user.js.map +1 -1
  36. package/build/utils/validate-mime-type.js +2 -0
  37. package/build/utils/validate-mime-type.js.map +1 -1
  38. package/build-module/components/index.js +1 -0
  39. package/build-module/components/index.js.map +1 -1
  40. package/build-module/components/media-upload/index.js +9 -8
  41. package/build-module/components/media-upload/index.js.map +1 -1
  42. package/build-module/components/media-upload-modal/index.js +49 -9
  43. package/build-module/components/media-upload-modal/index.js.map +2 -2
  44. package/build-module/index.js +1 -0
  45. package/build-module/index.js.map +1 -1
  46. package/build-module/lock-unlock.js +2 -1
  47. package/build-module/lock-unlock.js.map +1 -1
  48. package/build-module/private-apis.js +2 -1
  49. package/build-module/private-apis.js.map +1 -1
  50. package/build-module/utils/flatten-form-data.js +1 -0
  51. package/build-module/utils/flatten-form-data.js.map +1 -1
  52. package/build-module/utils/get-mime-types-array.js +1 -0
  53. package/build-module/utils/get-mime-types-array.js.map +1 -1
  54. package/build-module/utils/sideload-media.js +2 -1
  55. package/build-module/utils/sideload-media.js.map +1 -1
  56. package/build-module/utils/sideload-to-server.js +1 -0
  57. package/build-module/utils/sideload-to-server.js.map +1 -1
  58. package/build-module/utils/transform-attachment.js +1 -0
  59. package/build-module/utils/transform-attachment.js.map +1 -1
  60. package/build-module/utils/upload-error.js +3 -2
  61. package/build-module/utils/upload-error.js.map +1 -1
  62. package/build-module/utils/upload-media.js +1 -0
  63. package/build-module/utils/upload-media.js.map +1 -1
  64. package/build-module/utils/upload-to-server.js +1 -0
  65. package/build-module/utils/upload-to-server.js.map +1 -1
  66. package/build-module/utils/validate-file-size.js +1 -0
  67. package/build-module/utils/validate-file-size.js.map +1 -1
  68. package/build-module/utils/validate-mime-type-for-user.js +1 -0
  69. package/build-module/utils/validate-mime-type-for-user.js.map +1 -1
  70. package/build-module/utils/validate-mime-type.js +1 -0
  71. package/build-module/utils/validate-mime-type.js.map +1 -1
  72. package/build-types/components/media-upload-modal/index.d.ts.map +1 -1
  73. package/package.json +12 -11
  74. package/src/components/media-upload-modal/index.tsx +48 -7
  75. package/tsconfig.json +1 -0
  76. package/tsconfig.tsbuildinfo +1 -1
@@ -1,7 +1,8 @@
1
+ // packages/media-utils/src/utils/sideload-media.ts
1
2
  import { __, sprintf } from "@wordpress/i18n";
2
3
  import { sideloadToServer } from "./sideload-to-server";
3
4
  import { UploadError } from "./upload-error";
4
- const noop = () => {
5
+ var noop = () => {
5
6
  };
6
7
  async function sideloadMedia({
7
8
  file,
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/sideload-media.ts"],
4
4
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __, sprintf } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tOnChangeHandler,\n\tOnErrorHandler,\n\tCreateSideloadFile,\n\tRestAttachment,\n} from './types';\nimport { sideloadToServer } from './sideload-to-server';\nimport { UploadError } from './upload-error';\n\nconst noop = () => {};\n\ninterface SideloadMediaArgs {\n\t// Additional data to include in the request.\n\tadditionalData?: CreateSideloadFile;\n\t// File to sideload.\n\tfile: File;\n\t// Attachment ID.\n\tattachmentId: RestAttachment[ 'id' ];\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// Abort signal.\n\tsignal?: AbortSignal;\n}\n\n/**\n * Uploads a file to the server without creating an attachment.\n *\n * @param $0 Parameters object passed to the function.\n * @param $0.file Media File to Save.\n * @param $0.attachmentId Parent attachment ID.\n * @param $0.additionalData Additional data to include in the request.\n * @param $0.signal Abort signal.\n * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.\n * @param $0.onError Function called when an error happens.\n */\nexport async function sideloadMedia( {\n\tfile,\n\tattachmentId,\n\tadditionalData = {},\n\tsignal,\n\tonFileChange,\n\tonError = noop,\n}: SideloadMediaArgs ) {\n\ttry {\n\t\tconst attachment = await sideloadToServer(\n\t\t\tfile,\n\t\t\tattachmentId,\n\t\t\tadditionalData,\n\t\t\tsignal\n\t\t);\n\t\tonFileChange?.( [ attachment ] );\n\t} catch ( error ) {\n\t\tlet message;\n\t\tif ( error instanceof Error ) {\n\t\t\tmessage = error.message;\n\t\t} else {\n\t\t\tmessage = sprintf(\n\t\t\t\t// translators: %s: file name\n\t\t\t\t__( 'Error while sideloading file %s to the server.' ),\n\t\t\t\tfile.name\n\t\t\t);\n\t\t}\n\t\tonError(\n\t\t\tnew UploadError( {\n\t\t\t\tcode: 'GENERAL',\n\t\t\t\tmessage,\n\t\t\t\tfile,\n\t\t\t\tcause: error instanceof Error ? error : undefined,\n\t\t\t} )\n\t\t);\n\t}\n}\n"],
5
- "mappings": "AAGA,SAAS,IAAI,eAAe;AAW5B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAE5B,MAAM,OAAO,MAAM;AAAC;AA4BpB,eAAsB,cAAe;AAAA,EACpC;AAAA,EACA;AAAA,EACA,iBAAiB,CAAC;AAAA,EAClB;AAAA,EACA;AAAA,EACA,UAAU;AACX,GAAuB;AACtB,MAAI;AACH,UAAM,aAAa,MAAM;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,mBAAgB,CAAE,UAAW,CAAE;AAAA,EAChC,SAAU,OAAQ;AACjB,QAAI;AACJ,QAAK,iBAAiB,OAAQ;AAC7B,gBAAU,MAAM;AAAA,IACjB,OAAO;AACN,gBAAU;AAAA;AAAA,QAET,GAAI,gDAAiD;AAAA,QACrD,KAAK;AAAA,MACN;AAAA,IACD;AACA;AAAA,MACC,IAAI,YAAa;AAAA,QAChB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ,QAAQ;AAAA,MACzC,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
5
+ "mappings": ";AAGA,SAAS,IAAI,eAAe;AAW5B,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAE5B,IAAM,OAAO,MAAM;AAAC;AA4BpB,eAAsB,cAAe;AAAA,EACpC;AAAA,EACA;AAAA,EACA,iBAAiB,CAAC;AAAA,EAClB;AAAA,EACA;AAAA,EACA,UAAU;AACX,GAAuB;AACtB,MAAI;AACH,UAAM,aAAa,MAAM;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AACA,mBAAgB,CAAE,UAAW,CAAE;AAAA,EAChC,SAAU,OAAQ;AACjB,QAAI;AACJ,QAAK,iBAAiB,OAAQ;AAC7B,gBAAU,MAAM;AAAA,IACjB,OAAO;AACN,gBAAU;AAAA;AAAA,QAET,GAAI,gDAAiD;AAAA,QACrD,KAAK;AAAA,MACN;AAAA,IACD;AACA;AAAA,MACC,IAAI,YAAa;AAAA,QAChB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ,QAAQ;AAAA,MACzC,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/sideload-to-server.ts
1
2
  import apiFetch from "@wordpress/api-fetch";
2
3
  import { flattenFormData } from "./flatten-form-data";
3
4
  import { transformAttachment } from "./transform-attachment";
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/sideload-to-server.ts"],
4
4
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport type { CreateSideloadFile, RestAttachment } from './types';\nimport { flattenFormData } from './flatten-form-data';\nimport { transformAttachment } from './transform-attachment';\n\n/**\n * Uploads a file to the server without creating an attachment.\n *\n * @param file Media File to Save.\n * @param attachmentId Parent attachment ID.\n * @param additionalData Additional data to include in the request.\n * @param signal Abort signal.\n *\n * @return The saved attachment.\n */\nexport async function sideloadToServer(\n\tfile: File,\n\tattachmentId: RestAttachment[ 'id' ],\n\tadditionalData: CreateSideloadFile = {},\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\tpath: `/wp/v2/media/${ attachmentId }/sideload`,\n\t\t\tbody: data,\n\t\t\tmethod: 'POST',\n\t\t\tsignal,\n\t\t} )\n\t);\n}\n"],
5
- "mappings": "AAGA,OAAO,cAAc;AAMrB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AAYpC,eAAsB,iBACrB,MACA,cACA,iBAAqC,CAAC,GACtC,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,SAAO;AAAA,IACN,MAAM,SAA4B;AAAA,MACjC,MAAM,gBAAiB,YAAa;AAAA,MACpC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
5
+ "mappings": ";AAGA,OAAO,cAAc;AAMrB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AAYpC,eAAsB,iBACrB,MACA,cACA,iBAAqC,CAAC,GACtC,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,SAAO;AAAA,IACN,MAAM,SAA4B;AAAA,MACjC,MAAM,gBAAiB,YAAa;AAAA,MACpC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/transform-attachment.ts
1
2
  function transformAttachment(attachment) {
2
3
  const { alt_text, source_url, ...savedMediaProps } = attachment;
3
4
  return {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/transform-attachment.ts"],
4
4
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Attachment, RestAttachment } from './types';\n\n/**\n * Transforms an attachment object from the REST API shape into the shape expected by the block editor and other consumers.\n *\n * @param attachment REST API attachment object.\n */\nexport function transformAttachment( attachment: RestAttachment ): Attachment {\n\t// eslint-disable-next-line camelcase\n\tconst { alt_text, source_url, ...savedMediaProps } = attachment;\n\treturn {\n\t\t...savedMediaProps,\n\t\talt: attachment.alt_text,\n\t\tcaption: attachment.caption?.raw ?? '',\n\t\ttitle: attachment.title.raw,\n\t\turl: attachment.source_url,\n\t\tposter:\n\t\t\tattachment._embedded?.[ 'wp:featuredmedia' ]?.[ 0 ]?.source_url ||\n\t\t\tundefined,\n\t};\n}\n"],
5
- "mappings": "AAUO,SAAS,oBAAqB,YAAyC;AAE7E,QAAM,EAAE,UAAU,YAAY,GAAG,gBAAgB,IAAI;AACrD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,KAAK,WAAW;AAAA,IAChB,SAAS,WAAW,SAAS,OAAO;AAAA,IACpC,OAAO,WAAW,MAAM;AAAA,IACxB,KAAK,WAAW;AAAA,IAChB,QACC,WAAW,YAAa,kBAAmB,IAAK,CAAE,GAAG,cACrD;AAAA,EACF;AACD;",
5
+ "mappings": ";AAUO,SAAS,oBAAqB,YAAyC;AAE7E,QAAM,EAAE,UAAU,YAAY,GAAG,gBAAgB,IAAI;AACrD,SAAO;AAAA,IACN,GAAG;AAAA,IACH,KAAK,WAAW;AAAA,IAChB,SAAS,WAAW,SAAS,OAAO;AAAA,IACpC,OAAO,WAAW,MAAM;AAAA,IACxB,KAAK,WAAW;AAAA,IAChB,QACC,WAAW,YAAa,kBAAmB,IAAK,CAAE,GAAG,cACrD;AAAA,EACF;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,5 @@
1
- class UploadError extends Error {
1
+ // packages/media-utils/src/utils/upload-error.ts
2
+ var UploadError = class extends Error {
2
3
  code;
3
4
  file;
4
5
  constructor({ code, message, file, cause }) {
@@ -7,7 +8,7 @@ class UploadError extends Error {
7
8
  this.code = code;
8
9
  this.file = file;
9
10
  }
10
- }
11
+ };
11
12
  export {
12
13
  UploadError
13
14
  };
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/upload-error.ts"],
4
4
  "sourcesContent": ["interface UploadErrorArgs {\n\tcode: string;\n\tmessage: string;\n\tfile: File;\n\tcause?: Error;\n}\n\n/**\n * MediaError class.\n *\n * Small wrapper around the `Error` class\n * to hold an error code and a reference to a file object.\n */\nexport class UploadError extends Error {\n\tcode: string;\n\tfile: File;\n\n\tconstructor( { code, message, file, cause }: UploadErrorArgs ) {\n\t\tsuper( message, { cause } );\n\n\t\tObject.setPrototypeOf( this, new.target.prototype );\n\n\t\tthis.code = code;\n\t\tthis.file = file;\n\t}\n}\n"],
5
- "mappings": "AAaO,MAAM,oBAAoB,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,SAAS,MAAM,MAAM,GAAqB;AAC9D,UAAO,SAAS,EAAE,MAAM,CAAE;AAE1B,WAAO,eAAgB,MAAM,WAAW,SAAU;AAElD,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACb;AACD;",
5
+ "mappings": ";AAaO,IAAM,cAAN,cAA0B,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,SAAS,MAAM,MAAM,GAAqB;AAC9D,UAAO,SAAS,EAAE,MAAM,CAAE;AAE1B,WAAO,eAAgB,MAAM,WAAW,SAAU;AAElD,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACb;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/upload-media.ts
1
2
  import { __, sprintf } from "@wordpress/i18n";
2
3
  import { createBlobURL, revokeBlobURL } from "@wordpress/blob";
3
4
  import { uploadToServer } from "./upload-to-server";
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/upload-media.ts"],
4
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": "AAGA,SAAS,IAAI,eAAe;AAC5B,SAAS,eAAe,qBAAqB;AAW7C,SAAS,sBAAsB;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import apiFetch from "@wordpress/api-fetch";
2
3
  import { flattenFormData } from "./flatten-form-data";
3
4
  import { transformAttachment } from "./transform-attachment";
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/upload-to-server.ts"],
4
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": "AAGA,OAAO,cAAc;AAKrB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;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,SAAO;AAAA,IACN,MAAM,SAA4B;AAAA;AAAA,MAEjC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
5
+ "mappings": ";AAGA,OAAO,cAAc;AAKrB,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;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,SAAO;AAAA,IACN,MAAM,SAA4B;AAAA;AAAA,MAEjC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/validate-file-size.ts
1
2
  import { __, sprintf } from "@wordpress/i18n";
2
3
  import { UploadError } from "./upload-error";
3
4
  function validateFileSize(file, maxUploadFileSize) {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/validate-file-size.ts"],
4
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": "AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;AAQrB,SAAS,iBAAkB,MAAY,mBAA6B;AAE1E,MAAK,KAAK,QAAQ,GAAI;AACrB,UAAM,IAAI,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER,GAAI,yBAA0B;AAAA,QAC9B,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AAEA,MAAK,qBAAqB,KAAK,OAAO,mBAAoB;AACzD,UAAM,IAAI,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
5
+ "mappings": ";AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;AAQrB,SAAS,iBAAkB,MAAY,mBAA6B;AAE1E,MAAK,KAAK,QAAQ,GAAI;AACrB,UAAM,IAAI,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER,GAAI,yBAA0B;AAAA,QAC9B,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AAEA,MAAK,qBAAqB,KAAK,OAAO,mBAAoB;AACzD,UAAM,IAAI,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/validate-mime-type-for-user.ts
1
2
  import { __, sprintf } from "@wordpress/i18n";
2
3
  import { UploadError } from "./upload-error";
3
4
  import { getMimeTypesArray } from "./get-mime-types-array";
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/validate-mime-type-for-user.ts"],
4
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": "AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAQ3B,SAAS,wBACf,MACA,oBACC;AAED,QAAM,0BAA0B,kBAAmB,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,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
5
+ "mappings": ";AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAQ3B,SAAS,wBACf,MACA,oBACC;AAED,QAAM,0BAA0B,kBAAmB,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,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER;AAAA,UACC;AAAA,QACD;AAAA,QACA,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1,3 +1,4 @@
1
+ // packages/media-utils/src/utils/validate-mime-type.ts
1
2
  import { __, sprintf } from "@wordpress/i18n";
2
3
  import { UploadError } from "./upload-error";
3
4
  function validateMimeType(file, allowedTypes) {
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/validate-mime-type.ts"],
4
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": "AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;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,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER,GAAI,kDAAmD;AAAA,QACvD,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
5
+ "mappings": ";AAGA,SAAS,IAAI,eAAe;AAK5B,SAAS,mBAAmB;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,YAAa;AAAA,MACtB,MAAM;AAAA,MACN,SAAS;AAAA;AAAA,QAER,GAAI,kDAAmD;AAAA,QACvD,KAAK;AAAA,MACN;AAAA,MACA;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
6
  "names": []
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-upload-modal/index.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,mBAAmB,CAAC;AAUpE,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,sCAsOvB;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/media-upload-modal/index.tsx"],"names":[],"mappings":"AAkBA,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,sCA6QvB;AAED,eAAe,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/media-utils",
3
- "version": "5.34.0",
3
+ "version": "5.35.0",
4
4
  "description": "WordPress Media Upload Utils.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -36,18 +36,19 @@
36
36
  "wpScript": true,
37
37
  "types": "build-types",
38
38
  "dependencies": {
39
- "@wordpress/api-fetch": "^7.34.0",
40
- "@wordpress/blob": "^4.34.0",
41
- "@wordpress/components": "^30.7.0",
42
- "@wordpress/core-data": "^7.34.0",
43
- "@wordpress/data": "^10.34.0",
44
- "@wordpress/dataviews": "^10.2.0",
45
- "@wordpress/element": "^6.34.0",
46
- "@wordpress/i18n": "^6.7.0",
47
- "@wordpress/private-apis": "^1.34.0"
39
+ "@wordpress/api-fetch": "^7.35.0",
40
+ "@wordpress/blob": "^4.35.0",
41
+ "@wordpress/components": "^30.8.0",
42
+ "@wordpress/core-data": "^7.35.0",
43
+ "@wordpress/data": "^10.35.0",
44
+ "@wordpress/dataviews": "^10.3.0",
45
+ "@wordpress/element": "^6.35.0",
46
+ "@wordpress/i18n": "^6.8.0",
47
+ "@wordpress/icons": "^11.2.0",
48
+ "@wordpress/private-apis": "^1.35.0"
48
49
  },
49
50
  "publishConfig": {
50
51
  "access": "public"
51
52
  },
52
- "gitHead": "ceebff807958d2e8fc755b5a20473939c78b4d1d"
53
+ "gitHead": "77aa1f194edceafe8ac2a1b9438bf84b557e76e3"
53
54
  }
@@ -8,7 +8,8 @@ import {
8
8
  store as coreStore,
9
9
  } from '@wordpress/core-data';
10
10
  import { resolveSelect } from '@wordpress/data';
11
- import { Modal, DropZone } from '@wordpress/components';
11
+ import { Modal, DropZone, FormFileUpload, Button } from '@wordpress/components';
12
+ import { upload as uploadIcon } from '@wordpress/icons';
12
13
 
13
14
  /**
14
15
  * Internal dependencies
@@ -22,8 +23,9 @@ import { unlock } from '../../lock-unlock';
22
23
 
23
24
  const { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );
24
25
 
25
- // Layout constant - matching the picker grid layout type
26
+ // Layout constants - matching the picker layout types
26
27
  const LAYOUT_PICKER_GRID = 'pickerGrid';
28
+ const LAYOUT_PICKER_TABLE = 'pickerTable';
27
29
 
28
30
  interface MediaUploadModalProps {
29
31
  /**
@@ -185,7 +187,7 @@ export function MediaUploadModal( {
185
187
  if ( ! filters.media_type ) {
186
188
  filters.media_type = allowedTypes.includes( '*' )
187
189
  ? undefined
188
- : allowedTypes[ 0 ];
190
+ : allowedTypes;
189
191
  }
190
192
 
191
193
  return {
@@ -290,6 +292,23 @@ export function MediaUploadModal( {
290
292
  onClose?.();
291
293
  }, [ onClose ] );
292
294
 
295
+ // Use onUpload if provided, otherwise fall back to uploadMedia
296
+ const handleUpload = onUpload || uploadMedia;
297
+
298
+ const handleFileSelect = useCallback(
299
+ ( event: React.ChangeEvent< HTMLInputElement > ) => {
300
+ const files = event.target.files;
301
+ if ( files && files.length > 0 ) {
302
+ const filesArray = Array.from( files );
303
+ handleUpload( {
304
+ allowedTypes,
305
+ filesList: filesArray,
306
+ } );
307
+ }
308
+ },
309
+ [ allowedTypes, handleUpload ]
310
+ );
311
+
293
312
  const paginationInfo = useMemo(
294
313
  () => ( {
295
314
  totalItems,
@@ -301,17 +320,23 @@ export function MediaUploadModal( {
301
320
  const defaultLayouts = useMemo(
302
321
  () => ( {
303
322
  [ LAYOUT_PICKER_GRID ]: {},
323
+ [ LAYOUT_PICKER_TABLE ]: {},
304
324
  } ),
305
325
  []
306
326
  );
307
327
 
328
+ // Build accept attribute from allowedTypes
329
+ const acceptTypes = useMemo( () => {
330
+ if ( allowedTypes.includes( '*' ) ) {
331
+ return undefined;
332
+ }
333
+ return allowedTypes.join( ',' );
334
+ }, [ allowedTypes ] );
335
+
308
336
  if ( ! isOpen ) {
309
337
  return null;
310
338
  }
311
339
 
312
- // Use onUpload if provided, otherwise fall back to uploadMedia
313
- const handleUpload = onUpload || uploadMedia;
314
-
315
340
  return (
316
341
  <Modal
317
342
  title={ title }
@@ -319,6 +344,23 @@ export function MediaUploadModal( {
319
344
  isDismissible={ isDismissible }
320
345
  className={ modalClass }
321
346
  size="fill"
347
+ headerActions={
348
+ <FormFileUpload
349
+ accept={ acceptTypes }
350
+ multiple
351
+ onChange={ handleFileSelect }
352
+ __next40pxDefaultSize
353
+ render={ ( { openFileDialog } ) => (
354
+ <Button
355
+ onClick={ openFileDialog }
356
+ icon={ uploadIcon }
357
+ __next40pxDefaultSize
358
+ >
359
+ { __( 'Upload media' ) }
360
+ </Button>
361
+ ) }
362
+ />
363
+ }
322
364
  >
323
365
  <DropZone
324
366
  onFilesDrop={ ( files ) => {
@@ -341,7 +383,6 @@ export function MediaUploadModal( {
341
383
  handleUpload( {
342
384
  allowedTypes,
343
385
  filesList: filteredFiles,
344
- multiple,
345
386
  } );
346
387
  }
347
388
  } }
package/tsconfig.json CHANGED
@@ -14,6 +14,7 @@
14
14
  { "path": "../dataviews" },
15
15
  { "path": "../element" },
16
16
  { "path": "../i18n" },
17
+ { "path": "../icons" },
17
18
  { "path": "../private-apis" }
18
19
  ]
19
20
  }