@wordpress/media-fields 0.24.0 → 0.26.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 (34) hide show
  1. package/build/alt_text/index.cjs +3 -1
  2. package/build/alt_text/index.cjs.map +1 -1
  3. package/build/attached_to/index.cjs +9 -7
  4. package/build/attached_to/index.cjs.map +1 -1
  5. package/build/attached_to/view.cjs.map +1 -1
  6. package/build/author/index.cjs +8 -6
  7. package/build/author/index.cjs.map +1 -1
  8. package/build/author/view.cjs +10 -9
  9. package/build/author/view.cjs.map +1 -1
  10. package/build/filename/index.cjs +8 -6
  11. package/build/filename/index.cjs.map +1 -1
  12. package/build/filesize/index.cjs +54 -13
  13. package/build/filesize/index.cjs.map +1 -1
  14. package/build/index.cjs +19 -17
  15. package/build/media_dimensions/index.cjs +6 -1
  16. package/build/media_dimensions/index.cjs.map +1 -1
  17. package/build/media_thumbnail/index.cjs +8 -6
  18. package/build/media_thumbnail/index.cjs.map +1 -1
  19. package/build/media_thumbnail/view.cjs +9 -7
  20. package/build/media_thumbnail/view.cjs.map +1 -1
  21. package/build-module/alt_text/index.mjs +3 -1
  22. package/build-module/alt_text/index.mjs.map +1 -1
  23. package/build-module/author/view.mjs +1 -2
  24. package/build-module/author/view.mjs.map +1 -1
  25. package/build-module/filesize/index.mjs +54 -13
  26. package/build-module/filesize/index.mjs.map +1 -1
  27. package/build-module/media_dimensions/index.mjs +6 -1
  28. package/build-module/media_dimensions/index.mjs.map +1 -1
  29. package/build-style/style-rtl.css +3 -3
  30. package/build-style/style.css +3 -3
  31. package/build-types/author/view.d.ts.map +1 -1
  32. package/package.json +14 -14
  33. package/src/author/view.tsx +1 -2
  34. package/src/stories/index.story.tsx +16 -28
@@ -13,7 +13,9 @@ const altTextField = {
13
13
  label: (0, _wordpress_i18n.__)("Alt text"),
14
14
  description: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
15
15
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Link, {
16
- href: (0, _wordpress_i18n.__)("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
16
+ href:
17
+ /** translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */
18
+ (0, _wordpress_i18n.__)("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
17
19
  openInNewTab: true,
18
20
  children: (0, _wordpress_i18n.__)("Describe the purpose of the image.")
19
21
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","Link"],"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,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,UAAW;CACtB,aACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,MAAD;GACC,OAAA,GAECD,gBAAAA,GAAAA,CACC,wDACD;GAED,cAAA;GAEEA,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,oCAAqC;EACtC,CAAA;EACN,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;GACHA,GAAAA,gBAAAA,GAAAA,CAAI,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
+ {"version":3,"file":"index.cjs","names":["__","Link"],"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,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,UAAW;CACtB,aACC,iBAAA,GAAA,kBAAA,KAAA,CAAA,kBAAA,UAAA,EAAA,UAAA;EACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,cAAAA,MAAD;GACC;;IAECD,GAAAA,gBAAAA,GAAAA,CACC,wDACD;GAED,cAAA;GAEEA,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,oCAAqC;EACtC,CAAA;EACN,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD,CAAK,CAAA;GACHA,GAAAA,gBAAAA,GAAAA,CAAI,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"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -26,8 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
28
  }) : target, mod));
27
29
  let _wordpress_i18n = require("@wordpress/i18n");
28
30
  let __view_tsx = require("./view.cjs");
29
- __view_tsx = __toESM(__view_tsx);
30
31
  let __edit_tsx = require("./edit.cjs");
32
+ __view_tsx = __toESM(__view_tsx);
31
33
  __edit_tsx = __toESM(__edit_tsx);
32
34
  // packages/media-fields/src/attached_to/index.tsx
33
35
  const attachedToField = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","MediaAttachedToEdit","MediaAttachedToView"],"sources":["../../src/attached_to/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport MediaAttachedToView from './view';\nimport MediaAttachedToEdit from './edit';\n\nconst attachedToField: Partial< Field< MediaItem > > = {\n\tid: 'attached_to',\n\ttype: 'text',\n\tlabel: __( 'Attached to' ),\n\tEdit: MediaAttachedToEdit,\n\trender: MediaAttachedToView,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default attachedToField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,kBAAiD;CACtD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,aAAc;CACzB,MAAMC,WAAAA;CACN,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["__","MediaAttachedToEdit","MediaAttachedToView"],"sources":["../../src/attached_to/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport MediaAttachedToView from './view';\nimport MediaAttachedToEdit from './edit';\n\nconst attachedToField: Partial< Field< MediaItem > > = {\n\tid: 'attached_to',\n\ttype: 'text',\n\tlabel: __( 'Attached to' ),\n\tEdit: MediaAttachedToEdit,\n\trender: MediaAttachedToView,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default attachedToField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,kBAAiD;CACtD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,aAAc;CACzB,MAAMC,WAAAA;CACN,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;AACX"}
@@ -1 +1 @@
1
- {"version":3,"file":"view.cjs","names":["useState","getRenderedContent","__"],"sources":["../../src/attached_to/view.tsx"],"sourcesContent":["import { useState, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport default function MediaAttachedToView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\t// Store the displayed title in state, as the embedded post may be loaded\n\t// asynchronously. This ensures that the title remains stable after it\n\t// is updated by the user, and while it is re-fetched from the server.\n\tconst [ attachedPostTitle, setAttachedPostTitle ] = useState<\n\t\tstring | null\n\t>( null );\n\n\tconst parentId = item.post;\n\tconst embeddedPostId = item._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.id;\n\tconst embeddedPostTitle =\n\t\titem._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title;\n\n\tuseEffect( () => {\n\t\tif ( !! parentId && parentId === embeddedPostId ) {\n\t\t\tsetAttachedPostTitle(\n\t\t\t\tgetRenderedContent( embeddedPostTitle ) || __( '(no title)' )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! parentId ) {\n\t\t\tsetAttachedPostTitle( __( '(Unattached)' ) );\n\t\t}\n\t}, [ parentId, embeddedPostId, embeddedPostTitle ] );\n\n\treturn <>{ attachedPostTitle }</>;\n}\n"],"mappings":";;;;;;;;;;AAMA,SAAwB,oBAAqB,EAC5C,QAC0C;CAI1C,MAAM,CAAE,mBAAmB,yBAAA,GAAyBA,mBAAAA,SAAAA,CAEjD,IAAK;CAER,MAAM,WAAW,KAAK;CACtB,MAAM,iBAAiB,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE;CACpE,MAAM,oBACL,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE;CAE9C,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,IAAK,CAAC,CAAE,YAAY,aAAa,gBAChC,sBAAA,GACCC,iCAAAA,mBAAAA,CAAoB,iBAAkB,MAAA,GAAKC,gBAAAA,GAAAA,CAAI,YAAa,CAC7D;EAGD,IAAK,CAAE,UACN,sBAAA,GAAsBA,gBAAAA,GAAAA,CAAI,cAAe,CAAE;CAE7C,GAAG;EAAE;EAAU;EAAgB;CAAkB,CAAE;CAEnD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAA,kBAAA,UAAA,EAAA,UAAI,kBAAqB,CAAA;AACjC"}
1
+ {"version":3,"file":"view.cjs","names":["useState","useEffect","getRenderedContent","__"],"sources":["../../src/attached_to/view.tsx"],"sourcesContent":["import { useState, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport default function MediaAttachedToView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\t// Store the displayed title in state, as the embedded post may be loaded\n\t// asynchronously. This ensures that the title remains stable after it\n\t// is updated by the user, and while it is re-fetched from the server.\n\tconst [ attachedPostTitle, setAttachedPostTitle ] = useState<\n\t\tstring | null\n\t>( null );\n\n\tconst parentId = item.post;\n\tconst embeddedPostId = item._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.id;\n\tconst embeddedPostTitle =\n\t\titem._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title;\n\n\tuseEffect( () => {\n\t\tif ( !! parentId && parentId === embeddedPostId ) {\n\t\t\tsetAttachedPostTitle(\n\t\t\t\tgetRenderedContent( embeddedPostTitle ) || __( '(no title)' )\n\t\t\t);\n\t\t}\n\n\t\tif ( ! parentId ) {\n\t\t\tsetAttachedPostTitle( __( '(Unattached)' ) );\n\t\t}\n\t}, [ parentId, embeddedPostId, embeddedPostTitle ] );\n\n\treturn <>{ attachedPostTitle }</>;\n}\n"],"mappings":";;;;;;;;;;AAMA,SAAwB,oBAAqB,EAC5C,QAC0C;CAI1C,MAAM,CAAE,mBAAmB,yBAAA,GAAyBA,mBAAAA,SAAAA,CAEjD,IAAK;CAER,MAAM,WAAW,KAAK;CACtB,MAAM,iBAAiB,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE;CACpE,MAAM,oBACL,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE;CAE9CC,CAAAA,GAAAA,mBAAAA,UAAAA,OAAiB;EAChB,IAAK,CAAC,CAAE,YAAY,aAAa,gBAChC,sBAAA,GACCC,iCAAAA,mBAAAA,CAAoB,iBAAkB,MAAA,GAAKC,gBAAAA,GAAAA,CAAI,YAAa,CAC7D;EAGD,IAAK,CAAE,UACN,sBAAA,GAAsBA,gBAAAA,GAAAA,CAAI,cAAe,CAAE;CAE7C,GAAG;EAAE;EAAU;EAAgB;CAAkB,CAAE;CAEnD,OAAO,iBAAA,GAAA,kBAAA,IAAA,CAAA,kBAAA,UAAA,EAAA,UAAI,kBAAqB,CAAA;AACjC"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","resolveSelect","coreDataStore","AuthorView"],"sources":["../../src/author/index.tsx"],"sourcesContent":["import type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport type { MediaItem } from '../types';\nimport AuthorView from './view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Partial< Field< MediaItem > > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords< Author >(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t\twho: 'authors',\n\t\t\t\t\t_fields: 'id,name',\n\t\t\t\t\tcontext: 'view',\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n\treadOnly: true,\n};\n\nexport default authorField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,cAA6C;CAClD,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,QAAS;CACpB,IAAI;CACJ,MAAM;CACN,aAAa,YAAY;EAYxB,QAVG,OAAA,GAAMC,gBAAAA,cAAAA,CAAeC,qBAAAA,KAAc,CAAC,CAAC,iBACtC,QACA,QACA;GACC,UAAU;GACV,KAAK;GACL,SAAS;GACT,SAAS;EACV,CACD,KAAO,CAAC,EAAA,CACM,KAAO,EAAE,IAAI,YAAc;GACzC,OAAO;GACP,OAAO;EACR,EAAI;CACL;CACA,QAAQC,WAAAA;CACR,UAAU,EACT,WAAW,CAAE,SAAS,QAAS,EAChC;CACA,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["__","resolveSelect","coreDataStore","AuthorView"],"sources":["../../src/author/index.tsx"],"sourcesContent":["import type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\nimport { resolveSelect } from '@wordpress/data';\nimport { store as coreDataStore } from '@wordpress/core-data';\nimport type { MediaItem } from '../types';\nimport AuthorView from './view';\n\ninterface Author {\n\tid: number;\n\tname: string;\n}\n\nconst authorField: Partial< Field< MediaItem > > = {\n\tlabel: __( 'Author' ),\n\tid: 'author',\n\ttype: 'integer',\n\tgetElements: async () => {\n\t\tconst authors: Author[] =\n\t\t\t( await resolveSelect( coreDataStore ).getEntityRecords< Author >(\n\t\t\t\t'root',\n\t\t\t\t'user',\n\t\t\t\t{\n\t\t\t\t\tper_page: -1,\n\t\t\t\t\twho: 'authors',\n\t\t\t\t\t_fields: 'id,name',\n\t\t\t\t\tcontext: 'view',\n\t\t\t\t}\n\t\t\t) ) ?? [];\n\t\treturn authors.map( ( { id, name } ) => ( {\n\t\t\tvalue: id,\n\t\t\tlabel: name,\n\t\t} ) );\n\t},\n\trender: AuthorView,\n\tfilterBy: {\n\t\toperators: [ 'isAny', 'isNone' ],\n\t},\n\treadOnly: true,\n};\n\nexport default authorField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,MAAM,cAA6C;CAClD,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,QAAS;CACpB,IAAI;CACJ,MAAM;CACN,aAAa,YAAY;EAYxB,QAVG,OAAA,GAAMC,gBAAAA,cAAAA,CAAeC,qBAAAA,KAAc,CAAC,CAAC,iBACtC,QACA,QACA;GACC,UAAU;GACV,KAAK;GACL,SAAS;GACT,SAAS;EACV,CACD,KAAO,CAAC,EAAA,CACM,KAAO,EAAE,IAAI,YAAc;GACzC,OAAO;GACP,OAAO;EACR,EAAI;CACL;CACA,QAAQC,WAAAA;CACR,UAAU,EACT,WAAW,CAAE,SAAS,QAAS,EAChC;CACA,UAAU;AACX"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -25,12 +27,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
27
  enumerable: true
26
28
  }) : target, mod));
