@wordpress/media-fields 0.23.0 → 0.24.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 (89) hide show
  1. package/build/alt_text/index.cjs +31 -57
  2. package/build/alt_text/index.cjs.map +1 -7
  3. package/build/attached_to/edit.cjs +98 -133
  4. package/build/attached_to/edit.cjs.map +1 -7
  5. package/build/attached_to/index.cjs +33 -38
  6. package/build/attached_to/index.cjs.map +1 -7
  7. package/build/attached_to/view.cjs +25 -46
  8. package/build/attached_to/view.cjs.map +1 -7
  9. package/build/author/index.cjs +43 -56
  10. package/build/author/index.cjs.map +1 -7
  11. package/build/author/view.cjs +67 -74
  12. package/build/author/view.cjs.map +1 -7
  13. package/build/caption/index.cjs +21 -39
  14. package/build/caption/index.cjs.map +1 -7
  15. package/build/date_added/index.cjs +13 -34
  16. package/build/date_added/index.cjs.map +1 -7
  17. package/build/date_modified/index.cjs +13 -34
  18. package/build/date_modified/index.cjs.map +1 -7
  19. package/build/description/index.cjs +22 -40
  20. package/build/description/index.cjs.map +1 -7
  21. package/build/filename/index.cjs +33 -39
  22. package/build/filename/index.cjs.map +1 -7
  23. package/build/filename/view.cjs +23 -51
  24. package/build/filename/view.cjs.map +1 -7
  25. package/build/filesize/index.cjs +54 -83
  26. package/build/filesize/index.cjs.map +1 -7
  27. package/build/index.cjs +111 -63
  28. package/build/media_dimensions/index.cjs +19 -42
  29. package/build/media_dimensions/index.cjs.map +1 -7
  30. package/build/media_thumbnail/index.cjs +30 -36
  31. package/build/media_thumbnail/index.cjs.map +1 -7
  32. package/build/media_thumbnail/view.cjs +117 -162
  33. package/build/media_thumbnail/view.cjs.map +1 -7
  34. package/build/mime_type/index.cjs +16 -37
  35. package/build/mime_type/index.cjs.map +1 -7
  36. package/build/types.cjs +4 -18
  37. package/build/utils/get-media-type-from-mime-type.cjs +41 -56
  38. package/build/utils/get-media-type-from-mime-type.cjs.map +1 -7
  39. package/build/utils/get-raw-content.cjs +23 -38
  40. package/build/utils/get-raw-content.cjs.map +1 -7
  41. package/build/utils/get-rendered-content.cjs +23 -38
  42. package/build/utils/get-rendered-content.cjs.map +1 -7
  43. package/build-module/alt_text/index.mjs +25 -35
  44. package/build-module/alt_text/index.mjs.map +1 -7
  45. package/build-module/attached_to/edit.mjs +88 -110
  46. package/build-module/attached_to/edit.mjs.map +1 -7
  47. package/build-module/attached_to/index.mjs +12 -14
  48. package/build-module/attached_to/index.mjs.map +1 -7
  49. package/build-module/attached_to/view.mjs +19 -24
  50. package/build-module/attached_to/view.mjs.map +1 -7
  51. package/build-module/author/index.mjs +23 -32
  52. package/build-module/author/index.mjs.map +1 -7
  53. package/build-module/author/view.mjs +47 -53
  54. package/build-module/author/view.mjs.map +1 -7
  55. package/build-module/caption/index.mjs +16 -18
  56. package/build-module/caption/index.mjs.map +1 -7
  57. package/build-module/date_added/index.mjs +10 -14
  58. package/build-module/date_added/index.mjs.map +1 -7
  59. package/build-module/date_modified/index.mjs +10 -14
  60. package/build-module/date_modified/index.mjs.map +1 -7
  61. package/build-module/description/index.mjs +16 -18
  62. package/build-module/description/index.mjs.map +1 -7
  63. package/build-module/filename/index.mjs +13 -15
  64. package/build-module/filename/index.mjs.map +1 -7
  65. package/build-module/filename/view.mjs +16 -28
  66. package/build-module/filename/view.mjs.map +1 -7
  67. package/build-module/filesize/index.mjs +50 -63
  68. package/build-module/filesize/index.mjs.map +1 -7
  69. package/build-module/index.mjs +13 -28
  70. package/build-module/media_dimensions/index.mjs +15 -22
  71. package/build-module/media_dimensions/index.mjs.map +1 -7
  72. package/build-module/media_thumbnail/index.mjs +11 -13
  73. package/build-module/media_thumbnail/index.mjs.map +1 -7
  74. package/build-module/media_thumbnail/view.mjs +94 -136
  75. package/build-module/media_thumbnail/view.mjs.map +1 -7
  76. package/build-module/mime_type/index.mjs +13 -17
  77. package/build-module/mime_type/index.mjs.map +1 -7
  78. package/build-module/types.mjs +0 -1
  79. package/build-module/utils/get-media-type-from-mime-type.mjs +37 -32
  80. package/build-module/utils/get-media-type-from-mime-type.mjs.map +1 -7
  81. package/build-module/utils/get-raw-content.mjs +19 -14
  82. package/build-module/utils/get-raw-content.mjs.map +1 -7
  83. package/build-module/utils/get-rendered-content.mjs +19 -14
  84. package/build-module/utils/get-rendered-content.mjs.map +1 -7
  85. package/package.json +14 -14
  86. package/build/index.cjs.map +0 -7
  87. package/build/types.cjs.map +0 -7
  88. package/build-module/index.mjs.map +0 -7
  89. package/build-module/types.mjs.map +0 -7
