@wordpress/media-fields 0.1.1-next.6deb34194.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 (117) hide show
  1. package/LICENSE.md +788 -0
  2. package/README.md +52 -0
  3. package/build/alt_text/index.js +51 -0
  4. package/build/alt_text/index.js.map +7 -0
  5. package/build/caption/index.js +52 -0
  6. package/build/caption/index.js.map +7 -0
  7. package/build/description/index.js +52 -0
  8. package/build/description/index.js.map +7 -0
  9. package/build/filename/index.js +50 -0
  10. package/build/filename/index.js.map +7 -0
  11. package/build/filename/view.js +43 -0
  12. package/build/filename/view.js.map +7 -0
  13. package/build/filesize/index.js +90 -0
  14. package/build/filesize/index.js.map +7 -0
  15. package/build/index.js +62 -0
  16. package/build/index.js.map +7 -0
  17. package/build/media_dimensions/index.js +45 -0
  18. package/build/media_dimensions/index.js.map +7 -0
  19. package/build/media_thumbnail/index.js +47 -0
  20. package/build/media_thumbnail/index.js.map +7 -0
  21. package/build/media_thumbnail/view.js +94 -0
  22. package/build/media_thumbnail/view.js.map +7 -0
  23. package/build/mime_type/index.js +38 -0
  24. package/build/mime_type/index.js.map +7 -0
  25. package/build/types.js +19 -0
  26. package/build/types.js.map +7 -0
  27. package/build/utils/get-media-type-from-mime-type.js +60 -0
  28. package/build/utils/get-media-type-from-mime-type.js.map +7 -0
  29. package/build/utils/get-raw-content.js +42 -0
  30. package/build/utils/get-raw-content.js.map +7 -0
  31. package/build/utils/get-rendered-content.js +42 -0
  32. package/build/utils/get-rendered-content.js.map +7 -0
  33. package/build-module/alt_text/index.js +30 -0
  34. package/build-module/alt_text/index.js.map +7 -0
  35. package/build-module/caption/index.js +31 -0
  36. package/build-module/caption/index.js.map +7 -0
  37. package/build-module/description/index.js +31 -0
  38. package/build-module/description/index.js.map +7 -0
  39. package/build-module/filename/index.js +19 -0
  40. package/build-module/filename/index.js.map +7 -0
  41. package/build-module/filename/view.js +25 -0
  42. package/build-module/filename/view.js.map +7 -0
  43. package/build-module/filesize/index.js +69 -0
  44. package/build-module/filesize/index.js.map +7 -0
  45. package/build-module/index.js +20 -0
  46. package/build-module/index.js.map +7 -0
  47. package/build-module/media_dimensions/index.js +24 -0
  48. package/build-module/media_dimensions/index.js.map +7 -0
  49. package/build-module/media_thumbnail/index.js +16 -0
  50. package/build-module/media_thumbnail/index.js.map +7 -0
  51. package/build-module/media_thumbnail/view.js +77 -0
  52. package/build-module/media_thumbnail/view.js.map +7 -0
  53. package/build-module/mime_type/index.js +17 -0
  54. package/build-module/mime_type/index.js.map +7 -0
  55. package/build-module/types.js +1 -0
  56. package/build-module/types.js.map +7 -0
  57. package/build-module/utils/get-media-type-from-mime-type.js +35 -0
  58. package/build-module/utils/get-media-type-from-mime-type.js.map +7 -0
  59. package/build-module/utils/get-raw-content.js +17 -0
  60. package/build-module/utils/get-raw-content.js.map +7 -0
  61. package/build-module/utils/get-rendered-content.js +17 -0
  62. package/build-module/utils/get-rendered-content.js.map +7 -0
  63. package/build-style/style-rtl.css +130 -0
  64. package/build-style/style.css +130 -0
  65. package/build-types/alt_text/index.d.ts +5 -0
  66. package/build-types/alt_text/index.d.ts.map +1 -0
  67. package/build-types/caption/index.d.ts +5 -0
  68. package/build-types/caption/index.d.ts.map +1 -0
  69. package/build-types/description/index.d.ts +5 -0
  70. package/build-types/description/index.d.ts.map +1 -0
  71. package/build-types/filename/index.d.ts +8 -0
  72. package/build-types/filename/index.d.ts.map +1 -0
  73. package/build-types/filename/view.d.ts +7 -0
  74. package/build-types/filename/view.d.ts.map +1 -0
  75. package/build-types/filesize/index.d.ts +8 -0
  76. package/build-types/filesize/index.d.ts.map +1 -0
  77. package/build-types/index.d.ts +10 -0
  78. package/build-types/index.d.ts.map +1 -0
  79. package/build-types/media_dimensions/index.d.ts +5 -0
  80. package/build-types/media_dimensions/index.d.ts.map +1 -0
  81. package/build-types/media_thumbnail/index.d.ts +8 -0
  82. package/build-types/media_thumbnail/index.d.ts.map +1 -0
  83. package/build-types/media_thumbnail/view.d.ts +4 -0
  84. package/build-types/media_thumbnail/view.d.ts.map +1 -0
  85. package/build-types/mime_type/index.d.ts +5 -0
  86. package/build-types/mime_type/index.d.ts.map +1 -0
  87. package/build-types/stories/index.story.d.ts +25 -0
  88. package/build-types/stories/index.story.d.ts.map +1 -0
  89. package/build-types/types.d.ts +18 -0
  90. package/build-types/types.d.ts.map +1 -0
  91. package/build-types/utils/get-media-type-from-mime-type.d.ts +18 -0
  92. package/build-types/utils/get-media-type-from-mime-type.d.ts.map +1 -0
  93. package/build-types/utils/get-raw-content.d.ts +17 -0
  94. package/build-types/utils/get-raw-content.d.ts.map +1 -0
  95. package/build-types/utils/get-rendered-content.d.ts +17 -0
  96. package/build-types/utils/get-rendered-content.d.ts.map +1 -0
  97. package/package.json +61 -0
  98. package/src/alt_text/index.tsx +30 -0
  99. package/src/caption/index.tsx +35 -0
  100. package/src/description/index.tsx +37 -0
  101. package/src/filename/index.ts +26 -0
  102. package/src/filename/view.tsx +39 -0
  103. package/src/filesize/index.tsx +96 -0
  104. package/src/index.ts +15 -0
  105. package/src/media_dimensions/index.ts +29 -0
  106. package/src/media_thumbnail/index.tsx +22 -0
  107. package/src/media_thumbnail/style.scss +49 -0
  108. package/src/media_thumbnail/view.tsx +104 -0
  109. package/src/mime_type/index.ts +19 -0
  110. package/src/stories/index.story.tsx +290 -0
  111. package/src/style.scss +1 -0
  112. package/src/types.ts +24 -0
  113. package/src/utils/get-media-type-from-mime-type.ts +54 -0
  114. package/src/utils/get-raw-content.ts +32 -0
  115. package/src/utils/get-rendered-content.ts +32 -0
  116. package/tsconfig.json +31 -0
  117. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,7 @@
