@wordpress/media-fields 0.1.1-next.6deb34194.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +788 -0
- package/README.md +52 -0
- package/build/alt_text/index.js +51 -0
- package/build/alt_text/index.js.map +7 -0
- package/build/caption/index.js +52 -0
- package/build/caption/index.js.map +7 -0
- package/build/description/index.js +52 -0
- package/build/description/index.js.map +7 -0
- package/build/filename/index.js +50 -0
- package/build/filename/index.js.map +7 -0
- package/build/filename/view.js +43 -0
- package/build/filename/view.js.map +7 -0
- package/build/filesize/index.js +90 -0
- package/build/filesize/index.js.map +7 -0
- package/build/index.js +62 -0
- package/build/index.js.map +7 -0
- package/build/media_dimensions/index.js +45 -0
- package/build/media_dimensions/index.js.map +7 -0
- package/build/media_thumbnail/index.js +47 -0
- package/build/media_thumbnail/index.js.map +7 -0
- package/build/media_thumbnail/view.js +94 -0
- package/build/media_thumbnail/view.js.map +7 -0
- package/build/mime_type/index.js +38 -0
- package/build/mime_type/index.js.map +7 -0
- package/build/types.js +19 -0
- package/build/types.js.map +7 -0
- package/build/utils/get-media-type-from-mime-type.js +60 -0
- package/build/utils/get-media-type-from-mime-type.js.map +7 -0
- package/build/utils/get-raw-content.js +42 -0
- package/build/utils/get-raw-content.js.map +7 -0
- package/build/utils/get-rendered-content.js +42 -0
- package/build/utils/get-rendered-content.js.map +7 -0
- package/build-module/alt_text/index.js +30 -0
- package/build-module/alt_text/index.js.map +7 -0
- package/build-module/caption/index.js +31 -0
- package/build-module/caption/index.js.map +7 -0
- package/build-module/description/index.js +31 -0
- package/build-module/description/index.js.map +7 -0
- package/build-module/filename/index.js +19 -0
- package/build-module/filename/index.js.map +7 -0
- package/build-module/filename/view.js +25 -0
- package/build-module/filename/view.js.map +7 -0
- package/build-module/filesize/index.js +69 -0
- package/build-module/filesize/index.js.map +7 -0
- package/build-module/index.js +20 -0
- package/build-module/index.js.map +7 -0
- package/build-module/media_dimensions/index.js +24 -0
- package/build-module/media_dimensions/index.js.map +7 -0
- package/build-module/media_thumbnail/index.js +16 -0
- package/build-module/media_thumbnail/index.js.map +7 -0
- package/build-module/media_thumbnail/view.js +77 -0
- package/build-module/media_thumbnail/view.js.map +7 -0
- package/build-module/mime_type/index.js +17 -0
- package/build-module/mime_type/index.js.map +7 -0
- package/build-module/types.js +1 -0
- package/build-module/types.js.map +7 -0
- package/build-module/utils/get-media-type-from-mime-type.js +35 -0
- package/build-module/utils/get-media-type-from-mime-type.js.map +7 -0
- package/build-module/utils/get-raw-content.js +17 -0
- package/build-module/utils/get-raw-content.js.map +7 -0
- package/build-module/utils/get-rendered-content.js +17 -0
- package/build-module/utils/get-rendered-content.js.map +7 -0
- package/build-style/style-rtl.css +130 -0
- package/build-style/style.css +130 -0
- package/build-types/alt_text/index.d.ts +5 -0
- package/build-types/alt_text/index.d.ts.map +1 -0
- package/build-types/caption/index.d.ts +5 -0
- package/build-types/caption/index.d.ts.map +1 -0
- package/build-types/description/index.d.ts +5 -0
- package/build-types/description/index.d.ts.map +1 -0
- package/build-types/filename/index.d.ts +8 -0
- package/build-types/filename/index.d.ts.map +1 -0
- package/build-types/filename/view.d.ts +7 -0
- package/build-types/filename/view.d.ts.map +1 -0
- package/build-types/filesize/index.d.ts +8 -0
- package/build-types/filesize/index.d.ts.map +1 -0
- package/build-types/index.d.ts +10 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/media_dimensions/index.d.ts +5 -0
- package/build-types/media_dimensions/index.d.ts.map +1 -0
- package/build-types/media_thumbnail/index.d.ts +8 -0
- package/build-types/media_thumbnail/index.d.ts.map +1 -0
- package/build-types/media_thumbnail/view.d.ts +4 -0
- package/build-types/media_thumbnail/view.d.ts.map +1 -0
- package/build-types/mime_type/index.d.ts +5 -0
- package/build-types/mime_type/index.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts +25 -0
- package/build-types/stories/index.story.d.ts.map +1 -0
- package/build-types/types.d.ts +18 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/get-media-type-from-mime-type.d.ts +18 -0
- package/build-types/utils/get-media-type-from-mime-type.d.ts.map +1 -0
- package/build-types/utils/get-raw-content.d.ts +17 -0
- package/build-types/utils/get-raw-content.d.ts.map +1 -0
- package/build-types/utils/get-rendered-content.d.ts +17 -0
- package/build-types/utils/get-rendered-content.d.ts.map +1 -0
- package/package.json +61 -0
- package/src/alt_text/index.tsx +30 -0
- package/src/caption/index.tsx +35 -0
- package/src/description/index.tsx +37 -0
- package/src/filename/index.ts +26 -0
- package/src/filename/view.tsx +39 -0
- package/src/filesize/index.tsx +96 -0
- package/src/index.ts +15 -0
- package/src/media_dimensions/index.ts +29 -0
- package/src/media_thumbnail/index.tsx +22 -0
- package/src/media_thumbnail/style.scss +49 -0
- package/src/media_thumbnail/view.tsx +104 -0
- package/src/mime_type/index.ts +19 -0
- package/src/stories/index.story.tsx +290 -0
- package/src/style.scss +1 -0
- package/src/types.ts +24 -0
- package/src/utils/get-media-type-from-mime-type.ts +54 -0
- package/src/utils/get-raw-content.ts +32 -0
- package/src/utils/get-rendered-content.ts +32 -0
- package/tsconfig.json +31 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-fields/src/media_thumbnail/view.tsx
|
|
21
|
+
var view_exports = {};
|
|
22
|
+
__export(view_exports, {
|
|
23
|
+
default: () => MediaThumbnailView
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(view_exports);
|
|
26
|
+
var import_data = require("@wordpress/data");
|
|
27
|
+
var import_core_data = require("@wordpress/core-data");
|
|
28
|
+
var import_components = require("@wordpress/components");
|
|
29
|
+
var import_url = require("@wordpress/url");
|
|
30
|
+
var import_get_media_type_from_mime_type = require("../utils/get-media-type-from-mime-type");
|
|
31
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
32
|
+
function MediaThumbnailView({
|
|
33
|
+
item,
|
|
34
|
+
config
|
|
35
|
+
}) {
|
|
36
|
+
const _featuredMedia = (0, import_data.useSelect)(
|
|
37
|
+
(select) => {
|
|
38
|
+
if (!item.featured_media) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return select(import_core_data.store).getEntityRecord(
|
|
42
|
+
"postType",
|
|
43
|
+
"attachment",
|
|
44
|
+
item.featured_media
|
|
45
|
+
);
|
|
46
|
+
},
|
|
47
|
+
[item.featured_media]
|
|
48
|
+
);
|
|
49
|
+
const featuredMedia = item.featured_media ? _featuredMedia : item;
|
|
50
|
+
if (!featuredMedia) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const filename = (0, import_url.getFilename)(featuredMedia.source_url || "");
|
|
54
|
+
if (
|
|
55
|
+
// Ensure the featured media is an image.
|
|
56
|
+
(0, import_get_media_type_from_mime_type.getMediaTypeFromMimeType)(featuredMedia.mime_type).type === "image"
|
|
57
|
+
) {
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
59
|
+
"img",
|
|
60
|
+
{
|
|
61
|
+
className: "dataviews-media-field__media-thumbnail--image",
|
|
62
|
+
src: featuredMedia.source_url,
|
|
63
|
+
srcSet: featuredMedia?.media_details?.sizes ? Object.values(
|
|
64
|
+
featuredMedia.media_details.sizes
|
|
65
|
+
).map(
|
|
66
|
+
(size) => `${size.source_url} ${size.width}w`
|
|
67
|
+
).join(", ") : void 0,
|
|
68
|
+
sizes: config?.sizes || "100vw",
|
|
69
|
+
alt: featuredMedia.alt_text || featuredMedia.title.raw
|
|
70
|
+
}
|
|
71
|
+
) });
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataviews-media-field__media-thumbnail", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
74
|
+
import_components.__experimentalVStack,
|
|
75
|
+
{
|
|
76
|
+
justify: "center",
|
|
77
|
+
alignment: "center",
|
|
78
|
+
className: "dataviews-media-field__media-thumbnail__stack",
|
|
79
|
+
spacing: 0,
|
|
80
|
+
children: [
|
|
81
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
82
|
+
import_components.Icon,
|
|
83
|
+
{
|
|
84
|
+
className: "dataviews-media-field__media-thumbnail--icon",
|
|
85
|
+
icon: (0, import_get_media_type_from_mime_type.getMediaTypeFromMimeType)(item.mime_type).icon,
|
|
86
|
+
size: 24
|
|
87
|
+
}
|
|
88
|
+
),
|
|
89
|
+
!!filename && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dataviews-media-field__media-thumbnail__filename", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalTruncate, { className: "dataviews-media-field__media-thumbnail__filename__truncate", children: filename }) })
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
) });
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/media_thumbnail/view.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\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,\n} from '@wordpress/components';\nimport type { Attachment } from '@wordpress/core-data';\nimport { getFilename } from '@wordpress/url';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\n/**\n * Internal dependencies\n */\nimport { getMediaTypeFromMimeType } from '../utils/get-media-type-from-mime-type';\nimport type { MediaItem } from '../types';\n\nexport default function MediaThumbnailView( {\n\titem,\n\tconfig,\n}: DataViewRenderFieldProps< MediaItem > ) {\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< Attachment >(\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\tif (\n\t\t// Ensure the featured media is an image.\n\t\tgetMediaTypeFromMimeType( featuredMedia.mime_type ).type === 'image'\n\t) {\n\t\treturn (\n\t\t\t<div className=\"dataviews-media-field__media-thumbnail\">\n\t\t\t\t<img\n\t\t\t\t\tclassName=\"dataviews-media-field__media-thumbnail--image\"\n\t\t\t\t\tsrc={ featuredMedia.source_url }\n\t\t\t\t\tsrcSet={\n\t\t\t\t\t\tfeaturedMedia?.media_details?.sizes\n\t\t\t\t\t\t\t? (\n\t\t\t\t\t\t\t\t\tObject.values(\n\t\t\t\t\t\t\t\t\t\tfeaturedMedia.media_details.sizes\n\t\t\t\t\t\t\t\t\t) as Array< {\n\t\t\t\t\t\t\t\t\t\tsource_url: string;\n\t\t\t\t\t\t\t\t\t\twidth: number;\n\t\t\t\t\t\t\t\t\t} >\n\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t\t\t\t( size ) =>\n\t\t\t\t\t\t\t\t\t\t\t`${ size.source_url } ${ size.width }w`\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t.join( ', ' )\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tsizes={ config?.sizes || '100vw' }\n\t\t\t\t\talt={ featuredMedia.alt_text || featuredMedia.title.raw }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\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<Icon\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA0B;AAC1B,uBAAmC;AACnC,wBAIO;AAEP,iBAA4B;AAK5B,2CAAyC;AAqCrC;AAlCW,SAAR,mBAAqC;AAAA,EAC3C;AAAA,EACA;AACD,GAA2C;AAC1C,QAAM,qBAAiB;AAAA,IACtB,CAAE,WAAY;AAGb,UAAK,CAAE,KAAK,gBAAiB;AAC5B;AAAA,MACD;AACA,aAAO,OAAQ,iBAAAA,KAAU,EAAE;AAAA,QAC1B;AAAA,QACA;AAAA,QACA,KAAK;AAAA,MACN;AAAA,IACD;AAAA,IACA,CAAE,KAAK,cAAe;AAAA,EACvB;AACA,QAAM,gBAAgB,KAAK,iBAAiB,iBAAiB;AAG7D,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AAEA,QAAM,eAAW,wBAAa,cAAc,cAAc,EAAG;AAE7D;AAAA;AAAA,QAEC,+DAA0B,cAAc,SAAU,EAAE,SAAS;AAAA,IAC5D;AACD,WACC,4CAAC,SAAI,WAAU,0CACd;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,KAAM,cAAc;AAAA,QACpB,QACC,eAAe,eAAe,QAE3B,OAAO;AAAA,UACN,cAAc,cAAc;AAAA,QAC7B,EAKC;AAAA,UACA,CAAE,SACD,GAAI,KAAK,UAAW,IAAK,KAAK,KAAM;AAAA,QACtC,EACC,KAAM,IAAK,IACZ;AAAA,QAEJ,OAAQ,QAAQ,SAAS;AAAA,QACzB,KAAM,cAAc,YAAY,cAAc,MAAM;AAAA;AAAA,IACrD,GACD;AAAA,EAEF;AAEA,SACC,4CAAC,SAAI,WAAU,0CACd;AAAA,IAAC,kBAAAC;AAAA,IAAA;AAAA,MACA,SAAQ;AAAA,MACR,WAAU;AAAA,MACV,WAAU;AAAA,MACV,SAAU;AAAA,MAEV;AAAA;AAAA,UAAC;AAAA;AAAA,YACA,WAAU;AAAA,YACV,UAAO,+DAA0B,KAAK,SAAU,EAAE;AAAA,YAClD,MAAO;AAAA;AAAA,QACR;AAAA,QACE,CAAC,CAAE,YACJ,4CAAC,SAAI,WAAU,oDACd,sDAAC,kBAAAC,wBAAA,EAAS,WAAU,8DACjB,oBACH,GACD;AAAA;AAAA;AAAA,EAEF,GACD;AAEF;",
|
|
6
|
+
"names": ["coreStore", "VStack", "Truncate"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-fields/src/mime_type/index.ts
|
|
21
|
+
var mime_type_exports = {};
|
|
22
|
+
__export(mime_type_exports, {
|
|
23
|
+
default: () => mime_type_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(mime_type_exports);
|
|
26
|
+
var import_i18n = require("@wordpress/i18n");
|
|
27
|
+
var mimeTypeField = {
|
|
28
|
+
id: "mime_type",
|
|
29
|
+
type: "text",
|
|
30
|
+
label: (0, import_i18n.__)("File type"),
|
|
31
|
+
getValue: ({ item }) => item?.mime_type || "",
|
|
32
|
+
render: ({ item }) => item?.mime_type || "-",
|
|
33
|
+
enableSorting: true,
|
|
34
|
+
filterBy: false,
|
|
35
|
+
readOnly: true
|
|
36
|
+
};
|
|
37
|
+
var mime_type_default = mimeTypeField;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/mime_type/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\nconst mimeTypeField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'mime_type',\n\ttype: 'text',\n\tlabel: __( 'File type' ),\n\tgetValue: ( { item } ) => item?.mime_type || '',\n\trender: ( { item } ) => item?.mime_type || '-',\n\tenableSorting: true,\n\tfilterBy: false,\n\treadOnly: true,\n};\n\nexport default mimeTypeField;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AAInB,IAAM,gBAA6D;AAAA,EAClE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,WAAY;AAAA,EACvB,UAAU,CAAE,EAAE,KAAK,MAAO,MAAM,aAAa;AAAA,EAC7C,QAAQ,CAAE,EAAE,KAAK,MAAO,MAAM,aAAa;AAAA,EAC3C,eAAe;AAAA,EACf,UAAU;AAAA,EACV,UAAU;AACX;AAEA,IAAO,oBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/types.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// packages/media-fields/src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/types.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Attachment, Updatable, Post } from '@wordpress/core-data';\n\nexport type MediaKind = 'image' | 'video' | 'audio' | 'application';\n\nexport interface MediaType {\n\ttype: MediaKind;\n\tlabel: string;\n\ticon: JSX.Element;\n}\n\n// TODO: Update the Attachment type separately.\nexport interface MediaItem extends Attachment< 'edit' > {\n\t// featured_media is not in the Attachment type. See https://github.com/WordPress/gutenberg/blob/trunk/packages/core-data/src/entity-types/attachment.ts#L10\n\tfeatured_media: number;\n\t_embedded?: {\n\t\t// TODO: Include wp:attached-to properly, and backport PHP changes from wordpress-develop to support this.\n\t\t'wp:attached-to'?: Post[] | Partial< Post >[];\n\t};\n}\n\nexport type MediaItemUpdatable = Updatable< Attachment >;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-fields/src/utils/get-media-type-from-mime-type.ts
|
|
21
|
+
var get_media_type_from_mime_type_exports = {};
|
|
22
|
+
__export(get_media_type_from_mime_type_exports, {
|
|
23
|
+
getMediaTypeFromMimeType: () => getMediaTypeFromMimeType
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_media_type_from_mime_type_exports);
|
|
26
|
+
var import_i18n = require("@wordpress/i18n");
|
|
27
|
+
var import_icons = require("@wordpress/icons");
|
|
28
|
+
function getMediaTypeFromMimeType(mimeType) {
|
|
29
|
+
if (mimeType.startsWith("image/")) {
|
|
30
|
+
return {
|
|
31
|
+
type: "image",
|
|
32
|
+
label: (0, import_i18n.__)("Image"),
|
|
33
|
+
icon: import_icons.image
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (mimeType.startsWith("video/")) {
|
|
37
|
+
return {
|
|
38
|
+
type: "video",
|
|
39
|
+
label: (0, import_i18n.__)("Video"),
|
|
40
|
+
icon: import_icons.video
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (mimeType.startsWith("audio/")) {
|
|
44
|
+
return {
|
|
45
|
+
type: "audio",
|
|
46
|
+
label: (0, import_i18n.__)("Audio"),
|
|
47
|
+
icon: import_icons.audio
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
type: "application",
|
|
52
|
+
label: (0, import_i18n.__)("Application"),
|
|
53
|
+
icon: import_icons.file
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
getMediaTypeFromMimeType
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=get-media-type-from-mime-type.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/get-media-type-from-mime-type.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { audio, video, image, file } from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport type { MediaType } from '../types';\n\n/**\n * Get the media type from a mime type, including an icon.\n * TODO - media types should be formalized somewhere.\n *\n * References:\n * https://developer.wordpress.org/reference/functions/wp_mime_type_icon/\n * https://developer.wordpress.org/reference/hooks/mime_types/\n * https://developer.wordpress.org/reference/functions/wp_get_mime_types/\n *\n * @param mimeType - The mime type to get the media type from.\n * @return The media type.\n */\nexport function getMediaTypeFromMimeType( mimeType: string ): MediaType {\n\tif ( mimeType.startsWith( 'image/' ) ) {\n\t\treturn {\n\t\t\ttype: 'image',\n\t\t\tlabel: __( 'Image' ),\n\t\t\ticon: image,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'video/' ) ) {\n\t\treturn {\n\t\t\ttype: 'video',\n\t\t\tlabel: __( 'Video' ),\n\t\t\ticon: video,\n\t\t};\n\t}\n\n\tif ( mimeType.startsWith( 'audio/' ) ) {\n\t\treturn {\n\t\t\ttype: 'audio',\n\t\t\tlabel: __( 'Audio' ),\n\t\t\ticon: audio,\n\t\t};\n\t}\n\n\treturn {\n\t\ttype: 'application',\n\t\tlabel: __( 'Application' ),\n\t\ticon: file,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAmB;AACnB,mBAA0C;AAmBnC,SAAS,yBAA0B,UAA8B;AACvE,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,MAAK,SAAS,WAAY,QAAS,GAAI;AACtC,WAAO;AAAA,MACN,MAAM;AAAA,MACN,WAAO,gBAAI,OAAQ;AAAA,MACnB,MAAM;AAAA,IACP;AAAA,EACD;AAEA,SAAO;AAAA,IACN,MAAM;AAAA,IACN,WAAO,gBAAI,aAAc;AAAA,IACzB,MAAM;AAAA,EACP;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-fields/src/utils/get-raw-content.ts
|
|
21
|
+
var get_raw_content_exports = {};
|
|
22
|
+
__export(get_raw_content_exports, {
|
|
23
|
+
getRawContent: () => getRawContent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_raw_content_exports);
|
|
26
|
+
function getRawContent(content) {
|
|
27
|
+
if (!content) {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
if (typeof content === "string") {
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
if (typeof content === "object" && "raw" in content) {
|
|
34
|
+
return content.raw || "";
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
getRawContent
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=get-raw-content.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/get-raw-content.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Utility function to extract raw content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The raw content string, or empty string if content is falsy\n */\nexport function getRawContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' && 'raw' in content ) {\n\t\treturn content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,cACf,SACS;AACT,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,YAAY,SAAS,SAAU;AACtD,WAAO,QAAQ,OAAO;AAAA,EACvB;AAGA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// packages/media-fields/src/utils/get-rendered-content.ts
|
|
21
|
+
var get_rendered_content_exports = {};
|
|
22
|
+
__export(get_rendered_content_exports, {
|
|
23
|
+
getRenderedContent: () => getRenderedContent
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(get_rendered_content_exports);
|
|
26
|
+
function getRenderedContent(content) {
|
|
27
|
+
if (!content) {
|
|
28
|
+
return "";
|
|
29
|
+
}
|
|
30
|
+
if (typeof content === "string") {
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
if (typeof content === "object") {
|
|
34
|
+
return content.rendered || content.raw || "";
|
|
35
|
+
}
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
getRenderedContent
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=get-rendered-content.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/get-rendered-content.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Utility function to extract rendered content from either a string or an object\n * containing raw and rendered properties.\n *\n * This handles the inconsistency in WordPress REST API responses where\n * some fields like caption and description can be either:\n * - A simple string\n * - An object with { raw: string, rendered: string }\n *\n * @param content - The content to extract raw value from\n * @return The rendered content string, falling back to raw or empty string if content is falsy\n */\nexport function getRenderedContent(\n\tcontent: string | { raw: string; rendered: string } | undefined | null\n): string {\n\tif ( ! content ) {\n\t\treturn '';\n\t}\n\n\t// If it's a string, return it directly\n\tif ( typeof content === 'string' ) {\n\t\treturn content;\n\t}\n\n\t// If it's an object with raw property, return the raw value\n\tif ( typeof content === 'object' ) {\n\t\treturn content.rendered || content.raw || '';\n\t}\n\n\t// Fallback to empty string\n\treturn '';\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,SAAS,mBACf,SACS;AACT,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO;AAAA,EACR;AAGA,MAAK,OAAO,YAAY,UAAW;AAClC,WAAO,QAAQ,YAAY,QAAQ,OAAO;AAAA,EAC3C;AAGA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// packages/media-fields/src/alt_text/index.tsx
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { TextareaControl } from "@wordpress/components";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
var altTextField = {
|
|
6
|
+
id: "alt_text",
|
|
7
|
+
type: "text",
|
|
8
|
+
label: __("Alt text"),
|
|
9
|
+
isVisible: (item) => item?.media_type === "image",
|
|
10
|
+
render: ({ item }) => item?.alt_text || "-",
|
|
11
|
+
Edit: ({ field, onChange, data }) => {
|
|
12
|
+
return /* @__PURE__ */ jsx(
|
|
13
|
+
TextareaControl,
|
|
14
|
+
{
|
|
15
|
+
label: field.label,
|
|
16
|
+
value: data.alt_text || "",
|
|
17
|
+
onChange: (value) => onChange({ alt_text: value }),
|
|
18
|
+
rows: 2,
|
|
19
|
+
__nextHasNoMarginBottom: true
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
enableSorting: false,
|
|
24
|
+
filterBy: false
|
|
25
|
+
};
|
|
26
|
+
var alt_text_default = altTextField;
|
|
27
|
+
export {
|
|
28
|
+
alt_text_default as default
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/alt_text/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { TextareaControl } from '@wordpress/components';\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\tisVisible: ( item ) => item?.media_type === 'image',\n\trender: ( { item } ) => item?.alt_text || '-',\n\tEdit: ( { field, onChange, data } ) => {\n\t\treturn (\n\t\t\t<TextareaControl\n\t\t\t\tlabel={ field.label }\n\t\t\t\tvalue={ data.alt_text || '' }\n\t\t\t\tonChange={ ( value ) => onChange( { alt_text: value } ) }\n\t\t\t\trows={ 2 }\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t/>\n\t\t);\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default altTextField;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAY7B;AARH,IAAM,eAA4D;AAAA,EACjE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,UAAW;AAAA,EACtB,WAAW,CAAE,SAAU,MAAM,eAAe;AAAA,EAC5C,QAAQ,CAAE,EAAE,KAAK,MAAO,MAAM,YAAY;AAAA,EAC1C,MAAM,CAAE,EAAE,OAAO,UAAU,KAAK,MAAO;AACtC,WACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,MAAM;AAAA,QACd,OAAQ,KAAK,YAAY;AAAA,QACzB,UAAW,CAAE,UAAW,SAAU,EAAE,UAAU,MAAM,CAAE;AAAA,QACtD,MAAO;AAAA,QACP,yBAAuB;AAAA;AAAA,IACxB;AAAA,EAEF;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,mBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// packages/media-fields/src/caption/index.tsx
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { TextareaControl } from "@wordpress/components";
|
|
4
|
+
import { getRawContent } from "../utils/get-raw-content";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var captionField = {
|
|
7
|
+
id: "caption",
|
|
8
|
+
type: "text",
|
|
9
|
+
label: __("Caption"),
|
|
10
|
+
getValue: ({ item }) => getRawContent(item?.caption),
|
|
11
|
+
render: ({ item }) => getRawContent(item?.caption) || "-",
|
|
12
|
+
Edit: ({ field, onChange, data }) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
TextareaControl,
|
|
15
|
+
{
|
|
16
|
+
label: field.label,
|
|
17
|
+
value: getRawContent(data.caption) || "",
|
|
18
|
+
onChange: (value) => onChange({ caption: value }),
|
|
19
|
+
rows: 2,
|
|
20
|
+
__nextHasNoMarginBottom: true
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
enableSorting: false,
|
|
25
|
+
filterBy: false
|
|
26
|
+
};
|
|
27
|
+
var caption_default = captionField;
|
|
28
|
+
export {
|
|
29
|
+
caption_default as default
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/caption/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { TextareaControl } from '@wordpress/components';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getRawContent } from '../utils/get-raw-content';\n\nconst captionField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'caption',\n\ttype: 'text',\n\tlabel: __( 'Caption' ),\n\tgetValue: ( { item } ) => getRawContent( item?.caption ),\n\trender: ( { item } ) => getRawContent( item?.caption ) || '-',\n\tEdit: ( { field, onChange, data } ) => {\n\t\treturn (\n\t\t\t<TextareaControl\n\t\t\t\tlabel={ field.label }\n\t\t\t\tvalue={ getRawContent( data.caption ) || '' }\n\t\t\t\tonChange={ ( value ) => onChange( { caption: value } ) }\n\t\t\t\trows={ 2 }\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t/>\n\t\t);\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default captionField;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAOhC,SAAS,qBAAqB;AAU3B;AARH,IAAM,eAA4D;AAAA,EACjE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,SAAU;AAAA,EACrB,UAAU,CAAE,EAAE,KAAK,MAAO,cAAe,MAAM,OAAQ;AAAA,EACvD,QAAQ,CAAE,EAAE,KAAK,MAAO,cAAe,MAAM,OAAQ,KAAK;AAAA,EAC1D,MAAM,CAAE,EAAE,OAAO,UAAU,KAAK,MAAO;AACtC,WACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,MAAM;AAAA,QACd,OAAQ,cAAe,KAAK,OAAQ,KAAK;AAAA,QACzC,UAAW,CAAE,UAAW,SAAU,EAAE,SAAS,MAAM,CAAE;AAAA,QACrD,MAAO;AAAA,QACP,yBAAuB;AAAA;AAAA,IACxB;AAAA,EAEF;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// packages/media-fields/src/description/index.tsx
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { TextareaControl } from "@wordpress/components";
|
|
4
|
+
import { getRawContent } from "../utils/get-raw-content";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
var descriptionField = {
|
|
7
|
+
id: "description",
|
|
8
|
+
type: "text",
|
|
9
|
+
label: __("Description"),
|
|
10
|
+
getValue: ({ item }) => getRawContent(item?.description),
|
|
11
|
+
render: ({ item }) => /* @__PURE__ */ jsx("div", { children: getRawContent(item?.description) || "-" }),
|
|
12
|
+
Edit: ({ field, onChange, data }) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
TextareaControl,
|
|
15
|
+
{
|
|
16
|
+
label: field.label,
|
|
17
|
+
value: getRawContent(data.description) || "",
|
|
18
|
+
onChange: (value) => onChange({ description: value }),
|
|
19
|
+
rows: 5,
|
|
20
|
+
__nextHasNoMarginBottom: true
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
enableSorting: false,
|
|
25
|
+
filterBy: false
|
|
26
|
+
};
|
|
27
|
+
var description_default = descriptionField;
|
|
28
|
+
export {
|
|
29
|
+
description_default as default
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/description/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { TextareaControl } from '@wordpress/components';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\nimport { getRawContent } from '../utils/get-raw-content';\n\nconst descriptionField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'description',\n\ttype: 'text',\n\tlabel: __( 'Description' ),\n\tgetValue: ( { item } ) => getRawContent( item?.description ),\n\trender: ( { item } ) => (\n\t\t<div>{ getRawContent( item?.description ) || '-' }</div>\n\t),\n\tEdit: ( { field, onChange, data } ) => {\n\t\treturn (\n\t\t\t<TextareaControl\n\t\t\t\tlabel={ field.label }\n\t\t\t\tvalue={ getRawContent( data.description ) || '' }\n\t\t\t\tonChange={ ( value ) => onChange( { description: value } ) }\n\t\t\t\trows={ 5 }\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t/>\n\t\t);\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default descriptionField;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,uBAAuB;AAOhC,SAAS,qBAAqB;AAQ5B;AANF,IAAM,mBAAgE;AAAA,EACrE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,aAAc;AAAA,EACzB,UAAU,CAAE,EAAE,KAAK,MAAO,cAAe,MAAM,WAAY;AAAA,EAC3D,QAAQ,CAAE,EAAE,KAAK,MAChB,oBAAC,SAAM,wBAAe,MAAM,WAAY,KAAK,KAAK;AAAA,EAEnD,MAAM,CAAE,EAAE,OAAO,UAAU,KAAK,MAAO;AACtC,WACC;AAAA,MAAC;AAAA;AAAA,QACA,OAAQ,MAAM;AAAA,QACd,OAAQ,cAAe,KAAK,WAAY,KAAK;AAAA,QAC7C,UAAW,CAAE,UAAW,SAAU,EAAE,aAAa,MAAM,CAAE;AAAA,QACzD,MAAO;AAAA,QACP,yBAAuB;AAAA;AAAA,IACxB;AAAA,EAEF;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// packages/media-fields/src/filename/index.ts
|
|
2
|
+
import { __ } from "@wordpress/i18n";
|
|
3
|
+
import { getFilename } from "@wordpress/url";
|
|
4
|
+
import FileNameView from "./view";
|
|
5
|
+
var filenameField = {
|
|
6
|
+
id: "filename",
|
|
7
|
+
type: "text",
|
|
8
|
+
label: __("File name"),
|
|
9
|
+
getValue: ({ item }) => getFilename(item?.source_url || ""),
|
|
10
|
+
render: FileNameView,
|
|
11
|
+
enableSorting: false,
|
|
12
|
+
filterBy: false,
|
|
13
|
+
readOnly: true
|
|
14
|
+
};
|
|
15
|
+
var filename_default = filenameField;
|
|
16
|
+
export {
|
|
17
|
+
filename_default as default
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/filename/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { getFilename } from '@wordpress/url';\nimport type { Field } from '@wordpress/dataviews';\n\n/**\n * Internal dependencies\n */\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"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,UAAU;AACnB,SAAS,mBAAmB;AAO5B,OAAO,kBAAkB;AAEzB,IAAM,gBAA+C;AAAA,EACpD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,WAAY;AAAA,EACvB,UAAU,CAAE,EAAE,KAAK,MAClB,YAAa,MAAM,cAAc,EAAG;AAAA,EACrC,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,UAAU;AAAA,EACV,UAAU;AACX;AAEA,IAAO,mBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// packages/media-fields/src/filename/view.tsx
|
|
2
|
+
import {
|
|
3
|
+
Tooltip,
|
|
4
|
+
__experimentalTruncate as Truncate
|
|
5
|
+
} from "@wordpress/components";
|
|
6
|
+
import { useMemo } from "@wordpress/element";
|
|
7
|
+
import { getFilename } from "@wordpress/url";
|
|
8
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
9
|
+
var TRUNCATE_LENGTH = 15;
|
|
10
|
+
function FileNameView({
|
|
11
|
+
item
|
|
12
|
+
}) {
|
|
13
|
+
const fileName = useMemo(
|
|
14
|
+
() => item?.source_url ? getFilename(item.source_url) : null,
|
|
15
|
+
[item?.source_url]
|
|
16
|
+
);
|
|
17
|
+
if (!fileName) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
return fileName.length > TRUNCATE_LENGTH ? /* @__PURE__ */ jsx(Tooltip, { text: fileName, children: /* @__PURE__ */ jsx(Truncate, { children: fileName }) }) : /* @__PURE__ */ jsx(Fragment, { children: fileName });
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
FileNameView as default
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/filename/view.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {\n\tTooltip,\n\t__experimentalTruncate as Truncate,\n} from '@wordpress/components';\nimport { useMemo } from '@wordpress/element';\nimport { getFilename } from '@wordpress/url';\nimport type { DataViewRenderFieldProps } from '@wordpress/dataviews';\n/**\n * Internal dependencies\n */\nimport type { MediaItem } from '../types';\n\n// Hard-coded truncate length to match the available area in the media sidebar.\n// Longer file names will be truncated and wrapped in a tooltip showing the full name.\nconst TRUNCATE_LENGTH = 15;\n\nexport default function FileNameView( {\n\titem,\n}: DataViewRenderFieldProps< MediaItem > ) {\n\tconst fileName = useMemo(\n\t\t() => ( item?.source_url ? getFilename( item.source_url ) : null ),\n\t\t[ item?.source_url ]\n\t);\n\n\tif ( ! fileName ) {\n\t\treturn '';\n\t}\n\n\treturn fileName.length > TRUNCATE_LENGTH ? (\n\t\t<Tooltip text={ fileName }>\n\t\t\t<Truncate>{ fileName }</Truncate>\n\t\t</Tooltip>\n\t) : (\n\t\t<>{ fileName }</>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA;AAAA,EACC;AAAA,EACA,0BAA0B;AAAA,OACpB;AACP,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAyBzB,SAGD,UAHC;AAhBH,IAAM,kBAAkB;AAET,SAAR,aAA+B;AAAA,EACrC;AACD,GAA2C;AAC1C,QAAM,WAAW;AAAA,IAChB,MAAQ,MAAM,aAAa,YAAa,KAAK,UAAW,IAAI;AAAA,IAC5D,CAAE,MAAM,UAAW;AAAA,EACpB;AAEA,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,SAAO,SAAS,SAAS,kBACxB,oBAAC,WAAQ,MAAO,UACf,8BAAC,YAAW,oBAAU,GACvB,IAEA,gCAAI,oBAAU;AAEhB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// packages/media-fields/src/filesize/index.tsx
|
|
2
|
+
import { __, sprintf, _x } from "@wordpress/i18n";
|
|
3
|
+
var KB_IN_BYTES = 1024;
|
|
4
|
+
var MB_IN_BYTES = 1024 * KB_IN_BYTES;
|
|
5
|
+
var GB_IN_BYTES = 1024 * MB_IN_BYTES;
|
|
6
|
+
var TB_IN_BYTES = 1024 * GB_IN_BYTES;
|
|
7
|
+
var PB_IN_BYTES = 1024 * TB_IN_BYTES;
|
|
8
|
+
var EB_IN_BYTES = 1024 * PB_IN_BYTES;
|
|
9
|
+
var ZB_IN_BYTES = 1024 * EB_IN_BYTES;
|
|
10
|
+
var YB_IN_BYTES = 1024 * ZB_IN_BYTES;
|
|
11
|
+
function getBytesString(bytes, unitSymbol, decimals = 2) {
|
|
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
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function formatFileSize(bytes, decimals = 2) {
|
|
23
|
+
if (bytes === 0) {
|
|
24
|
+
return getBytesString(0, _x("B", "unit symbol"), decimals);
|
|
25
|
+
}
|
|
26
|
+
const quant = {
|
|
27
|
+
/* translators: Unit symbol for yottabyte. */
|
|
28
|
+
[_x("YB", "unit symbol")]: YB_IN_BYTES,
|
|
29
|
+
/* translators: Unit symbol for zettabyte. */
|
|
30
|
+
[_x("ZB", "unit symbol")]: ZB_IN_BYTES,
|
|
31
|
+
/* translators: Unit symbol for exabyte. */
|
|
32
|
+
[_x("EB", "unit symbol")]: EB_IN_BYTES,
|
|
33
|
+
/* translators: Unit symbol for petabyte. */
|
|
34
|
+
[_x("PB", "unit symbol")]: PB_IN_BYTES,
|
|
35
|
+
/* translators: Unit symbol for terabyte. */
|
|
36
|
+
[_x("TB", "unit symbol")]: TB_IN_BYTES,
|
|
37
|
+
/* translators: Unit symbol for gigabyte. */
|
|
38
|
+
[_x("GB", "unit symbol")]: GB_IN_BYTES,
|
|
39
|
+
/* translators: Unit symbol for megabyte. */
|
|
40
|
+
[_x("MB", "unit symbol")]: MB_IN_BYTES,
|
|
41
|
+
/* translators: Unit symbol for kilobyte. */
|
|
42
|
+
[_x("KB", "unit symbol")]: KB_IN_BYTES,
|
|
43
|
+
/* translators: Unit symbol for byte. */
|
|
44
|
+
[_x("B", "unit symbol")]: 1
|
|
45
|
+
};
|
|
46
|
+
for (const [unit, mag] of Object.entries(quant)) {
|
|
47
|
+
if (bytes >= mag) {
|
|
48
|
+
return getBytesString(bytes / mag, unit, decimals);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
var filesizeField = {
|
|
54
|
+
id: "filesize",
|
|
55
|
+
type: "text",
|
|
56
|
+
label: __("File size"),
|
|
57
|
+
getValue: ({ item }) => item?.media_details?.filesize ? formatFileSize(item?.media_details?.filesize) : "",
|
|
58
|
+
isVisible: (item) => {
|
|
59
|
+
return !!item?.media_details?.filesize;
|
|
60
|
+
},
|
|
61
|
+
enableSorting: false,
|
|
62
|
+
filterBy: false,
|
|
63
|
+
readOnly: true
|
|
64
|
+
};
|
|
65
|
+
var filesize_default = filesizeField;
|
|
66
|
+
export {
|
|
67
|
+
filesize_default as default
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=index.js.map
|