@wordpress/fields 0.2.0 → 0.4.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 (202) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +28 -0
  3. package/build/actions/delete-post.js +4 -4
  4. package/build/actions/delete-post.js.map +1 -1
  5. package/build/actions/duplicate-post.js +2 -2
  6. package/build/actions/duplicate-post.js.map +1 -1
  7. package/build/actions/utils.js +2 -2
  8. package/build/actions/utils.js.map +1 -1
  9. package/build/actions/view-post-revisions.js +1 -1
  10. package/build/actions/view-post-revisions.js.map +1 -1
  11. package/build/fields/comment-status/index.js +40 -0
  12. package/build/fields/comment-status/index.js.map +1 -0
  13. package/build/fields/date/date-view.js +69 -0
  14. package/build/fields/date/date-view.js.map +1 -0
  15. package/build/fields/date/index.js +29 -0
  16. package/build/fields/date/index.js.map +1 -0
  17. package/build/fields/featured-image/featured-image-edit.js +113 -0
  18. package/build/fields/featured-image/featured-image-edit.js.map +1 -0
  19. package/build/fields/featured-image/featured-image-view.js +41 -0
  20. package/build/fields/featured-image/featured-image-view.js.map +1 -0
  21. package/build/fields/featured-image/index.js +27 -0
  22. package/build/fields/featured-image/index.js.map +1 -0
  23. package/build/fields/index.js +49 -0
  24. package/build/fields/index.js.map +1 -1
  25. package/build/fields/order/index.js +1 -1
  26. package/build/fields/order/index.js.map +1 -1
  27. package/build/fields/parent/index.js +31 -0
  28. package/build/fields/parent/index.js.map +1 -0
  29. package/build/fields/parent/parent-edit.js +243 -0
  30. package/build/fields/parent/parent-edit.js.map +1 -0
  31. package/build/fields/parent/parent-view.js +39 -0
  32. package/build/fields/parent/parent-view.js.map +1 -0
  33. package/build/fields/parent/utils.js +20 -0
  34. package/build/fields/parent/utils.js.map +1 -0
  35. package/build/fields/password/edit.js +65 -0
  36. package/build/fields/password/edit.js.map +1 -0
  37. package/build/fields/password/index.js +30 -0
  38. package/build/fields/password/index.js.map +1 -0
  39. package/build/fields/slug/index.js +27 -0
  40. package/build/fields/slug/index.js.map +1 -0
  41. package/build/fields/slug/slug-edit.js +129 -0
  42. package/build/fields/slug/slug-edit.js.map +1 -0
  43. package/build/fields/slug/slug-view.js +31 -0
  44. package/build/fields/slug/slug-view.js.map +1 -0
  45. package/build/fields/slug/utils.js +21 -0
  46. package/build/fields/slug/utils.js.map +1 -0
  47. package/build/fields/status/index.js +37 -0
  48. package/build/fields/status/index.js.map +1 -0
  49. package/build/fields/status/status-elements.js +46 -0
  50. package/build/fields/status/status-elements.js.map +1 -0
  51. package/build/fields/status/status-view.js +41 -0
  52. package/build/fields/status/status-view.js.map +1 -0
  53. package/build/fields/title/index.js +5 -1
  54. package/build/fields/title/index.js.map +1 -1
  55. package/build/fields/title/title-view.js +61 -0
  56. package/build/fields/title/title-view.js.map +1 -0
  57. package/build/mutation/index.js +2 -2
  58. package/build/mutation/index.js.map +1 -1
  59. package/build/types.js.map +1 -1
  60. package/build-module/actions/delete-post.js +5 -5
  61. package/build-module/actions/delete-post.js.map +1 -1
  62. package/build-module/actions/duplicate-post.js +2 -2
  63. package/build-module/actions/duplicate-post.js.map +1 -1
  64. package/build-module/actions/utils.js +2 -2
  65. package/build-module/actions/utils.js.map +1 -1
  66. package/build-module/actions/view-post-revisions.js +1 -1
  67. package/build-module/actions/view-post-revisions.js.map +1 -1
  68. package/build-module/fields/comment-status/index.js +35 -0
  69. package/build-module/fields/comment-status/index.js.map +1 -0
  70. package/build-module/fields/date/date-view.js +62 -0
  71. package/build-module/fields/date/date-view.js.map +1 -0
  72. package/build-module/fields/date/index.js +23 -0
  73. package/build-module/fields/date/index.js.map +1 -0
  74. package/build-module/fields/featured-image/featured-image-edit.js +104 -0
  75. package/build-module/fields/featured-image/featured-image-edit.js.map +1 -0
  76. package/build-module/fields/featured-image/featured-image-view.js +33 -0
  77. package/build-module/fields/featured-image/featured-image-view.js.map +1 -0
  78. package/build-module/fields/featured-image/index.js +22 -0
  79. package/build-module/fields/featured-image/index.js.map +1 -0
  80. package/build-module/fields/index.js +7 -0
  81. package/build-module/fields/index.js.map +1 -1
  82. package/build-module/fields/order/index.js +2 -1
  83. package/build-module/fields/order/index.js.map +1 -1
  84. package/build-module/fields/parent/index.js +26 -0
  85. package/build-module/fields/parent/index.js.map +1 -0
  86. package/build-module/fields/parent/parent-edit.js +232 -0
  87. package/build-module/fields/parent/parent-edit.js.map +1 -0
  88. package/build-module/fields/parent/parent-view.js +32 -0
  89. package/build-module/fields/parent/parent-view.js.map +1 -0
  90. package/build-module/fields/parent/utils.js +14 -0
  91. package/build-module/fields/parent/utils.js.map +1 -0
  92. package/build-module/fields/password/edit.js +58 -0
  93. package/build-module/fields/password/edit.js.map +1 -0
  94. package/build-module/fields/password/index.js +23 -0
  95. package/build-module/fields/password/index.js.map +1 -0
  96. package/build-module/fields/slug/index.js +21 -0
  97. package/build-module/fields/slug/index.js.map +1 -0
  98. package/build-module/fields/slug/slug-edit.js +123 -0
  99. package/build-module/fields/slug/slug-edit.js.map +1 -0
  100. package/build-module/fields/slug/slug-view.js +25 -0
  101. package/build-module/fields/slug/slug-view.js.map +1 -0
  102. package/build-module/fields/slug/utils.js +13 -0
  103. package/build-module/fields/slug/utils.js.map +1 -0
  104. package/build-module/fields/status/index.js +31 -0
  105. package/build-module/fields/status/index.js.map +1 -0
  106. package/build-module/fields/status/status-elements.js +40 -0
  107. package/build-module/fields/status/status-elements.js.map +1 -0
  108. package/build-module/fields/status/status-view.js +34 -0
  109. package/build-module/fields/status/status-view.js.map +1 -0
  110. package/build-module/fields/title/index.js +4 -1
  111. package/build-module/fields/title/index.js.map +1 -1
  112. package/build-module/fields/title/title-view.js +55 -0
  113. package/build-module/fields/title/title-view.js.map +1 -0
  114. package/build-module/mutation/index.js +2 -2
  115. package/build-module/mutation/index.js.map +1 -1
  116. package/build-module/types.js.map +1 -1
  117. package/build-style/style-rtl.css +213 -0
  118. package/build-style/style.css +213 -0
  119. package/build-types/actions/delete-post.d.ts.map +1 -1
  120. package/build-types/fields/comment-status/index.d.ts +14 -0
  121. package/build-types/fields/comment-status/index.d.ts.map +1 -0
  122. package/build-types/fields/date/date-view.d.ts +9 -0
  123. package/build-types/fields/date/date-view.d.ts.map +1 -0
  124. package/build-types/fields/date/index.d.ts +14 -0
  125. package/build-types/fields/date/index.d.ts.map +1 -0
  126. package/build-types/fields/featured-image/featured-image-edit.d.ts +7 -0
  127. package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -0
  128. package/build-types/fields/featured-image/featured-image-view.d.ts +7 -0
  129. package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -0
  130. package/build-types/fields/featured-image/index.d.ts +11 -0
  131. package/build-types/fields/featured-image/index.d.ts.map +1 -0
  132. package/build-types/fields/index.d.ts +7 -0
  133. package/build-types/fields/index.d.ts.map +1 -1
  134. package/build-types/fields/order/index.d.ts.map +1 -1
  135. package/build-types/fields/parent/index.d.ts +14 -0
  136. package/build-types/fields/parent/index.d.ts.map +1 -0
  137. package/build-types/fields/parent/parent-edit.d.ts +12 -0
  138. package/build-types/fields/parent/parent-edit.d.ts.map +1 -0
  139. package/build-types/fields/parent/parent-view.d.ts +7 -0
  140. package/build-types/fields/parent/parent-view.d.ts.map +1 -0
  141. package/build-types/fields/parent/utils.d.ts +6 -0
  142. package/build-types/fields/parent/utils.d.ts.map +1 -0
  143. package/build-types/fields/password/edit.d.ts +8 -0
  144. package/build-types/fields/password/edit.d.ts.map +1 -0
  145. package/build-types/fields/password/index.d.ts +14 -0
  146. package/build-types/fields/password/index.d.ts.map +1 -0
  147. package/build-types/fields/slug/index.d.ts +11 -0
  148. package/build-types/fields/slug/index.d.ts.map +1 -0
  149. package/build-types/fields/slug/slug-edit.d.ts +8 -0
  150. package/build-types/fields/slug/slug-edit.d.ts.map +1 -0
  151. package/build-types/fields/slug/slug-view.d.ts +9 -0
  152. package/build-types/fields/slug/slug-view.d.ts.map +1 -0
  153. package/build-types/fields/slug/utils.d.ts +6 -0
  154. package/build-types/fields/slug/utils.d.ts.map +1 -0
  155. package/build-types/fields/status/index.d.ts +14 -0
  156. package/build-types/fields/status/index.d.ts.map +1 -0
  157. package/build-types/fields/status/status-elements.d.ts +13 -0
  158. package/build-types/fields/status/status-elements.d.ts.map +1 -0
  159. package/build-types/fields/status/status-view.d.ts +9 -0
  160. package/build-types/fields/status/status-view.d.ts.map +1 -0
  161. package/build-types/fields/title/index.d.ts.map +1 -1
  162. package/build-types/fields/title/title-view.d.ts +9 -0
  163. package/build-types/fields/title/title-view.d.ts.map +1 -0
  164. package/build-types/lock-unlock.d.ts +1 -1
  165. package/build-types/lock-unlock.d.ts.map +1 -1
  166. package/build-types/types.d.ts +5 -1
  167. package/build-types/types.d.ts.map +1 -1
  168. package/package.json +27 -22
  169. package/src/actions/delete-post.tsx +8 -5
  170. package/src/actions/duplicate-post.tsx +2 -2
  171. package/src/actions/utils.ts +2 -2
  172. package/src/actions/view-post-revisions.tsx +1 -1
  173. package/src/fields/comment-status/index.tsx +40 -0
  174. package/src/fields/date/date-view.tsx +92 -0
  175. package/src/fields/date/index.tsx +23 -0
  176. package/src/fields/featured-image/featured-image-edit.tsx +123 -0
  177. package/src/fields/featured-image/featured-image-view.tsx +38 -0
  178. package/src/fields/featured-image/index.ts +23 -0
  179. package/src/fields/featured-image/style.scss +95 -0
  180. package/src/fields/index.ts +7 -0
  181. package/src/fields/order/index.ts +2 -1
  182. package/src/fields/parent/index.ts +26 -0
  183. package/src/fields/parent/parent-edit.tsx +348 -0
  184. package/src/fields/parent/parent-view.tsx +33 -0
  185. package/src/fields/parent/utils.ts +18 -0
  186. package/src/fields/password/edit.tsx +68 -0
  187. package/src/fields/password/index.tsx +24 -0
  188. package/src/fields/slug/index.ts +22 -0
  189. package/src/fields/slug/slug-edit.tsx +153 -0
  190. package/src/fields/slug/slug-view.tsx +27 -0
  191. package/src/fields/slug/style.scss +22 -0
  192. package/src/fields/slug/utils.ts +15 -0
  193. package/src/fields/status/index.tsx +32 -0
  194. package/src/fields/status/status-elements.tsx +50 -0
  195. package/src/fields/status/status-view.tsx +28 -0
  196. package/src/fields/title/index.ts +3 -0
  197. package/src/fields/title/title-view.tsx +62 -0
  198. package/src/mutation/index.ts +3 -3
  199. package/src/style.scss +2 -0
  200. package/src/types.ts +5 -1
  201. package/tsconfig.json +10 -7
  202. package/tsconfig.tsbuildinfo +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/fields",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,6 +25,7 @@
