@wordpress/media-fields 0.23.0 → 0.25.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 (91) hide show
  1. package/build/alt_text/index.cjs +31 -57
  2. package/build/alt_text/index.cjs.map +1 -7
  3. package/build/attached_to/edit.cjs +98 -133
  4. package/build/attached_to/edit.cjs.map +1 -7
  5. package/build/attached_to/index.cjs +33 -38
  6. package/build/attached_to/index.cjs.map +1 -7
  7. package/build/attached_to/view.cjs +25 -46
  8. package/build/attached_to/view.cjs.map +1 -7
  9. package/build/author/index.cjs +43 -56
  10. package/build/author/index.cjs.map +1 -7
  11. package/build/author/view.cjs +67 -74
  12. package/build/author/view.cjs.map +1 -7
  13. package/build/caption/index.cjs +21 -39
  14. package/build/caption/index.cjs.map +1 -7
  15. package/build/date_added/index.cjs +13 -34
  16. package/build/date_added/index.cjs.map +1 -7
  17. package/build/date_modified/index.cjs +13 -34
  18. package/build/date_modified/index.cjs.map +1 -7
  19. package/build/description/index.cjs +22 -40
  20. package/build/description/index.cjs.map +1 -7
  21. package/build/filename/index.cjs +33 -39
  22. package/build/filename/index.cjs.map +1 -7
  23. package/build/filename/view.cjs +23 -51
  24. package/build/filename/view.cjs.map +1 -7
  25. package/build/filesize/index.cjs +54 -83
  26. package/build/filesize/index.cjs.map +1 -7
  27. package/build/index.cjs +111 -63
  28. package/build/media_dimensions/index.cjs +19 -42
  29. package/build/media_dimensions/index.cjs.map +1 -7
  30. package/build/media_thumbnail/index.cjs +30 -36
  31. package/build/media_thumbnail/index.cjs.map +1 -7
  32. package/build/media_thumbnail/view.cjs +117 -162
  33. package/build/media_thumbnail/view.cjs.map +1 -7
  34. package/build/mime_type/index.cjs +16 -37
  35. package/build/mime_type/index.cjs.map +1 -7
  36. package/build/types.cjs +4 -18
  37. package/build/utils/get-media-type-from-mime-type.cjs +41 -56
  38. package/build/utils/get-media-type-from-mime-type.cjs.map +1 -7
  39. package/build/utils/get-raw-content.cjs +23 -38
  40. package/build/utils/get-raw-content.cjs.map +1 -7
  41. package/build/utils/get-rendered-content.cjs +23 -38
  42. package/build/utils/get-rendered-content.cjs.map +1 -7
  43. package/build-module/alt_text/index.mjs +25 -35
  44. package/build-module/alt_text/index.mjs.map +1 -7
  45. package/build-module/attached_to/edit.mjs +88 -110
  46. package/build-module/attached_to/edit.mjs.map +1 -7
  47. package/build-module/attached_to/index.mjs +12 -14
  48. package/build-module/attached_to/index.mjs.map +1 -7
  49. package/build-module/attached_to/view.mjs +19 -24
  50. package/build-module/attached_to/view.mjs.map +1 -7
  51. package/build-module/author/index.mjs +23 -32
  52. package/build-module/author/index.mjs.map +1 -7
  53. package/build-module/author/view.mjs +47 -53
  54. package/build-module/author/view.mjs.map +1 -7
  55. package/build-module/caption/index.mjs +16 -18
  56. package/build-module/caption/index.mjs.map +1 -7
  57. package/build-module/date_added/index.mjs +10 -14
  58. package/build-module/date_added/index.mjs.map +1 -7
  59. package/build-module/date_modified/index.mjs +10 -14
  60. package/build-module/date_modified/index.mjs.map +1 -7
  61. package/build-module/description/index.mjs +16 -18
  62. package/build-module/description/index.mjs.map +1 -7
  63. package/build-module/filename/index.mjs +13 -15
  64. package/build-module/filename/index.mjs.map +1 -7
  65. package/build-module/filename/view.mjs +16 -28
  66. package/build-module/filename/view.mjs.map +1 -7
  67. package/build-module/filesize/index.mjs +50 -63
  68. package/build-module/filesize/index.mjs.map +1 -7
  69. package/build-module/index.mjs +13 -28
  70. package/build-module/media_dimensions/index.mjs +15 -22
  71. package/build-module/media_dimensions/index.mjs.map +1 -7
  72. package/build-module/media_thumbnail/index.mjs +11 -13
  73. package/build-module/media_thumbnail/index.mjs.map +1 -7
  74. package/build-module/media_thumbnail/view.mjs +94 -136
  75. package/build-module/media_thumbnail/view.mjs.map +1 -7
  76. package/build-module/mime_type/index.mjs +13 -17
  77. package/build-module/mime_type/index.mjs.map +1 -7
  78. package/build-module/types.mjs +0 -1
  79. package/build-module/utils/get-media-type-from-mime-type.mjs +37 -32
  80. package/build-module/utils/get-media-type-from-mime-type.mjs.map +1 -7
  81. package/build-module/utils/get-raw-content.mjs +19 -14
  82. package/build-module/utils/get-raw-content.mjs.map +1 -7
  83. package/build-module/utils/get-rendered-content.mjs +19 -14
  84. package/build-module/utils/get-rendered-content.mjs.map +1 -7
  85. package/build-style/style-rtl.css +3 -3
  86. package/build-style/style.css +3 -3
  87. package/package.json +14 -14
  88. package/build/index.cjs.map +0 -7
  89. package/build/types.cjs.map +0 -7
  90. package/build-module/index.mjs.map +0 -7
  91. package/build-module/types.mjs.map +0 -7