@@ -1,60 +1,45 @@
1
1
  "use strict";
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
-
20
- // packages/media-fields/src/utils/get-media-type-from-mime-type.ts
21
- var get_media_type_from_mime_type_exports = {};
22
- __export(get_media_type_from_mime_type_exports, {
23
- getMediaTypeFromMimeType: () => getMediaTypeFromMimeType
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(get_media_type_from_mime_type_exports);
26
- var import_i18n = require("@wordpress/i18n");
27
- var import_icons = require("@wordpress/icons");
6
+ let _wordpress_i18n = require("@wordpress/i18n");
7
+ let _wordpress_icons = require("@wordpress/icons");
8
+ // packages/media-fields/src/utils/get-media-type-from-mime-type.ts
9
+ /**
10
+ * Get the media type from a mime type, including an icon.
11
+ * TODO - media types should be formalized somewhere.
12
+ *
13
+ * References:
14
+ * https://developer.wordpress.org/reference/functions/wp_mime_type_icon/
15
+ * https://developer.wordpress.org/reference/hooks/mime_types/
16
+ * https://developer.wordpress.org/reference/functions/wp_get_mime_types/
17
+ *
18
+ * @param mimeType - The mime type to get the media type from.
19
+ * @return The media type.
20
+ */
28
21
  function getMediaTypeFromMimeType(mimeType) {
29
- if (mimeType.startsWith("image/")) {
30
- return {
31
- type: "image",
32
- label: (0, import_i18n.__)("Image"),
33
- icon: import_icons.image
34
- };
35
- }
36
- if (mimeType.startsWith("video/")) {
37
- return {
38
- type: "video",
39
- label: (0, import_i18n.__)("Video"),
40
- icon: import_icons.video
41
- };
42
- }
43
- if (mimeType.startsWith("audio/")) {
44
- return {
45
- type: "audio",
46
- label: (0, import_i18n.__)("Audio"),
47
- icon: import_icons.audio
48
- };
49
- }
50
- return {
51
- type: "application",
52
- label: (0, import_i18n.__)("Application"),
53
- icon: import_icons.file
54
- };
22
+ if (mimeType.startsWith("image/")) return {
23
+ type: "image",
24
+ label: (0, _wordpress_i18n.__)("Image"),
25
+ icon: _wordpress_icons.image
26
+ };
27
+ if (mimeType.startsWith("video/")) return {
28
+ type: "video",
29
+ label: (0, _wordpress_i18n.__)("Video"),
30
+ icon: _wordpress_icons.video
31
+ };
32
+ if (mimeType.startsWith("audio/")) return {
33
+ type: "audio",
34
+ label: (0, _wordpress_i18n.__)("Audio"),
35
+ icon: _wordpress_icons.audio
36
+ };
37
+ return {
38
+ type: "application",
39
+ label: (0, _wordpress_i18n.__)("Application"),
40
+ icon: _wordpress_icons.file
41
+ };
55
42
  }
56
- // Annotate the CommonJS export names for ESM import in node:
57
- 0 && (module.exports = {
58
- getMediaTypeFromMimeType
59
- });
60
- //# sourceMappingURL=get-media-type-from-mime-type.cjs.map
43
+ exports.getMediaTypeFromMimeType = getMediaTypeFromMimeType;
44
+
45
+ //# sourceMappingURL=get-media-type-from-mime-type.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/get-media-type-from-mime-type.ts"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { audio, video, image, file } from '@wordpress/icons';\nimport type { MediaType } from '../types';\n\n/**\n * Get the media type from a mime type, including an icon.\n * TODO - media types should be formalized somewhere.\n *\n * References:\n * https://developer.wordpress.org/reference/functions/wp_mime_type_icon/\n * https://developer.wordpress.org/reference/hooks/mime_types/\n * https://developer.wordpress.org/reference/functions/wp_get_mime_types/\n *\n * @param mimeType - The mime type to get the media type from.\n * @return The media type.\n */\nexport function getMediaTypeFromMimeType( mimeType: string ): MediaType {\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn {\n\t\t\ttype: 'image',\n\t\t\tlabel: __( 'Image' ),\n\t\t\ticon: image,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn {\n\t\t\ttype: 'video',\n\t\t\tlabel: __( 'Video' ),\n\t\t\ticon: video,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn {\n\t\t\ttype: 'audio',\n\t\t\tlabel: __( 'Audio' ),\n\t\t\ticon: audio,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'application',\n\t\tlabel: __( 'Application' ),\n\t\ticon: file,\n\t};\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,mBAA0C;AAenC,SAAS,yBAA0B,UAA8B;AACvE,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,WAAO,gBAAI,aAAc;AAAA,IACzB,MAAM;AAAA,EACP;AACD;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-media-type-from-mime-type.cjs","names":["__","image","video","audio","file"],"sources":["../../src/utils/get-media-type-from-mime-type.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { audio, video, image, file } from '@wordpress/icons';\nimport type { MediaType } from '../types';\n\n/**\n * Get the media type from a mime type, including an icon.\n * TODO - media types should be formalized somewhere.\n *\n * References:\n * https://developer.wordpress.org/reference/functions/wp_mime_type_icon/\n * https://developer.wordpress.org/reference/hooks/mime_types/\n * https://developer.wordpress.org/reference/functions/wp_get_mime_types/\n *\n * @param mimeType - The mime type to get the media type from.\n * @return The media type.\n */\nexport function getMediaTypeFromMimeType( mimeType: string ): MediaType {\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn {\n\t\t\ttype: 'image',\n\t\t\tlabel: __( 'Image' ),\n\t\t\ticon: image,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn {\n\t\t\ttype: 'video',\n\t\t\tlabel: __( 'Video' ),\n\t\t\ticon: video,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn {\n\t\t\ttype: 'audio',\n\t\t\tlabel: __( 'Audio' ),\n\t\t\ticon: audio,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'application',\n\t\tlabel: __( 'Application' ),\n\t\ticon: file,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgBA,SAAgB,yBAA0B,UAA8B;CACvE,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO;EACN,MAAM;EACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,MAAMC,iBAAAA;CACP;CAGD,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO;EACN,MAAM;EACN,QAAA,GAAOD,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,MAAME,iBAAAA;CACP;CAGD,IAAK,SAAS,WAAY,QAAS,GAClC,OAAO;EACN,MAAM;EACN,QAAA,GAAOF,gBAAAA,GAAAA,CAAI,OAAQ;EACnB,MAAMG,iBAAAA;CACP;CAGD,OAAO;EACN,MAAM;EACN,QAAA,GAAOH,gBAAAA,GAAAA,CAAI,aAAc;EACzB,MAAMI,iBAAAA;CACP;AACD"}
@@ -1,42 +1,27 @@
1
1
  "use strict";
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
-
20
- // packages/media-fields/src/utils/get-raw-content.ts
21
- var get_raw_content_exports = {};
22
- __export(get_raw_content_exports, {
23
- getRawContent: () => getRawContent
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(get_raw_content_exports);
6
+ // packages/media-fields/src/utils/get-raw-content.ts
7
+ /**
8
+ * Utility function to extract raw content from either a string or an object
9
+ * containing raw and rendered properties.
10
+ *
11
+ * This handles the inconsistency in WordPress REST API responses where
12
+ * some fields like caption and description can be either:
13
+ * - A simple string
14
+ * - An object with { raw: string, rendered: string }
15
+ *
16
+ * @param content - The content to extract raw value from
17
+ * @return The raw content string, or empty string if content is falsy
18
+ */
26
19
  function getRawContent(content) {
27
- if (!content) {
28
- return "";
29
- }
30
- if (typeof content === "string") {
31
- return content;
32
- }
33
- if (typeof content === "object" && "raw" in content) {
34
- return content.raw || "";
35
- }
36
- return "";
20
+ if (!content) return "";
21
+ if (typeof content === "string") return content;
22
+ if (typeof content === "object" && "raw" in content) return content.raw || "";
23
+ return "";
37
24
  }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- getRawContent
41
- });
42
- //# sourceMappingURL=get-raw-content.cjs.map
25
+ exports.getRawContent = getRawContent;
26
+
27
+ //# sourceMappingURL=get-raw-content.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/get-raw-content.ts"],
4
- "sourcesContent": ["/**\n * Utility function to extract raw content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The raw content string, or empty string if content is falsy\n */\nexport function getRawContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' && 'raw' in content ) {\n\t\treturn content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,cACf,SACS;AACT,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,YAAY,SAAS,SAAU;AACtD,WAAO,QAAQ,OAAO;AAAA,EACvB;AAGA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-raw-content.cjs","names":[],"sources":["../../src/utils/get-raw-content.ts"],"sourcesContent":["/**\n * Utility function to extract raw content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The raw content string, or empty string if content is falsy\n */\nexport function getRawContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' && 'raw' in content ) {\n\t\treturn content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAYA,SAAgB,cACf,SACS;CACT,IAAK,CAAE,SACN,OAAO;CAIR,IAAK,OAAO,YAAY,UACvB,OAAO;CAIR,IAAK,OAAO,YAAY,YAAY,SAAS,SAC5C,OAAO,QAAQ,OAAO;CAIvB,OAAO;AACR"}
@@ -1,42 +1,27 @@
1
1
  "use strict";
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
-
20
- // packages/media-fields/src/utils/get-rendered-content.ts
21
- var get_rendered_content_exports = {};
22
- __export(get_rendered_content_exports, {
23
- getRenderedContent: () => getRenderedContent
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(get_rendered_content_exports);
6
+ // packages/media-fields/src/utils/get-rendered-content.ts
7
+ /**
8
+ * Utility function to extract rendered content from either a string or an object
9
+ * containing raw and rendered properties.
10
+ *
11
+ * This handles the inconsistency in WordPress REST API responses where
12
+ * some fields like caption and description can be either:
13
+ * - A simple string
14
+ * - An object with { raw: string, rendered: string }
15
+ *
16
+ * @param content - The content to extract raw value from
17
+ * @return The rendered content string, falling back to raw or empty string if content is falsy
18
+ */
26
19
  function getRenderedContent(content) {
27
- if (!content) {
28
- return "";
29
- }
30
- if (typeof content === "string") {
31
- return content;
32
- }
33
- if (typeof content === "object") {
34
- return content.rendered || content.raw || "";
35
- }
36
- return "";
20
+ if (!content) return "";
21
+ if (typeof content === "string") return content;
22
+ if (typeof content === "object") return content.rendered || content.raw || "";
23
+ return "";
37
24
  }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- getRenderedContent
41
- });
42
- //# sourceMappingURL=get-rendered-content.cjs.map
25
+ exports.getRenderedContent = getRenderedContent;
26
+
27
+ //# sourceMappingURL=get-rendered-content.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/utils/get-rendered-content.ts"],
4
- "sourcesContent": ["/**\n * Utility function to extract rendered content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The rendered content string, falling back to raw or empty string if content is falsy\n */\nexport function getRenderedContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' ) {\n\t\treturn content.rendered || content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,mBACf,SACS;AACT,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO,QAAQ,YAAY,QAAQ,OAAO;AAAA,EAC3C;AAGA,SAAO;AACR;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"get-rendered-content.cjs","names":[],"sources":["../../src/utils/get-rendered-content.ts"],"sourcesContent":["/**\n * Utility function to extract rendered content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The rendered content string, falling back to raw or empty string if content is falsy\n */\nexport function getRenderedContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' ) {\n\t\treturn content.rendered || content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAYA,SAAgB,mBACf,SACS;CACT,IAAK,CAAE,SACN,OAAO;CAIR,IAAK,OAAO,YAAY,UACvB,OAAO;CAIR,IAAK,OAAO,YAAY,UACvB,OAAO,QAAQ,YAAY,QAAQ,OAAO;CAI3C,OAAO;AACR"}
@@ -1,39 +1,29 @@
1
- // packages/media-fields/src/alt_text/index.tsx
2
1
  import { __ } from "@wordpress/i18n";
3
2
  import { Link } from "@wordpress/ui";
4
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- var altTextField = {
6
- id: "alt_text",
7
- type: "text",
8
- label: __("Alt text"),
9
- description: /* @__PURE__ */ jsxs(Fragment, { children: [
10
- /* @__PURE__ */ jsx(
11
- Link,
12
- {
13
- href: (
14
- // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.
15
- __(
16
- "https://www.w3.org/WAI/tutorials/images/decision-tree/"
17
- )
18
- ),
19
- openInNewTab: true,
20
- children: __("Describe the purpose of the image.")
21
- }
22
- ),
23
- /* @__PURE__ */ jsx("br", {}),
24
- __("Leave empty if decorative.")
25
- ] }),
26
- isVisible: (item) => item?.media_type === "image",
27
- render: ({ item }) => item?.alt_text || "-",
28
- Edit: {
29
- control: "textarea",
30
- rows: 2
31
- },
32
- enableSorting: false,
33
- filterBy: false
34
- };
35
- var alt_text_default = altTextField;
36
- export {
37
- alt_text_default as default
4
+ // packages/media-fields/src/alt_text/index.tsx
5
+ const altTextField = {
6
+ id: "alt_text",
7
+ type: "text",
8
+ label: __("Alt text"),
9
+ description: /* @__PURE__ */ jsxs(Fragment, { children: [
10
+ /* @__PURE__ */ jsx(Link, {
11
+ href: __("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
12
+ openInNewTab: true,
13
+ children: __("Describe the purpose of the image.")
14
+ }),
15
+ /* @__PURE__ */ jsx("br", {}),
16
+ __("Leave empty if decorative.")
17
+ ] }),
18
+ isVisible: (item) => item?.media_type === "image",
19
+ render: ({ item }) => item?.alt_text || "-",
20
+ Edit: {
21
+ control: "textarea",
22
+ rows: 2
23
+ },
24
+ enableSorting: false,
25
+ filterBy: false
38
26
  };
39
- //# sourceMappingURL=index.mjs.map
27
+ export { altTextField as default };
28
+
29
+ //# sourceMappingURL=index.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/alt_text/index.tsx"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { Link } from '@wordpress/ui';\nimport type { Field } from '@wordpress/dataviews';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\n\nconst altTextField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'alt_text',\n\ttype: 'text',\n\tlabel: __( 'Alt text' ),\n\tdescription: (\n\t\t<>\n\t\t\t<Link\n\t\t\t\thref={\n\t\t\t\t\t// translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.\n\t\t\t\t\t__(\n\t\t\t\t\t\t'https://www.w3.org/WAI/tutorials/images/decision-tree/'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\topenInNewTab\n\t\t\t>\n\t\t\t\t{ __( 'Describe the purpose of the image.' ) }\n\t\t\t</Link>\n\t\t\t<br />\n\t\t\t{ __( 'Leave empty if decorative.' ) }\n\t\t</>\n\t),\n\tisVisible: ( item ) => item?.media_type === 'image',\n\trender: ( { item } ) => item?.alt_text || '-',\n\tEdit: {\n\t\tcontrol: 'textarea',\n\t\trows: 2,\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default altTextField;\n"],
5
- "mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,YAAY;AASnB,mBACC,KADD;AALF,IAAM,eAA4D;AAAA,EACjE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,aACC,iCACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA;AAAA,UAEC;AAAA,YACC;AAAA,UACD;AAAA;AAAA,QAED,cAAY;AAAA,QAEV,aAAI,oCAAqC;AAAA;AAAA,IAC5C;AAAA,IACA,oBAAC,QAAG;AAAA,IACF,GAAI,4BAA6B;AAAA,KACpC;AAAA,EAED,WAAW,CAAE,SAAU,MAAM,eAAe;AAAA,EAC5C,QAAQ,CAAE,EAAE,KAAK,MAAO,MAAM,YAAY;AAAA,EAC1C,MAAM;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,EACP;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,mBAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/alt_text/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { Link } from '@wordpress/ui';\nimport type { Field } from '@wordpress/dataviews';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\n\nconst altTextField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'alt_text',\n\ttype: 'text',\n\tlabel: __( 'Alt text' ),\n\tdescription: (\n\t\t<>\n\t\t\t<Link\n\t\t\t\thref={\n\t\t\t\t\t// translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.\n\t\t\t\t\t__(\n\t\t\t\t\t\t'https://www.w3.org/WAI/tutorials/images/decision-tree/'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\topenInNewTab\n\t\t\t>\n\t\t\t\t{ __( 'Describe the purpose of the image.' ) }\n\t\t\t</Link>\n\t\t\t<br />\n\t\t\t{ __( 'Leave empty if decorative.' ) }\n\t\t</>\n\t),\n\tisVisible: ( item ) => item?.media_type === 'image',\n\trender: ( { item } ) => item?.alt_text || '-',\n\tEdit: {\n\t\tcontrol: 'textarea',\n\t\trows: 2,\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default altTextField;\n"],"mappings":";;;;AAKA,MAAM,eAA4D;CACjE,IAAI;CACJ,MAAM;CACN,OAAO,GAAI,UAAW;CACtB,aACC,qBAAA,UAAA,EAAA,UAAA;EACC,oBAAC,MAAD;GACC,MAEC,GACC,wDACD;GAED,cAAA;GAEE,UAAA,GAAI,oCAAqC;EACtC,CAAA;EACN,oBAAC,MAAD,CAAK,CAAA;EACH,GAAI,4BAA6B;CAClC,EAAA,CAAA;CAEH,YAAa,SAAU,MAAM,eAAe;CAC5C,SAAU,EAAE,WAAY,MAAM,YAAY;CAC1C,MAAM;EACL,SAAS;EACT,MAAM;CACP;CACA,eAAe;CACf,UAAU;AACX"}
@@ -1,8 +1,4 @@
1
- // packages/media-fields/src/attached_to/edit.tsx
2
- import {
3
- __experimentalFetchLinkSuggestions as fetchLinkSuggestions,
4
- store as coreStore
5
- } from "@wordpress/core-data";
1
+ import { __experimentalFetchLinkSuggestions, store } from "@wordpress/core-data";
6
2
  import { ComboboxControl } from "@wordpress/components";
7
3
  import { __ } from "@wordpress/i18n";
8
4
  import { useState } from "@wordpress/element";
@@ -10,109 +6,91 @@ import { useDebounce, useEvent } from "@wordpress/compose";
10
6
  import { useSelect } from "@wordpress/data";
11
7
  import { getRenderedContent } from "../utils/get-rendered-content.mjs";
12
8
  import { jsx } from "react/jsx-runtime";
13
- function MediaAttachedToEdit({
14
- data,
15
- onChange
16
- }) {
17
- const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
18
- {
19
- label: getRenderedContent(
20
- data._embedded?.["wp:attached-to"]?.[0]?.title
21
- ),
22
- value: data.post.toString()
23
- }
24
- ] : [];
25
- const [options, setOptions] = useState(defaultPost);
26
- const [searchResults, setSearchResults] = useState(
27
- []
28
- );
29
- const [isLoading, setIsLoading] = useState(false);
30
- const [value, setValue] = useState(
31
- data?.post?.toString() ?? null
32
- );
33
- const postTypes = useSelect(
34
- (select) => select(coreStore).getPostTypes(),
35
- []
36
- );
37
- const handleDetach = () => {
38
- onChange({
39
- post: 0,
40
- _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
41
- });
42
- setValue(null);
43
- };
44
- const onValueChange = async (filterValue) => {
45
- setIsLoading(true);
46
- const results = await fetchLinkSuggestions(
47
- filterValue,
48
- /*
49
- * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
50
- * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
51
- */
52
- { type: "post", isInitialSuggestions: true },
53
- {}
54
- );
55
- setSearchResults(results);
56
- const suggestions = results.map((result) => {
57
- return {
58
- label: result.title,
59
- value: result.id.toString()
60
- };
61
- });
62
- const includeCurrent = !filterValue && suggestions.findIndex((s) => s.value === value) === -1;
63
- setOptions(suggestions.concat(includeCurrent ? defaultPost : []));
64
- setIsLoading(false);
65
- };
66
- const debouncedValueChange = useDebounce(useEvent(onValueChange), 300);
67
- const handleSelectOption = (selectedPostId) => {
68
- if (!selectedPostId) {
69
- handleDetach();
70
- return;
71
- }
72
- setValue(selectedPostId);
73
- if (selectedPostId) {
74
- const selectedPost = searchResults.find(
75
- (result) => result.id === Number(selectedPostId)
76
- );
77
- if (selectedPost && postTypes) {
78
- const postType = postTypes.find(
79
- (_postType) => _postType.slug === selectedPost?.type
80
- );
81
- const attachedTo = {
82
- ...postType && { type: postType.slug },
83
- id: Number(selectedPostId),
84
- title: {
85
- raw: selectedPost.title,
86
- rendered: selectedPost.title
87
- }
88
- };
89
- onChange({
90
- post: Number(selectedPostId),
91
- _embedded: {
92
- ...data?._embedded,
93
- "wp:attached-to": [attachedTo]
94
- }
95
- });
96
- }
97
- }
98
- };
99
- return /* @__PURE__ */ jsx(
100
- ComboboxControl,
101
- {
102
- className: "dataviews-media-field__attached-to",
103
- isLoading,
104
- label: __("Attached to"),
105
- help: __("Attach this file to a single post or page."),
106
- value,
107
- options,
108
- onFilterValueChange: (filterValue) => debouncedValueChange(filterValue),
109
- onChange: handleSelectOption,
110
- hideLabelFromVision: true,
111
- expandOnFocus: false
112
- }
113
- );
9
+ // packages/media-fields/src/attached_to/edit.tsx
10
+ function MediaAttachedToEdit({ data, onChange }) {
11
+ const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [{
12
+ label: getRenderedContent(data._embedded?.["wp:attached-to"]?.[0]?.title),
13
+ value: data.post.toString()
14
+ }] : [];
15
+ const [options, setOptions] = useState(defaultPost);
16
+ const [searchResults, setSearchResults] = useState([]);
17
+ const [isLoading, setIsLoading] = useState(false);
18
+ const [value, setValue] = useState(data?.post?.toString() ?? null);
19
+ const postTypes = useSelect((select) => select(store).getPostTypes(), []);
20
+ const handleDetach = () => {
21
+ onChange({
22
+ post: 0,
23
+ _embedded: {
24
+ ...data?._embedded,
25
+ "wp:attached-to": void 0
26
+ }
27
+ });
28
+ setValue(null);
29
+ };
30
+ const onValueChange = async (filterValue) => {
31
+ setIsLoading(true);
32
+ const results = await __experimentalFetchLinkSuggestions(filterValue, {
33
+ type: "post",
34
+ isInitialSuggestions: true
35
+ }, {});
36
+ setSearchResults(results);
37
+ const suggestions = results.map((result) => {
38
+ return {
39
+ label: result.title,
40
+ value: result.id.toString()
41
+ };
42
+ });
43
+ const includeCurrent = !filterValue && suggestions.findIndex((s) => s.value === value) === -1;
44
+ setOptions(suggestions.concat(includeCurrent ? defaultPost : []));
45
+ setIsLoading(false);
46
+ };
47
+ const debouncedValueChange = useDebounce(useEvent(onValueChange), 300);
48
+ /**
49
+ * Handle selection.
50
+ *
51
+ * @param {Object} selectedPostId The selected post id.
52
+ */
53
+ const handleSelectOption = (selectedPostId) => {
54
+ if (!selectedPostId) {
55
+ handleDetach();
56
+ return;
57
+ }
58
+ setValue(selectedPostId);
59
+ if (selectedPostId) {
60
+ const selectedPost = searchResults.find((result) => result.id === Number(selectedPostId));
61
+ if (selectedPost && postTypes) {
62
+ const postType = postTypes.find((_postType) => _postType.slug === selectedPost?.type);
63
+ const attachedTo = {
64
+ ...postType && { type: postType.slug },
65
+ id: Number(selectedPostId),
66
+ title: {
67
+ raw: selectedPost.title,
68
+ rendered: selectedPost.title
69
+ }
70
+ };
71
+ onChange({
72
+ post: Number(selectedPostId),
73
+ _embedded: {
74
+ ...data?._embedded,
75
+ "wp:attached-to": [attachedTo]
76
+ }
77
+ });
78
+ }
79
+ }
80
+ };
81
+ return /* @__PURE__ */ jsx(ComboboxControl, {
82
+ className: "dataviews-media-field__attached-to",
83
+ isLoading,
84
+ label: __("Attached to"),
85
+ help: __("Attach this file to a single post or page."),
86
+ value,
87
+ options,
88
+ onFilterValueChange: (filterValue) => debouncedValueChange(filterValue),
89
+ onChange: handleSelectOption,
90
+ hideLabelFromVision: true,
91
+ expandOnFocus: false
92
+ });
114
93
  }
115
- export {
116
- MediaAttachedToEdit as default
117
- };
118
- //# sourceMappingURL=edit.mjs.map
94
+ export { MediaAttachedToEdit as default };
95
+
96
+ //# sourceMappingURL=edit.mjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/attached_to/edit.tsx"],
4
- "sourcesContent": ["import {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { ComboboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDebounce, useEvent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\nexport default function MediaAttachedToEdit( {\n\tdata,\n\tonChange,\n}: DataFormControlProps< MediaItem > ) {\n\tconst defaultPost =\n\t\t!! data.post && !! data?._embedded?.[ 'wp:attached-to' ]?.[ 0 ]\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: getRenderedContent(\n\t\t\t\t\t\t\tdata._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue: data.post.toString(),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\tconst [ options, setOptions ] =\n\t\tuseState< { label: string; value: string }[] >( defaultPost );\n\tconst [ searchResults, setSearchResults ] = useState< SearchResult[] >(\n\t\t[]\n\t);\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ value, setValue ] = useState< string | null >(\n\t\tdata?.post?.toString() ?? null\n\t);\n\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes(),\n\t\t[]\n\t);\n\tconst handleDetach = () => {\n\t\tonChange( {\n\t\t\tpost: 0,\n\t\t\t_embedded: { ...data?._embedded, 'wp:attached-to': undefined },\n\t\t} );\n\t\tsetValue( null );\n\t};\n\n\tconst onValueChange = async ( filterValue: string ) => {\n\t\tsetIsLoading( true );\n\t\tconst results = await fetchLinkSuggestions(\n\t\t\tfilterValue,\n\t\t\t/*\n\t\t\t * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.\n\t\t\t * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.\n\t\t\t */\n\t\t\t{ type: 'post', isInitialSuggestions: true },\n\t\t\t{}\n\t\t);\n\t\tsetSearchResults( results );\n\t\tconst suggestions = results.map( ( result ) => {\n\t\t\treturn {\n\t\t\t\tlabel: result.title,\n\t\t\t\tvalue: result.id.toString(),\n\t\t\t};\n\t\t} );\n\t\tconst includeCurrent =\n\t\t\t! filterValue &&\n\t\t\tsuggestions.findIndex( ( s ) => s.value === value ) === -1;\n\t\tsetOptions( suggestions.concat( includeCurrent ? defaultPost : [] ) );\n\t\tsetIsLoading( false );\n\t};\n\n\t// `onValueChange` closes over state, so it's wrapped in `useEvent` to give\n\t// `useDebounce` a stable function. Debouncing an inline function instead\n\t// rebuilds the timer on every render, so nothing is debounced and each\n\t// keystroke fires its own request.\n\tconst debouncedValueChange = useDebounce( useEvent( onValueChange ), 300 );\n\n\t/**\n\t * Handle selection.\n\t *\n\t * @param {Object} selectedPostId The selected post id.\n\t */\n\tconst handleSelectOption = ( selectedPostId: string | null ) => {\n\t\tif ( ! selectedPostId ) {\n\t\t\thandleDetach();\n\t\t\treturn;\n\t\t}\n\t\tsetValue( selectedPostId );\n\t\tif ( selectedPostId ) {\n\t\t\tconst selectedPost = searchResults.find(\n\t\t\t\t( result ) => result.id === Number( selectedPostId )\n\t\t\t);\n\t\t\t// Although unlikely, it's technically possible for selectedPost to not be found.\n\t\t\t// E.g. if the user selects an option just as new search results are loaded.\n\t\t\t// TODO: Add error handling for when selectedPost is not found.\n\t\t\tif ( selectedPost && postTypes ) {\n\t\t\t\tconst postType = postTypes.find(\n\t\t\t\t\t( _postType: { slug: string } ) =>\n\t\t\t\t\t\t_postType.slug === selectedPost?.type\n\t\t\t\t);\n\n\t\t\t\tconst attachedTo = {\n\t\t\t\t\t...( postType && { type: postType.slug } ),\n\t\t\t\t\tid: Number( selectedPostId ),\n\t\t\t\t\ttitle: {\n\t\t\t\t\t\traw: selectedPost.title,\n\t\t\t\t\t\trendered: selectedPost.title,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tonChange( {\n\t\t\t\t\tpost: Number( selectedPostId ),\n\t\t\t\t\t_embedded: {\n\t\t\t\t\t\t...data?._embedded,\n\t\t\t\t\t\t'wp:attached-to': [ attachedTo ],\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\tclassName=\"dataviews-media-field__attached-to\"\n\t\t\tisLoading={ isLoading }\n\t\t\tlabel={ __( 'Attached to' ) }\n\t\t\thelp={ __( 'Attach this file to a single post or page.' ) }\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonFilterValueChange={ ( filterValue: unknown ) =>\n\t\t\t\tdebouncedValueChange( filterValue as string )\n\t\t\t}\n\t\t\tonChange={ handleSelectOption }\n\t\t\thideLabelFromVision\n\t\t\t// Opening the panel shouldn't imply the user has decided to change\n\t\t\t// the attachment, so wait for them to search before showing the list.\n\t\t\texpandOnFocus={ false }\n\t\t/>\n\t);\n}\n"],
5
- "mappings": "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",
6
- "names": []
7
- }
1
+ {"version":3,"file":"edit.mjs","names":["coreStore","fetchLinkSuggestions"],"sources":["../../src/attached_to/edit.tsx"],"sourcesContent":["import {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { ComboboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDebounce, useEvent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\nexport default function MediaAttachedToEdit( {\n\tdata,\n\tonChange,\n}: DataFormControlProps< MediaItem > ) {\n\tconst defaultPost =\n\t\t!! data.post && !! data?._embedded?.[ 'wp:attached-to' ]?.[ 0 ]\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: getRenderedContent(\n\t\t\t\t\t\t\tdata._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue: data.post.toString(),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\tconst [ options, setOptions ] =\n\t\tuseState< { label: string; value: string }[] >( defaultPost );\n\tconst [ searchResults, setSearchResults ] = useState< SearchResult[] >(\n\t\t[]\n\t);\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ value, setValue ] = useState< string | null >(\n\t\tdata?.post?.toString() ?? null\n\t);\n\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes(),\n\t\t[]\n\t);\n\tconst handleDetach = () => {\n\t\tonChange( {\n\t\t\tpost: 0,\n\t\t\t_embedded: { ...data?._embedded, 'wp:attached-to': undefined },\n\t\t} );\n\t\tsetValue( null );\n\t};\n\n\tconst onValueChange = async ( filterValue: string ) => {\n\t\tsetIsLoading( true );\n\t\tconst results = await fetchLinkSuggestions(\n\t\t\tfilterValue,\n\t\t\t/*\n\t\t\t * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.\n\t\t\t * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.\n\t\t\t */\n\t\t\t{ type: 'post', isInitialSuggestions: true },\n\t\t\t{}\n\t\t);\n\t\tsetSearchResults( results );\n\t\tconst suggestions = results.map( ( result ) => {\n\t\t\treturn {\n\t\t\t\tlabel: result.title,\n\t\t\t\tvalue: result.id.toString(),\n\t\t\t};\n\t\t} );\n\t\tconst includeCurrent =\n\t\t\t! filterValue &&\n\t\t\tsuggestions.findIndex( ( s ) => s.value === value ) === -1;\n\t\tsetOptions( suggestions.concat( includeCurrent ? defaultPost : [] ) );\n\t\tsetIsLoading( false );\n\t};\n\n\t// `onValueChange` closes over state, so it's wrapped in `useEvent` to give\n\t// `useDebounce` a stable function. Debouncing an inline function instead\n\t// rebuilds the timer on every render, so nothing is debounced and each\n\t// keystroke fires its own request.\n\tconst debouncedValueChange = useDebounce( useEvent( onValueChange ), 300 );\n\n\t/**\n\t * Handle selection.\n\t *\n\t * @param {Object} selectedPostId The selected post id.\n\t */\n\tconst handleSelectOption = ( selectedPostId: string | null ) => {\n\t\tif ( ! selectedPostId ) {\n\t\t\thandleDetach();\n\t\t\treturn;\n\t\t}\n\t\tsetValue( selectedPostId );\n\t\tif ( selectedPostId ) {\n\t\t\tconst selectedPost = searchResults.find(\n\t\t\t\t( result ) => result.id === Number( selectedPostId )\n\t\t\t);\n\t\t\t// Although unlikely, it's technically possible for selectedPost to not be found.\n\t\t\t// E.g. if the user selects an option just as new search results are loaded.\n\t\t\t// TODO: Add error handling for when selectedPost is not found.\n\t\t\tif ( selectedPost && postTypes ) {\n\t\t\t\tconst postType = postTypes.find(\n\t\t\t\t\t( _postType: { slug: string } ) =>\n\t\t\t\t\t\t_postType.slug === selectedPost?.type\n\t\t\t\t);\n\n\t\t\t\tconst attachedTo = {\n\t\t\t\t\t...( postType && { type: postType.slug } ),\n\t\t\t\t\tid: Number( selectedPostId ),\n\t\t\t\t\ttitle: {\n\t\t\t\t\t\traw: selectedPost.title,\n\t\t\t\t\t\trendered: selectedPost.title,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tonChange( {\n\t\t\t\t\tpost: Number( selectedPostId ),\n\t\t\t\t\t_embedded: {\n\t\t\t\t\t\t...data?._embedded,\n\t\t\t\t\t\t'wp:attached-to': [ attachedTo ],\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\tclassName=\"dataviews-media-field__attached-to\"\n\t\t\tisLoading={ isLoading }\n\t\t\tlabel={ __( 'Attached to' ) }\n\t\t\thelp={ __( 'Attach this file to a single post or page.' ) }\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonFilterValueChange={ ( filterValue: unknown ) =>\n\t\t\t\tdebouncedValueChange( filterValue as string )\n\t\t\t}\n\t\t\tonChange={ handleSelectOption }\n\t\t\thideLabelFromVision\n\t\t\t// Opening the panel shouldn't imply the user has decided to change\n\t\t\t// the attachment, so wait for them to search before showing the list.\n\t\t\texpandOnFocus={ false }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;AAoCA,SAAwB,oBAAqB,EAC5C,MACA,YACsC;CACtC,MAAM,cACL,CAAC,CAAE,KAAK,QAAQ,CAAC,CAAE,MAAM,YAAa,iBAAkB,GAAI,KACzD,CACA;EACC,OAAO,mBACN,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE,KAC9C;EACA,OAAO,KAAK,KAAK,SAAS;CAC3B,CACD,IACC,CAAC;CACL,MAAM,CAAE,SAAS,cAChB,SAAgD,WAAY;CAC7D,MAAM,CAAE,eAAe,oBAAqB,SAC3C,CAAC,CACF;CACA,MAAM,CAAE,WAAW,gBAAiB,SAAU,KAAM;CACpD,MAAM,CAAE,OAAO,YAAa,SAC3B,MAAM,MAAM,SAAS,KAAK,IAC3B;CAEA,MAAM,YAAY,WACf,WAAY,OAAQA,KAAU,CAAC,CAAC,aAAa,GAC/C,CAAC,CACF;CACA,MAAM,qBAAqB;EAC1B,SAAU;GACT,MAAM;GACN,WAAW;IAAE,GAAG,MAAM;IAAW,kBAAkB,KAAA;GAAU;EAC9D,CAAE;EACF,SAAU,IAAK;CAChB;CAEA,MAAM,gBAAgB,OAAQ,gBAAyB;EACtD,aAAc,IAAK;EACnB,MAAM,UAAU,MAAMC,mCACrB,aAKA;GAAE,MAAM;GAAQ,sBAAsB;EAAK,GAC3C,CAAC,CACF;EACA,iBAAkB,OAAQ;EAC1B,MAAM,cAAc,QAAQ,KAAO,WAAY;GAC9C,OAAO;IACN,OAAO,OAAO;IACd,OAAO,OAAO,GAAG,SAAS;GAC3B;EACD,CAAE;EACF,MAAM,iBACL,CAAE,eACF,YAAY,WAAa,MAAO,EAAE,UAAU,KAAM,MAAM;EACzD,WAAY,YAAY,OAAQ,iBAAiB,cAAc,CAAC,CAAE,CAAE;EACpE,aAAc,KAAM;CACrB;CAMA,MAAM,uBAAuB,YAAa,SAAU,aAAc,GAAG,GAAI;;;;;;CAOzE,MAAM,sBAAuB,mBAAmC;EAC/D,IAAK,CAAE,gBAAiB;GACvB,aAAa;GACb;EACD;EACA,SAAU,cAAe;EACzB,IAAK,gBAAiB;GACrB,MAAM,eAAe,cAAc,MAChC,WAAY,OAAO,OAAO,OAAQ,cAAe,CACpD;GAIA,IAAK,gBAAgB,WAAY;IAChC,MAAM,WAAW,UAAU,MACxB,cACD,UAAU,SAAS,cAAc,IACnC;IAEA,MAAM,aAAa;KAClB,GAAK,YAAY,EAAE,MAAM,SAAS,KAAK;KACvC,IAAI,OAAQ,cAAe;KAC3B,OAAO;MACN,KAAK,aAAa;MAClB,UAAU,aAAa;KACxB;IACD;IAEA,SAAU;KACT,MAAM,OAAQ,cAAe;KAC7B,WAAW;MACV,GAAG,MAAM;MACT,kBAAkB,CAAE,UAAW;KAChC;IACD,CAAE;GACH;EACD;CACD;CAEA,OACC,oBAAC,iBAAD;EACC,WAAU;EACE;EACZ,OAAQ,GAAI,aAAc;EAC1B,MAAO,GAAI,4CAA6C;EAChD;EACE;EACV,sBAAwB,gBACvB,qBAAsB,WAAsB;EAE7C,UAAW;EACX,qBAAA;EAGA,eAAgB;CAChB,CAAA;AAEH"}