@wordpress/media-utils 5.31.1-next.f56bd8138.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 (70) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/index.js +36 -11
  3. package/build/components/index.js.map +7 -1
  4. package/build/components/media-upload/index.js +156 -221
  5. package/build/components/media-upload/index.js.map +7 -1
  6. package/build/index.js +44 -65
  7. package/build/index.js.map +7 -1
  8. package/build/lock-unlock.js +31 -14
  9. package/build/lock-unlock.js.map +7 -1
  10. package/build/private-apis.js +31 -17
  11. package/build/private-apis.js.map +7 -1
  12. package/build/utils/flatten-form-data.js +28 -20
  13. package/build/utils/flatten-form-data.js.map +7 -1
  14. package/build/utils/get-mime-types-array.js +38 -20
  15. package/build/utils/get-mime-types-array.js.map +7 -1
  16. package/build/utils/sideload-media.js +50 -38
  17. package/build/utils/sideload-media.js.map +7 -1
  18. package/build/utils/sideload-to-server.js +53 -36
  19. package/build/utils/sideload-to-server.js.map +7 -1
  20. package/build/utils/transform-attachment.js +29 -23
  21. package/build/utils/transform-attachment.js.map +7 -1
  22. package/build/utils/types.js +16 -5
  23. package/build/utils/types.js.map +7 -1
  24. package/build/utils/upload-error.js +30 -21
  25. package/build/utils/upload-error.js.map +7 -1
  26. package/build/utils/upload-media.js +62 -71
  27. package/build/utils/upload-media.js.map +7 -1
  28. package/build/utils/upload-to-server.js +54 -27
  29. package/build/utils/upload-to-server.js.map +7 -1
  30. package/build/utils/validate-file-size.js +44 -32
  31. package/build/utils/validate-file-size.js.map +7 -1
  32. package/build/utils/validate-mime-type-for-user.js +42 -30
  33. package/build/utils/validate-mime-type-for-user.js.map +7 -1
  34. package/build/utils/validate-mime-type.js +37 -32
  35. package/build/utils/validate-mime-type.js.map +7 -1
  36. package/build-module/components/index.js +5 -2
  37. package/build-module/components/index.js.map +7 -1
  38. package/build-module/components/media-upload/index.js +137 -215
  39. package/build-module/components/media-upload/index.js.map +7 -1
  40. package/build-module/index.js +16 -8
  41. package/build-module/index.js.map +7 -1
  42. package/build-module/lock-unlock.js +8 -7
  43. package/build-module/lock-unlock.js.map +7 -1
  44. package/build-module/private-apis.js +7 -11
  45. package/build-module/private-apis.js.map +7 -1
  46. package/build-module/utils/flatten-form-data.js +7 -17
  47. package/build-module/utils/flatten-form-data.js.map +7 -1
  48. package/build-module/utils/get-mime-types-array.js +17 -17
  49. package/build-module/utils/get-mime-types-array.js.map +7 -1
  50. package/build-module/utils/sideload-media.js +28 -34
  51. package/build-module/utils/sideload-media.js.map +7 -1
  52. package/build-module/utils/sideload-to-server.js +22 -33
  53. package/build-module/utils/sideload-to-server.js.map +7 -1
  54. package/build-module/utils/transform-attachment.js +8 -20
  55. package/build-module/utils/transform-attachment.js.map +7 -1
  56. package/build-module/utils/types.js +1 -2
  57. package/build-module/utils/types.js.map +7 -1
  58. package/build-module/utils/upload-error.js +9 -17
  59. package/build-module/utils/upload-error.js.map +7 -1
  60. package/build-module/utils/upload-media.js +36 -63
  61. package/build-module/utils/upload-media.js.map +7 -1
  62. package/build-module/utils/upload-to-server.js +23 -22
  63. package/build-module/utils/upload-to-server.js.map +7 -1
  64. package/build-module/utils/validate-file-size.js +19 -25
  65. package/build-module/utils/validate-file-size.js.map +7 -1
  66. package/build-module/utils/validate-mime-type-for-user.js +18 -24
  67. package/build-module/utils/validate-mime-type-for-user.js.map +7 -1
  68. package/build-module/utils/validate-mime-type.js +14 -27
  69. package/build-module/utils/validate-mime-type.js.map +7 -1
  70. package/package.json +15 -8
@@ -1,32 +1,31 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var sideload_media_exports = {};
20
+ __export(sideload_media_exports, {
21
+ sideloadMedia: () => sideloadMedia
5
22
  });