@@ -1,60 +1,34 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-fields/src/alt_text/index.tsx
21
- var alt_text_exports = {};
22
- __export(alt_text_exports, {
23
- default: () => alt_text_default
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(alt_text_exports);
26
- var import_i18n = require("@wordpress/i18n");
27
- var import_ui = require("@wordpress/ui");
28
- var import_jsx_runtime = require("react/jsx-runtime");
29
- var altTextField = {
30
- id: "alt_text",
31
- type: "text",
32
- label: (0, import_i18n.__)("Alt text"),
33
- description: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
34
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
35
- import_ui.Link,
36
- {
37
- href: (
38
- // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.
39
- (0, import_i18n.__)(
40
- "https://www.w3.org/WAI/tutorials/images/decision-tree/"
41
- )
42
- ),
43
- openInNewTab: true,
44
- children: (0, import_i18n.__)("Describe the purpose of the image.")
45
- }
46
- ),
47
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
48
- (0, import_i18n.__)("Leave empty if decorative.")
49
- ] }),
50
- isVisible: (item) => item?.media_type === "image",
51
- render: ({ item }) => item?.alt_text || "-",
52
- Edit: {
53
- control: "textarea",
54
- rows: 2
55
- },
56
- enableSorting: false,
57
- filterBy: false
6
+ let _wordpress_i18n = require("@wordpress/i18n");
7
+ let _wordpress_ui = require("@wordpress/ui");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ // packages/media-fields/src/alt_text/index.tsx
10
+ const altTextField = {
11
+ id: "alt_text",
12
+ type: "text",
13
+ label: (0, _wordpress_i18n.__)("Alt text"),
14
+ description: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
15
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Link, {
16
+ href: (0, _wordpress_i18n.__)("https://www.w3.org/WAI/tutorials/images/decision-tree/"),
17
+ openInNewTab: true,
18
+ children: (0, _wordpress_i18n.__)("Describe the purpose of the image.")
19
+ }),
20
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("br", {}),
21
+ (0, _wordpress_i18n.__)("Leave empty if decorative.")
22
+ ] }),
23
+ isVisible: (item) => item?.media_type === "image",
24
+ render: ({ item }) => item?.alt_text || "-",
25
+ Edit: {
26
+ control: "textarea",
27
+ rows: 2
28
+ },
29
+ enableSorting: false,
30
+ filterBy: false
58
31
  };