25
25
  "main": "build/index.js",
26
26
  "module": "build-module/index.js",
27
27
  "react-native": "src/index",
28
+ "wpScript": true,
28
29
  "types": "build-types",
29
30
  "sideEffects": [
30
31
  "build-style/**",
@@ -32,27 +33,31 @@
32
33
  ],
33
34
  "dependencies": {
34
35
  "@babel/runtime": "7.25.7",
35
- "@wordpress/api-fetch": "^7.10.0",
36
- "@wordpress/blob": "^4.10.0",
37
- "@wordpress/blocks": "^13.10.0",
38
- "@wordpress/components": "^28.10.0",
39
- "@wordpress/compose": "^7.10.0",
40
- "@wordpress/core-data": "^7.10.0",
41
- "@wordpress/data": "^10.10.0",
42
- "@wordpress/dataviews": "^4.6.0",
43
- "@wordpress/element": "^6.10.0",
44
- "@wordpress/hooks": "^4.10.0",
45
- "@wordpress/html-entities": "^4.10.0",
46
- "@wordpress/i18n": "^5.10.0",
47
- "@wordpress/icons": "^10.10.0",
48
- "@wordpress/notices": "^5.10.0",
49
- "@wordpress/patterns": "^2.10.0",
50
- "@wordpress/primitives": "^4.10.0",
51
- "@wordpress/private-apis": "^1.10.0",
52
- "@wordpress/url": "^4.10.0",
53
- "@wordpress/warning": "^3.10.0",
36
+ "@wordpress/api-fetch": "*",
37
+ "@wordpress/blob": "*",
38
+ "@wordpress/blocks": "*",
39
+ "@wordpress/components": "*",
40
+ "@wordpress/compose": "*",
41
+ "@wordpress/core-data": "*",
42
+ "@wordpress/data": "*",
43
+ "@wordpress/dataviews": "*",
44
+ "@wordpress/date": "*",
45
+ "@wordpress/element": "*",
46
+ "@wordpress/hooks": "*",
47
+ "@wordpress/html-entities": "*",
48
+ "@wordpress/i18n": "*",
49
+ "@wordpress/icons": "*",
50
+ "@wordpress/media-utils": "*",
51
+ "@wordpress/notices": "*",
52
+ "@wordpress/patterns": "*",
53
+ "@wordpress/primitives": "*",
54
+ "@wordpress/private-apis": "*",
55
+ "@wordpress/router": "*",
56
+ "@wordpress/url": "*",
57
+ "@wordpress/warning": "*",
54
58
  "change-case": "4.1.2",
55
- "client-zip": "^2.4.5"
59
+ "client-zip": "^2.4.5",
60
+ "remove-accents": "^0.5.0"
56
61
  },