27
29
  let clsx = require("clsx");
28
- clsx = __toESM(clsx);
29
- let _wordpress_i18n = require("@wordpress/i18n");
30
30
  let _wordpress_element = require("@wordpress/element");
31
31
  let _wordpress_icons = require("@wordpress/icons");
32
32
  let _wordpress_components = require("@wordpress/components");
33
33
  let react_jsx_runtime = require("react/jsx-runtime");
34
+ clsx = __toESM(clsx);
34
35
  // packages/media-fields/src/author/view.tsx
35
36
  function AuthorView({ item }) {
36
37
  const author = item?._embedded?.author?.[0];
@@ -58,7 +59,7 @@ function AuthorView({ item }) {
58
59
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
59
60
  ref: imgRef,
60
61
  onLoad: handleLoad,
61
- alt: (0, _wordpress_i18n.__)("Author avatar"),
62
+ alt: "",
62
63
  src: imageUrl
63
64
  })
64
65
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"view.cjs","names":["useState","useCallback","HStack","__","WCIcon","authorIcon"],"sources":["../../src/author/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback, useEffect } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport {\n\t__experimentalHStack as HStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nexport default function AuthorView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst author = item?._embedded?.author?.[ 0 ];\n\tconst text = author?.name;\n\tconst imageUrl = author?.avatar_urls?.[ 48 ];\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t */\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseEffect( () => {\n\t\tsetLoadingState( 'loading' );\n\t}, [ imageUrl ] );\n\n\tconst imgRef = useCallback( ( img: HTMLImageElement | null ) => {\n\t\tif ( img?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t}\n\t}, [] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'media-author-field__avatar', {\n\t\t\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tref={ imgRef }\n\t\t\t\t\t\tonLoad={ handleLoad }\n\t\t\t\t\t\talt={ __( 'Author avatar' ) }\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"media-author-field__icon\">\n\t\t\t\t\t<WCIcon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"media-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,SAAwB,WAAY,EACnC,QAC0C;CAC1C,MAAM,SAAS,MAAM,WAAW,SAAU;CAC1C,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ,cAAe;CAMxC,MAAM,CAAE,cAAc,oBAAA,GAAoBA,mBAAAA,SAAAA,CAEvC,SAAU;CAEb,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,gBAAiB,SAAU;CAC5B,GAAG,CAAE,QAAS,CAAE;CAEhB,MAAM,UAAA,GAASC,mBAAAA,YAAAA,EAAe,QAAkC;EAC/D,IAAK,KAAK,UACT,gBAAiB,SAAU;CAE7B,GAAG,CAAC,CAAE;CAEN,MAAM,mBAAmB;EACxB,IAAK,iBAAiB,WACrB,gBAAiB,QAAS;CAE5B;CAEA,OACC,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,sBAAD;EAAQ,WAAU;EAAO,SAAU;EAAnC,UAAA;GACG,CAAC,CAAE,YACJ,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IACC,YAAA,GAAY,KAAA,QAAA,CAAM,8BAA8B;KAC/C,cAAc,iBAAiB;KAC/B,aAAa,iBAAiB;IAC/B,CAAE;IAEF,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KACC,KAAM;KACN,QAAS;KACT,MAAA,GAAMC,gBAAAA,GAAAA,CAAI,eAAgB;KAC1B,KAAM;IACN,CAAA;GACG,CAAA;GAEJ,CAAE,YACH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,MAAD,EAAQ,MAAOC,iBAAAA,oBAAc,CAAA;GACzB,CAAA;GAEN,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IAAM,WAAU;IAA6B,UAAA;GAAY,CAAA;EAClD;;AAEV"}
1
+ {"version":3,"file":"view.cjs","names":["useState","useEffect","useCallback","HStack","clsx","WCIcon","authorIcon"],"sources":["../../src/author/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useState, useCallback, useEffect } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport {\n\t__experimentalHStack as HStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nexport default function AuthorView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst author = item?._embedded?.author?.[ 0 ];\n\tconst text = author?.name;\n\tconst imageUrl = author?.avatar_urls?.[ 48 ];\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t */\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseEffect( () => {\n\t\tsetLoadingState( 'loading' );\n\t}, [ imageUrl ] );\n\n\tconst imgRef = useCallback( ( img: HTMLImageElement | null ) => {\n\t\tif ( img?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t}\n\t}, [] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'media-author-field__avatar', {\n\t\t\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tref={ imgRef }\n\t\t\t\t\t\tonLoad={ handleLoad }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"media-author-field__icon\">\n\t\t\t\t\t<WCIcon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"media-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAwB,WAAY,EACnC,QAC0C;CAC1C,MAAM,SAAS,MAAM,WAAW,SAAU;CAC1C,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ,cAAe;CAMxC,MAAM,CAAE,cAAc,oBAAA,GAAoBA,mBAAAA,SAAAA,CAEvC,SAAU;CAEbC,CAAAA,GAAAA,mBAAAA,UAAAA,OAAiB;EAChB,gBAAiB,SAAU;CAC5B,GAAG,CAAE,QAAS,CAAE;CAEhB,MAAM,UAAA,GAASC,mBAAAA,YAAAA,EAAe,QAAkC;EAC/D,IAAK,KAAK,UACT,gBAAiB,SAAU;CAE7B,GAAG,CAAC,CAAE;CAEN,MAAM,mBAAmB;EACxB,IAAK,iBAAiB,WACrB,gBAAiB,QAAS;CAE5B;CAEA,OACC,iBAAA,GAAA,kBAAA,KAAA,CAACC,sBAAAA,sBAAD;EAAQ,WAAU;EAAO,SAAU;EAAnC,UAAA;GACG,CAAC,CAAE,YACJ,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IACC,YAAA,GAAYC,KAAAA,QAAAA,CAAM,8BAA8B;KAC/C,cAAc,iBAAiB;KAC/B,aAAa,iBAAiB;IAC/B,CAAE;IAEF,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;KACC,KAAM;KACN,QAAS;KACT,KAAI;KACJ,KAAM;IACN,CAAA;GACG,CAAA;GAEJ,CAAE,YACH,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,WAAU;IACd,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,MAAD,EAAQ,MAAOC,iBAAAA,oBAAc,CAAA;GACzB,CAAA;GAEN,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;IAAM,WAAU;IAA6B,UAAA;GAAY,CAAA;EAClD;;AAEV"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","getFilename","FileNameView"],"sources":["../../src/filename/index.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { getFilename } from '@wordpress/url';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport FileNameView from './view';\n\nconst filenameField: Partial< Field< MediaItem > > = {\n\tid: 'filename',\n\ttype: 'text',\n\tlabel: __( 'File name' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\tgetFilename( item?.source_url || '' ),\n\trender: FileNameView,\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filenameField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,WAAY;CACvB,WAAY,EAAE,YAAA,GACbC,eAAAA,YAAAA,CAAa,MAAM,cAAc,EAAG;CACrC,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["__","getFilename","FileNameView"],"sources":["../../src/filename/index.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { getFilename } from '@wordpress/url';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport FileNameView from './view';\n\nconst filenameField: Partial< Field< MediaItem > > = {\n\tid: 'filename',\n\ttype: 'text',\n\tlabel: __( 'File name' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\tgetFilename( item?.source_url || '' ),\n\trender: FileNameView,\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filenameField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,WAAY;CACvB,WAAY,EAAE,YAAA,GACbC,eAAAA,YAAAA,CAAa,MAAM,cAAc,EAAG;CACrC,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
@@ -14,10 +14,15 @@ const EB_IN_BYTES = 1024 * PB_IN_BYTES;
14
14
  const ZB_IN_BYTES = 1024 * EB_IN_BYTES;
15
15
  const YB_IN_BYTES = 1024 * ZB_IN_BYTES;
16
16
  function getBytesString(bytes, unitSymbol, decimals = 2) {
17
- return (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._x)("%1$s %2$s", "file size"), bytes.toLocaleString(void 0, {
18
- minimumFractionDigits: 0,
19
- maximumFractionDigits: decimals
20
- }), unitSymbol);
17
+ return (0, _wordpress_i18n.sprintf)(
18
+ /** translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB). */
19
+ (0, _wordpress_i18n._x)("%1$s %2$s", "file size"),
20
+ bytes.toLocaleString(void 0, {
21
+ minimumFractionDigits: 0,
22
+ maximumFractionDigits: decimals
23
+ }),
24
+ unitSymbol
25
+ );
21
26
  }
22
27
  /**
23
28
  * Converts bytes to a human-readable file size string with a specified number of decimal places.
@@ -31,15 +36,51 @@ function getBytesString(bytes, unitSymbol, decimals = 2) {
31
36
  function formatFileSize(bytes, decimals = 2) {
32
37
  if (bytes === 0) return getBytesString(0, (0, _wordpress_i18n._x)("B", "unit symbol"), decimals);
33
38
  const quant = {
34
- [(0, _wordpress_i18n._x)("YB", "unit symbol")]: YB_IN_BYTES,
35
- [(0, _wordpress_i18n._x)("ZB", "unit symbol")]: ZB_IN_BYTES,
36
- [(0, _wordpress_i18n._x)("EB", "unit symbol")]: EB_IN_BYTES,
37
- [(0, _wordpress_i18n._x)("PB", "unit symbol")]: PB_IN_BYTES,
38
- [(0, _wordpress_i18n._x)("TB", "unit symbol")]: TB_IN_BYTES,
39
- [(0, _wordpress_i18n._x)("GB", "unit symbol")]: GB_IN_BYTES,
40
- [(0, _wordpress_i18n._x)("MB", "unit symbol")]: MB_IN_BYTES,
41
- [(0, _wordpress_i18n._x)("KB", "unit symbol")]: KB_IN_BYTES,
42
- [(0, _wordpress_i18n._x)("B", "unit symbol")]: 1
39
+ [(0, _wordpress_i18n._x)(
40
+ /** translators: Unit symbol for yottabyte. */
41
+ "YB",
42
+ "unit symbol"
43
+ )]: YB_IN_BYTES,
44
+ [(0, _wordpress_i18n._x)(
45
+ /** translators: Unit symbol for zettabyte. */
46
+ "ZB",
47
+ "unit symbol"
48
+ )]: ZB_IN_BYTES,
49
+ [(0, _wordpress_i18n._x)(
50
+ /** translators: Unit symbol for exabyte. */
51
+ "EB",
52
+ "unit symbol"
53
+ )]: EB_IN_BYTES,
54
+ [(0, _wordpress_i18n._x)(
55
+ /** translators: Unit symbol for petabyte. */
56
+ "PB",
57
+ "unit symbol"
58
+ )]: PB_IN_BYTES,
59
+ [(0, _wordpress_i18n._x)(
60
+ /** translators: Unit symbol for terabyte. */
61
+ "TB",
62
+ "unit symbol"
63
+ )]: TB_IN_BYTES,
64
+ [(0, _wordpress_i18n._x)(
65
+ /** translators: Unit symbol for gigabyte. */
66
+ "GB",
67
+ "unit symbol"
68
+ )]: GB_IN_BYTES,
69
+ [(0, _wordpress_i18n._x)(
70
+ /** translators: Unit symbol for megabyte. */
71
+ "MB",
72
+ "unit symbol"
73
+ )]: MB_IN_BYTES,
74
+ [(0, _wordpress_i18n._x)(
75
+ /** translators: Unit symbol for kilobyte. */
76
+ "KB",
77
+ "unit symbol"
78
+ )]: KB_IN_BYTES,
79
+ [(0, _wordpress_i18n._x)(
80
+ /** translators: Unit symbol for byte. */
81
+ "B",
82
+ "unit symbol"
83
+ )]: 1
43
84
  };
44
85
  for (const [unit, mag] of Object.entries(quant)) if (bytes >= mag) return getBytesString(bytes / mag, unit, decimals);
45
86
  return "";
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["sprintf","_x","__"],"sources":["../../src/filesize/index.tsx"],"sourcesContent":["import { __, sprintf, _x } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nconst KB_IN_BYTES = 1024;\nconst MB_IN_BYTES = 1024 * KB_IN_BYTES;\nconst GB_IN_BYTES = 1024 * MB_IN_BYTES;\nconst TB_IN_BYTES = 1024 * GB_IN_BYTES;\nconst PB_IN_BYTES = 1024 * TB_IN_BYTES;\nconst EB_IN_BYTES = 1024 * PB_IN_BYTES;\nconst ZB_IN_BYTES = 1024 * EB_IN_BYTES;\nconst YB_IN_BYTES = 1024 * ZB_IN_BYTES;\n\nfunction getBytesString(\n\tbytes: number,\n\tunitSymbol: string,\n\tdecimals = 2\n): string {\n\treturn sprintf(\n\t\t// translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).\n\t\t_x( '%1$s %2$s', 'file size' ),\n\t\tbytes.toLocaleString( undefined, {\n\t\t\tminimumFractionDigits: 0,\n\t\t\tmaximumFractionDigits: decimals,\n\t\t} ),\n\t\tunitSymbol\n\t);\n}\n\n/**\n * Converts bytes to a human-readable file size string with a specified number of decimal places.\n *\n * This logic is comparable to core's `size_format()` function.\n *\n * @param bytes The size in bytes.\n * @param decimals The number of decimal places to include in the result.\n * @return The human-readable file size string.\n */\nfunction formatFileSize( bytes: number, decimals = 2 ): string {\n\tif ( bytes === 0 ) {\n\t\treturn getBytesString( 0, _x( 'B', 'unit symbol' ), decimals );\n\t}\n\tconst quant = {\n\t\t/* translators: Unit symbol for yottabyte. */\n\t\t[ _x( 'YB', 'unit symbol' ) ]: YB_IN_BYTES,\n\t\t/* translators: Unit symbol for zettabyte. */\n\t\t[ _x( 'ZB', 'unit symbol' ) ]: ZB_IN_BYTES,\n\t\t/* translators: Unit symbol for exabyte. */\n\t\t[ _x( 'EB', 'unit symbol' ) ]: EB_IN_BYTES,\n\t\t/* translators: Unit symbol for petabyte. */\n\t\t[ _x( 'PB', 'unit symbol' ) ]: PB_IN_BYTES,\n\t\t/* translators: Unit symbol for terabyte. */\n\t\t[ _x( 'TB', 'unit symbol' ) ]: TB_IN_BYTES,\n\t\t/* translators: Unit symbol for gigabyte. */\n\t\t[ _x( 'GB', 'unit symbol' ) ]: GB_IN_BYTES,\n\t\t/* translators: Unit symbol for megabyte. */\n\t\t[ _x( 'MB', 'unit symbol' ) ]: MB_IN_BYTES,\n\t\t/* translators: Unit symbol for kilobyte. */\n\t\t[ _x( 'KB', 'unit symbol' ) ]: KB_IN_BYTES,\n\t\t/* translators: Unit symbol for byte. */\n\t\t[ _x( 'B', 'unit symbol' ) ]: 1,\n\t};\n\n\tfor ( const [ unit, mag ] of Object.entries( quant ) ) {\n\t\tif ( bytes >= mag ) {\n\t\t\treturn getBytesString( bytes / mag, unit, decimals );\n\t\t}\n\t}\n\n\treturn ''; // Fallback in case no unit matches, though this should not happen.\n}\n\nconst filesizeField: Partial< Field< MediaItem > > = {\n\tid: 'filesize',\n\ttype: 'text',\n\tlabel: __( 'File size' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\titem?.media_details?.filesize\n\t\t\t? formatFileSize( item?.media_details?.filesize )\n\t\t\t: '',\n\tisVisible: ( item: MediaItem ) => {\n\t\treturn !! item?.media_details?.filesize;\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filesizeField;\n"],"mappings":";;;;;;;AAIA,MAAM,cAAc;AACpB,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAE3B,SAAS,eACR,OACA,YACA,WAAW,GACF;CACT,QAAA,GAAOA,gBAAAA,QAAAA,EAAAA,GAENC,gBAAAA,GAAAA,CAAI,aAAa,WAAY,GAC7B,MAAM,eAAgB,KAAA,GAAW;EAChC,uBAAuB;EACvB,uBAAuB;CACxB,CAAE,GACF,UACD;AACD;;;;;;;;;;AAWA,SAAS,eAAgB,OAAe,WAAW,GAAY;CAC9D,IAAK,UAAU,GACd,OAAO,eAAgB,IAAA,GAAGA,gBAAAA,GAAAA,CAAI,KAAK,aAAc,GAAG,QAAS;CAE9D,MAAM,QAAQ;IAEXA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,MAAM,aAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA,CAAI,KAAK,aAAc,IAAK;CAC/B;CAEA,KAAM,MAAM,CAAE,MAAM,QAAS,OAAO,QAAS,KAAM,GAClD,IAAK,SAAS,KACb,OAAO,eAAgB,QAAQ,KAAK,MAAM,QAAS;CAIrD,OAAO;AACR;AAEA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOC,gBAAAA,GAAAA,CAAI,WAAY;CACvB,WAAY,EAAE,WACb,MAAM,eAAe,WAClB,eAAgB,MAAM,eAAe,QAAS,IAC9C;CACJ,YAAa,SAAqB;EACjC,OAAO,CAAC,CAAE,MAAM,eAAe;CAChC;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["sprintf","_x","__"],"sources":["../../src/filesize/index.tsx"],"sourcesContent":["import { __, sprintf, _x } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nconst KB_IN_BYTES = 1024;\nconst MB_IN_BYTES = 1024 * KB_IN_BYTES;\nconst GB_IN_BYTES = 1024 * MB_IN_BYTES;\nconst TB_IN_BYTES = 1024 * GB_IN_BYTES;\nconst PB_IN_BYTES = 1024 * TB_IN_BYTES;\nconst EB_IN_BYTES = 1024 * PB_IN_BYTES;\nconst ZB_IN_BYTES = 1024 * EB_IN_BYTES;\nconst YB_IN_BYTES = 1024 * ZB_IN_BYTES;\n\nfunction getBytesString(\n\tbytes: number,\n\tunitSymbol: string,\n\tdecimals = 2\n): string {\n\treturn sprintf(\n\t\t// translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).\n\t\t_x( '%1$s %2$s', 'file size' ),\n\t\tbytes.toLocaleString( undefined, {\n\t\t\tminimumFractionDigits: 0,\n\t\t\tmaximumFractionDigits: decimals,\n\t\t} ),\n\t\tunitSymbol\n\t);\n}\n\n/**\n * Converts bytes to a human-readable file size string with a specified number of decimal places.\n *\n * This logic is comparable to core's `size_format()` function.\n *\n * @param bytes The size in bytes.\n * @param decimals The number of decimal places to include in the result.\n * @return The human-readable file size string.\n */\nfunction formatFileSize( bytes: number, decimals = 2 ): string {\n\tif ( bytes === 0 ) {\n\t\treturn getBytesString( 0, _x( 'B', 'unit symbol' ), decimals );\n\t}\n\tconst quant = {\n\t\t/* translators: Unit symbol for yottabyte. */\n\t\t[ _x( 'YB', 'unit symbol' ) ]: YB_IN_BYTES,\n\t\t/* translators: Unit symbol for zettabyte. */\n\t\t[ _x( 'ZB', 'unit symbol' ) ]: ZB_IN_BYTES,\n\t\t/* translators: Unit symbol for exabyte. */\n\t\t[ _x( 'EB', 'unit symbol' ) ]: EB_IN_BYTES,\n\t\t/* translators: Unit symbol for petabyte. */\n\t\t[ _x( 'PB', 'unit symbol' ) ]: PB_IN_BYTES,\n\t\t/* translators: Unit symbol for terabyte. */\n\t\t[ _x( 'TB', 'unit symbol' ) ]: TB_IN_BYTES,\n\t\t/* translators: Unit symbol for gigabyte. */\n\t\t[ _x( 'GB', 'unit symbol' ) ]: GB_IN_BYTES,\n\t\t/* translators: Unit symbol for megabyte. */\n\t\t[ _x( 'MB', 'unit symbol' ) ]: MB_IN_BYTES,\n\t\t/* translators: Unit symbol for kilobyte. */\n\t\t[ _x( 'KB', 'unit symbol' ) ]: KB_IN_BYTES,\n\t\t/* translators: Unit symbol for byte. */\n\t\t[ _x( 'B', 'unit symbol' ) ]: 1,\n\t};\n\n\tfor ( const [ unit, mag ] of Object.entries( quant ) ) {\n\t\tif ( bytes >= mag ) {\n\t\t\treturn getBytesString( bytes / mag, unit, decimals );\n\t\t}\n\t}\n\n\treturn ''; // Fallback in case no unit matches, though this should not happen.\n}\n\nconst filesizeField: Partial< Field< MediaItem > > = {\n\tid: 'filesize',\n\ttype: 'text',\n\tlabel: __( 'File size' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\titem?.media_details?.filesize\n\t\t\t? formatFileSize( item?.media_details?.filesize )\n\t\t\t: '',\n\tisVisible: ( item: MediaItem ) => {\n\t\treturn !! item?.media_details?.filesize;\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filesizeField;\n"],"mappings":";;;;;;;AAIA,MAAM,cAAc;AACpB,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAE3B,SAAS,eACR,OACA,YACA,WAAW,GACF;CACT,QAAA,GAAOA,gBAAAA,QAAAA;;GAENC,GAAAA,gBAAAA,GAAAA,CAAI,aAAa,WAAY;EAC7B,MAAM,eAAgB,KAAA,GAAW;GAChC,uBAAuB;GACvB,uBAAuB;EACxB,CAAE;EACF;CACD;AACD;;;;;;;;;;AAWA,SAAS,eAAgB,OAAe,WAAW,GAAY;CAC9D,IAAK,UAAU,GACd,OAAO,eAAgB,IAAA,GAAGA,gBAAAA,GAAAA,CAAI,KAAK,aAAc,GAAG,QAAS;CAE9D,MAAM,QAAQ;IAEXA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAM;EAAc,IAAK;IAE7BA,GAAAA,gBAAAA,GAAAA;;GAAI;GAAK;EAAc,IAAK;CAC/B;CAEA,KAAM,MAAM,CAAE,MAAM,QAAS,OAAO,QAAS,KAAM,GAClD,IAAK,SAAS,KACb,OAAO,eAAgB,QAAQ,KAAK,MAAM,QAAS;CAIrD,OAAO;AACR;AAEA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,QAAA,GAAOC,gBAAAA,GAAAA,CAAI,WAAY;CACvB,WAAY,EAAE,WACb,MAAM,eAAe,WAClB,eAAgB,MAAM,eAAe,QAAS,IAC9C;CACJ,YAAa,SAAqB;EACjC,OAAO,CAAC,CAAE,MAAM,eAAe;CAChC;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
package/build/index.cjs CHANGED
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -25,28 +27,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
27
  enumerable: true
26
28
  }) : target, mod));