1
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
2
+ /**
3
+ * Internal dependencies
4
+ */
5
+ import type { MediaItem } from '../types';
6
+ export default function FileNameView({ item, }: DataViewRenderFieldProps<MediaItem>): "" | import("react").JSX.Element;
7
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/filename/view.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAM1C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,EACrC,IAAI,GACJ,EAAE,wBAAwB,CAAE,SAAS,CAAE,oCAiBvC"}
@@ -0,0 +1,8 @@
1
+ import type { Field } from '@wordpress/dataviews';
2
+ /**
3
+ * Internal dependencies
4
+ */
5
+ import type { MediaItem } from '../types';
6
+ declare const filesizeField: Partial<Field<MediaItem>>;
7
+ export default filesizeField;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filesize/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAsE1C,QAAA,MAAM,aAAa,EAAE,OAAO,CAAE,KAAK,CAAE,SAAS,CAAE,CAc/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { default as altTextField } from './alt_text';
2
+ export { default as captionField } from './caption';
3
+ export { default as descriptionField } from './description';
4
+ export { default as filenameField } from './filename';
5
+ export { default as filesizeField } from './filesize';
6
+ export { default as mediaDimensionsField } from './media_dimensions';
7
+ export { default as mediaThumbnailField } from './media_thumbnail';
8
+ export { default as mimeTypeField } from './mime_type';
9
+ export type { MediaItem, MediaKind, MediaType, MediaItemUpdatable, } from './types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAEvD,YAAY,EACX,SAAS,EACT,SAAS,EACT,SAAS,EACT,kBAAkB,GAClB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Attachment, Updatable } from '@wordpress/core-data';
2
+ import type { Field } from '@wordpress/dataviews';
3
+ declare const mediaDimensionsField: Partial<Field<Updatable<Attachment>>>;
4
+ export default mediaDimensionsField;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/media_dimensions/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,QAAA,MAAM,oBAAoB,EAAE,OAAO,CAAE,KAAK,CAAE,SAAS,CAAE,UAAU,CAAE,CAAE,CAmBpE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Field } from '@wordpress/dataviews';
2
+ /**
3
+ * Internal dependencies
4
+ */
5
+ import type { MediaItem } from '../types';
6
+ declare const mediaThumbnailField: Partial<Field<MediaItem>>;
7
+ export default mediaThumbnailField;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/media_thumbnail/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAG1C,QAAA,MAAM,mBAAmB,EAAE,OAAO,CAAE,KAAK,CAAE,SAAS,CAAE,CAOrD,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
2
+ import type { MediaItem } from '../types';
3
+ export default function MediaThumbnailView({ item, config, }: DataViewRenderFieldProps<MediaItem>): import("react").JSX.Element | null;
4
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/media_thumbnail/view.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAKrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,EAC3C,IAAI,EACJ,MAAM,GACN,EAAE,wBAAwB,CAAE,SAAS,CAAE,sCAiFvC"}
@@ -0,0 +1,5 @@
1
+ import type { Attachment, Updatable } from '@wordpress/core-data';
2
+ import type { Field } from '@wordpress/dataviews';
3
+ declare const mimeTypeField: Partial<Field<Updatable<Attachment>>>;
4
+ export default mimeTypeField;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mime_type/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAElD,QAAA,MAAM,aAAa,EAAE,OAAO,CAAE,KAAK,CAAE,SAAS,CAAE,UAAU,CAAE,CAAE,CAS7D,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { DataForm } from '@wordpress/dataviews';
2
+ declare const _default: {
3
+ title: string;
4
+ component: typeof DataForm;
5
+ };
6
+ export default _default;
7
+ export declare const DataFormsPreview: {
8
+ render: ({ type }: {
9
+ type: "regular" | "panel";
10
+ }) => import("react").JSX.Element;
11
+ argTypes: {
12
+ type: {
13
+ control: {
14
+ type: string;
15
+ };
16
+ description: string;
17
+ options: string[];
18
+ };
19
+ };
20
+ args: {
21
+ type: string;
22
+ };
23
+ };
24
+ export declare const DataViewsPreview: () => import("react").JSX.Element;
25
+ //# sourceMappingURL=index.story.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.story.d.ts","sourceRoot":"","sources":["../../src/stories/index.story.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAwB,MAAM,sBAAsB,CAAC;;;;;AAkBtE,wBAGE;AA8MF,eAAO,MAAM,gBAAgB;uBA1CU;QAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAA;KAAE;;;;;;;;;;;;;CAsDnE,CAAC;AAEF,eAAO,MAAM,gBAAgB,mCA4C5B,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Attachment, Updatable, Post } from '@wordpress/core-data';
5
+ export type MediaKind = 'image' | 'video' | 'audio' | 'application';
6
+ export interface MediaType {
7
+ type: MediaKind;
8
+ label: string;
9
+ icon: JSX.Element;
10
+ }
11
+ export interface MediaItem extends Attachment<'edit'> {
12
+ featured_media: number;
13
+ _embedded?: {
14
+ 'wp:attached-to'?: Post[] | Partial<Post>[];
15
+ };
16
+ }
17
+ export type MediaItemUpdatable = Updatable<Attachment>;
18
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAExE,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;AAEpE,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC;CAClB;AAGD,MAAM,WAAW,SAAU,SAAQ,UAAU,CAAE,MAAM,CAAE;IAEtD,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE;QAEX,gBAAgB,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,CAAE,IAAI,CAAE,EAAE,CAAC;KAC9C,CAAC;CACF;AAED,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAE,UAAU,CAAE,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import type { MediaType } from '../types';
5
+ /**
6
+ * Get the media type from a mime type, including an icon.
7
+ * TODO - media types should be formalized somewhere.
8
+ *
9
+ * References:
10
+ * https://developer.wordpress.org/reference/functions/wp_mime_type_icon/
11
+ * https://developer.wordpress.org/reference/hooks/mime_types/
12
+ * https://developer.wordpress.org/reference/functions/wp_get_mime_types/
13
+ *
14
+ * @param mimeType - The mime type to get the media type from.
15
+ * @return The media type.
16
+ */
17
+ export declare function getMediaTypeFromMimeType(mimeType: string): MediaType;
18
+ //# sourceMappingURL=get-media-type-from-mime-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-media-type-from-mime-type.d.ts","sourceRoot":"","sources":["../../src/utils/get-media-type-from-mime-type.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CAAE,QAAQ,EAAE,MAAM,GAAI,SAAS,CA8BtE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utility function to extract raw content from either a string or an object
3
+ * containing raw and rendered properties.
4
+ *
5
+ * This handles the inconsistency in WordPress REST API responses where
6
+ * some fields like caption and description can be either:
7
+ * - A simple string
8
+ * - An object with { raw: string, rendered: string }
9
+ *
10
+ * @param content - The content to extract raw value from
11
+ * @return The raw content string, or empty string if content is falsy
12
+ */
13
+ export declare function getRawContent(content: string | {
14
+ raw: string;
15
+ rendered: string;
16
+ } | undefined | null): string;
17
+ //# sourceMappingURL=get-raw-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-raw-content.d.ts","sourceRoot":"","sources":["../../src/utils/get-raw-content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAAG,IAAI,GACpE,MAAM,CAiBR"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Utility function to extract rendered content from either a string or an object
3
+ * containing raw and rendered properties.
4
+ *
5
+ * This handles the inconsistency in WordPress REST API responses where
6
+ * some fields like caption and description can be either:
7
+ * - A simple string
8
+ * - An object with { raw: string, rendered: string }
9
+ *
10
+ * @param content - The content to extract raw value from
11
+ * @return The rendered content string, falling back to raw or empty string if content is falsy
12
+ */
13
+ export declare function getRenderedContent(content: string | {
14
+ raw: string;
15
+ rendered: string;
16
+ } | undefined | null): string;
17
+ //# sourceMappingURL=get-rendered-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-rendered-content.d.ts","sourceRoot":"","sources":["../../src/utils/get-rendered-content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GAAG,IAAI,GACpE,MAAM,CAiBR"}
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@wordpress/media-fields",
3
+ "version": "0.1.1-next.6deb34194.0",
4
+ "description": "Reusable field definitions for displaying and editing media attachment properties in WordPress.",
5
+ "author": "The WordPress Contributors",
6
+ "license": "GPL-2.0-or-later",
7
+ "keywords": [
8
+ "wordpress",
9
+ "gutenberg",
10
+ "media",
11
+ "fields",
12
+ "dataviews"
13
+ ],
14
+ "homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/media-fields/README.md",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/WordPress/gutenberg.git",
18
+ "directory": "packages/media-fields"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/WordPress/gutenberg/issues"
22
+ },
23
+ "engines": {
24
+ "node": ">=18.12.0",
25
+ "npm": ">=8.19.2"
26
+ },
27
+ "main": "build/index.js",
28
+ "module": "build-module/index.js",
29
+ "exports": {
30
+ ".": {
31
+ "types": "./build-types/index.d.ts",
32
+ "import": "./build-module/index.js",
33
+ "require": "./build/index.js"
34
+ },
35
+ "./package.json": "./package.json"
36
+ },
37
+ "react-native": "src/index",
38
+ "types": "build-types",
39
+ "sideEffects": [
40
+ "build-style/**",
41
+ "src/**/*.scss"
42
+ ],
43
+ "dependencies": {
44
+ "@wordpress/components": "^31.0.1-next.6deb34194.0",
45
+ "@wordpress/core-data": "^7.36.1-next.6deb34194.0",
46
+ "@wordpress/data": "^10.36.1-next.6deb34194.0",
47
+ "@wordpress/dataviews": "^11.1.1-next.6deb34194.0",
48
+ "@wordpress/element": "^6.36.1-next.6deb34194.0",
49
+ "@wordpress/i18n": "^6.9.1-next.6deb34194.0",
50
+ "@wordpress/icons": "^11.3.1-next.6deb34194.0",
51
+ "@wordpress/primitives": "^4.36.1-next.6deb34194.0",
52
+ "@wordpress/url": "^4.36.1-next.6deb34194.0"
53
+ },
54
+ "peerDependencies": {
55
+ "react": "^18.0.0"
56
+ },
57
+ "publishConfig": {
58
+ "access": "public"
59
+ },
60
+ "gitHead": "457096e9e9b3896d2d4fe54fc19d7fb571ee9a44"
61
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { TextareaControl } from '@wordpress/components';
6
+ import type { Field } from '@wordpress/dataviews';
7
+ import type { Attachment, Updatable } from '@wordpress/core-data';
8
+
9
+ const altTextField: Partial< Field< Updatable< Attachment > > > = {
10
+ id: 'alt_text',
11
+ type: 'text',
12
+ label: __( 'Alt text' ),
13
+ isVisible: ( item ) => item?.media_type === 'image',
14
+ render: ( { item } ) => item?.alt_text || '-',
15
+ Edit: ( { field, onChange, data } ) => {
16
+ return (
17
+ <TextareaControl
18
+ label={ field.label }
19
+ value={ data.alt_text || '' }
20
+ onChange={ ( value ) => onChange( { alt_text: value } ) }
21
+ rows={ 2 }
22
+ __nextHasNoMarginBottom
23
+ />
24
+ );
25
+ },
26
+ enableSorting: false,
27
+ filterBy: false,
28
+ };
29
+
30
+ export default altTextField;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { TextareaControl } from '@wordpress/components';
6
+ import type { Attachment, Updatable } from '@wordpress/core-data';
7
+ import type { Field } from '@wordpress/dataviews';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { getRawContent } from '../utils/get-raw-content';
13
+
14
+ const captionField: Partial< Field< Updatable< Attachment > > > = {
15
+ id: 'caption',
16
+ type: 'text',
17
+ label: __( 'Caption' ),
18
+ getValue: ( { item } ) => getRawContent( item?.caption ),
19
+ render: ( { item } ) => getRawContent( item?.caption ) || '-',
20
+ Edit: ( { field, onChange, data } ) => {
21
+ return (
22
+ <TextareaControl
23
+ label={ field.label }
24
+ value={ getRawContent( data.caption ) || '' }
25
+ onChange={ ( value ) => onChange( { caption: value } ) }
26
+ rows={ 2 }
27
+ __nextHasNoMarginBottom
28
+ />
29
+ );
30
+ },
31
+ enableSorting: false,
32
+ filterBy: false,
33
+ };
34
+
35
+ export default captionField;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { TextareaControl } from '@wordpress/components';
6
+ import type { Attachment, Updatable } from '@wordpress/core-data';
7
+ import type { Field } from '@wordpress/dataviews';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import { getRawContent } from '../utils/get-raw-content';
13
+
14
+ const descriptionField: Partial< Field< Updatable< Attachment > > > = {
15
+ id: 'description',
16
+ type: 'text',
17
+ label: __( 'Description' ),
18
+ getValue: ( { item } ) => getRawContent( item?.description ),
19
+ render: ( { item } ) => (
20
+ <div>{ getRawContent( item?.description ) || '-' }</div>
21
+ ),
22
+ Edit: ( { field, onChange, data } ) => {
23
+ return (
24
+ <TextareaControl
25
+ label={ field.label }
26
+ value={ getRawContent( data.description ) || '' }
27
+ onChange={ ( value ) => onChange( { description: value } ) }
28
+ rows={ 5 }
29
+ __nextHasNoMarginBottom
30
+ />
31
+ );
32
+ },
33
+ enableSorting: false,
34
+ filterBy: false,
35
+ };
36
+
37
+ export default descriptionField;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import { getFilename } from '@wordpress/url';
6
+ import type { Field } from '@wordpress/dataviews';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { MediaItem } from '../types';
12
+ import FileNameView from './view';
13
+
14
+ const filenameField: Partial< Field< MediaItem > > = {
15
+ id: 'filename',
16
+ type: 'text',
17
+ label: __( 'File name' ),
18
+ getValue: ( { item }: { item: MediaItem } ) =>
19
+ getFilename( item?.source_url || '' ),
20
+ render: FileNameView,
21
+ enableSorting: false,
22
+ filterBy: false,
23
+ readOnly: true,
24
+ };
25
+
26
+ export default filenameField;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ Tooltip,
6
+ __experimentalTruncate as Truncate,
7
+ } from '@wordpress/components';
8
+ import { useMemo } from '@wordpress/element';
9
+ import { getFilename } from '@wordpress/url';
10
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import type { MediaItem } from '../types';
15
+
16
+ // Hard-coded truncate length to match the available area in the media sidebar.
17
+ // Longer file names will be truncated and wrapped in a tooltip showing the full name.
18
+ const TRUNCATE_LENGTH = 15;
19
+
20
+ export default function FileNameView( {
21
+ item,
22
+ }: DataViewRenderFieldProps< MediaItem > ) {
23
+ const fileName = useMemo(
24
+ () => ( item?.source_url ? getFilename( item.source_url ) : null ),
25
+ [ item?.source_url ]
26
+ );
27
+
28
+ if ( ! fileName ) {
29
+ return '';
30
+ }
31
+
32
+ return fileName.length > TRUNCATE_LENGTH ? (
33
+ <Tooltip text={ fileName }>
34
+ <Truncate>{ fileName }</Truncate>
35
+ </Tooltip>
36
+ ) : (
37
+ <>{ fileName }</>
38
+ );
39
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __, sprintf, _x } from '@wordpress/i18n';
5
+ import type { Field } from '@wordpress/dataviews';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { MediaItem } from '../types';
11
+
12
+ const KB_IN_BYTES = 1024;
13
+ const MB_IN_BYTES = 1024 * KB_IN_BYTES;
14
+ const GB_IN_BYTES = 1024 * MB_IN_BYTES;
15
+ const TB_IN_BYTES = 1024 * GB_IN_BYTES;
16
+ const PB_IN_BYTES = 1024 * TB_IN_BYTES;
17
+ const EB_IN_BYTES = 1024 * PB_IN_BYTES;
18
+ const ZB_IN_BYTES = 1024 * EB_IN_BYTES;
19
+ const YB_IN_BYTES = 1024 * ZB_IN_BYTES;
20
+
21
+ function getBytesString(
22
+ bytes: number,
23
+ unitSymbol: string,
24
+ decimals = 2
25
+ ): string {
26
+ return sprintf(
27
+ // translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).
28
+ _x( '%1$s %2$s', 'file size' ),
29
+ bytes.toLocaleString( undefined, {
30
+ minimumFractionDigits: 0,
31
+ maximumFractionDigits: decimals,
32
+ } ),
33
+ unitSymbol
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Converts bytes to a human-readable file size string with a specified number of decimal places.
39
+ *
40
+ * This logic is comparable to core's `size_format()` function.
41
+ *
42
+ * @param bytes The size in bytes.
43
+ * @param decimals The number of decimal places to include in the result.
44
+ * @return The human-readable file size string.
45
+ */
46
+ function formatFileSize( bytes: number, decimals = 2 ): string {
47
+ if ( bytes === 0 ) {
48
+ return getBytesString( 0, _x( 'B', 'unit symbol' ), decimals );
49
+ }
50
+ const quant = {
51
+ /* translators: Unit symbol for yottabyte. */
52
+ [ _x( 'YB', 'unit symbol' ) ]: YB_IN_BYTES,
53
+ /* translators: Unit symbol for zettabyte. */
54
+ [ _x( 'ZB', 'unit symbol' ) ]: ZB_IN_BYTES,
55
+ /* translators: Unit symbol for exabyte. */
56
+ [ _x( 'EB', 'unit symbol' ) ]: EB_IN_BYTES,
57
+ /* translators: Unit symbol for petabyte. */
58
+ [ _x( 'PB', 'unit symbol' ) ]: PB_IN_BYTES,
59
+ /* translators: Unit symbol for terabyte. */
60
+ [ _x( 'TB', 'unit symbol' ) ]: TB_IN_BYTES,
61
+ /* translators: Unit symbol for gigabyte. */
62
+ [ _x( 'GB', 'unit symbol' ) ]: GB_IN_BYTES,
63
+ /* translators: Unit symbol for megabyte. */
64
+ [ _x( 'MB', 'unit symbol' ) ]: MB_IN_BYTES,
65
+ /* translators: Unit symbol for kilobyte. */
66
+ [ _x( 'KB', 'unit symbol' ) ]: KB_IN_BYTES,
67
+ /* translators: Unit symbol for byte. */
68
+ [ _x( 'B', 'unit symbol' ) ]: 1,
69
+ };
70
+
71
+ for ( const [ unit, mag ] of Object.entries( quant ) ) {
72
+ if ( bytes >= mag ) {
73
+ return getBytesString( bytes / mag, unit, decimals );
74
+ }
75
+ }
76
+
77
+ return ''; // Fallback in case no unit matches, though this should not happen.
78
+ }
79
+
80
+ const filesizeField: Partial< Field< MediaItem > > = {
81
+ id: 'filesize',
82
+ type: 'text',
83
+ label: __( 'File size' ),
84
+ getValue: ( { item }: { item: MediaItem } ) =>
85
+ item?.media_details?.filesize
86
+ ? formatFileSize( item?.media_details?.filesize )
87
+ : '',
88
+ isVisible: ( item: MediaItem ) => {
89
+ return !! item?.media_details?.filesize;
90
+ },
91
+ enableSorting: false,
92
+ filterBy: false,
93
+ readOnly: true,
94
+ };
95
+
96
+ export default filesizeField;
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { default as altTextField } from './alt_text';
2
+ export { default as captionField } from './caption';
3
+ export { default as descriptionField } from './description';
4
+ export { default as filenameField } from './filename';
5
+ export { default as filesizeField } from './filesize';
6
+ export { default as mediaDimensionsField } from './media_dimensions';
7
+ export { default as mediaThumbnailField } from './media_thumbnail';
8
+ export { default as mimeTypeField } from './mime_type';
9
+
10
+ export type {
11
+ MediaItem,
12
+ MediaKind,
13
+ MediaType,
14
+ MediaItemUpdatable,
15
+ } from './types';
@@ -0,0 +1,29 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __, _x, sprintf } from '@wordpress/i18n';
5
+ import type { Attachment, Updatable } from '@wordpress/core-data';
6
+ import type { Field } from '@wordpress/dataviews';
7
+
8
+ const mediaDimensionsField: Partial< Field< Updatable< Attachment > > > = {
9
+ id: 'media_dimensions',
10
+ type: 'text',
11
+ label: __( 'Dimensions' ),
12
+ getValue: ( { item } ) =>
13
+ item?.media_details?.width && item?.media_details?.height
14
+ ? sprintf(
15
+ // translators: 1: Width. 2: Height.
16
+ _x( '%1$s × %2$s', 'image dimensions' ),
17
+ item?.media_details?.width?.toString(),
18
+ item?.media_details?.height?.toString()
19
+ )
20
+ : '',
21
+ isVisible: ( item ) => {
22
+ return !! ( item?.media_details?.width && item?.media_details?.height );
23
+ },
24
+ enableSorting: false,
25
+ filterBy: false,
26
+ readOnly: true,
27
+ };
28
+
29
+ export default mediaDimensionsField;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import type { Field } from '@wordpress/dataviews';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { MediaItem } from '../types';
11
+ import MediaThumbnailView from './view';
12
+
13
+ const mediaThumbnailField: Partial< Field< MediaItem > > = {
14
+ id: 'media_thumbnail',
15
+ type: 'media',
16
+ label: __( 'Thumbnail' ),
17
+ render: MediaThumbnailView,
18
+ enableSorting: false,
19
+ filterBy: false,
20
+ };
21
+
22
+ export default mediaThumbnailField;
@@ -0,0 +1,49 @@
1
+ @use "@wordpress/base-styles/mixins";
2
+ @use "@wordpress/base-styles/colors";
3
+ @use "@wordpress/base-styles/variables";
4
+
5
+ .dataviews-media-field__media-thumbnail {
6
+ display: flex;
7
+ align-items: center;
8
+ position: relative;
9
+ height: 100%;
10
+ }
11
+
12
+ .dataviews-media-field__media-thumbnail--image {
13
+ display: block;
14
+ width: 100%;
15
+ height: 100%;
16
+ object-fit: cover;
17
+ }
18
+
19
+ .dataviews-media-field__media-thumbnail__stack {
20
+ color: colors.$gray-700;
21
+ box-sizing: border-box;
22
+ width: 100%;
23
+ height: 100%;
24
+ }
25
+
26
+ .dataviews-media-field__media-thumbnail--icon {
27
+ color: colors.$gray-700;
28
+ fill: currentColor;
29
+ }
30
+
31
+ .dataviews-media-field__media-thumbnail__filename {
32
+ box-sizing: border-box;
33
+ text-align: center;
34
+ padding: 0 variables.$grid-unit-20;
35
+ width: 100%;
36
+ container-type: inline-size;
37
+ @include mixins.body-small();
38
+
39
+ &__truncate {
40
+ // Use a top margin instead of gap on the parent, as the text will not
41
+ // always be rendered. This ensures the icon is vertically centered in all contexts.
42
+ margin-top: variables.$grid-unit-05;
43
+
44
+ // Hide filename when previews are very small, as rendered in list views.
45
+ @container (max-width: 90px) {
46
+ display: none !important;
47
+ }
48
+ }
49
+ }