59
- var alt_text_default = altTextField;
60
- //# sourceMappingURL=index.cjs.map
32
+ exports.default = altTextField;
33
+
34
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/alt_text/index.tsx"],
4
- "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { Link } from '@wordpress/ui';\nimport type { Field } from '@wordpress/dataviews';\nimport type { Attachment, Updatable } from '@wordpress/core-data';\n\nconst altTextField: Partial< Field< Updatable< Attachment > > > = {\n\tid: 'alt_text',\n\ttype: 'text',\n\tlabel: __( 'Alt text' ),\n\tdescription: (\n\t\t<>\n\t\t\t<Link\n\t\t\t\thref={\n\t\t\t\t\t// translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.\n\t\t\t\t\t__(\n\t\t\t\t\t\t'https://www.w3.org/WAI/tutorials/images/decision-tree/'\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\topenInNewTab\n\t\t\t>\n\t\t\t\t{ __( 'Describe the purpose of the image.' ) }\n\t\t\t</Link>\n\t\t\t<br />\n\t\t\t{ __( 'Leave empty if decorative.' ) }\n\t\t</>\n\t),\n\tisVisible: ( item ) => item?.media_type === 'image',\n\trender: ( { item } ) => item?.alt_text || '-',\n\tEdit: {\n\t\tcontrol: 'textarea',\n\t\trows: 2,\n\t},\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\nexport default altTextField;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,gBAAqB;AASnB;AALF,IAAM,eAA4D;AAAA,EACjE,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,UAAW;AAAA,EACtB,aACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA;AAAA,cAEC;AAAA,YACC;AAAA,UACD;AAAA;AAAA,QAED,cAAY;AAAA,QAEV,8BAAI,oCAAqC;AAAA;AAAA,IAC5C;AAAA,IACA,4CAAC,QAAG;AAAA,QACF,gBAAI,4BAA6B;AAAA,KACpC;AAAA,EAED,WAAW,CAAE,SAAU,MAAM,eAAe;AAAA,EAC5C,QAAQ,CAAE,EAAE,KAAK,MAAO,MAAM,YAAY;AAAA,EAC1C,MAAM;AAAA,IACL,SAAS;AAAA,IACT,MAAM;AAAA,EACP;AAAA,EACA,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,mBAAQ;",
6
- "names": []
7
- }
1
+ {"version":3,"file":"index.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,136 +1,101 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-fields/src/attached_to/edit.tsx
21
- var edit_exports = {};
22
- __export(edit_exports, {
23
- default: () => MediaAttachedToEdit
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(edit_exports);
26
- var import_core_data = require("@wordpress/core-data");
27
- var import_components = require("@wordpress/components");
28
- var import_i18n = require("@wordpress/i18n");
29
- var import_element = require("@wordpress/element");
30
- var import_compose = require("@wordpress/compose");
31
- var import_data = require("@wordpress/data");
32
- var import_get_rendered_content = require("../utils/get-rendered-content.cjs");
33
- var import_jsx_runtime = require("react/jsx-runtime");
34
- function MediaAttachedToEdit({
35
- data,
36
- onChange
37
- }) {
38
- const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [
39
- {
40
- label: (0, import_get_rendered_content.getRenderedContent)(
41
- data._embedded?.["wp:attached-to"]?.[0]?.title
42
- ),
43
- value: data.post.toString()
44
- }
45
- ] : [];
46
- const [options, setOptions] = (0, import_element.useState)(defaultPost);
47
- const [searchResults, setSearchResults] = (0, import_element.useState)(
48
- []
49
- );
50
- const [isLoading, setIsLoading] = (0, import_element.useState)(false);
51
- const [value, setValue] = (0, import_element.useState)(
52
- data?.post?.toString() ?? null
53
- );
54
- const postTypes = (0, import_data.useSelect)(
55
- (select) => select(import_core_data.store).getPostTypes(),
56
- []
57
- );
58
- const handleDetach = () => {
59
- onChange({
60
- post: 0,
61
- _embedded: { ...data?._embedded, "wp:attached-to": void 0 }
62
- });
63
- setValue(null);
64
- };
65
- const onValueChange = async (filterValue) => {
66
- setIsLoading(true);
67
- const results = await (0, import_core_data.__experimentalFetchLinkSuggestions)(
68
- filterValue,
69
- /*
70
- * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.
71
- * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.
72
- */
73
- { type: "post", isInitialSuggestions: true },
74
- {}
75
- );
76
- setSearchResults(results);
77
- const suggestions = results.map((result) => {
78
- return {
79
- label: result.title,
80
- value: result.id.toString()
81
- };
82
- });
83
- const includeCurrent = !filterValue && suggestions.findIndex((s) => s.value === value) === -1;
84
- setOptions(suggestions.concat(includeCurrent ? defaultPost : []));
85
- setIsLoading(false);
86
- };
87
- const debouncedValueChange = (0, import_compose.useDebounce)((0, import_compose.useEvent)(onValueChange), 300);
88
- const handleSelectOption = (selectedPostId) => {
89
- if (!selectedPostId) {
90
- handleDetach();
91
- return;
92
- }
93
- setValue(selectedPostId);
94
- if (selectedPostId) {
95
- const selectedPost = searchResults.find(
96
- (result) => result.id === Number(selectedPostId)
97
- );
98
- if (selectedPost && postTypes) {
99
- const postType = postTypes.find(
100
- (_postType) => _postType.slug === selectedPost?.type
101
- );
102
- const attachedTo = {
103
- ...postType && { type: postType.slug },
104
- id: Number(selectedPostId),
105
- title: {
106
- raw: selectedPost.title,
107
- rendered: selectedPost.title
108
- }
109
- };
110
- onChange({
111
- post: Number(selectedPostId),
112
- _embedded: {
113
- ...data?._embedded,
114
- "wp:attached-to": [attachedTo]
115
- }
116
- });
117
- }
118
- }
119
- };
120
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
121
- import_components.ComboboxControl,
122
- {
123
- className: "dataviews-media-field__attached-to",
124
- isLoading,
125
- label: (0, import_i18n.__)("Attached to"),
126
- help: (0, import_i18n.__)("Attach this file to a single post or page."),
127
- value,
128
- options,
129
- onFilterValueChange: (filterValue) => debouncedValueChange(filterValue),
130
- onChange: handleSelectOption,
131
- hideLabelFromVision: true,
132
- expandOnFocus: false
133
- }
134
- );
6
+ let _wordpress_core_data = require("@wordpress/core-data");
7
+ let _wordpress_components = require("@wordpress/components");
8
+ let _wordpress_i18n = require("@wordpress/i18n");
9
+ let _wordpress_element = require("@wordpress/element");
10
+ let _wordpress_compose = require("@wordpress/compose");
11
+ let _wordpress_data = require("@wordpress/data");
12
+ let ___utils_get_rendered_content_ts = require("../utils/get-rendered-content.cjs");
13
+ let react_jsx_runtime = require("react/jsx-runtime");
14
+ // packages/media-fields/src/attached_to/edit.tsx
15
+ function MediaAttachedToEdit({ data, onChange }) {
16
+ const defaultPost = !!data.post && !!data?._embedded?.["wp:attached-to"]?.[0] ? [{
17
+ label: (0, ___utils_get_rendered_content_ts.getRenderedContent)(data._embedded?.["wp:attached-to"]?.[0]?.title),
18
+ value: data.post.toString()
19
+ }] : [];
20
+ const [options, setOptions] = (0, _wordpress_element.useState)(defaultPost);
21
+ const [searchResults, setSearchResults] = (0, _wordpress_element.useState)([]);
22
+ const [isLoading, setIsLoading] = (0, _wordpress_element.useState)(false);
23
+ const [value, setValue] = (0, _wordpress_element.useState)(data?.post?.toString() ?? null);
24
+ const postTypes = (0, _wordpress_data.useSelect)((select) => select(_wordpress_core_data.store).getPostTypes(), []);
25
+ const handleDetach = () => {
26
+ onChange({
27
+ post: 0,
28
+ _embedded: {
29
+ ...data?._embedded,
30
+ "wp:attached-to": void 0
31
+ }
32
+ });
33
+ setValue(null);
34
+ };
35
+ const onValueChange = async (filterValue) => {
36
+ setIsLoading(true);
37
+ const results = await (0, _wordpress_core_data.__experimentalFetchLinkSuggestions)(filterValue, {
38
+ type: "post",
39
+ isInitialSuggestions: true
40
+ }, {});
41
+ setSearchResults(results);
42
+ const suggestions = results.map((result) => {
43
+ return {
44
+ label: result.title,
45
+ value: result.id.toString()
46
+ };
47
+ });
48
+ const includeCurrent = !filterValue && suggestions.findIndex((s) => s.value === value) === -1;
49
+ setOptions(suggestions.concat(includeCurrent ? defaultPost : []));
50
+ setIsLoading(false);
51
+ };
52
+ const debouncedValueChange = (0, _wordpress_compose.useDebounce)((0, _wordpress_compose.useEvent)(onValueChange), 300);
53
+ /**
54
+ * Handle selection.
55
+ *
56
+ * @param {Object} selectedPostId The selected post id.
57
+ */
58
+ const handleSelectOption = (selectedPostId) => {
59
+ if (!selectedPostId) {
60
+ handleDetach();
61
+ return;
62
+ }
63
+ setValue(selectedPostId);
64
+ if (selectedPostId) {
65
+ const selectedPost = searchResults.find((result) => result.id === Number(selectedPostId));
66
+ if (selectedPost && postTypes) {
67
+ const postType = postTypes.find((_postType) => _postType.slug === selectedPost?.type);
68
+ const attachedTo = {
69
+ ...postType && { type: postType.slug },
70
+ id: Number(selectedPostId),
71
+ title: {
72
+ raw: selectedPost.title,
73
+ rendered: selectedPost.title
74
+ }
75
+ };
76
+ onChange({
77
+ post: Number(selectedPostId),
78
+ _embedded: {
79
+ ...data?._embedded,
80
+ "wp:attached-to": [attachedTo]
81
+ }
82
+ });
83
+ }
84
+ }
85
+ };
86
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_components.ComboboxControl, {
87
+ className: "dataviews-media-field__attached-to",
88
+ isLoading,
89
+ label: (0, _wordpress_i18n.__)("Attached to"),
90
+ help: (0, _wordpress_i18n.__)("Attach this file to a single post or page."),
91
+ value,
92
+ options,
93
+ onFilterValueChange: (filterValue) => debouncedValueChange(filterValue),
94
+ onChange: handleSelectOption,
95
+ hideLabelFromVision: true,
96
+ expandOnFocus: false
97
+ });
135
98
  }
136
- //# sourceMappingURL=edit.cjs.map
99
+ exports.default = MediaAttachedToEdit;
100
+
101
+ //# sourceMappingURL=edit.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/attached_to/edit.tsx"],
4
- "sourcesContent": ["import {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { ComboboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDebounce, useEvent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\nexport default function MediaAttachedToEdit( {\n\tdata,\n\tonChange,\n}: DataFormControlProps< MediaItem > ) {\n\tconst defaultPost =\n\t\t!! data.post && !! data?._embedded?.[ 'wp:attached-to' ]?.[ 0 ]\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: getRenderedContent(\n\t\t\t\t\t\t\tdata._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue: data.post.toString(),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\tconst [ options, setOptions ] =\n\t\tuseState< { label: string; value: string }[] >( defaultPost );\n\tconst [ searchResults, setSearchResults ] = useState< SearchResult[] >(\n\t\t[]\n\t);\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ value, setValue ] = useState< string | null >(\n\t\tdata?.post?.toString() ?? null\n\t);\n\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes(),\n\t\t[]\n\t);\n\tconst handleDetach = () => {\n\t\tonChange( {\n\t\t\tpost: 0,\n\t\t\t_embedded: { ...data?._embedded, 'wp:attached-to': undefined },\n\t\t} );\n\t\tsetValue( null );\n\t};\n\n\tconst onValueChange = async ( filterValue: string ) => {\n\t\tsetIsLoading( true );\n\t\tconst results = await fetchLinkSuggestions(\n\t\t\tfilterValue,\n\t\t\t/*\n\t\t\t * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.\n\t\t\t * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.\n\t\t\t */\n\t\t\t{ type: 'post', isInitialSuggestions: true },\n\t\t\t{}\n\t\t);\n\t\tsetSearchResults( results );\n\t\tconst suggestions = results.map( ( result ) => {\n\t\t\treturn {\n\t\t\t\tlabel: result.title,\n\t\t\t\tvalue: result.id.toString(),\n\t\t\t};\n\t\t} );\n\t\tconst includeCurrent =\n\t\t\t! filterValue &&\n\t\t\tsuggestions.findIndex( ( s ) => s.value === value ) === -1;\n\t\tsetOptions( suggestions.concat( includeCurrent ? defaultPost : [] ) );\n\t\tsetIsLoading( false );\n\t};\n\n\t// `onValueChange` closes over state, so it's wrapped in `useEvent` to give\n\t// `useDebounce` a stable function. Debouncing an inline function instead\n\t// rebuilds the timer on every render, so nothing is debounced and each\n\t// keystroke fires its own request.\n\tconst debouncedValueChange = useDebounce( useEvent( onValueChange ), 300 );\n\n\t/**\n\t * Handle selection.\n\t *\n\t * @param {Object} selectedPostId The selected post id.\n\t */\n\tconst handleSelectOption = ( selectedPostId: string | null ) => {\n\t\tif ( ! selectedPostId ) {\n\t\t\thandleDetach();\n\t\t\treturn;\n\t\t}\n\t\tsetValue( selectedPostId );\n\t\tif ( selectedPostId ) {\n\t\t\tconst selectedPost = searchResults.find(\n\t\t\t\t( result ) => result.id === Number( selectedPostId )\n\t\t\t);\n\t\t\t// Although unlikely, it's technically possible for selectedPost to not be found.\n\t\t\t// E.g. if the user selects an option just as new search results are loaded.\n\t\t\t// TODO: Add error handling for when selectedPost is not found.\n\t\t\tif ( selectedPost && postTypes ) {\n\t\t\t\tconst postType = postTypes.find(\n\t\t\t\t\t( _postType: { slug: string } ) =>\n\t\t\t\t\t\t_postType.slug === selectedPost?.type\n\t\t\t\t);\n\n\t\t\t\tconst attachedTo = {\n\t\t\t\t\t...( postType && { type: postType.slug } ),\n\t\t\t\t\tid: Number( selectedPostId ),\n\t\t\t\t\ttitle: {\n\t\t\t\t\t\traw: selectedPost.title,\n\t\t\t\t\t\trendered: selectedPost.title,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tonChange( {\n\t\t\t\t\tpost: Number( selectedPostId ),\n\t\t\t\t\t_embedded: {\n\t\t\t\t\t\t...data?._embedded,\n\t\t\t\t\t\t'wp:attached-to': [ attachedTo ],\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\tclassName=\"dataviews-media-field__attached-to\"\n\t\t\tisLoading={ isLoading }\n\t\t\tlabel={ __( 'Attached to' ) }\n\t\t\thelp={ __( 'Attach this file to a single post or page.' ) }\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonFilterValueChange={ ( filterValue: unknown ) =>\n\t\t\t\tdebouncedValueChange( filterValue as string )\n\t\t\t}\n\t\t\tonChange={ handleSelectOption }\n\t\t\thideLabelFromVision\n\t\t\t// Opening the panel shouldn't imply the user has decided to change\n\t\t\t// the attachment, so wait for them to search before showing the list.\n\t\t\texpandOnFocus={ false }\n\t\t/>\n\t);\n}\n"],
5
- "mappings": "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",
6
- "names": ["coreStore", "fetchLinkSuggestions"]
7
- }
1
+ {"version":3,"file":"edit.cjs","names":["getRenderedContent","useState","useSelect","coreStore","fetchLinkSuggestions","useDebounce","useEvent","ComboboxControl","__"],"sources":["../../src/attached_to/edit.tsx"],"sourcesContent":["import {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\tstore as coreStore,\n} from '@wordpress/core-data';\nimport { ComboboxControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { useState } from '@wordpress/element';\nimport { useDebounce, useEvent } from '@wordpress/compose';\nimport { useSelect } from '@wordpress/data';\nimport type { DataFormControlProps } from '@wordpress/dataviews';\nimport type { MediaItem } from '../types';\nimport { getRenderedContent } from '../utils/get-rendered-content';\n\nexport type SearchResult = {\n\t/**\n\t * Post or term id.\n\t */\n\tid: number;\n\t/**\n\t * Link url.\n\t */\n\turl: string;\n\t/**\n\t * Title of the link.\n\t */\n\ttitle: string;\n\t/**\n\t * The taxonomy or post type slug or type URL.\n\t */\n\ttype: string;\n\t/**\n\t * Link kind of post-type or taxonomy\n\t */\n\tkind?: string;\n};\n\nexport default function MediaAttachedToEdit( {\n\tdata,\n\tonChange,\n}: DataFormControlProps< MediaItem > ) {\n\tconst defaultPost =\n\t\t!! data.post && !! data?._embedded?.[ 'wp:attached-to' ]?.[ 0 ]\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tlabel: getRenderedContent(\n\t\t\t\t\t\t\tdata._embedded?.[ 'wp:attached-to' ]?.[ 0 ]?.title\n\t\t\t\t\t\t),\n\t\t\t\t\t\tvalue: data.post.toString(),\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\tconst [ options, setOptions ] =\n\t\tuseState< { label: string; value: string }[] >( defaultPost );\n\tconst [ searchResults, setSearchResults ] = useState< SearchResult[] >(\n\t\t[]\n\t);\n\tconst [ isLoading, setIsLoading ] = useState( false );\n\tconst [ value, setValue ] = useState< string | null >(\n\t\tdata?.post?.toString() ?? null\n\t);\n\n\tconst postTypes = useSelect(\n\t\t( select ) => select( coreStore ).getPostTypes(),\n\t\t[]\n\t);\n\tconst handleDetach = () => {\n\t\tonChange( {\n\t\t\tpost: 0,\n\t\t\t_embedded: { ...data?._embedded, 'wp:attached-to': undefined },\n\t\t} );\n\t\tsetValue( null );\n\t};\n\n\tconst onValueChange = async ( filterValue: string ) => {\n\t\tsetIsLoading( true );\n\t\tconst results = await fetchLinkSuggestions(\n\t\t\tfilterValue,\n\t\t\t/*\n\t\t\t * @TODO `fetchLinkSuggestions()` should accept `perPage` as an option argument.\n\t\t\t * `isInitialSuggestions` limits the result to 3, otherwise it's hardcoded to 20.\n\t\t\t */\n\t\t\t{ type: 'post', isInitialSuggestions: true },\n\t\t\t{}\n\t\t);\n\t\tsetSearchResults( results );\n\t\tconst suggestions = results.map( ( result ) => {\n\t\t\treturn {\n\t\t\t\tlabel: result.title,\n\t\t\t\tvalue: result.id.toString(),\n\t\t\t};\n\t\t} );\n\t\tconst includeCurrent =\n\t\t\t! filterValue &&\n\t\t\tsuggestions.findIndex( ( s ) => s.value === value ) === -1;\n\t\tsetOptions( suggestions.concat( includeCurrent ? defaultPost : [] ) );\n\t\tsetIsLoading( false );\n\t};\n\n\t// `onValueChange` closes over state, so it's wrapped in `useEvent` to give\n\t// `useDebounce` a stable function. Debouncing an inline function instead\n\t// rebuilds the timer on every render, so nothing is debounced and each\n\t// keystroke fires its own request.\n\tconst debouncedValueChange = useDebounce( useEvent( onValueChange ), 300 );\n\n\t/**\n\t * Handle selection.\n\t *\n\t * @param {Object} selectedPostId The selected post id.\n\t */\n\tconst handleSelectOption = ( selectedPostId: string | null ) => {\n\t\tif ( ! selectedPostId ) {\n\t\t\thandleDetach();\n\t\t\treturn;\n\t\t}\n\t\tsetValue( selectedPostId );\n\t\tif ( selectedPostId ) {\n\t\t\tconst selectedPost = searchResults.find(\n\t\t\t\t( result ) => result.id === Number( selectedPostId )\n\t\t\t);\n\t\t\t// Although unlikely, it's technically possible for selectedPost to not be found.\n\t\t\t// E.g. if the user selects an option just as new search results are loaded.\n\t\t\t// TODO: Add error handling for when selectedPost is not found.\n\t\t\tif ( selectedPost && postTypes ) {\n\t\t\t\tconst postType = postTypes.find(\n\t\t\t\t\t( _postType: { slug: string } ) =>\n\t\t\t\t\t\t_postType.slug === selectedPost?.type\n\t\t\t\t);\n\n\t\t\t\tconst attachedTo = {\n\t\t\t\t\t...( postType && { type: postType.slug } ),\n\t\t\t\t\tid: Number( selectedPostId ),\n\t\t\t\t\ttitle: {\n\t\t\t\t\t\traw: selectedPost.title,\n\t\t\t\t\t\trendered: selectedPost.title,\n\t\t\t\t\t},\n\t\t\t\t};\n\n\t\t\t\tonChange( {\n\t\t\t\t\tpost: Number( selectedPostId ),\n\t\t\t\t\t_embedded: {\n\t\t\t\t\t\t...data?._embedded,\n\t\t\t\t\t\t'wp:attached-to': [ attachedTo ],\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<ComboboxControl\n\t\t\tclassName=\"dataviews-media-field__attached-to\"\n\t\t\tisLoading={ isLoading }\n\t\t\tlabel={ __( 'Attached to' ) }\n\t\t\thelp={ __( 'Attach this file to a single post or page.' ) }\n\t\t\tvalue={ value }\n\t\t\toptions={ options }\n\t\t\tonFilterValueChange={ ( filterValue: unknown ) =>\n\t\t\t\tdebouncedValueChange( filterValue as string )\n\t\t\t}\n\t\t\tonChange={ handleSelectOption }\n\t\t\thideLabelFromVision\n\t\t\t// Opening the panel shouldn't imply the user has decided to change\n\t\t\t// the attachment, so wait for them to search before showing the list.\n\t\t\texpandOnFocus={ false }\n\t\t/>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,SAAwB,oBAAqB,EAC5C,MACA,YACsC;CACtC,MAAM,cACL,CAAC,CAAE,KAAK,QAAQ,CAAC,CAAE,MAAM,YAAa,iBAAkB,GAAI,KACzD,CACA;EACC,QAAA,GAAOA,iCAAAA,mBAAAA,CACN,KAAK,YAAa,iBAAkB,GAAI,EAAG,EAAE,KAC9C;EACA,OAAO,KAAK,KAAK,SAAS;CAC3B,CACD,IACC,CAAC;CACL,MAAM,CAAE,SAAS,eAAA,GAChBC,mBAAAA,SAAAA,CAAgD,WAAY;CAC7D,MAAM,CAAE,eAAe,qBAAA,GAAqBA,mBAAAA,SAAAA,CAC3C,CAAC,CACF;CACA,MAAM,CAAE,WAAW,iBAAA,GAAiBA,mBAAAA,SAAAA,CAAU,KAAM;CACpD,MAAM,CAAE,OAAO,aAAA,GAAaA,mBAAAA,SAAAA,CAC3B,MAAM,MAAM,SAAS,KAAK,IAC3B;CAEA,MAAM,aAAA,GAAYC,gBAAAA,UAAAA,EACf,WAAY,OAAQC,qBAAAA,KAAU,CAAC,CAAC,aAAa,GAC/C,CAAC,CACF;CACA,MAAM,qBAAqB;EAC1B,SAAU;GACT,MAAM;GACN,WAAW;IAAE,GAAG,MAAM;IAAW,kBAAkB,KAAA;GAAU;EAC9D,CAAE;EACF,SAAU,IAAK;CAChB;CAEA,MAAM,gBAAgB,OAAQ,gBAAyB;EACtD,aAAc,IAAK;EACnB,MAAM,UAAU,OAAA,GAAMC,qBAAAA,mCAAAA,CACrB,aAKA;GAAE,MAAM;GAAQ,sBAAsB;EAAK,GAC3C,CAAC,CACF;EACA,iBAAkB,OAAQ;EAC1B,MAAM,cAAc,QAAQ,KAAO,WAAY;GAC9C,OAAO;IACN,OAAO,OAAO;IACd,OAAO,OAAO,GAAG,SAAS;GAC3B;EACD,CAAE;EACF,MAAM,iBACL,CAAE,eACF,YAAY,WAAa,MAAO,EAAE,UAAU,KAAM,MAAM;EACzD,WAAY,YAAY,OAAQ,iBAAiB,cAAc,CAAC,CAAE,CAAE;EACpE,aAAc,KAAM;CACrB;CAMA,MAAM,wBAAA,GAAuBC,mBAAAA,YAAAA,EAAAA,GAAaC,mBAAAA,SAAAA,CAAU,aAAc,GAAG,GAAI;;;;;;CAOzE,MAAM,sBAAuB,mBAAmC;EAC/D,IAAK,CAAE,gBAAiB;GACvB,aAAa;GACb;EACD;EACA,SAAU,cAAe;EACzB,IAAK,gBAAiB;GACrB,MAAM,eAAe,cAAc,MAChC,WAAY,OAAO,OAAO,OAAQ,cAAe,CACpD;GAIA,IAAK,gBAAgB,WAAY;IAChC,MAAM,WAAW,UAAU,MACxB,cACD,UAAU,SAAS,cAAc,IACnC;IAEA,MAAM,aAAa;KAClB,GAAK,YAAY,EAAE,MAAM,SAAS,KAAK;KACvC,IAAI,OAAQ,cAAe;KAC3B,OAAO;MACN,KAAK,aAAa;MAClB,UAAU,aAAa;KACxB;IACD;IAEA,SAAU;KACT,MAAM,OAAQ,cAAe;KAC7B,WAAW;MACV,GAAG,MAAM;MACT,kBAAkB,CAAE,UAAW;KAChC;IACD,CAAE;GACH;EACD;CACD;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAACC,sBAAAA,iBAAD;EACC,WAAU;EACE;EACZ,QAAA,GAAQC,gBAAAA,GAAAA,CAAI,aAAc;EAC1B,OAAA,GAAOA,gBAAAA,GAAAA,CAAI,4CAA6C;EAChD;EACE;EACV,sBAAwB,gBACvB,qBAAsB,WAAsB;EAE7C,UAAW;EACX,qBAAA;EAGA,eAAgB;CAChB,CAAA;AAEH"}
@@ -1,49 +1,44 @@
1
1
  "use strict";
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
5
+ });
6
+ // \0rolldown/runtime.js
2
7
  var __create = Object.create;