27
29
  let __alt_text_index_tsx = require("./alt_text/index.cjs");
28
- __alt_text_index_tsx = __toESM(__alt_text_index_tsx);
29
30
  let __attached_to_index_tsx = require("./attached_to/index.cjs");
30
- __attached_to_index_tsx = __toESM(__attached_to_index_tsx);
31
31
  let __author_index_tsx = require("./author/index.cjs");
32
- __author_index_tsx = __toESM(__author_index_tsx);
33
32
  let __caption_index_tsx = require("./caption/index.cjs");
34
- __caption_index_tsx = __toESM(__caption_index_tsx);
35
33
  let __date_added_index_tsx = require("./date_added/index.cjs");
36
- __date_added_index_tsx = __toESM(__date_added_index_tsx);
37
34
  let __date_modified_index_tsx = require("./date_modified/index.cjs");
38
- __date_modified_index_tsx = __toESM(__date_modified_index_tsx);
39
35
  let __description_index_tsx = require("./description/index.cjs");
40
- __description_index_tsx = __toESM(__description_index_tsx);
41
36
  let __filename_index_ts = require("./filename/index.cjs");
42
- __filename_index_ts = __toESM(__filename_index_ts);
43
37
  let __filesize_index_tsx = require("./filesize/index.cjs");