6
- exports.sideloadMedia = sideloadMedia;
7
- var _i18n = require("@wordpress/i18n");
8
- var _sideloadToServer = require("./sideload-to-server");
9
- var _uploadError = require("./upload-error");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- const noop = () => {};
19
- /**
20
- * Uploads a file to the server without creating an attachment.
21
- *
22
- * @param $0 Parameters object passed to the function.
23
- * @param $0.file Media File to Save.
24
- * @param $0.attachmentId Parent attachment ID.
25
- * @param $0.additionalData Additional data to include in the request.
26
- * @param $0.signal Abort signal.
27
- * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.
28
- * @param $0.onError Function called when an error happens.
29
- */
23
+ module.exports = __toCommonJS(sideload_media_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_sideload_to_server = require("./sideload-to-server");
26
+ var import_upload_error = require("./upload-error");
27
+ const noop = () => {
28
+ };
30
29
  async function sideloadMedia({
31
30
  file,
32
31
  attachmentId,
@@ -36,23 +35,36 @@ async function sideloadMedia({
36
35
  onError = noop
37
36
  }) {
38
37
  try {
39
- const attachment = await (0, _sideloadToServer.sideloadToServer)(file, attachmentId, additionalData, signal);
38
+ const attachment = await (0, import_sideload_to_server.sideloadToServer)(
39
+ file,
40
+ attachmentId,
41
+ additionalData,
42
+ signal
43
+ );
40
44
  onFileChange?.([attachment]);
41
45
  } catch (error) {
42
46
  let message;
43
47
  if (error instanceof Error) {
44
48
  message = error.message;
45
49
  } else {
46
- message = (0, _i18n.sprintf)(
47
- // translators: %s: file name
48
- (0, _i18n.__)('Error while sideloading file %s to the server.'), file.name);
50
+ message = (0, import_i18n.sprintf)(
51
+ // translators: %s: file name
52
+ (0, import_i18n.__)("Error while sideloading file %s to the server."),
53
+ file.name
54
+ );
49
55
  }
50
- onError(new _uploadError.UploadError({
51
- code: 'GENERAL',
52
- message,
53
- file,
54
- cause: error instanceof Error ? error : undefined
55
- }));
56
+ onError(
57
+ new import_upload_error.UploadError({
58
+ code: "GENERAL",
59
+ message,
60
+ file,
61
+ cause: error instanceof Error ? error : void 0
62
+ })
63
+ );
56
64
  }
57
65
  }
58
- //# sourceMappingURL=sideload-media.js.map
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ sideloadMedia
69
+ });
70
+ //# sourceMappingURL=sideload-media.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_i18n","require","_sideloadToServer","_uploadError","noop","sideloadMedia","file","attachmentId","additionalData","signal","onFileChange","onError","attachment","sideloadToServer","error","message","Error","sprintf","__","name","UploadError","code","cause","undefined"],"sources":["@wordpress/media-utils/src/utils/sideload-media.ts"],"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"],"mappings":";;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AAWA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAUA,MAAMG,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAiBrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,aAAaA,CAAE;EACpCC,IAAI;EACJC,YAAY;EACZC,cAAc,GAAG,CAAC,CAAC;EACnBC,MAAM;EACNC,YAAY;EACZC,OAAO,GAAGP;AACQ,CAAC,EAAG;EACtB,IAAI;IACH,MAAMQ,UAAU,GAAG,MAAM,IAAAC,kCAAgB,EACxCP,IAAI,EACJC,YAAY,EACZC,cAAc,EACdC,MACD,CAAC;IACDC,YAAY,GAAI,CAAEE,UAAU,CAAG,CAAC;EACjC,CAAC,CAAC,OAAQE,KAAK,EAAG;IACjB,IAAIC,OAAO;IACX,IAAKD,KAAK,YAAYE,KAAK,EAAG;MAC7BD,OAAO,GAAGD,KAAK,CAACC,OAAO;IACxB,CAAC,MAAM;MACNA,OAAO,GAAG,IAAAE,aAAO;MAChB;MACA,IAAAC,QAAE,EAAE,gDAAiD,CAAC,EACtDZ,IAAI,CAACa,IACN,CAAC;IACF;IACAR,OAAO,CACN,IAAIS,wBAAW,CAAE;MAChBC,IAAI,EAAE,SAAS;MACfN,OAAO;MACPT,IAAI;MACJgB,KAAK,EAAER,KAAK,YAAYE,KAAK,GAAGF,KAAK,GAAGS;IACzC,CAAE,CACH,CAAC;EACF;AACD","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/sideload-media.ts"],
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA4B;AAW5B,gCAAiC;AACjC,0BAA4B;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,UAAM;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,oBAAU;AAAA;AAAA,YAET,gBAAI,gDAAiD;AAAA,QACrD,KAAK;AAAA,MACN;AAAA,IACD;AACA;AAAA,MACC,IAAI,gCAAa;AAAA,QAChB,MAAM;AAAA,QACN;AAAA,QACA;AAAA,QACA,OAAO,iBAAiB,QAAQ,QAAQ;AAAA,MACzC,CAAE;AAAA,IACH;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1,43 +1,60 @@
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 sideload_to_server_exports = {};
30
+ __export(sideload_to_server_exports, {
31
+ sideloadToServer: () => sideloadToServer
6
32
  });
7
- exports.sideloadToServer = sideloadToServer;
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
-
19
- /**
20
- * Uploads a file to the server without creating an attachment.
21
- *
22
- * @param file Media File to Save.
23
- * @param attachmentId Parent attachment ID.
24
- * @param additionalData Additional data to include in the request.
25
- * @param signal Abort signal.
26
- *
27
- * @return The saved attachment.
28
- */
33
+ module.exports = __toCommonJS(sideload_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");
29
37
  async function sideloadToServer(file, attachmentId, additionalData = {}, signal) {
30
- // Create upload payload.
31
38
  const data = new FormData();
32
- data.append('file', file, file.name || file.type.replace('/', '.'));
39
+ data.append("file", file, file.name || file.type.replace("/", "."));
33
40
  for (const [key, value] of Object.entries(additionalData)) {
34
- (0, _flattenFormData.flattenFormData)(data, key, value);
41
+ (0, import_flatten_form_data.flattenFormData)(
42
+ data,
43
+ key,
44
+ value
45
+ );
35
46
  }
36
- return (0, _transformAttachment.transformAttachment)(await (0, _apiFetch.default)({
37
- path: `/wp/v2/media/${attachmentId}/sideload`,
38
- body: data,
39
- method: 'POST',
40
- signal
41
- }));
47
+ return (0, import_transform_attachment.transformAttachment)(
48
+ await (0, import_api_fetch.default)({
49
+ path: `/wp/v2/media/${attachmentId}/sideload`,
50
+ body: data,
51
+ method: "POST",
52
+ signal
53
+ })
54
+ );
42
55
  }
43
- //# sourceMappingURL=sideload-to-server.js.map
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ sideloadToServer
59
+ });
60
+ //# sourceMappingURL=sideload-to-server.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_apiFetch","_interopRequireDefault","require","_flattenFormData","_transformAttachment","sideloadToServer","file","attachmentId","additionalData","signal","data","FormData","append","name","type","replace","key","value","Object","entries","flattenFormData","transformAttachment","apiFetch","path","body","method"],"sources":["@wordpress/media-utils/src/utils/sideload-to-server.ts"],"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"],"mappings":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,sBAAA,CAAAC,OAAA;AAMA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAF,OAAA;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeG,gBAAgBA,CACrCC,IAAU,EACVC,YAAoC,EACpCC,cAAkC,GAAG,CAAC,CAAC,EACvCC,MAAoB,EACnB;EACD;EACA,MAAMC,IAAI,GAAG,IAAIC,QAAQ,CAAC,CAAC;EAC3BD,IAAI,CAACE,MAAM,CAAE,MAAM,EAAEN,IAAI,EAAEA,IAAI,CAACO,IAAI,IAAIP,IAAI,CAACQ,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;IACjCC,IAAI,EAAE,gBAAiBhB,YAAY,WAAY;IAC/CiB,IAAI,EAAEd,IAAI;IACVe,MAAM,EAAE,MAAM;IACdhB;EACD,CAAE,CACH,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/sideload-to-server.ts"],
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAqB;AAMrB,+BAAgC;AAChC,kCAAoC;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,aAAO;AAAA,IACN,UAAM,iBAAAA,SAA4B;AAAA,MACjC,MAAM,gBAAiB,YAAa;AAAA,MACpC,MAAM;AAAA,MACN,QAAQ;AAAA,MACR;AAAA,IACD,CAAE;AAAA,EACH;AACD;",
6
+ "names": ["apiFetch"]
7
+ }
@@ -1,33 +1,39 @@
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 transform_attachment_exports = {};
20
+ __export(transform_attachment_exports, {
21
+ transformAttachment: () => transformAttachment
5
22
  });