3
8
  var __defProp = Object.defineProperty;
4
9
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
10
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
11
  var __getProtoOf = Object.getPrototypeOf;
7
12
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
13
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
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
+ });
20
+ }
21
+ return to;
19
22
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ let _wordpress_i18n = require("@wordpress/i18n");
28
+ let __view_tsx = require("./view.cjs");
29
+ __view_tsx = __toESM(__view_tsx);
30
+ let __edit_tsx = require("./edit.cjs");
31
+ __edit_tsx = __toESM(__edit_tsx);
30
32
  // packages/media-fields/src/attached_to/index.tsx
31
- var attached_to_exports = {};
32
- __export(attached_to_exports, {
33
- default: () => attached_to_default
34
- });
35
- module.exports = __toCommonJS(attached_to_exports);
36
- var import_i18n = require("@wordpress/i18n");
37
- var import_view = __toESM(require("./view.cjs"));
38
- var import_edit = __toESM(require("./edit.cjs"));
39
- var attachedToField = {
40
- id: "attached_to",
41
- type: "text",
42
- label: (0, import_i18n.__)("Attached to"),
43
- Edit: import_edit.default,
44
- render: import_view.default,
45
- enableSorting: false,
46
- filterBy: false
33
+ const attachedToField = {
34
+ id: "attached_to",
35
+ type: "text",
36
+ label: (0, _wordpress_i18n.__)("Attached to"),
37
+ Edit: __edit_tsx.default,
38
+ render: __view_tsx.default,
39
+ enableSorting: false,
40
+ filterBy: false
47
41
  };
48
- var attached_to_default = attachedToField;
49
- //# sourceMappingURL=index.cjs.map
42
+ exports.default = attachedToField;
43
+
44
+ //# sourceMappingURL=index.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/attached_to/index.tsx"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AAGnB,kBAAgC;AAChC,kBAAgC;AAEhC,IAAM,kBAAiD;AAAA,EACtD,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,aAAc;AAAA,EACzB,MAAM,YAAAA;AAAA,EACN,QAAQ,YAAAC;AAAA,EACR,eAAe;AAAA,EACf,UAAU;AACX;AAEA,IAAO,sBAAQ;",
6
- "names": ["MediaAttachedToEdit", "MediaAttachedToView"]
7
- }
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,49 +1,28 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/media-fields/src/attached_to/view.tsx
21
- var view_exports = {};
22
- __export(view_exports, {
23
- default: () => MediaAttachedToView
2
+ Object.defineProperties(exports, {
3
+ __esModule: { value: true },
4
+ [Symbol.toStringTag]: { value: "Module" }
24
5
  });
25
- module.exports = __toCommonJS(view_exports);
26
- var import_element = require("@wordpress/element");
27
- var import_i18n = require("@wordpress/i18n");
28
- var import_get_rendered_content = require("../utils/get-rendered-content.cjs");
29
- var import_jsx_runtime = require("react/jsx-runtime");
30
- function MediaAttachedToView({
31
- item
32
- }) {
33
- const [attachedPostTitle, setAttachedPostTitle] = (0, import_element.useState)(null);
34
- const parentId = item.post;
35
- const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
36
- const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
37
- (0, import_element.useEffect)(() => {
38
- if (!!parentId && parentId === embeddedPostId) {
39
- setAttachedPostTitle(
40
- (0, import_get_rendered_content.getRenderedContent)(embeddedPostTitle) || (0, import_i18n.__)("(no title)")
41
- );
42
- }
43
- if (!parentId) {
44
- setAttachedPostTitle((0, import_i18n.__)("(Unattached)"));
45
- }
46
- }, [parentId, embeddedPostId, embeddedPostTitle]);
47
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: attachedPostTitle });
6
+ let _wordpress_element = require("@wordpress/element");
7
+ let _wordpress_i18n = require("@wordpress/i18n");
8
+ let ___utils_get_rendered_content_ts = require("../utils/get-rendered-content.cjs");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ // packages/media-fields/src/attached_to/view.tsx
11
+ function MediaAttachedToView({ item }) {
12
+ const [attachedPostTitle, setAttachedPostTitle] = (0, _wordpress_element.useState)(null);
13
+ const parentId = item.post;
14
+ const embeddedPostId = item._embedded?.["wp:attached-to"]?.[0]?.id;
15
+ const embeddedPostTitle = item._embedded?.["wp:attached-to"]?.[0]?.title;
16
+ (0, _wordpress_element.useEffect)(() => {
17
+ if (!!parentId && parentId === embeddedPostId) setAttachedPostTitle((0, ___utils_get_rendered_content_ts.getRenderedContent)(embeddedPostTitle) || (0, _wordpress_i18n.__)("(no title)"));
18
+ if (!parentId) setAttachedPostTitle((0, _wordpress_i18n.__)("(Unattached)"));
19
+ }, [
20
+ parentId,
21
+ embeddedPostId,
22
+ embeddedPostTitle
23
+ ]);
24
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: attachedPostTitle });
48
25
  }