57
62
  "peerDependencies": {
58
63
  "react": "^18.0.0"
@@ -60,5 +65,5 @@
60
65
  "publishConfig": {
61
66
  "access": "public"
62
67
  },
63
- "gitHead": "ab34a7ac935fd1478eac63b596242d83270897ee"
68
+ "gitHead": "510540d99f3d222a96f08d3d7b66c9e7a726f705"
64
69
  }
@@ -2,7 +2,7 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import { trash } from '@wordpress/icons';
5
- import { __, _n, sprintf } from '@wordpress/i18n';
5
+ import { __, _x, _n, sprintf } from '@wordpress/i18n';
6
6
  import { useState } from '@wordpress/element';
7
7
  import {
8
8
  Button,
@@ -66,8 +66,8 @@ const deletePostAction: Action< Template | TemplatePart | Pattern > = {
66
66
  items.length
67
67
  )
68
68
  : sprintf(
69
- // translators: %s: The template or template part's titles
70
- __( 'Delete "%s"?' ),
69
+ // translators: %s: The template or template part's title
70
+ _x( 'Delete "%s"?', 'template part' ),
71
71
  getItemTitle( items[ 0 ] )
72
72
  ) }
73
73
  </Text>
@@ -100,8 +100,11 @@ const deletePostAction: Action< Template | TemplatePart | Pattern > = {
100
100
  )