6
- exports.transformAttachment = transformAttachment;
7
- /**
8
- * Internal dependencies
9
- */
10
-
11
- /**
12
- * Transforms an attachment object from the REST API shape into the shape expected by the block editor and other consumers.
13
- *
14
- * @param attachment REST API attachment object.
15
- */
23
+ module.exports = __toCommonJS(transform_attachment_exports);
16
24
  function transformAttachment(attachment) {
17
- var _attachment$caption$r;
18
- // eslint-disable-next-line camelcase
19
- const {
20
- alt_text,
21
- source_url,
22
- ...savedMediaProps
23
- } = attachment;
25
+ const { alt_text, source_url, ...savedMediaProps } = attachment;
24
26
  return {
25
27
  ...savedMediaProps,
26
28
  alt: attachment.alt_text,
27
- caption: (_attachment$caption$r = attachment.caption?.raw) !== null && _attachment$caption$r !== void 0 ? _attachment$caption$r : '',
29
+ caption: attachment.caption?.raw ?? "",
28
30
  title: attachment.title.raw,
29
31
  url: attachment.source_url,
30
- poster: attachment._embedded?.['wp:featuredmedia']?.[0]?.source_url || undefined
32
+ poster: attachment._embedded?.["wp:featuredmedia"]?.[0]?.source_url || void 0
31
33
  };
32
34
  }