44
- __filesize_index_tsx = __toESM(__filesize_index_tsx);
45
38
  let __media_dimensions_index_ts = require("./media_dimensions/index.cjs");
46
- __media_dimensions_index_ts = __toESM(__media_dimensions_index_ts);
47
39
  let __media_thumbnail_index_tsx = require("./media_thumbnail/index.cjs");
48
- __media_thumbnail_index_tsx = __toESM(__media_thumbnail_index_tsx);
49
40
  let __mime_type_index_ts = require("./mime_type/index.cjs");
41
+ __alt_text_index_tsx = __toESM(__alt_text_index_tsx);
42
+ __attached_to_index_tsx = __toESM(__attached_to_index_tsx);
43
+ __author_index_tsx = __toESM(__author_index_tsx);
44
+ __caption_index_tsx = __toESM(__caption_index_tsx);
45
+ __date_added_index_tsx = __toESM(__date_added_index_tsx);
46
+ __date_modified_index_tsx = __toESM(__date_modified_index_tsx);
47
+ __description_index_tsx = __toESM(__description_index_tsx);
48
+ __filename_index_ts = __toESM(__filename_index_ts);
49
+ __filesize_index_tsx = __toESM(__filesize_index_tsx);
50
+ __media_dimensions_index_ts = __toESM(__media_dimensions_index_ts);
51
+ __media_thumbnail_index_tsx = __toESM(__media_thumbnail_index_tsx);
50
52
  __mime_type_index_ts = __toESM(__mime_type_index_ts);
51
53
  Object.defineProperty(exports, "altTextField", {
52
54
  enumerable: true,
@@ -9,7 +9,12 @@ const mediaDimensionsField = {
9
9
  id: "media_dimensions",
10
10
  type: "text",
11
11
  label: (0, _wordpress_i18n.__)("Dimensions"),
12
- getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n._x)("%1$s × %2$s", "image dimensions"), item?.media_details?.width?.toString(), item?.media_details?.height?.toString()) : "",
12
+ getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? (0, _wordpress_i18n.sprintf)(
13
+ /** translators: 1: Width. 2: Height. */
14
+ (0, _wordpress_i18n._x)("%1$s × %2$s", "image dimensions"),
15
+ item?.media_details?.width?.toString(),
16
+ item?.media_details?.height?.toString()
17
+ ) : "",
13
18
  isVisible: (item) => {
14
19
  return !!(item?.media_details?.width && item?.media_details?.height);
15
20
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","sprintf","_x"],"sources":["../../src/media_dimensions/index.ts"],"sourcesContent":["import { __, _x, sprintf } from '@wordpress/i18n';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\nconst mediaDimensionsField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'media_dimensions',\n\ttype: 'text',\n\tlabel: __( 'Dimensions' ),\n\tgetValue: ( { item } ) =>\n\t\titem?.media_details?.width && item?.media_details?.height\n\t\t\t? sprintf(\n\t\t\t\t\t// translators: 1: Width. 2: Height.\n\t\t\t\t\t_x( '%1$s × %2$s', 'image dimensions' ),\n\t\t\t\t\titem?.media_details?.width?.toString(),\n\t\t\t\t\titem?.media_details?.height?.toString()\n\t\t\t\t)\n\t\t\t: '',\n\tisVisible: ( item ) => {\n\t\treturn !! ( item?.media_details?.width && item?.media_details?.height );\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default mediaDimensionsField;\n"],"mappings":";;;;;;;AAIA,MAAM,uBAAoE;CACzE,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,YAAa;CACxB,WAAY,EAAE,WACb,MAAM,eAAe,SAAS,MAAM,eAAe,UAAA,GAChDC,gBAAAA,QAAAA,EAAAA,GAEAC,gBAAAA,GAAAA,CAAI,eAAe,kBAAmB,GACtC,MAAM,eAAe,OAAO,SAAS,GACrC,MAAM,eAAe,QAAQ,SAAS,CACvC,IACC;CACJ,YAAa,SAAU;EACtB,OAAO,CAAC,EAAI,MAAM,eAAe,SAAS,MAAM,eAAe;CAChE;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["__","sprintf","_x"],"sources":["../../src/media_dimensions/index.ts"],"sourcesContent":["import { __, _x, sprintf } from '@wordpress/i18n';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\nconst mediaDimensionsField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'media_dimensions',\n\ttype: 'text',\n\tlabel: __( 'Dimensions' ),\n\tgetValue: ( { item } ) =>\n\t\titem?.media_details?.width && item?.media_details?.height\n\t\t\t? sprintf(\n\t\t\t\t\t// translators: 1: Width. 2: Height.\n\t\t\t\t\t_x( '%1$s × %2$s', 'image dimensions' ),\n\t\t\t\t\titem?.media_details?.width?.toString(),\n\t\t\t\t\titem?.media_details?.height?.toString()\n\t\t\t\t)\n\t\t\t: '',\n\tisVisible: ( item ) => {\n\t\treturn !! ( item?.media_details?.width && item?.media_details?.height );\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default mediaDimensionsField;\n"],"mappings":";;;;;;;AAIA,MAAM,uBAAoE;CACzE,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,YAAa;CACxB,WAAY,EAAE,WACb,MAAM,eAAe,SAAS,MAAM,eAAe,UAAA,GAChDC,gBAAAA,QAAAA;;GAEAC,GAAAA,gBAAAA,GAAAA,CAAI,eAAe,kBAAmB;EACtC,MAAM,eAAe,OAAO,SAAS;EACrC,MAAM,eAAe,QAAQ,SAAS;CACvC,IACC;CACJ,YAAa,SAAU;EACtB,OAAO,CAAC,EAAI,MAAM,eAAe,SAAS,MAAM,eAAe;CAChE;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__","MediaThumbnailView"],"sources":["../../src/media_thumbnail/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport MediaThumbnailView from './view';\n\nconst mediaThumbnailField: Partial< Field< MediaItem > > = {\n\tid: 'media_thumbnail',\n\ttype: 'media',\n\tlabel: __( 'Thumbnail' ),\n\trender: MediaThumbnailView,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default mediaThumbnailField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,sBAAqD;CAC1D,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,WAAY;CACvB,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;AACX"}
1
+ {"version":3,"file":"index.cjs","names":["__","MediaThumbnailView"],"sources":["../../src/media_thumbnail/index.tsx"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport MediaThumbnailView from './view';\n\nconst mediaThumbnailField: Partial< Field< MediaItem > > = {\n\tid: 'media_thumbnail',\n\ttype: 'media',\n\tlabel: __( 'Thumbnail' ),\n\trender: MediaThumbnailView,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default mediaThumbnailField;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,MAAM,sBAAqD;CAC1D,IAAI;CACJ,MAAM;CACN,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,WAAY;CACvB,QAAQC,WAAAA;CACR,eAAe;CACf,UAAU;AACX"}
@@ -11,12 +11,14 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
11
11
  var __getProtoOf = Object.getPrototypeOf;
12
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
- key = keys[i];
16
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
- get: ((k) => from[k]).bind(null, key),
18
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
- });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
16
+ desc = __getOwnPropDesc(from, key);
17
+ __defProp(to, key, {
18
+ get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
19
+ enumerable: !desc || desc.enumerable
20
+ });
21
+ }
20
22
  }
21
23
  return to;
22
24
  };
@@ -25,7 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
27
  enumerable: true
26
28
  }) : target, mod));
27
29
  let clsx = require("clsx");
28
- clsx = __toESM(clsx);
29
30
  let _wordpress_data = require("@wordpress/data");
30
31
  let _wordpress_core_data = require("@wordpress/core-data");
31
32
  let _wordpress_components = require("@wordpress/components");
@@ -33,6 +34,7 @@ let _wordpress_element = require("@wordpress/element");
33
34
  let _wordpress_url = require("@wordpress/url");
34
35
  let ___utils_get_media_type_from_mime_type_ts = require("../utils/get-media-type-from-mime-type.cjs");
35
36
  let react_jsx_runtime = require("react/jsx-runtime");
37
+ clsx = __toESM(clsx);
36
38
  // packages/media-fields/src/media_thumbnail/view.tsx