101
101
  )
102
102
  : sprintf(
103
- /* translators: The template/part's name. */
104
- __( '"%s" deleted.' ),
103
+ /* translators: %s: The template/part's name. */
104
+ _x(
105
+ '"%s" deleted.',
106
+ 'template part'
107
+ ),
105
108
  decodeEntities(
106
109
  getItemTitle( item )
107
110
  )
@@ -38,7 +38,7 @@ const duplicatePost: Action< BasePost > = {
38
38
  ...items[ 0 ],
39
39
  title: sprintf(
40
40
  /* translators: %s: Existing template title */
41
- __( '%s (Copy)' ),
41
+ _x( '%s (Copy)', 'template' ),
42
42
  getItemTitle( items[ 0 ] )
43
43
  ),
44
44
  } );
@@ -104,7 +104,7 @@ const duplicatePost: Action< BasePost > = {
104
104
 
105
105
  createSuccessNotice(
106
106
  sprintf(
107
- // translators: %s: Title of the created template e.g: "Category".
107
+ // translators: %s: Title of the created post or template, e.g: "Hello world".
108
108
  __( '"%s" successfully created.' ),
109
109
  decodeEntities( newItem.title?.rendered || item.title )
110
110
  ),
@@ -34,10 +34,10 @@ export function getItemTitle( item: Post ) {
34
34
  if ( typeof item.title === 'string' ) {
35
35
  return decodeEntities( item.title );
36
36
  }
37
- if ( 'rendered' in item.title ) {
37
+ if ( item.title && 'rendered' in item.title ) {
38
38
  return decodeEntities( item.title.rendered );
39
39
  }
40
- if ( 'raw' in item.title ) {
40
+ if ( item.title && 'raw' in item.title ) {
41
41
  return decodeEntities( item.title.raw );
42
42
  }
43
43
  return '';
@@ -17,7 +17,7 @@ const viewPostRevisions: Action< Post > = {
17
17
  const revisionsCount =
18
18
  items[ 0 ]._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
19
19
  return sprintf(
20
- /* translators: %s: number of revisions */
20
+ /* translators: %s: number of revisions. */
21
21
  __( 'View revisions (%s)' ),
22
22
  revisionsCount
23
23
  );
@@ -0,0 +1,40 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePost } from '../../types';
11
+
12
+ const commentStatusField: Field< BasePost > = {
13
+ id: 'comment_status',
14
+ label: __( 'Discussion' ),
15
+ type: 'text',
16
+ Edit: 'radio',
17
+ enableSorting: false,
18
+ filterBy: {
19
+ operators: [],
20
+ },
21
+ elements: [
22
+ {
23
+ value: 'open',
24
+ label: __( 'Open' ),
25
+ description: __( 'Visitors can add new comments and replies.' ),
26
+ },
27
+ {
28
+ value: 'closed',
29
+ label: __( 'Closed' ),
30
+ description: __(
31
+ 'Visitors cannot add new comments or replies. Existing comments remain visible.'
32
+ ),
33
+ },
34
+ ],
35
+ };
36
+
37
+ /**
38
+ * Comment status field for BasePost.
39
+ */
40
+ export default commentStatusField;
@@ -0,0 +1,92 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __, sprintf } from '@wordpress/i18n';
5
+ import { createInterpolateElement } from '@wordpress/element';
6
+ import { dateI18n, getDate, getSettings } from '@wordpress/date';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { BasePost } from '../../types';
12
+
13
+ const getFormattedDate = ( dateToDisplay: string | null ) =>
14
+ dateI18n(
15
+ getSettings().formats.datetimeAbbreviated,
16
+ getDate( dateToDisplay )
17
+ );
18
+
19
+ const DateView = ( { item }: { item: BasePost } ) => {
20
+ const isDraftOrPrivate = [ 'draft', 'private' ].includes(
21
+ item.status ?? ''
22
+ );
23
+ if ( isDraftOrPrivate ) {
24
+ return createInterpolateElement(
25
+ sprintf(
26
+ /* translators: %s: page creation or modification date. */
27
+ __( '<span>Modified: <time>%s</time></span>' ),
28
+ getFormattedDate( item.date ?? null )
29
+ ),
30
+ {
31
+ span: <span />,
32
+ time: <time />,
33
+ }
34
+ );
35
+ }
36
+
37
+ const isScheduled = item.status === 'future';
38
+ if ( isScheduled ) {
39
+ return createInterpolateElement(
40
+ sprintf(
41
+ /* translators: %s: page creation date */
42
+ __( '<span>Scheduled: <time>%s</time></span>' ),
43
+ getFormattedDate( item.date ?? null )
44
+ ),
45
+ {
46
+ span: <span />,
47
+ time: <time />,
48
+ }
49
+ );
50
+ }
51
+
52
+ const isPublished = item.status === 'publish';
53
+ if ( isPublished ) {
54
+ return createInterpolateElement(
55
+ sprintf(
56
+ /* translators: %s: page creation time */
57
+ __( '<span>Published: <time>%s</time></span>' ),
58
+ getFormattedDate( item.date ?? null )
59
+ ),
60
+ {
61
+ span: <span />,
62
+ time: <time />,
63
+ }
64
+ );
65
+ }
66
+
67
+ // Pending posts show the modified date if it's newer.
68
+ const dateToDisplay =
69
+ getDate( item.modified ?? null ) > getDate( item.date ?? null )
70
+ ? item.modified
71
+ : item.date;
72
+
73
+ const isPending = item.status === 'pending';
74
+ if ( isPending ) {
75
+ return createInterpolateElement(
76
+ sprintf(
77
+ /* translators: %s: page creation or modification date. */
78
+ __( '<span>Modified: <time>%s</time></span>' ),
79
+ getFormattedDate( dateToDisplay ?? null )
80
+ ),
81
+ {
82
+ span: <span />,
83
+ time: <time />,
84
+ }
85
+ );
86
+ }
87
+
88
+ // Unknow status.
89
+ return <time>{ getFormattedDate( item.date ?? null ) }</time>;
90
+ };
91
+
92
+ export default DateView;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePost } from '../../types';
11
+ import DateView from './date-view';
12
+
13
+ const dateField: Field< BasePost > = {
14
+ id: 'date',
15
+ type: 'datetime',
16
+ label: __( 'Date' ),
17
+ render: DateView,
18
+ };
19
+
20
+ /**
21
+ * Date field for BasePost.
22
+ */
23
+ export default dateField;
@@ -0,0 +1,123 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Button, __experimentalGrid as Grid } from '@wordpress/components';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { useCallback, useRef } from '@wordpress/element';
7
+ // @ts-ignore
8
+ import { MediaUpload } from '@wordpress/media-utils';
9
+ import { lineSolid } from '@wordpress/icons';
10
+ import { store as coreStore } from '@wordpress/core-data';
11
+ import type { DataFormControlProps } from '@wordpress/dataviews';
12
+ import { __ } from '@wordpress/i18n';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import type { BasePost } from '../../types';
18
+
19
+ export const FeaturedImageEdit = ( {
20
+ data,
21
+ field,
22
+ onChange,
23
+ }: DataFormControlProps< BasePost > ) => {
24
+ const { id } = field;
25
+
26
+ const value = field.getValue( { item: data } );
27
+
28
+ const media = useSelect(
29
+ ( select ) => {
30
+ const { getEntityRecord } = select( coreStore );
31
+ return getEntityRecord( 'root', 'media', value );
32
+ },
33
+ [ value ]
34
+ );
35
+
36
+ const onChangeControl = useCallback(
37
+ ( newValue: number ) =>
38
+ onChange( {
39
+ [ id ]: newValue,
40
+ } ),
41
+ [ id, onChange ]
42
+ );
43
+
44
+ const url = media?.source_url;
45
+ const title = media?.title?.rendered;
46
+ const ref = useRef( null );
47
+
48
+ return (
49
+ <fieldset className="fields-controls__featured-image">
50
+ <div className="fields-controls__featured-image-container">
51
+ <MediaUpload
52
+ onSelect={ ( selectedMedia: { id: number } ) => {
53
+ onChangeControl( selectedMedia.id );
54
+ } }
55
+ allowedTypes={ [ 'image' ] }
56
+ render={ ( { open }: { open: () => void } ) => {
57
+ return (
58
+ <div
59
+ ref={ ref }
60
+ role="button"
61
+ tabIndex={ -1 }
62
+ onClick={ () => {
63
+ open();
64
+ } }
65
+ onKeyDown={ open }
66
+ >
67
+ <Grid
68
+ rowGap={ 0 }
69
+ columnGap={ 8 }
70
+ templateColumns="24px 1fr 24px"
71
+ >
72
+ { url && (
73
+ <>
74
+ <img
75
+ className="fields-controls__featured-image-image"
76
+ alt=""
77
+ width={ 24 }
78
+ height={ 24 }
79
+ src={ url }
80
+ />
81
+ <span className="fields-controls__featured-image-title">
82
+ { title }
83
+ </span>
84
+ </>
85
+ ) }
86
+ { ! url && (
87
+ <>
88
+ <span
89
+ className="fields-controls__featured-image-placeholder"
90
+ style={ {
91
+ width: '24px',
92
+ height: '24px',
93
+ } }
94
+ />
95
+ <span className="fields-controls__featured-image-title">
96
+ { __( 'Choose an image…' ) }
97
+ </span>
98
+ </>
99
+ ) }
100
+ { url && (
101
+ <>
102
+ <Button
103
+ size="small"
104
+ className="fields-controls__featured-image-remove-button"
105
+ icon={ lineSolid }
106
+ onClick={ (
107
+ event: React.MouseEvent< HTMLButtonElement >
108
+ ) => {
109
+ event.stopPropagation();
110
+ onChangeControl( 0 );
111
+ } }
112
+ />
113
+ </>
114
+ ) }
115
+ </Grid>
116
+ </div>
117
+ );
118
+ } }
119
+ />
120
+ </div>
121
+ </fieldset>
122
+ );
123
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useSelect } from '@wordpress/data';
5
+ import { store as coreStore } from '@wordpress/core-data';
6
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { BasePost } from '../../types';
12
+
13
+ export const FeaturedImageView = ( {
14
+ item,
15
+ }: DataViewRenderFieldProps< BasePost > ) => {
16
+ const mediaId = item.featured_media;
17
+
18
+ const media = useSelect(
19
+ ( select ) => {
20
+ const { getEntityRecord } = select( coreStore );
21
+ return mediaId ? getEntityRecord( 'root', 'media', mediaId ) : null;
22
+ },
23
+ [ mediaId ]
24
+ );
25
+ const url = media?.source_url;
26
+
27
+ if ( url ) {
28
+ return (
29
+ <img
30
+ className="fields-controls__featured-image-image"
31
+ src={ url }
32
+ alt=""
33
+ />
34
+ );
35
+ }
36
+
37
+ return <span className="fields-controls__featured-image-placeholder" />;
38
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePost } from '../../types';
11
+ import { FeaturedImageEdit } from './featured-image-edit';
12
+ import { FeaturedImageView } from './featured-image-view';
13
+
14
+ const featuredImageField: Field< BasePost > = {
15
+ id: 'featured_media',
16
+ type: 'text',
17
+ label: __( 'Featured Image' ),
18
+ Edit: FeaturedImageEdit,
19
+ render: FeaturedImageView,
20
+ enableSorting: false,
21
+ };
22
+
23
+ export default featuredImageField;
@@ -0,0 +1,95 @@
1
+ .fields-controls__featured-image-placeholder {
2
+ border-radius: $radius-small;
3
+ box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
4
+ display: inline-block;
5
+ padding: 0;
6
+ background:
7
+ $white
8
+ linear-gradient(-45deg, transparent 48%, $gray-300 48%, $gray-300 52%, transparent 52%);
9
+ }
10
+
11
+ .fields-controls__featured-image-title {
12
+ width: 100%;
13
+ color: $gray-900;
14
+ white-space: nowrap;
15
+ text-overflow: ellipsis;
16
+ overflow: hidden;
17
+ }
18
+
19
+ .fields-controls__featured-image-image {
20
+ width: 100%;
21
+ height: 100%;
22
+ border-radius: $radius-small;
23
+ align-self: center;
24
+ }
25
+
26
+ .fields-controls__featured-image-container {
27
+ .fields-controls__featured-image-placeholder {
28
+ margin: 0;
29
+ }
30
+
31
+ span {
32
+ margin-right: auto;
33
+ }
34
+ }
35
+
36
+ fieldset.fields-controls__featured-image {
37
+ .fields-controls__featured-image-container {
38
+ border: $border-width solid $gray-300;
39
+ border-radius: $radius-small;
40
+ padding: 8px 12px;
41
+ cursor: pointer;
42
+ &:hover {
43
+ background-color: $gray-100;
44
+ }
45
+ }
46
+
47
+ .fields-controls__featured-image-placeholder {
48
+ width: 24px;
49
+ height: 24px;
50
+ }
51
+
52
+ span {
53
+ align-self: center;
54
+ text-align: start;
55
+ white-space: nowrap;
56
+ }
57
+
58
+ .fields-controls__featured-image-upload-button {
59
+ padding: 0;
60
+ height: fit-content;
61
+ &:hover,
62
+ &:focus {
63
+ border: 0;
64
+ color: unset;
65
+ }
66
+ }
67
+
68
+ .fields-controls__featured-image-remove-button {
69
+ place-self: end;
70
+ }
71
+ }
72
+
73
+ .dataforms-layouts-panel__field-control {
74
+ .fields-controls__featured-image-image {
75
+ width: 16px;
76
+ height: 16px;
77
+ }
78
+
79
+ .fields-controls__featured-image-placeholder {
80
+ width: 16px;
81
+ height: 16px;
82
+ }
83
+ }
84
+
85
+ .dataviews-view-table__cell-content-wrapper {
86
+ .fields-controls__featured-image-image {
87
+ width: 32px;
88
+ height: 32px;
89
+ }
90
+
91
+ .fields-controls__featured-image-placeholder {
92
+ width: 32px;
93
+ height: 32px;
94
+ }
95
+ }
@@ -1,2 +1,9 @@
1
+ export { default as slugField } from './slug';
1
2
  export { default as titleField } from './title';
2
3
  export { default as orderField } from './order';
4
+ export { default as featuredImageField } from './featured-image';
5
+ export { default as parentField } from './parent';
6
+ export { default as passwordField } from './password';
7
+ export { default as statusField } from './status';
8
+ export { default as commentStatusField } from './comment-status';
9
+ export { default as dateField } from './date';
@@ -3,14 +3,15 @@
3
3
  */
4
4
  import type { Field } from '@wordpress/dataviews';
5
5
  import { __ } from '@wordpress/i18n';
6
+
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
10
  import type { BasePost } from '../../types';
10
11
 
11
12
  const orderField: Field< BasePost > = {
12
- type: 'integer',
13
13
  id: 'menu_order',
14
+ type: 'integer',
14
15
  label: __( 'Order' ),
15
16
  description: __( 'Determines the order of pages.' ),
16
17
  };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ import type { BasePost } from '../../types';
11
+ import { ParentEdit } from './parent-edit';
12
+ import { ParentView } from './parent-view';
13
+
14
+ const parentField: Field< BasePost > = {
15
+ id: 'parent',
16
+ type: 'text',
17
+ label: __( 'Parent' ),
18
+ Edit: ParentEdit,
19
+ render: ParentView,
20
+ enableSorting: true,
21
+ };
22
+
23
+ /**
24
+ * This field is used to display the post parent.
25
+ */
26
+ export default parentField;