33
- //# sourceMappingURL=transform-attachment.js.map
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ transformAttachment
38
+ });
39
+ //# sourceMappingURL=transform-attachment.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["transformAttachment","attachment","_attachment$caption$r","alt_text","source_url","savedMediaProps","alt","caption","raw","title","url","poster","_embedded","undefined"],"sources":["@wordpress/media-utils/src/utils/transform-attachment.ts"],"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"],"mappings":";;;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASA,mBAAmBA,CAAEC,UAA0B,EAAe;EAAA,IAAAC,qBAAA;EAC7E;EACA,MAAM;IAAEC,QAAQ;IAAEC,UAAU;IAAE,GAAGC;EAAgB,CAAC,GAAGJ,UAAU;EAC/D,OAAO;IACN,GAAGI,eAAe;IAClBC,GAAG,EAAEL,UAAU,CAACE,QAAQ;IACxBI,OAAO,GAAAL,qBAAA,GAAED,UAAU,CAACM,OAAO,EAAEC,GAAG,cAAAN,qBAAA,cAAAA,qBAAA,GAAI,EAAE;IACtCO,KAAK,EAAER,UAAU,CAACQ,KAAK,CAACD,GAAG;IAC3BE,GAAG,EAAET,UAAU,CAACG,UAAU;IAC1BO,MAAM,EACLV,UAAU,CAACW,SAAS,GAAI,kBAAkB,CAAE,GAAI,CAAC,CAAE,EAAER,UAAU,IAC/DS;EACF,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/transform-attachment.ts"],
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
+ "names": []
7
+ }
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=types.js.map
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
17
+ //# sourceMappingURL=types.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":[],"sources":["@wordpress/media-utils/src/utils/types.ts"],"sourcesContent":["/**\n * A media attachment object in a REST API context.\n *\n * Simplified version of what's defined in the wp-types package.\n *\n * @see https://www.npmjs.com/package/wp-types\n */\ninterface WP_REST_API_Attachment {\n\t/**\n\t * Unique identifier for the attachment.\n\t */\n\tid: number;\n\t/**\n\t * The ID of the featured media for the post.\n\t */\n\tfeatured_media: number;\n\t/**\n\t * URL to the attachment.\n\t */\n\tlink: string;\n\t/**\n\t * The date the attachment was published, in the site's timezone.\n\t */\n\tdate: string;\n\t/**\n\t * The date the attachment was published, as GMT.\n\t */\n\tdate_gmt: string;\n\t/**\n\t * The date the attachment was last modified, in the site's timezone.\n\t */\n\tmodified: string;\n\t/**\n\t * The date the attachment was last modified, as GMT.\n\t */\n\tmodified_gmt: string;\n\t/**\n\t * An alphanumeric identifier for the attachment unique to its type.\n\t */\n\tslug: string;\n\t/**\n\t * A named status for the attachment.\n\t */\n\tstatus: string;\n\t/**\n\t * Type of Post for the attachment.\n\t */\n\ttype: 'attachment';\n\t/**\n\t * Alternative text to display when attachment is not displayed.\n\t */\n\talt_text: string;\n\t/**\n\t * The attachment caption.\n\t */\n\tcaption: {\n\t\t/**\n\t\t * Caption for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML caption for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * The attachment description.\n\t */\n\tdescription: {\n\t\t/**\n\t\t * Description for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML description for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * Attachment type.\n\t */\n\tmedia_type: 'image' | 'file';\n\t/**\n\t * The attachment MIME type.\n\t */\n\tmime_type: string;\n\t/**\n\t * Details about the media file, specific to its type.\n\t */\n\tmedia_details: {\n\t\t[ k: string ]: unknown;\n\t};\n\t/**\n\t * The ID for the associated post of the attachment.\n\t */\n\tpost: number | null;\n\t/**\n\t * URL to the original attachment file.\n\t */\n\tsource_url: string;\n\t/**\n\t * List of the missing image sizes of the attachment. Only present when using the 'edit' context.\n\t */\n\tmissing_image_sizes?: string[];\n\t/**\n\t * Permalink template for the attachment. Only present when using the 'edit' context and the post type is public.\n\t */\n\tpermalink_template?: string;\n\t/**\n\t * Slug automatically generated from the attachment title. Only present when using the 'edit' context and the post type is public.\n\t */\n\tgenerated_slug?: string;\n\t/**\n\t * An array of the class names for the post container element.\n\t */\n\tclass_list: string[];\n\t/**\n\t * The title for the attachment.\n\t */\n\ttitle: {\n\t\t/**\n\t\t * Title for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML title for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * The ID for the author of the attachment.\n\t */\n\tauthor: number;\n\t/**\n\t * Whether or not comments are open on the attachment.\n\t */\n\tcomment_status: string;\n\t/**\n\t * Whether or not the attachment can be pinged.\n\t */\n\tping_status: string;\n\t/**\n\t * Meta fields.\n\t */\n\tmeta:\n\t\t| []\n\t\t| {\n\t\t\t\t[ k: string ]: unknown;\n\t\t };\n\t/**\n\t * The theme file to use to display the attachment.\n\t */\n\ttemplate: string;\n\t_links: {\n\t\t[ k: string ]: {\n\t\t\thref: string;\n\t\t\tembeddable?: boolean;\n\t\t\t[ k: string ]: unknown;\n\t\t}[];\n\t};\n\t/**\n\t * The embedded representation of relations. Only present when the '_embed' query parameter is set.\n\t */\n\t_embedded?: {\n\t\t/**\n\t\t * The author of the post.\n\t\t */\n\t\tauthor: unknown[];\n\t\t/**\n\t\t * The featured image post.\n\t\t */\n\t\t'wp:featuredmedia'?: WP_REST_API_Attachment[];\n\t\t[ k: string ]: unknown;\n\t};\n\t[ k: string ]: unknown;\n}\n\n/**\n * REST API attachment object with additional fields added by this project.\n */\nexport interface RestAttachment extends WP_REST_API_Attachment {}\n\ntype BetterOmit< T, K extends PropertyKey > = {\n\t[ P in keyof T as P extends K ? never : P ]: T[ P ];\n};\n\n/**\n * Transformed attachment object.\n */\nexport type Attachment = BetterOmit<\n\tRestAttachment,\n\t'alt_text' | 'source_url' | 'caption' | 'title'\n> & {\n\talt: WP_REST_API_Attachment[ 'alt_text' ];\n\tcaption: WP_REST_API_Attachment[ 'caption' ][ 'raw' ] & string;\n\ttitle: WP_REST_API_Attachment[ 'title' ][ 'raw' ];\n\turl: WP_REST_API_Attachment[ 'source_url' ];\n\tposter?: WP_REST_API_Attachment[ 'source_url' ];\n};\n\nexport type OnChangeHandler = ( attachments: Partial< Attachment >[] ) => void;\nexport type OnErrorHandler = ( error: Error ) => void;\n\nexport type CreateRestAttachment = Partial< RestAttachment >;\n\nexport type AdditionalData = BetterOmit< CreateRestAttachment, 'meta' >;\n\nexport interface CreateSideloadFile {\n\timage_size?: string;\n\tupload_request?: string;\n}\n\nexport interface SideloadAdditionalData {\n\tpost: RestAttachment[ 'id' ];\n\timage_size?: string;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/types.ts"],
4
+ "sourcesContent": ["/**\n * A media attachment object in a REST API context.\n *\n * Simplified version of what's defined in the wp-types package.\n *\n * @see https://www.npmjs.com/package/wp-types\n */\ninterface WP_REST_API_Attachment {\n\t/**\n\t * Unique identifier for the attachment.\n\t */\n\tid: number;\n\t/**\n\t * The ID of the featured media for the post.\n\t */\n\tfeatured_media: number;\n\t/**\n\t * URL to the attachment.\n\t */\n\tlink: string;\n\t/**\n\t * The date the attachment was published, in the site's timezone.\n\t */\n\tdate: string;\n\t/**\n\t * The date the attachment was published, as GMT.\n\t */\n\tdate_gmt: string;\n\t/**\n\t * The date the attachment was last modified, in the site's timezone.\n\t */\n\tmodified: string;\n\t/**\n\t * The date the attachment was last modified, as GMT.\n\t */\n\tmodified_gmt: string;\n\t/**\n\t * An alphanumeric identifier for the attachment unique to its type.\n\t */\n\tslug: string;\n\t/**\n\t * A named status for the attachment.\n\t */\n\tstatus: string;\n\t/**\n\t * Type of Post for the attachment.\n\t */\n\ttype: 'attachment';\n\t/**\n\t * Alternative text to display when attachment is not displayed.\n\t */\n\talt_text: string;\n\t/**\n\t * The attachment caption.\n\t */\n\tcaption: {\n\t\t/**\n\t\t * Caption for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML caption for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * The attachment description.\n\t */\n\tdescription: {\n\t\t/**\n\t\t * Description for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML description for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * Attachment type.\n\t */\n\tmedia_type: 'image' | 'file';\n\t/**\n\t * The attachment MIME type.\n\t */\n\tmime_type: string;\n\t/**\n\t * Details about the media file, specific to its type.\n\t */\n\tmedia_details: {\n\t\t[ k: string ]: unknown;\n\t};\n\t/**\n\t * The ID for the associated post of the attachment.\n\t */\n\tpost: number | null;\n\t/**\n\t * URL to the original attachment file.\n\t */\n\tsource_url: string;\n\t/**\n\t * List of the missing image sizes of the attachment. Only present when using the 'edit' context.\n\t */\n\tmissing_image_sizes?: string[];\n\t/**\n\t * Permalink template for the attachment. Only present when using the 'edit' context and the post type is public.\n\t */\n\tpermalink_template?: string;\n\t/**\n\t * Slug automatically generated from the attachment title. Only present when using the 'edit' context and the post type is public.\n\t */\n\tgenerated_slug?: string;\n\t/**\n\t * An array of the class names for the post container element.\n\t */\n\tclass_list: string[];\n\t/**\n\t * The title for the attachment.\n\t */\n\ttitle: {\n\t\t/**\n\t\t * Title for the attachment, as it exists in the database. Only present when using the 'edit' context.\n\t\t */\n\t\traw?: string;\n\t\t/**\n\t\t * HTML title for the attachment, transformed for display.\n\t\t */\n\t\trendered: string;\n\t};\n\t/**\n\t * The ID for the author of the attachment.\n\t */\n\tauthor: number;\n\t/**\n\t * Whether or not comments are open on the attachment.\n\t */\n\tcomment_status: string;\n\t/**\n\t * Whether or not the attachment can be pinged.\n\t */\n\tping_status: string;\n\t/**\n\t * Meta fields.\n\t */\n\tmeta:\n\t\t| []\n\t\t| {\n\t\t\t\t[ k: string ]: unknown;\n\t\t };\n\t/**\n\t * The theme file to use to display the attachment.\n\t */\n\ttemplate: string;\n\t_links: {\n\t\t[ k: string ]: {\n\t\t\thref: string;\n\t\t\tembeddable?: boolean;\n\t\t\t[ k: string ]: unknown;\n\t\t}[];\n\t};\n\t/**\n\t * The embedded representation of relations. Only present when the '_embed' query parameter is set.\n\t */\n\t_embedded?: {\n\t\t/**\n\t\t * The author of the post.\n\t\t */\n\t\tauthor: unknown[];\n\t\t/**\n\t\t * The featured image post.\n\t\t */\n\t\t'wp:featuredmedia'?: WP_REST_API_Attachment[];\n\t\t[ k: string ]: unknown;\n\t};\n\t[ k: string ]: unknown;\n}\n\n/**\n * REST API attachment object with additional fields added by this project.\n */\nexport interface RestAttachment extends WP_REST_API_Attachment {}\n\ntype BetterOmit< T, K extends PropertyKey > = {\n\t[ P in keyof T as P extends K ? never : P ]: T[ P ];\n};\n\n/**\n * Transformed attachment object.\n */\nexport type Attachment = BetterOmit<\n\tRestAttachment,\n\t'alt_text' | 'source_url' | 'caption' | 'title'\n> & {\n\talt: WP_REST_API_Attachment[ 'alt_text' ];\n\tcaption: WP_REST_API_Attachment[ 'caption' ][ 'raw' ] & string;\n\ttitle: WP_REST_API_Attachment[ 'title' ][ 'raw' ];\n\turl: WP_REST_API_Attachment[ 'source_url' ];\n\tposter?: WP_REST_API_Attachment[ 'source_url' ];\n};\n\nexport type OnChangeHandler = ( attachments: Partial< Attachment >[] ) => void;\nexport type OnErrorHandler = ( error: Error ) => void;\n\nexport type CreateRestAttachment = Partial< RestAttachment >;\n\nexport type AdditionalData = BetterOmit< CreateRestAttachment, 'meta' >;\n\nexport interface CreateSideloadFile {\n\timage_size?: string;\n\tupload_request?: string;\n}\n\nexport interface SideloadAdditionalData {\n\tpost: RestAttachment[ 'id' ];\n\timage_size?: string;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,29 +1,38 @@
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 upload_error_exports = {};
20
+ __export(upload_error_exports, {
21
+ UploadError: () => UploadError
5
22
  });
6
- exports.UploadError = void 0;
7
- /**
8
- * MediaError class.
9
- *
10
- * Small wrapper around the `Error` class
11
- * to hold an error code and a reference to a file object.
12
- */
23
+ module.exports = __toCommonJS(upload_error_exports);
13
24
  class UploadError extends Error {
14
- constructor({
15
- code,
16
- message,
17
- file,
18
- cause
19
- }) {
20
- super(message, {
21
- cause
22
- });
25
+ code;
26
+ file;
27
+ constructor({ code, message, file, cause }) {
28
+ super(message, { cause });
23
29
  Object.setPrototypeOf(this, new.target.prototype);
24
30
  this.code = code;
25
31
  this.file = file;
26
32
  }
27
33
  }
28
- exports.UploadError = UploadError;
29
- //# sourceMappingURL=upload-error.js.map
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ UploadError
37
+ });
38
+ //# sourceMappingURL=upload-error.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["UploadError","Error","constructor","code","message","file","cause","Object","setPrototypeOf","new","target","prototype","exports"],"sources":["@wordpress/media-utils/src/utils/upload-error.ts"],"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"],"mappings":";;;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,WAAW,SAASC,KAAK,CAAC;EAItCC,WAAWA,CAAE;IAAEC,IAAI;IAAEC,OAAO;IAAEC,IAAI;IAAEC;EAAuB,CAAC,EAAG;IAC9D,KAAK,CAAEF,OAAO,EAAE;MAAEE;IAAM,CAAE,CAAC;IAE3BC,MAAM,CAACC,cAAc,CAAE,IAAI,EAAEC,GAAG,CAACC,MAAM,CAACC,SAAU,CAAC;IAEnD,IAAI,CAACR,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACE,IAAI,GAAGA,IAAI;EACjB;AACD;AAACO,OAAA,CAAAZ,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/upload-error.ts"],
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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;",
6
+ "names": []
7
+ }
@@ -1,39 +1,33 @@
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 upload_media_exports = {};
20
+ __export(upload_media_exports, {
21
+ uploadMedia: () => uploadMedia
5
22
  });
