@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
@@ -0,0 +1,22 @@
1
+ .fields-controls__slug {
2
+ .fields-controls__slug-external-icon {
3
+ margin-left: 5ch;
4
+ }
5
+
6
+ .fields-controls__slug-input input.components-input-control__input {
7
+ padding-inline-start: 0 !important;
8
+ }
9
+
10
+ .fields-controls__slug-help-link {
11
+ word-break: break-word;
12
+ }
13
+
14
+ .fields-controls__slug-help {
15
+ display: flex;
16
+ flex-direction: column;
17
+
18
+ .fields-controls__slug-help-slug {
19
+ font-weight: 600;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { cleanForSlug } from '@wordpress/url';
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import type { BasePost } from '../../types';
9
+ import { getItemTitle } from '../../actions/utils';
10
+
11
+ export const getSlug = ( item: BasePost ): string => {
12
+ return (
13
+ item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString()
14
+ );
15
+ };
@@ -0,0 +1,32 @@
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 StatusView from './status-view';
12
+ import STATUSES from './status-elements';
13
+
14
+ const OPERATOR_IS_ANY = 'isAny';
15
+
16
+ const statusField: Field< BasePost > = {
17
+ label: __( 'Status' ),
18
+ id: 'status',
19
+ type: 'text',
20
+ elements: STATUSES,
21
+ render: StatusView,
22
+ Edit: 'radio',
23
+ enableSorting: false,
24
+ filterBy: {
25
+ operators: [ OPERATOR_IS_ANY ],
26
+ },
27
+ };
28
+
29
+ /**
30
+ * Status field for BasePost.
31
+ */
32
+ export default statusField;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ trash,
6
+ drafts,
7
+ published,
8
+ scheduled,
9
+ pending,
10
+ notAllowed,
11
+ } from '@wordpress/icons';
12
+ import { __ } from '@wordpress/i18n';
13
+
14
+ // See https://github.com/WordPress/gutenberg/issues/55886
15
+ // We do not support custom statutes at the moment.
16
+ const STATUSES = [
17
+ {
18
+ value: 'draft',
19
+ label: __( 'Draft' ),
20
+ icon: drafts,
21
+ description: __( 'Not ready to publish.' ),
22
+ },
23
+ {
24
+ value: 'future',
25
+ label: __( 'Scheduled' ),
26
+ icon: scheduled,
27
+ description: __( 'Publish automatically on a chosen date.' ),
28
+ },
29
+ {
30
+ value: 'pending',
31
+ label: __( 'Pending Review' ),
32
+ icon: pending,
33
+ description: __( 'Waiting for review before publishing.' ),
34
+ },
35
+ {
36
+ value: 'private',
37
+ label: __( 'Private' ),
38
+ icon: notAllowed,
39
+ description: __( 'Only visible to site admins and editors.' ),
40
+ },
41
+ {
42
+ value: 'publish',
43
+ label: __( 'Published' ),
44
+ icon: published,
45
+ description: __( 'Visible to everyone.' ),
46
+ },
47
+ { value: 'trash', label: __( 'Trash' ), icon: trash },
48
+ ];
49
+
50
+ export default STATUSES;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __experimentalHStack as HStack, Icon } from '@wordpress/components';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import type { BasePost } from '../../types';
10
+ import STATUSES from './status-elements';
11
+
12
+ function StatusView( { item }: { item: BasePost } ) {
13
+ const status = STATUSES.find( ( { value } ) => value === item.status );
14
+ const label = status?.label || item.status;
15
+ const icon = status?.icon;
16
+ return (
17
+ <HStack alignment="left" spacing={ 0 }>
18
+ { icon && (
19
+ <div className="edit-site-post-list__status-icon">
20
+ <Icon icon={ icon } />
21
+ </div>
22
+ ) }
23
+ <span>{ label }</span>
24
+ </HStack>
25
+ );
26
+ }
27
+
28
+ export default StatusView;
@@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
9
9
  */
10
10
  import type { BasePost } from '../../types';
11
11
  import { getItemTitle } from '../../actions/utils';
12
+ import TitleView from './title-view';
12
13
 
13
14
  const titleField: Field< BasePost > = {
14
15
  type: 'text',
@@ -16,6 +17,8 @@ const titleField: Field< BasePost > = {
16
17
  label: __( 'Title' ),
17
18
  placeholder: __( 'No title' ),
18
19
  getValue: ( { item } ) => getItemTitle( item ),
20
+ render: TitleView,
21
+ enableHiding: false,
19
22
  };
20
23
 
21
24
  export default titleField;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { __experimentalHStack as HStack } from '@wordpress/components';
5
+ import { decodeEntities } from '@wordpress/html-entities';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { useSelect } from '@wordpress/data';
8
+ import { store as coreStore } from '@wordpress/core-data';
9
+ import type { Settings } from '@wordpress/core-data';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import type { BasePost } from '../../types';
15
+ import { getItemTitle } from '../../actions/utils';
16
+
17
+ const TitleView = ( { item }: { item: BasePost } ) => {
18
+ const { frontPageId, postsPageId } = useSelect( ( select ) => {
19
+ const { getEntityRecord } = select( coreStore );
20
+ const siteSettings: Settings | undefined = getEntityRecord(
21
+ 'root',
22
+ 'site',
23
+ ''
24
+ );
25
+ return {
26
+ frontPageId: siteSettings?.page_on_front,
27
+ postsPageId: siteSettings?.page_for_posts,
28
+ };
29
+ }, [] );
30
+
31
+ const renderedTitle = getItemTitle( item );
32
+
33
+ let suffix;
34
+ if ( item.id === frontPageId ) {
35
+ suffix = (
36
+ <span className="edit-site-post-list__title-badge">
37
+ { __( 'Homepage' ) }
38
+ </span>
39
+ );
40
+ } else if ( item.id === postsPageId ) {
41
+ suffix = (
42
+ <span className="edit-site-post-list__title-badge">
43
+ { __( 'Posts Page' ) }
44
+ </span>
45
+ );
46
+ }
47
+
48
+ return (
49
+ <HStack
50
+ className="edit-site-post-list__title"
51
+ alignment="center"
52
+ justify="flex-start"
53
+ >
54
+ <span>
55
+ { decodeEntities( renderedTitle ) || __( '(no title)' ) }
56
+ </span>
57
+ { suffix }
58
+ </HStack>
59
+ );
60
+ };
61
+
62
+ export default TitleView;
@@ -10,9 +10,9 @@ import { dispatch } from '@wordpress/data';
10
10
  */
11
11
  import type { CoreDataError, Post } from '../types';
12
12
 
13
- const getErrorMessagesFromPromises = < T >(
13
+ function getErrorMessagesFromPromises< T >(
14
14
  allSettledResults: PromiseSettledResult< T >[]
15
- ) => {
15
+ ) {
16
16
  const errorMessages = new Set< string >();
17
17
  // If there was at lease one failure.
18
18
  if ( allSettledResults.length === 1 ) {
@@ -36,7 +36,7 @@ const getErrorMessagesFromPromises = < T >(
36
36
  }
37
37
  }
38
38
  return errorMessages;
39
- };
39
+ }
40
40
 
41
41
  export type NoticeSettings< T extends Post > = {
42
42
  success: {
package/src/style.scss ADDED
@@ -0,0 +1,2 @@
1
+ @import "./fields/slug/style.scss";
2
+ @import "./fields/featured-image/style.scss";
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  type PostStatus =
2
- | 'published'
2
+ | 'publish'
3
3
  | 'draft'
4
4
  | 'pending'
5
5
  | 'private'
@@ -35,6 +35,10 @@ export interface BasePost extends CommonPost {
35
35
  menu_order?: number;
36
36
  ping_status?: 'open' | 'closed';
37
37
  link?: string;
38
+ slug?: string;
39
+ permalink_template?: string;
40
+ date?: string;
41
+ modified?: string;
38
42
  }
39
43
 
40
44
  export interface Template extends CommonPost {
package/tsconfig.json CHANGED
@@ -8,22 +8,25 @@
8
8
  },
9
9
  "references": [
10
10
  { "path": "../api-fetch" },
11
+ { "path": "../blob" },
11
12
  { "path": "../components" },
12
13
  { "path": "../compose" },
14
+ { "path": "../core-data" },
13
15
  { "path": "../data" },
16
+ { "path": "../dataviews" },
17
+ { "path": "../date" },
14
18
  { "path": "../element" },
19
+ { "path": "../hooks" },
20
+ { "path": "../html-entities" },
15
21
  { "path": "../i18n" },
16
22
  { "path": "../icons" },
23
+ { "path": "../media-utils" },
24
+ { "path": "../notices" },
17
25
  { "path": "../primitives" },
18
26
  { "path": "../private-apis" },
19
- { "path": "../warning" },
27
+ { "path": "../router" },
20
28
  { "path": "../url" },
21
- { "path": "../notices" },
22
- { "path": "../dataviews" },
23
- { "path": "../blob" },
24
- { "path": "../core-data" },
25
- { "path": "../hooks" },
26
- { "path": "../html-entities" }
29
+ { "path": "../warning" }
27
30
  ],
28
31
  "include": [ "src" ]
29
32
  }