37
39
  /**
38
40
  * Given the available image sizes and a target display width, returns the URL
@@ -1 +1 @@
1
- {"version":3,"file":"view.cjs","names":["VStack","WCIcon","getMediaTypeFromMimeType","Truncate","useRef","useState","useSelect","coreStore","getFilename"],"sources":["../../src/media_thumbnail/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\t__experimentalTruncate as Truncate,\n\t__experimentalVStack as VStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport { useState, useRef, useLayoutEffect } from '@wordpress/element';\nimport type { Attachment } from '@wordpress/core-data';\nimport { getFilename } from '@wordpress/url';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport { getMediaTypeFromMimeType } from '../utils/get-media-type-from-mime-type';\nimport type { MediaItem } from '../types';\n\n/**\n * Given the available image sizes and a target display width, returns the URL\n * of the smallest size whose width is >= the target. Falls back to the largest\n * available size, or the original source_url.\n *\n * @param featuredMedia The media item with size details.\n * @param configSizes The target display size string (e.g. '900px').\n */\nexport function getBestImageUrl(\n\tfeaturedMedia: Attachment | MediaItem,\n\tconfigSizes?: string\n): string {\n\tconst sizes = featuredMedia?.media_details?.sizes;\n\tif ( ! sizes ) {\n\t\treturn featuredMedia.source_url;\n\t}\n\n\tconst sizeEntries = Object.values( sizes );\n\n\tif ( ! sizeEntries.length ) {\n\t\treturn featuredMedia.source_url;\n\t}\n\n\t// Parse target width from config.sizes (e.g. '900px' → 900).\n\tconst targetWidth = configSizes ? parseInt( configSizes, 10 ) : NaN;\n\n\tif ( ! Number.isNaN( targetWidth ) ) {\n\t\t// Filter to entries that have a valid numeric width.\n\t\tconst validEntries = sizeEntries.filter(\n\t\t\t( s ) => typeof s.width === 'number' && ! Number.isNaN( s.width )\n\t\t);\n\n\t\tif ( ! validEntries.length ) {\n\t\t\treturn featuredMedia.source_url;\n\t\t}\n\n\t\t// Sort ascending by width.\n\t\tconst sorted = validEntries.toSorted( ( a, b ) => a.width - b.width );\n\t\t// Pick the smallest size that is >= target width.\n\t\tconst match = sorted.find( ( s ) => s.width >= targetWidth );\n\t\tif ( match ) {\n\t\t\treturn match.source_url;\n\t\t}\n\t\t// No size large enough — use the largest available.\n\t\treturn sorted[ sorted.length - 1 ].source_url;\n\t}\n\n\t// If we can't parse the target, fall back to source_url.\n\treturn featuredMedia.source_url;\n}\n\nfunction FallbackView( {\n\titem,\n\tfilename,\n}: {\n\titem: MediaItem;\n\tfilename: string;\n} ) {\n\treturn (\n\t\t<div className=\"dataviews-media-field__media-thumbnail\">\n\t\t\t<VStack\n\t\t\t\tjustify=\"center\"\n\t\t\t\talignment=\"center\"\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail__stack\"\n\t\t\t\tspacing={ 0 }\n\t\t\t>\n\t\t\t\t<WCIcon\n\t\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--icon\"\n\t\t\t\t\ticon={ getMediaTypeFromMimeType( item.mime_type ).icon }\n\t\t\t\t\tsize={ 24 }\n\t\t\t\t/>\n\t\t\t\t{ !! filename && (\n\t\t\t\t\t<div className=\"dataviews-media-field__media-thumbnail__filename\">\n\t\t\t\t\t\t<Truncate className=\"dataviews-media-field__media-thumbnail__filename__truncate\">\n\t\t\t\t\t\t\t{ filename }\n\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n\nfunction ImageView( {\n\titem,\n\tconfigSizes,\n\tonError,\n}: {\n\titem: Attachment | MediaItem;\n\tconfigSizes?: string;\n\tonError: () => void;\n} ) {\n\tconst imageUrl = getBestImageUrl( item, configSizes );\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t *\n\t * useLayoutEffect runs synchronously after DOM mutations but before paint,\n\t * so we can check img.complete to detect disk-cached images and skip the\n\t * fade-in animation entirely.\n\t */\n\tconst imgRef = useRef< HTMLImageElement >( null );\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseLayoutEffect( () => {\n\t\tif ( imgRef.current?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t} else {\n\t\t\tsetLoadingState( 'loading' );\n\t\t}\n\t}, [ imageUrl ] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'dataviews-media-field__media-thumbnail', {\n\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t} ) }\n\t\t>\n\t\t\t<img\n\t\t\t\tref={ imgRef }\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--image\"\n\t\t\t\tsrc={ imageUrl }\n\t\t\t\talt={ item.alt_text || item.title.raw }\n\t\t\t\tonLoad={ handleLoad }\n\t\t\t\tonError={ onError }\n\t\t\t\tloading=\"lazy\"\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nexport default function MediaThumbnailView( {\n\titem,\n\tconfig,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst [ imageError, setImageError ] = useState( false );\n\n\tconst _featuredMedia = useSelect(\n\t\t( select ) => {\n\t\t\t// Avoid the network request if it's not needed. `featured_media` is\n\t\t\t// 0 for images and media without featured media.\n\t\t\tif ( ! item.featured_media ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\titem.featured_media\n\t\t\t);\n\t\t},\n\t\t[ item.featured_media ]\n\t);\n\tconst featuredMedia = item.featured_media ? _featuredMedia : item;\n\n\t// Fetching.\n\tif ( ! featuredMedia ) {\n\t\treturn null;\n\t}\n\n\tconst filename = getFilename( featuredMedia.source_url || '' );\n\n\t// Show fallback if image failed to load or if not an image type.\n\tif (\n\t\timageError ||\n\t\tgetMediaTypeFromMimeType( featuredMedia.mime_type ).type !== 'image'\n\t) {\n\t\treturn (\n\t\t\t<FallbackView item={ featuredMedia } filename={ filename || '' } />\n\t\t);\n\t}\n\n\treturn (\n\t\t<ImageView\n\t\t\titem={ featuredMedia }\n\t\t\tconfigSizes={ config?.sizes }\n\t\t\tonError={ () => setImageError( true ) }\n\t\t/>\n\t);\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"view.cjs","names":["VStack","WCIcon","getMediaTypeFromMimeType","Truncate","useRef","useState","useLayoutEffect","clsx","useSelect","coreStore","getFilename"],"sources":["../../src/media_thumbnail/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\t__experimentalTruncate as Truncate,\n\t__experimentalVStack as VStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport { useState, useRef, useLayoutEffect } from '@wordpress/element';\nimport type { Attachment } from '@wordpress/core-data';\nimport { getFilename } from '@wordpress/url';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport { getMediaTypeFromMimeType } from '../utils/get-media-type-from-mime-type';\nimport type { MediaItem } from '../types';\n\n/**\n * Given the available image sizes and a target display width, returns the URL\n * of the smallest size whose width is >= the target. Falls back to the largest\n * available size, or the original source_url.\n *\n * @param featuredMedia The media item with size details.\n * @param configSizes The target display size string (e.g. '900px').\n */\nexport function getBestImageUrl(\n\tfeaturedMedia: Attachment | MediaItem,\n\tconfigSizes?: string\n): string {\n\tconst sizes = featuredMedia?.media_details?.sizes;\n\tif ( ! sizes ) {\n\t\treturn featuredMedia.source_url;\n\t}\n\n\tconst sizeEntries = Object.values( sizes );\n\n\tif ( ! sizeEntries.length ) {\n\t\treturn featuredMedia.source_url;\n\t}\n\n\t// Parse target width from config.sizes (e.g. '900px' → 900).\n\tconst targetWidth = configSizes ? parseInt( configSizes, 10 ) : NaN;\n\n\tif ( ! Number.isNaN( targetWidth ) ) {\n\t\t// Filter to entries that have a valid numeric width.\n\t\tconst validEntries = sizeEntries.filter(\n\t\t\t( s ) => typeof s.width === 'number' && ! Number.isNaN( s.width )\n\t\t);\n\n\t\tif ( ! validEntries.length ) {\n\t\t\treturn featuredMedia.source_url;\n\t\t}\n\n\t\t// Sort ascending by width.\n\t\tconst sorted = validEntries.toSorted( ( a, b ) => a.width - b.width );\n\t\t// Pick the smallest size that is >= target width.\n\t\tconst match = sorted.find( ( s ) => s.width >= targetWidth );\n\t\tif ( match ) {\n\t\t\treturn match.source_url;\n\t\t}\n\t\t// No size large enough — use the largest available.\n\t\treturn sorted[ sorted.length - 1 ].source_url;\n\t}\n\n\t// If we can't parse the target, fall back to source_url.\n\treturn featuredMedia.source_url;\n}\n\nfunction FallbackView( {\n\titem,\n\tfilename,\n}: {\n\titem: MediaItem;\n\tfilename: string;\n} ) {\n\treturn (\n\t\t<div className=\"dataviews-media-field__media-thumbnail\">\n\t\t\t<VStack\n\t\t\t\tjustify=\"center\"\n\t\t\t\talignment=\"center\"\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail__stack\"\n\t\t\t\tspacing={ 0 }\n\t\t\t>\n\t\t\t\t<WCIcon\n\t\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--icon\"\n\t\t\t\t\ticon={ getMediaTypeFromMimeType( item.mime_type ).icon }\n\t\t\t\t\tsize={ 24 }\n\t\t\t\t/>\n\t\t\t\t{ !! filename && (\n\t\t\t\t\t<div className=\"dataviews-media-field__media-thumbnail__filename\">\n\t\t\t\t\t\t<Truncate className=\"dataviews-media-field__media-thumbnail__filename__truncate\">\n\t\t\t\t\t\t\t{ filename }\n\t\t\t\t\t\t</Truncate>\n\t\t\t\t\t</div>\n\t\t\t\t) }\n\t\t\t</VStack>\n\t\t</div>\n\t);\n}\n\nfunction ImageView( {\n\titem,\n\tconfigSizes,\n\tonError,\n}: {\n\titem: Attachment | MediaItem;\n\tconfigSizes?: string;\n\tonError: () => void;\n} ) {\n\tconst imageUrl = getBestImageUrl( item, configSizes );\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t *\n\t * useLayoutEffect runs synchronously after DOM mutations but before paint,\n\t * so we can check img.complete to detect disk-cached images and skip the\n\t * fade-in animation entirely.\n\t */\n\tconst imgRef = useRef< HTMLImageElement >( null );\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseLayoutEffect( () => {\n\t\tif ( imgRef.current?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t} else {\n\t\t\tsetLoadingState( 'loading' );\n\t\t}\n\t}, [ imageUrl ] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<div\n\t\t\tclassName={ clsx( 'dataviews-media-field__media-thumbnail', {\n\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t} ) }\n\t\t>\n\t\t\t<img\n\t\t\t\tref={ imgRef }\n\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--image\"\n\t\t\t\tsrc={ imageUrl }\n\t\t\t\talt={ item.alt_text || item.title.raw }\n\t\t\t\tonLoad={ handleLoad }\n\t\t\t\tonError={ onError }\n\t\t\t\tloading=\"lazy\"\n\t\t\t/>\n\t\t</div>\n\t);\n}\n\nexport default function MediaThumbnailView( {\n\titem,\n\tconfig,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst [ imageError, setImageError ] = useState( false );\n\n\tconst _featuredMedia = useSelect(\n\t\t( select ) => {\n\t\t\t// Avoid the network request if it's not needed. `featured_media` is\n\t\t\t// 0 for images and media without featured media.\n\t\t\tif ( ! item.featured_media ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn select( coreStore ).getEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'attachment',\n\t\t\t\titem.featured_media\n\t\t\t);\n\t\t},\n\t\t[ item.featured_media ]\n\t);\n\tconst featuredMedia = item.featured_media ? _featuredMedia : item;\n\n\t// Fetching.\n\tif ( ! featuredMedia ) {\n\t\treturn null;\n\t}\n\n\tconst filename = getFilename( featuredMedia.source_url || '' );\n\n\t// Show fallback if image failed to load or if not an image type.\n\tif (\n\t\timageError ||\n\t\tgetMediaTypeFromMimeType( featuredMedia.mime_type ).type !== 'image'\n\t) {\n\t\treturn (\n\t\t\t<FallbackView item={ featuredMedia } filename={ filename || '' } />\n\t\t);\n\t}\n\n\treturn (\n\t\t<ImageView\n\t\t\titem={ featuredMedia }\n\t\t\tconfigSizes={ config?.sizes }\n\t\t\tonError={ () => setImageError( true ) }\n\t\t/>\n\t);\n}\n"],"mappings":"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"}
@@ -8,7 +8,9 @@ const altTextField = {
8
8
  label: __("Alt text"),
9
9
  description: /* @__PURE__ */ jsxs(Fragment, { children: [
10
10
  /* @__PURE__ */ jsx(Link, {
11
- href: __("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
11
+ href:
12
+ /** translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */
13
+ __("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
12
14
  openInNewTab: true,
13
15
  children: __("Describe the purpose of the image.")
14
16
  }),
@@ -1 +1 @@
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
+ {"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;;GAEC,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,5 +1,4 @@
1
1
  import clsx from "clsx";
2
- import { __ } from "@wordpress/i18n";
3
2
  import { useCallback, useEffect, useState } from "@wordpress/element";
4
3
  import { commentAuthorAvatar } from "@wordpress/icons";
5
4
  import { Icon, __experimentalHStack } from "@wordpress/components";
@@ -31,7 +30,7 @@ function AuthorView({ item }) {
31
30
  children: /* @__PURE__ */ jsx("img", {
32
31
  ref: imgRef,
33
32
  onLoad: handleLoad,
34
- alt: __("Author avatar"),
33
+ alt: "",
35
34
  src: imageUrl
36
35
  })
37
36
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"view.mjs","names":["HStack","WCIcon","authorIcon"],"sources":["../../src/author/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __ } from '@wordpress/i18n';\nimport { useState, useCallback, useEffect } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport {\n\t__experimentalHStack as HStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nexport default function AuthorView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst author = item?._embedded?.author?.[ 0 ];\n\tconst text = author?.name;\n\tconst imageUrl = author?.avatar_urls?.[ 48 ];\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t */\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseEffect( () => {\n\t\tsetLoadingState( 'loading' );\n\t}, [ imageUrl ] );\n\n\tconst imgRef = useCallback( ( img: HTMLImageElement | null ) => {\n\t\tif ( img?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t}\n\t}, [] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'media-author-field__avatar', {\n\t\t\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tref={ imgRef }\n\t\t\t\t\t\tonLoad={ handleLoad }\n\t\t\t\t\t\talt={ __( 'Author avatar' ) }\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"media-author-field__icon\">\n\t\t\t\t\t<WCIcon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"media-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";;;;;;;AAWA,SAAwB,WAAY,EACnC,QAC0C;CAC1C,MAAM,SAAS,MAAM,WAAW,SAAU;CAC1C,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ,cAAe;CAMxC,MAAM,CAAE,cAAc,mBAAoB,SAEvC,SAAU;CAEb,gBAAiB;EAChB,gBAAiB,SAAU;CAC5B,GAAG,CAAE,QAAS,CAAE;CAEhB,MAAM,SAAS,aAAe,QAAkC;EAC/D,IAAK,KAAK,UACT,gBAAiB,SAAU;CAE7B,GAAG,CAAC,CAAE;CAEN,MAAM,mBAAmB;EACxB,IAAK,iBAAiB,WACrB,gBAAiB,QAAS;CAE5B;CAEA,OACC,qBAACA,sBAAD;EAAQ,WAAU;EAAO,SAAU;EAAnC,UAAA;GACG,CAAC,CAAE,YACJ,oBAAC,OAAD;IACC,WAAY,KAAM,8BAA8B;KAC/C,cAAc,iBAAiB;KAC/B,aAAa,iBAAiB;IAC/B,CAAE;IAEF,UAAA,oBAAC,OAAD;KACC,KAAM;KACN,QAAS;KACT,KAAM,GAAI,eAAgB;KAC1B,KAAM;IACN,CAAA;GACG,CAAA;GAEJ,CAAE,YACH,oBAAC,OAAD;IAAK,WAAU;IACd,UAAA,oBAACC,MAAD,EAAQ,MAAOC,oBAAc,CAAA;GACzB,CAAA;GAEN,oBAAC,QAAD;IAAM,WAAU;IAA6B,UAAA;GAAY,CAAA;EAClD;;AAEV"}
1
+ {"version":3,"file":"view.mjs","names":["HStack","WCIcon","authorIcon"],"sources":["../../src/author/view.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport { useState, useCallback, useEffect } from '@wordpress/element';\nimport { commentAuthorAvatar as authorIcon } from '@wordpress/icons';\nimport {\n\t__experimentalHStack as HStack,\n\tIcon as WCIcon,\n} from '@wordpress/components';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nexport default function AuthorView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst author = item?._embedded?.author?.[ 0 ];\n\tconst text = author?.name;\n\tconst imageUrl = author?.avatar_urls?.[ 48 ];\n\n\t/*\n\t * Use three states to avoid fade-in animation for cached images:\n\t * 'instant' = image already cached, 'loading' = waiting, 'loaded' = just finished.\n\t */\n\tconst [ loadingState, setLoadingState ] = useState<\n\t\t'instant' | 'loading' | 'loaded'\n\t>( 'loading' );\n\n\tuseEffect( () => {\n\t\tsetLoadingState( 'loading' );\n\t}, [ imageUrl ] );\n\n\tconst imgRef = useCallback( ( img: HTMLImageElement | null ) => {\n\t\tif ( img?.complete ) {\n\t\t\tsetLoadingState( 'instant' );\n\t\t}\n\t}, [] );\n\n\tconst handleLoad = () => {\n\t\tif ( loadingState === 'loading' ) {\n\t\t\tsetLoadingState( 'loaded' );\n\t\t}\n\t};\n\n\treturn (\n\t\t<HStack alignment=\"left\" spacing={ 0 }>\n\t\t\t{ !! imageUrl && (\n\t\t\t\t<div\n\t\t\t\t\tclassName={ clsx( 'media-author-field__avatar', {\n\t\t\t\t\t\t'is-loading': loadingState === 'loading',\n\t\t\t\t\t\t'is-loaded': loadingState === 'loaded',\n\t\t\t\t\t} ) }\n\t\t\t\t>\n\t\t\t\t\t<img\n\t\t\t\t\t\tref={ imgRef }\n\t\t\t\t\t\tonLoad={ handleLoad }\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t\tsrc={ imageUrl }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t{ ! imageUrl && (\n\t\t\t\t<div className=\"media-author-field__icon\">\n\t\t\t\t\t<WCIcon icon={ authorIcon } />\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\t<span className=\"media-author-field__name\">{ text }</span>\n\t\t</HStack>\n\t);\n}\n"],"mappings":";;;;;;AAUA,SAAwB,WAAY,EACnC,QAC0C;CAC1C,MAAM,SAAS,MAAM,WAAW,SAAU;CAC1C,MAAM,OAAO,QAAQ;CACrB,MAAM,WAAW,QAAQ,cAAe;CAMxC,MAAM,CAAE,cAAc,mBAAoB,SAEvC,SAAU;CAEb,gBAAiB;EAChB,gBAAiB,SAAU;CAC5B,GAAG,CAAE,QAAS,CAAE;CAEhB,MAAM,SAAS,aAAe,QAAkC;EAC/D,IAAK,KAAK,UACT,gBAAiB,SAAU;CAE7B,GAAG,CAAC,CAAE;CAEN,MAAM,mBAAmB;EACxB,IAAK,iBAAiB,WACrB,gBAAiB,QAAS;CAE5B;CAEA,OACC,qBAACA,sBAAD;EAAQ,WAAU;EAAO,SAAU;EAAnC,UAAA;GACG,CAAC,CAAE,YACJ,oBAAC,OAAD;IACC,WAAY,KAAM,8BAA8B;KAC/C,cAAc,iBAAiB;KAC/B,aAAa,iBAAiB;IAC/B,CAAE;IAEF,UAAA,oBAAC,OAAD;KACC,KAAM;KACN,QAAS;KACT,KAAI;KACJ,KAAM;IACN,CAAA;GACG,CAAA;GAEJ,CAAE,YACH,oBAAC,OAAD;IAAK,WAAU;IACd,UAAA,oBAACC,MAAD,EAAQ,MAAOC,oBAAc,CAAA;GACzB,CAAA;GAEN,oBAAC,QAAD;IAAM,WAAU;IAA6B,UAAA;GAAY,CAAA;EAClD;;AAEV"}
@@ -9,10 +9,15 @@ const EB_IN_BYTES = 1024 * PB_IN_BYTES;
9
9
  const ZB_IN_BYTES = 1024 * EB_IN_BYTES;
10
10
  const YB_IN_BYTES = 1024 * ZB_IN_BYTES;
11
11
  function getBytesString(bytes, unitSymbol, decimals = 2) {
12
- return sprintf(_x("%1$s %2$s", "file size"), bytes.toLocaleString(void 0, {
13
- minimumFractionDigits: 0,
14
- maximumFractionDigits: decimals
15
- }), unitSymbol);
12
+ return sprintf(
13
+ /** translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB). */
14
+ _x("%1$s %2$s", "file size"),
15
+ bytes.toLocaleString(void 0, {
16
+ minimumFractionDigits: 0,
17
+ maximumFractionDigits: decimals
18
+ }),
19
+ unitSymbol
20
+ );
16
21
  }
17
22
  /**
18
23
  * Converts bytes to a human-readable file size string with a specified number of decimal places.
@@ -26,15 +31,51 @@ function getBytesString(bytes, unitSymbol, decimals = 2) {
26
31
  function formatFileSize(bytes, decimals = 2) {
27
32
  if (bytes === 0) return getBytesString(0, _x("B", "unit symbol"), decimals);
28
33
  const quant = {
29
- [_x("YB", "unit symbol")]: YB_IN_BYTES,
30
- [_x("ZB", "unit symbol")]: ZB_IN_BYTES,
31
- [_x("EB", "unit symbol")]: EB_IN_BYTES,
32
- [_x("PB", "unit symbol")]: PB_IN_BYTES,
33
- [_x("TB", "unit symbol")]: TB_IN_BYTES,
34
- [_x("GB", "unit symbol")]: GB_IN_BYTES,
35
- [_x("MB", "unit symbol")]: MB_IN_BYTES,
36
- [_x("KB", "unit symbol")]: KB_IN_BYTES,
37
- [_x("B", "unit symbol")]: 1
34
+ [_x(
35
+ /** translators: Unit symbol for yottabyte. */
36
+ "YB",
37
+ "unit symbol"
38
+ )]: YB_IN_BYTES,
39
+ [_x(
40
+ /** translators: Unit symbol for zettabyte. */
41
+ "ZB",
42
+ "unit symbol"
43
+ )]: ZB_IN_BYTES,
44
+ [_x(
45
+ /** translators: Unit symbol for exabyte. */
46
+ "EB",
47
+ "unit symbol"
48
+ )]: EB_IN_BYTES,
49
+ [_x(
50
+ /** translators: Unit symbol for petabyte. */
51
+ "PB",
52
+ "unit symbol"
53
+ )]: PB_IN_BYTES,
54
+ [_x(
55
+ /** translators: Unit symbol for terabyte. */
56
+ "TB",
57
+ "unit symbol"
58
+ )]: TB_IN_BYTES,
59
+ [_x(
60
+ /** translators: Unit symbol for gigabyte. */
61
+ "GB",
62
+ "unit symbol"
63
+ )]: GB_IN_BYTES,
64
+ [_x(
65
+ /** translators: Unit symbol for megabyte. */
66
+ "MB",
67
+ "unit symbol"
68
+ )]: MB_IN_BYTES,
69
+ [_x(
70
+ /** translators: Unit symbol for kilobyte. */
71
+ "KB",
72
+ "unit symbol"
73
+ )]: KB_IN_BYTES,
74
+ [_x(
75
+ /** translators: Unit symbol for byte. */
76
+ "B",
77
+ "unit symbol"
78
+ )]: 1
38
79
  };
39
80
  for (const [unit, mag] of Object.entries(quant)) if (bytes >= mag) return getBytesString(bytes / mag, unit, decimals);
40
81
  return "";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/filesize/index.tsx"],"sourcesContent":["import { __, sprintf, _x } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nconst KB_IN_BYTES = 1024;\nconst MB_IN_BYTES = 1024 * KB_IN_BYTES;\nconst GB_IN_BYTES = 1024 * MB_IN_BYTES;\nconst TB_IN_BYTES = 1024 * GB_IN_BYTES;\nconst PB_IN_BYTES = 1024 * TB_IN_BYTES;\nconst EB_IN_BYTES = 1024 * PB_IN_BYTES;\nconst ZB_IN_BYTES = 1024 * EB_IN_BYTES;\nconst YB_IN_BYTES = 1024 * ZB_IN_BYTES;\n\nfunction getBytesString(\n\tbytes: number,\n\tunitSymbol: string,\n\tdecimals = 2\n): string {\n\treturn sprintf(\n\t\t// translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).\n\t\t_x( '%1$s %2$s', 'file size' ),\n\t\tbytes.toLocaleString( undefined, {\n\t\t\tminimumFractionDigits: 0,\n\t\t\tmaximumFractionDigits: decimals,\n\t\t} ),\n\t\tunitSymbol\n\t);\n}\n\n/**\n * Converts bytes to a human-readable file size string with a specified number of decimal places.\n *\n * This logic is comparable to core's `size_format()` function.\n *\n * @param bytes The size in bytes.\n * @param decimals The number of decimal places to include in the result.\n * @return The human-readable file size string.\n */\nfunction formatFileSize( bytes: number, decimals = 2 ): string {\n\tif ( bytes === 0 ) {\n\t\treturn getBytesString( 0, _x( 'B', 'unit symbol' ), decimals );\n\t}\n\tconst quant = {\n\t\t/* translators: Unit symbol for yottabyte. */\n\t\t[ _x( 'YB', 'unit symbol' ) ]: YB_IN_BYTES,\n\t\t/* translators: Unit symbol for zettabyte. */\n\t\t[ _x( 'ZB', 'unit symbol' ) ]: ZB_IN_BYTES,\n\t\t/* translators: Unit symbol for exabyte. */\n\t\t[ _x( 'EB', 'unit symbol' ) ]: EB_IN_BYTES,\n\t\t/* translators: Unit symbol for petabyte. */\n\t\t[ _x( 'PB', 'unit symbol' ) ]: PB_IN_BYTES,\n\t\t/* translators: Unit symbol for terabyte. */\n\t\t[ _x( 'TB', 'unit symbol' ) ]: TB_IN_BYTES,\n\t\t/* translators: Unit symbol for gigabyte. */\n\t\t[ _x( 'GB', 'unit symbol' ) ]: GB_IN_BYTES,\n\t\t/* translators: Unit symbol for megabyte. */\n\t\t[ _x( 'MB', 'unit symbol' ) ]: MB_IN_BYTES,\n\t\t/* translators: Unit symbol for kilobyte. */\n\t\t[ _x( 'KB', 'unit symbol' ) ]: KB_IN_BYTES,\n\t\t/* translators: Unit symbol for byte. */\n\t\t[ _x( 'B', 'unit symbol' ) ]: 1,\n\t};\n\n\tfor ( const [ unit, mag ] of Object.entries( quant ) ) {\n\t\tif ( bytes >= mag ) {\n\t\t\treturn getBytesString( bytes / mag, unit, decimals );\n\t\t}\n\t}\n\n\treturn ''; // Fallback in case no unit matches, though this should not happen.\n}\n\nconst filesizeField: Partial< Field< MediaItem > > = {\n\tid: 'filesize',\n\ttype: 'text',\n\tlabel: __( 'File size' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\titem?.media_details?.filesize\n\t\t\t? formatFileSize( item?.media_details?.filesize )\n\t\t\t: '',\n\tisVisible: ( item: MediaItem ) => {\n\t\treturn !! item?.media_details?.filesize;\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filesizeField;\n"],"mappings":";;AAIA,MAAM,cAAc;AACpB,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAE3B,SAAS,eACR,OACA,YACA,WAAW,GACF;CACT,OAAO,QAEN,GAAI,aAAa,WAAY,GAC7B,MAAM,eAAgB,KAAA,GAAW;EAChC,uBAAuB;EACvB,uBAAuB;CACxB,CAAE,GACF,UACD;AACD;;;;;;;;;;AAWA,SAAS,eAAgB,OAAe,WAAW,GAAY;CAC9D,IAAK,UAAU,GACd,OAAO,eAAgB,GAAG,GAAI,KAAK,aAAc,GAAG,QAAS;CAE9D,MAAM,QAAQ;GAEX,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,MAAM,aAAc,IAAK;GAE7B,GAAI,KAAK,aAAc,IAAK;CAC/B;CAEA,KAAM,MAAM,CAAE,MAAM,QAAS,OAAO,QAAS,KAAM,GAClD,IAAK,SAAS,KACb,OAAO,eAAgB,QAAQ,KAAK,MAAM,QAAS;CAIrD,OAAO;AACR;AAEA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,OAAO,GAAI,WAAY;CACvB,WAAY,EAAE,WACb,MAAM,eAAe,WAClB,eAAgB,MAAM,eAAe,QAAS,IAC9C;CACJ,YAAa,SAAqB;EACjC,OAAO,CAAC,CAAE,MAAM,eAAe;CAChC;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/filesize/index.tsx"],"sourcesContent":["import { __, sprintf, _x } from '@wordpress/i18n';\nimport type { Field } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\n\nconst KB_IN_BYTES = 1024;\nconst MB_IN_BYTES = 1024 * KB_IN_BYTES;\nconst GB_IN_BYTES = 1024 * MB_IN_BYTES;\nconst TB_IN_BYTES = 1024 * GB_IN_BYTES;\nconst PB_IN_BYTES = 1024 * TB_IN_BYTES;\nconst EB_IN_BYTES = 1024 * PB_IN_BYTES;\nconst ZB_IN_BYTES = 1024 * EB_IN_BYTES;\nconst YB_IN_BYTES = 1024 * ZB_IN_BYTES;\n\nfunction getBytesString(\n\tbytes: number,\n\tunitSymbol: string,\n\tdecimals = 2\n): string {\n\treturn sprintf(\n\t\t// translators: 1: Actual bytes of a file. 2: The unit symbol (e.g. MB).\n\t\t_x( '%1$s %2$s', 'file size' ),\n\t\tbytes.toLocaleString( undefined, {\n\t\t\tminimumFractionDigits: 0,\n\t\t\tmaximumFractionDigits: decimals,\n\t\t} ),\n\t\tunitSymbol\n\t);\n}\n\n/**\n * Converts bytes to a human-readable file size string with a specified number of decimal places.\n *\n * This logic is comparable to core's `size_format()` function.\n *\n * @param bytes The size in bytes.\n * @param decimals The number of decimal places to include in the result.\n * @return The human-readable file size string.\n */\nfunction formatFileSize( bytes: number, decimals = 2 ): string {\n\tif ( bytes === 0 ) {\n\t\treturn getBytesString( 0, _x( 'B', 'unit symbol' ), decimals );\n\t}\n\tconst quant = {\n\t\t/* translators: Unit symbol for yottabyte. */\n\t\t[ _x( 'YB', 'unit symbol' ) ]: YB_IN_BYTES,\n\t\t/* translators: Unit symbol for zettabyte. */\n\t\t[ _x( 'ZB', 'unit symbol' ) ]: ZB_IN_BYTES,\n\t\t/* translators: Unit symbol for exabyte. */\n\t\t[ _x( 'EB', 'unit symbol' ) ]: EB_IN_BYTES,\n\t\t/* translators: Unit symbol for petabyte. */\n\t\t[ _x( 'PB', 'unit symbol' ) ]: PB_IN_BYTES,\n\t\t/* translators: Unit symbol for terabyte. */\n\t\t[ _x( 'TB', 'unit symbol' ) ]: TB_IN_BYTES,\n\t\t/* translators: Unit symbol for gigabyte. */\n\t\t[ _x( 'GB', 'unit symbol' ) ]: GB_IN_BYTES,\n\t\t/* translators: Unit symbol for megabyte. */\n\t\t[ _x( 'MB', 'unit symbol' ) ]: MB_IN_BYTES,\n\t\t/* translators: Unit symbol for kilobyte. */\n\t\t[ _x( 'KB', 'unit symbol' ) ]: KB_IN_BYTES,\n\t\t/* translators: Unit symbol for byte. */\n\t\t[ _x( 'B', 'unit symbol' ) ]: 1,\n\t};\n\n\tfor ( const [ unit, mag ] of Object.entries( quant ) ) {\n\t\tif ( bytes >= mag ) {\n\t\t\treturn getBytesString( bytes / mag, unit, decimals );\n\t\t}\n\t}\n\n\treturn ''; // Fallback in case no unit matches, though this should not happen.\n}\n\nconst filesizeField: Partial< Field< MediaItem > > = {\n\tid: 'filesize',\n\ttype: 'text',\n\tlabel: __( 'File size' ),\n\tgetValue: ( { item }: { item: MediaItem } ) =>\n\t\titem?.media_details?.filesize\n\t\t\t? formatFileSize( item?.media_details?.filesize )\n\t\t\t: '',\n\tisVisible: ( item: MediaItem ) => {\n\t\treturn !! item?.media_details?.filesize;\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default filesizeField;\n"],"mappings":";;AAIA,MAAM,cAAc;AACpB,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAC3B,MAAM,cAAc,OAAO;AAE3B,SAAS,eACR,OACA,YACA,WAAW,GACF;CACT,OAAO;;EAEN,GAAI,aAAa,WAAY;EAC7B,MAAM,eAAgB,KAAA,GAAW;GAChC,uBAAuB;GACvB,uBAAuB;EACxB,CAAE;EACF;CACD;AACD;;;;;;;;;;AAWA,SAAS,eAAgB,OAAe,WAAW,GAAY;CAC9D,IAAK,UAAU,GACd,OAAO,eAAgB,GAAG,GAAI,KAAK,aAAc,GAAG,QAAS;CAE9D,MAAM,QAAQ;GAEX;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAM;EAAc,IAAK;GAE7B;;GAAI;GAAK;EAAc,IAAK;CAC/B;CAEA,KAAM,MAAM,CAAE,MAAM,QAAS,OAAO,QAAS,KAAM,GAClD,IAAK,SAAS,KACb,OAAO,eAAgB,QAAQ,KAAK,MAAM,QAAS;CAIrD,OAAO;AACR;AAEA,MAAM,gBAA+C;CACpD,IAAI;CACJ,MAAM;CACN,OAAO,GAAI,WAAY;CACvB,WAAY,EAAE,WACb,MAAM,eAAe,WAClB,eAAgB,MAAM,eAAe,QAAS,IAC9C;CACJ,YAAa,SAAqB;EACjC,OAAO,CAAC,CAAE,MAAM,eAAe;CAChC;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
@@ -4,7 +4,12 @@ const mediaDimensionsField = {
4
4
  id: "media_dimensions",
5
5
  type: "text",
6
6
  label: __("Dimensions"),
7
- getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? sprintf(_x("%1$s × %2$s", "image dimensions"), item?.media_details?.width?.toString(), item?.media_details?.height?.toString()) : "",
7
+ getValue: ({ item }) => item?.media_details?.width && item?.media_details?.height ? sprintf(
8
+ /** translators: 1: Width. 2: Height. */
9
+ _x("%1$s × %2$s", "image dimensions"),
10
+ item?.media_details?.width?.toString(),
11
+ item?.media_details?.height?.toString()
12
+ ) : "",
8
13
  isVisible: (item) => {
9
14
  return !!(item?.media_details?.width && item?.media_details?.height);
10
15
  },
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/media_dimensions/index.ts"],"sourcesContent":["import { __, _x, sprintf } from '@wordpress/i18n';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\nconst mediaDimensionsField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'media_dimensions',\n\ttype: 'text',\n\tlabel: __( 'Dimensions' ),\n\tgetValue: ( { item } ) =>\n\t\titem?.media_details?.width && item?.media_details?.height\n\t\t\t? sprintf(\n\t\t\t\t\t// translators: 1: Width. 2: Height.\n\t\t\t\t\t_x( '%1$s × %2$s', 'image dimensions' ),\n\t\t\t\t\titem?.media_details?.width?.toString(),\n\t\t\t\t\titem?.media_details?.height?.toString()\n\t\t\t\t)\n\t\t\t: '',\n\tisVisible: ( item ) => {\n\t\treturn !! ( item?.media_details?.width && item?.media_details?.height );\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default mediaDimensionsField;\n"],"mappings":";;AAIA,MAAM,uBAAoE;CACzE,IAAI;CACJ,MAAM;CACN,OAAO,GAAI,YAAa;CACxB,WAAY,EAAE,WACb,MAAM,eAAe,SAAS,MAAM,eAAe,SAChD,QAEA,GAAI,eAAe,kBAAmB,GACtC,MAAM,eAAe,OAAO,SAAS,GACrC,MAAM,eAAe,QAAQ,SAAS,CACvC,IACC;CACJ,YAAa,SAAU;EACtB,OAAO,CAAC,EAAI,MAAM,eAAe,SAAS,MAAM,eAAe;CAChE;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/media_dimensions/index.ts"],"sourcesContent":["import { __, _x, sprintf } from '@wordpress/i18n';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\nconst mediaDimensionsField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'media_dimensions',\n\ttype: 'text',\n\tlabel: __( 'Dimensions' ),\n\tgetValue: ( { item } ) =>\n\t\titem?.media_details?.width && item?.media_details?.height\n\t\t\t? sprintf(\n\t\t\t\t\t// translators: 1: Width. 2: Height.\n\t\t\t\t\t_x( '%1$s × %2$s', 'image dimensions' ),\n\t\t\t\t\titem?.media_details?.width?.toString(),\n\t\t\t\t\titem?.media_details?.height?.toString()\n\t\t\t\t)\n\t\t\t: '',\n\tisVisible: ( item ) => {\n\t\treturn !! ( item?.media_details?.width && item?.media_details?.height );\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default mediaDimensionsField;\n"],"mappings":";;AAIA,MAAM,uBAAoE;CACzE,IAAI;CACJ,MAAM;CACN,OAAO,GAAI,YAAa;CACxB,WAAY,EAAE,WACb,MAAM,eAAe,SAAS,MAAM,eAAe,SAChD;;EAEA,GAAI,eAAe,kBAAmB;EACtC,MAAM,eAAe,OAAO,SAAS;EACrC,MAAM,eAAe,QAAQ,SAAS;CACvC,IACC;CACJ,YAAa,SAAU;EACtB,OAAO,CAAC,EAAI,MAAM,eAAe,SAAS,MAAM,eAAe;CAChE;CACA,eAAe;CACf,UAAU;CACV,UAAU;AACX"}
@@ -202,10 +202,10 @@
202
202
  padding: 0 16px;
203
203
  width: 100%;
204
204
  container-type: inline-size;
205
- font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
205
+ font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
206
206
  font-weight: var(--wpds-typography-font-weight-default, 400);
207
- font-size: 12px;
208
- line-height: 16px;
207
+ font-size: var(--wpds-typography-font-size-sm, 12px);
208
+ line-height: var(--wpds-typography-line-height-xs, 16px);
209
209
  }
210
210
  .dataviews-media-field__media-thumbnail__filename__truncate {
211
211
  margin-top: 4px;
@@ -202,10 +202,10 @@
202
202
  padding: 0 16px;
203
203
  width: 100%;
204
204
  container-type: inline-size;
205
- font-family: -apple-system, system-ui, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
205
+ font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
206
206
  font-weight: var(--wpds-typography-font-weight-default, 400);
207
- font-size: 12px;
208
- line-height: 16px;
207
+ font-size: var(--wpds-typography-font-size-sm, 12px);
208
+ line-height: var(--wpds-typography-line-height-xs, 16px);
209
209
  }
210
210
  .dataviews-media-field__media-thumbnail__filename__truncate {
211
211
  margin-top: 4px;
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/author/view.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAE,EACnC,IAAI,GACJ,EAAE,wBAAwB,CAAE,SAAS,CAAE,+BAsDvC"}
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/author/view.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAE,EACnC,IAAI,GACJ,EAAE,wBAAwB,CAAE,SAAS,CAAE,+BAsDvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/media-fields",
3
- "version": "0.24.0",
3
+ "version": "0.26.0",
4
4
  "description": "Reusable field definitions for displaying and editing media attachment properties in WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -46,24 +46,24 @@
46
46
  "src/**/*.scss"
47
47
  ],
48
48
  "dependencies": {
49
- "@wordpress/base-styles": "^15.0.0",
50
- "@wordpress/components": "^44.0.0",
51
- "@wordpress/compose": "^9.1.0",
52
- "@wordpress/core-data": "^9.1.0",
53
- "@wordpress/data": "^11.1.0",
54
- "@wordpress/dataviews": "^22.0.0",
55
- "@wordpress/element": "^10.1.0",
56
- "@wordpress/i18n": "^7.1.0",
57
- "@wordpress/icons": "^20.0.0",
58
- "@wordpress/ui": "^0.26.0",
59
- "@wordpress/url": "^5.1.0",
49
+ "@wordpress/base-styles": "^15.2.0",
50
+ "@wordpress/components": "^45.1.0",
51
+ "@wordpress/compose": "^9.3.0",
52
+ "@wordpress/core-data": "^9.3.0",
53
+ "@wordpress/data": "^11.3.0",
54
+ "@wordpress/dataviews": "^22.2.0",
55
+ "@wordpress/element": "^10.3.0",
56
+ "@wordpress/i18n": "^7.3.0",
57
+ "@wordpress/icons": "^21.1.0",
58
+ "@wordpress/ui": "^0.28.0",
59
+ "@wordpress/url": "^5.3.0",
60
60
  "clsx": "^2.1.1"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@testing-library/dom": "^10.4.2",
64
64
  "@testing-library/jest-dom": "^7.0.1",
65
65
  "@testing-library/react": "^16.3.3",
66
- "vitest": "^5.0.5"
66
+ "vitest": "^5.1.1"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@types/react": "^18 || ^19",
@@ -82,5 +82,5 @@
82
82
  "publishConfig": {
83
83
  "access": "public"
84
84
  },
85
- "gitHead": "9b70363b9f93cff0583a1f3153738d383cf5a49e"
85
+ "gitHead": "7f19202f61aeba8f4bdce892a1a0df485ad76e2b"
86
86
  }
@@ -1,5 +1,4 @@
1
1
  import clsx from 'clsx';
2
- import { __ } from '@wordpress/i18n';
3
2
  import { useState, useCallback, useEffect } from '@wordpress/element';
4
3
  import { commentAuthorAvatar as authorIcon } from '@wordpress/icons';
5
4
  import {
@@ -52,7 +51,7 @@ export default function AuthorView( {
52
51
  <img
53
52
  ref={ imgRef }
54
53
  onLoad={ handleLoad }
55
- alt={ __( 'Author avatar' ) }
54
+ alt=""
56
55
  src={ imageUrl }
57
56
  />
58
57
  </div>
@@ -23,14 +23,17 @@ export default {
23
23
  component: DataForm,
24
24
  };
25
25
 
26
+ // Served from `storybook/static`.
27
+ const IMAGE_URL = 'landscape.svg';
28
+
26
29
  // Sample data for media fields
27
30
  const sampleMediaItem: MediaItem = {
28
31
  id: 123,
29
32
  date: '2024-01-15T10:30:00',
30
33
  date_gmt: '2024-01-15T10:30:00',
31
34
  guid: {
32
- raw: 'https://cldup.com/cXyG__fTLN.jpg',
33
- rendered: 'https://cldup.com/cXyG__fTLN.jpg',
35
+ raw: IMAGE_URL,
36
+ rendered: IMAGE_URL,
34
37
  },
35
38
  modified: '2024-01-15T10:30:00',
36
39
  modified_gmt: '2024-01-15T10:30:00',
@@ -52,7 +55,7 @@ const sampleMediaItem: MediaItem = {
52
55
  permalink_template: 'https://example.com/?attachment_id=123',
53
56
  generated_slug: 'sample-image',
54
57
  class_list: [ 'post-123', 'attachment' ],
55
- alt_text: 'A beautiful sample image',
58
+ alt_text: 'Sun above green hills',
56
59
  caption: {
57
60
  raw: 'A caption for the image',
58
61
  rendered: '<p>A caption for the image</p>\n',
@@ -62,15 +65,15 @@ const sampleMediaItem: MediaItem = {
62
65
  rendered:
63
66
  '<p>This is a detailed description of the sample image. It contains useful information about what the image depicts and its context.</p>',
64
67
  },
65
- mime_type: 'image/jpeg',
68
+ mime_type: 'image/svg+xml',
66
69
  media_type: 'image',
67
70
  post: null,
68
- source_url: 'https://cldup.com/cXyG__fTLN.jpg',
71
+ source_url: IMAGE_URL,
69
72
  media_details: {
70
- file: 'sample-image.jpg',
71
- width: 1920,
72
- height: 1080,
73
- filesize: 524288,
73
+ file: 'landscape.svg',
74
+ width: 1200,
75
+ height: 600,
76
+ filesize: 273,
74
77
  image_meta: {
75
78
  aperture: '2.8',
76
79
  credit: '',
@@ -85,24 +88,7 @@ const sampleMediaItem: MediaItem = {
85
88
  orientation: '1',
86
89
  keywords: [],
87
90
  },
88
- sizes: {
89
- thumbnail: {
90
- file: 'sample-image-150x150.jpg',
91
- width: 150,
92
- height: 150,
93
- filesize: 8192,
94
- mime_type: 'image/jpeg',
95
- source_url: 'https://cldup.com/cXyG__fTLN.jpg',
96
- },
97
- medium: {
98
- file: 'sample-image-300x169.jpg',
99
- width: 300,
100
- height: 169,
101
- filesize: 24576,
102
- mime_type: 'image/jpeg',
103
- source_url: 'https://cldup.com/cXyG__fTLN.jpg',
104
- },
105
- },
91
+ sizes: {},
106
92
  },
107
93
  missing_image_sizes: [],
108
94
  _embedded: {
@@ -262,7 +248,9 @@ const sampleMediaItemBrokenImage: MediaItem = {
262
248
  mime_type: 'image/jpeg',
263
249
  media_type: 'image',
264
250
  post: null,
265
- source_url: 'https://example.com/this-image-does-not-exist.jpg',
251
+ // Data that is not an image fails to load without a request. The data ends
252
+ // with a file name for the file name field.
253
+ source_url: 'data:image/jpeg,/this-image-does-not-exist.jpg',
266
254
  media_details: {
267
255
  file: 'broken-image.jpg',
268
256
  width: 1920,