6
- exports.uploadMedia = uploadMedia;
7
- var _i18n = require("@wordpress/i18n");
8
- var _blob = require("@wordpress/blob");
9
- var _uploadToServer = require("./upload-to-server");
10
- var _validateMimeType = require("./validate-mime-type");
11
- var _validateMimeTypeForUser = require("./validate-mime-type-for-user");
12
- var _validateFileSize = require("./validate-file-size");
13
- var _uploadError = require("./upload-error");
14
- /**
15
- * WordPress dependencies
16
- */
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
-
22
- /**
23
- * Upload a media file when the file upload button is activated
24
- * or when adding a file to the editor via drag & drop.
25
- *
26
- * @param $0 Parameters object passed to the function.
27
- * @param $0.allowedTypes Array with the types of media that can be uploaded, if unset all types are allowed.
28
- * @param $0.additionalData Additional data to include in the request.
29
- * @param $0.filesList List of files.
30
- * @param $0.maxUploadFileSize Maximum upload size in bytes allowed for the site.
31
- * @param $0.onError Function called when an error happens.
32
- * @param $0.onFileChange Function called each time a file or a temporary representation of the file is available.
33
- * @param $0.wpAllowedMimeTypes List of allowed mime types and file extensions.
34
- * @param $0.signal Abort signal.
35
- * @param $0.multiple Whether to allow multiple files to be uploaded.
36
- */
23
+ module.exports = __toCommonJS(upload_media_exports);
24
+ var import_i18n = require("@wordpress/i18n");
25
+ var import_blob = require("@wordpress/blob");
26
+ var import_upload_to_server = require("./upload-to-server");
27
+ var import_validate_mime_type = require("./validate-mime-type");
28
+ var import_validate_mime_type_for_user = require("./validate-mime-type-for-user");
29
+ var import_validate_file_size = require("./validate-file-size");
30
+ var import_upload_error = require("./upload-error");
37
31
  function uploadMedia({
38
32
  wpAllowedMimeTypes,
39
33
  allowedTypes,
@@ -46,83 +40,80 @@ function uploadMedia({
46
40
  multiple = true
47
41
  }) {
48
42
  if (!multiple && filesList.length > 1) {
49
- onError?.(new Error((0, _i18n.__)('Only one file can be used here.')));
43
+ onError?.(new Error((0, import_i18n.__)("Only one file can be used here.")));
50
44
  return;
51
45
  }
52
46
  const validFiles = [];
53
47
  const filesSet = [];
54
48
  const setAndUpdateFiles = (index, value) => {
55
- // For client-side media processing, this is handled by the upload-media package.
56
49
  if (!window.__experimentalMediaProcessing) {
57
50
  if (filesSet[index]?.url) {
58
- (0, _blob.revokeBlobURL)(filesSet[index].url);
51
+ (0, import_blob.revokeBlobURL)(filesSet[index].url);
59
52
  }
60
53
  }
61
54
  filesSet[index] = value;
62
- onFileChange?.(filesSet.filter(attachment => attachment !== null));
55
+ onFileChange?.(
56
+ filesSet.filter((attachment) => attachment !== null)
57
+ );
63
58
  };
64
59
  for (const mediaFile of filesList) {
65
- // Verify if user is allowed to upload this mime type.
66
- // Defer to the server when type not detected.
67
60
  try {
68
- (0, _validateMimeTypeForUser.validateMimeTypeForUser)(mediaFile, wpAllowedMimeTypes);
61
+ (0, import_validate_mime_type_for_user.validateMimeTypeForUser)(mediaFile, wpAllowedMimeTypes);
69
62
  } catch (error) {
70
63
  onError?.(error);
71
64
  continue;
72
65
  }
73
-
74
- // Check if the caller (e.g. a block) supports this mime type.
75
- // Defer to the server when type not detected.
76
66
  try {
77
- (0, _validateMimeType.validateMimeType)(mediaFile, allowedTypes);
67
+ (0, import_validate_mime_type.validateMimeType)(mediaFile, allowedTypes);
78
68
  } catch (error) {
79
69
  onError?.(error);
80
70
  continue;
81
71
  }
82
-
83
- // Verify if file is greater than the maximum file upload size allowed for the site.
84
72
  try {
85
- (0, _validateFileSize.validateFileSize)(mediaFile, maxUploadFileSize);
73
+ (0, import_validate_file_size.validateFileSize)(mediaFile, maxUploadFileSize);
86
74
  } catch (error) {
87
75
  onError?.(error);
88
76
  continue;
89
77
  }
90
78
  validFiles.push(mediaFile);
91
-
92
- // For client-side media processing, this is handled by the upload-media package.
93
79
  if (!window.__experimentalMediaProcessing) {
94
- // Set temporary URL to create placeholder media file, this is replaced
95
- // with final file from media gallery when upload is `done` below.
96
- filesSet.push({
97
- url: (0, _blob.createBlobURL)(mediaFile)
98
- });
80
+ filesSet.push({ url: (0, import_blob.createBlobURL)(mediaFile) });
99
81
  onFileChange?.(filesSet);
100
82
  }
101
83
  }
102
84
  validFiles.map(async (file, index) => {
103
85
  try {
104
- const attachment = await (0, _uploadToServer.uploadToServer)(file, additionalData, signal);
86
+ const attachment = await (0, import_upload_to_server.uploadToServer)(
87
+ file,
88
+ additionalData,
89
+ signal
90
+ );
105
91
  setAndUpdateFiles(index, attachment);
106
92
  } catch (error) {
107
- // Reset to empty on failure.
108
93
  setAndUpdateFiles(index, null);
109
-
110
- // @wordpress/api-fetch throws any response that isn't in the 200 range as-is.
111
94
  let message;
112
- if (typeof error === 'object' && error !== null && 'message' in error) {
113
- message = typeof error.message === 'string' ? error.message : String(error.message);
95
+ if (typeof error === "object" && error !== null && "message" in error) {
96
+ message = typeof error.message === "string" ? error.message : String(error.message);
114
97
  } else {
115
- message = (0, _i18n.sprintf)(
116
- // translators: %s: file name
117
- (0, _i18n.__)('Error while uploading file %s to the media library.'), file.name);
98
+ message = (0, import_i18n.sprintf)(
99
+ // translators: %s: file name
100
+ (0, import_i18n.__)("Error while uploading file %s to the media library."),
101
+ file.name
102
+ );
118
103
  }
119
- onError?.(new _uploadError.UploadError({
120
- code: 'GENERAL',
121
- message,
122
- file,
123
- cause: error instanceof Error ? error : undefined
124
- }));
104
+ onError?.(
105
+ new import_upload_error.UploadError({
106
+ code: "GENERAL",
107
+ message,
108
+ file,
109
+ cause: error instanceof Error ? error : void 0
110
+ })
111
+ );
125
112
  }
126
113
  });
127
114
  }
128
- //# sourceMappingURL=upload-media.js.map
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ uploadMedia
118
+ });
119
+ //# sourceMappingURL=upload-media.js.map