49
- //# sourceMappingURL=view.cjs.map
26
+ exports.default = MediaAttachedToView;
27
+
28
+ //# sourceMappingURL=view.cjs.map
@@ -1,7 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/attached_to/view.tsx"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAoC;AACpC,kBAAmB;AAGnB,kCAAmC;AA6B3B;AA3BO,SAAR,oBAAsC;AAAA,EAC5C;AACD,GAA2C;AAI1C,QAAM,CAAE,mBAAmB,oBAAqB,QAAI,yBAEjD,IAAK;AAER,QAAM,WAAW,KAAK;AACtB,QAAM,iBAAiB,KAAK,YAAa,gBAAiB,IAAK,CAAE,GAAG;AACpE,QAAM,oBACL,KAAK,YAAa,gBAAiB,IAAK,CAAE,GAAG;AAE9C,gCAAW,MAAM;AAChB,QAAK,CAAC,CAAE,YAAY,aAAa,gBAAiB;AACjD;AAAA,YACC,gDAAoB,iBAAkB,SAAK,gBAAI,YAAa;AAAA,MAC7D;AAAA,IACD;AAEA,QAAK,CAAE,UAAW;AACjB,+BAAsB,gBAAI,cAAe,CAAE;AAAA,IAC5C;AAAA,EACD,GAAG,CAAE,UAAU,gBAAgB,iBAAkB,CAAE;AAEnD,SAAO,2EAAI,6BAAmB;AAC/B;",
6
- "names": []
7
- }
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"}