@wordpress/fields 0.3.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 (164) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +16 -0
  3. package/build/actions/utils.js +2 -2
  4. package/build/actions/utils.js.map +1 -1
  5. package/build/fields/comment-status/index.js +40 -0
  6. package/build/fields/comment-status/index.js.map +1 -0
  7. package/build/fields/date/date-view.js +69 -0
  8. package/build/fields/date/date-view.js.map +1 -0
  9. package/build/fields/date/index.js +29 -0
  10. package/build/fields/date/index.js.map +1 -0
  11. package/build/fields/featured-image/featured-image-edit.js.map +1 -1
  12. package/build/fields/featured-image/featured-image-view.js.map +1 -1
  13. package/build/fields/featured-image/index.js +0 -3
  14. package/build/fields/featured-image/index.js.map +1 -1
  15. package/build/fields/index.js +28 -0
  16. package/build/fields/index.js.map +1 -1
  17. package/build/fields/order/index.js +1 -1
  18. package/build/fields/order/index.js.map +1 -1
  19. package/build/fields/parent/index.js +0 -3
  20. package/build/fields/parent/index.js.map +1 -1
  21. package/build/fields/parent/parent-edit.js +6 -6
  22. package/build/fields/parent/parent-edit.js.map +1 -1
  23. package/build/fields/parent/parent-view.js +1 -1
  24. package/build/fields/parent/parent-view.js.map +1 -1
  25. package/build/fields/password/edit.js +65 -0
  26. package/build/fields/password/edit.js.map +1 -0
  27. package/build/fields/password/index.js +30 -0
  28. package/build/fields/password/index.js.map +1 -0
  29. package/build/fields/slug/index.js +0 -3
  30. package/build/fields/slug/index.js.map +1 -1
  31. package/build/fields/slug/slug-edit.js +23 -26
  32. package/build/fields/slug/slug-edit.js.map +1 -1
  33. package/build/fields/slug/slug-view.js +3 -2
  34. package/build/fields/slug/slug-view.js.map +1 -1
  35. package/build/fields/slug/utils.js +21 -0
  36. package/build/fields/slug/utils.js.map +1 -0
  37. package/build/fields/status/index.js +37 -0
  38. package/build/fields/status/index.js.map +1 -0
  39. package/build/fields/status/status-elements.js +46 -0
  40. package/build/fields/status/status-elements.js.map +1 -0
  41. package/build/fields/status/status-view.js +41 -0
  42. package/build/fields/status/status-view.js.map +1 -0
  43. package/build/fields/title/index.js +5 -1
  44. package/build/fields/title/index.js.map +1 -1
  45. package/build/fields/title/title-view.js +61 -0
  46. package/build/fields/title/title-view.js.map +1 -0
  47. package/build/types.js.map +1 -1
  48. package/build-module/actions/utils.js +2 -2
  49. package/build-module/actions/utils.js.map +1 -1
  50. package/build-module/fields/comment-status/index.js +35 -0
  51. package/build-module/fields/comment-status/index.js.map +1 -0
  52. package/build-module/fields/date/date-view.js +62 -0
  53. package/build-module/fields/date/date-view.js.map +1 -0
  54. package/build-module/fields/date/index.js +23 -0
  55. package/build-module/fields/date/index.js.map +1 -0
  56. package/build-module/fields/featured-image/featured-image-edit.js +1 -2
  57. package/build-module/fields/featured-image/featured-image-edit.js.map +1 -1
  58. package/build-module/fields/featured-image/featured-image-view.js.map +1 -1
  59. package/build-module/fields/featured-image/index.js +2 -4
  60. package/build-module/fields/featured-image/index.js.map +1 -1
  61. package/build-module/fields/index.js +4 -0
  62. package/build-module/fields/index.js.map +1 -1
  63. package/build-module/fields/order/index.js +2 -1
  64. package/build-module/fields/order/index.js.map +1 -1
  65. package/build-module/fields/parent/index.js +2 -4
  66. package/build-module/fields/parent/index.js.map +1 -1
  67. package/build-module/fields/parent/parent-edit.js +10 -8
  68. package/build-module/fields/parent/parent-edit.js.map +1 -1
  69. package/build-module/fields/parent/parent-view.js +1 -1
  70. package/build-module/fields/parent/parent-view.js.map +1 -1
  71. package/build-module/fields/password/edit.js +58 -0
  72. package/build-module/fields/password/edit.js.map +1 -0
  73. package/build-module/fields/password/index.js +23 -0
  74. package/build-module/fields/password/index.js.map +1 -0
  75. package/build-module/fields/slug/index.js +2 -4
  76. package/build-module/fields/slug/index.js.map +1 -1
  77. package/build-module/fields/slug/slug-edit.js +25 -27
  78. package/build-module/fields/slug/slug-edit.js.map +1 -1
  79. package/build-module/fields/slug/slug-view.js +3 -2
  80. package/build-module/fields/slug/slug-view.js.map +1 -1
  81. package/build-module/fields/slug/utils.js +13 -0
  82. package/build-module/fields/slug/utils.js.map +1 -0
  83. package/build-module/fields/status/index.js +31 -0
  84. package/build-module/fields/status/index.js.map +1 -0
  85. package/build-module/fields/status/status-elements.js +40 -0
  86. package/build-module/fields/status/status-elements.js.map +1 -0
  87. package/build-module/fields/status/status-view.js +34 -0
  88. package/build-module/fields/status/status-view.js.map +1 -0
  89. package/build-module/fields/title/index.js +4 -1
  90. package/build-module/fields/title/index.js.map +1 -1
  91. package/build-module/fields/title/title-view.js +55 -0
  92. package/build-module/fields/title/title-view.js.map +1 -0
  93. package/build-module/types.js.map +1 -1
  94. package/build-style/{styles-rtl.css → style-rtl.css} +79 -0
  95. package/build-style/{styles.css → style.css} +79 -0
  96. package/build-types/fields/comment-status/index.d.ts +14 -0
  97. package/build-types/fields/comment-status/index.d.ts.map +1 -0
  98. package/build-types/fields/date/date-view.d.ts +9 -0
  99. package/build-types/fields/date/date-view.d.ts.map +1 -0
  100. package/build-types/fields/date/index.d.ts +14 -0
  101. package/build-types/fields/date/index.d.ts.map +1 -0
  102. package/build-types/fields/featured-image/featured-image-edit.d.ts.map +1 -1
  103. package/build-types/fields/featured-image/featured-image-view.d.ts +1 -1
  104. package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -1
  105. package/build-types/fields/featured-image/index.d.ts.map +1 -1
  106. package/build-types/fields/index.d.ts +4 -0
  107. package/build-types/fields/index.d.ts.map +1 -1
  108. package/build-types/fields/order/index.d.ts.map +1 -1
  109. package/build-types/fields/parent/index.d.ts.map +1 -1
  110. package/build-types/fields/parent/parent-edit.d.ts +3 -0
  111. package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
  112. package/build-types/fields/parent/parent-view.d.ts +1 -1
  113. package/build-types/fields/parent/parent-view.d.ts.map +1 -1
  114. package/build-types/fields/password/edit.d.ts +8 -0
  115. package/build-types/fields/password/edit.d.ts.map +1 -0
  116. package/build-types/fields/password/index.d.ts +14 -0
  117. package/build-types/fields/password/index.d.ts.map +1 -0
  118. package/build-types/fields/slug/index.d.ts.map +1 -1
  119. package/build-types/fields/slug/slug-edit.d.ts.map +1 -1
  120. package/build-types/fields/slug/slug-view.d.ts.map +1 -1
  121. package/build-types/fields/slug/utils.d.ts +6 -0
  122. package/build-types/fields/slug/utils.d.ts.map +1 -0
  123. package/build-types/fields/status/index.d.ts +14 -0
  124. package/build-types/fields/status/index.d.ts.map +1 -0
  125. package/build-types/fields/status/status-elements.d.ts +13 -0
  126. package/build-types/fields/status/status-elements.d.ts.map +1 -0
  127. package/build-types/fields/status/status-view.d.ts +9 -0
  128. package/build-types/fields/status/status-view.d.ts.map +1 -0
  129. package/build-types/fields/title/index.d.ts.map +1 -1
  130. package/build-types/fields/title/title-view.d.ts +9 -0
  131. package/build-types/fields/title/title-view.d.ts.map +1 -0
  132. package/build-types/lock-unlock.d.ts +1 -1
  133. package/build-types/lock-unlock.d.ts.map +1 -1
  134. package/build-types/types.d.ts +3 -1
  135. package/build-types/types.d.ts.map +1 -1
  136. package/package.json +4 -3
  137. package/src/actions/utils.ts +2 -2
  138. package/src/fields/comment-status/index.tsx +40 -0
  139. package/src/fields/date/date-view.tsx +92 -0
  140. package/src/fields/date/index.tsx +23 -0
  141. package/src/fields/featured-image/featured-image-edit.tsx +2 -1
  142. package/src/fields/featured-image/featured-image-view.tsx +1 -1
  143. package/src/fields/featured-image/index.ts +1 -2
  144. package/src/fields/index.ts +4 -0
  145. package/src/fields/order/index.ts +2 -1
  146. package/src/fields/parent/index.ts +1 -2
  147. package/src/fields/parent/parent-edit.tsx +9 -9
  148. package/src/fields/parent/parent-view.tsx +2 -2
  149. package/src/fields/password/edit.tsx +68 -0
  150. package/src/fields/password/index.tsx +24 -0
  151. package/src/fields/slug/index.ts +1 -2
  152. package/src/fields/slug/slug-edit.tsx +21 -24
  153. package/src/fields/slug/slug-view.tsx +3 -2
  154. package/src/fields/slug/utils.ts +15 -0
  155. package/src/fields/status/index.tsx +32 -0
  156. package/src/fields/status/status-elements.tsx +50 -0
  157. package/src/fields/status/status-view.tsx +28 -0
  158. package/src/fields/title/index.ts +3 -0
  159. package/src/fields/title/title-view.tsx +62 -0
  160. package/src/style.scss +2 -0
  161. package/src/types.ts +3 -1
  162. package/tsconfig.json +10 -9
  163. package/tsconfig.tsbuildinfo +1 -1
  164. package/src/styles.scss +0 -1
@@ -1,3 +1,8 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import removeAccents from 'remove-accents';
5
+
1
6
  /**
2
7
  * WordPress dependencies
3
8
  */
@@ -12,21 +17,16 @@ import {
12
17
  // @ts-ignore
13
18
  import { store as coreStore } from '@wordpress/core-data';
14
19
  import type { DataFormControlProps } from '@wordpress/dataviews';
15
-
16
- /**
17
- * External dependencies
18
- */
19
- import removeAccents from 'remove-accents';
20
+ import { debounce } from '@wordpress/compose';
21
+ import { decodeEntities } from '@wordpress/html-entities';
22
+ import { __, sprintf } from '@wordpress/i18n';
23
+ import { filterURLForDisplay } from '@wordpress/url';
20
24
 
21
25
  /**
22
26
  * Internal dependencies
23
27
  */
24
- import { debounce } from '@wordpress/compose';
25
- import { decodeEntities } from '@wordpress/html-entities';
26
- import { __, sprintf } from '@wordpress/i18n';
27
28
  import type { BasePost } from '../../types';
28
29
  import { getTitleWithFallbackName } from './utils';
29
- import { filterURLForDisplay } from '@wordpress/url';
30
30
 
31
31
  type TreeBase = {
32
32
  id: number;
@@ -3,14 +3,14 @@
3
3
  */
4
4
  import { useSelect } from '@wordpress/data';
5
5
  import { store as coreStore } from '@wordpress/core-data';
6
+ import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
7
+ import { __ } from '@wordpress/i18n';
6
8
 
7
9
  /**
8
10
  * Internal dependencies
9
11
  */
10
12
  import type { BasePost } from '../../types';
11
- import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
12
13
  import { getTitleWithFallbackName } from './utils';
13
- import { __ } from '@wordpress/i18n';
14
14
 
15
15
  export const ParentView = ( {
16
16
  item,
@@ -0,0 +1,68 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ CheckboxControl,
6
+ __experimentalVStack as VStack,
7
+ TextControl,
8
+ } from '@wordpress/components';
9
+ import type { DataFormControlProps } from '@wordpress/dataviews';
10
+ import { useState } from '@wordpress/element';
11
+ import { __ } from '@wordpress/i18n';
12
+
13
+ /**
14
+ * Internal dependencies
15
+ */
16
+ import type { BasePost } from '../../types';
17
+
18
+ function PasswordEdit( {
19
+ data,
20
+ onChange,
21
+ field,
22
+ }: DataFormControlProps< BasePost > ) {
23
+ const [ showPassword, setShowPassword ] = useState(
24
+ !! field.getValue( { item: data } )
25
+ );
26
+
27
+ const handleTogglePassword = ( value: boolean ) => {
28
+ setShowPassword( value );
29
+ if ( ! value ) {
30
+ onChange( { password: '' } );
31
+ }
32
+ };
33
+
34
+ return (
35
+ <VStack
36
+ as="fieldset"
37
+ spacing={ 4 }
38
+ className="fields-controls__password"
39
+ >
40
+ <CheckboxControl
41
+ __nextHasNoMarginBottom
42
+ label={ __( 'Password protected' ) }
43
+ help={ __( 'Only visible to those who know the password' ) }
44
+ checked={ showPassword }
45
+ onChange={ handleTogglePassword }
46
+ />
47
+ { showPassword && (
48
+ <div className="fields-controls__password-input">
49
+ <TextControl
50
+ label={ __( 'Password' ) }
51
+ onChange={ ( value ) =>
52
+ onChange( {
53
+ password: value,
54
+ } )
55
+ }
56
+ value={ field.getValue( { item: data } ) || '' }
57
+ placeholder={ __( 'Use a secure password' ) }
58
+ type="text"
59
+ __next40pxDefaultSize
60
+ __nextHasNoMarginBottom
61
+ maxLength={ 255 }
62
+ />
63
+ </div>
64
+ ) }
65
+ </VStack>
66
+ );
67
+ }
68
+ export default PasswordEdit;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import type { BasePost } from '../../types';
10
+ import PasswordEdit from './edit';
11
+
12
+ const passwordField: Field< BasePost > = {
13
+ id: 'password',
14
+ type: 'text',
15
+ Edit: PasswordEdit,
16
+ enableSorting: false,
17
+ enableHiding: false,
18
+ isVisible: ( item ) => item.status !== 'private',
19
+ };
20
+
21
+ /**
22
+ * This field is used to display the post password.
23
+ */
24
+ export default passwordField;
@@ -2,12 +2,12 @@
2
2
  * WordPress dependencies
3
3
  */
4
4
  import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
5
6
 
6
7
  /**
7
8
  * Internal dependencies
8
9
  */
9
10
  import type { BasePost } from '../../types';
10
- import { __ } from '@wordpress/i18n';
11
11
  import SlugEdit from './slug-edit';
12
12
  import SlugView from './slug-view';
13
13
 
@@ -15,7 +15,6 @@ const slugField: Field< BasePost > = {
15
15
  id: 'slug',
16
16
  type: 'text',
17
17
  label: __( 'Slug' ),
18
- getValue: ( { item } ) => item.slug,
19
18
  Edit: SlugEdit,
20
19
  render: SlugView,
21
20
  };
@@ -21,6 +21,7 @@ import { __ } from '@wordpress/i18n';
21
21
  * Internal dependencies
22
22
  */
23
23
  import type { BasePost } from '../../types';
24
+ import { getSlug } from './utils';
24
25
 
25
26
  const SlugEdit = ( {
26
27
  field,
@@ -29,7 +30,7 @@ const SlugEdit = ( {
29
30
  }: DataFormControlProps< BasePost > ) => {
30
31
  const { id } = field;
31
32
 
32
- const slug = field.getValue( { item: data } ) ?? '';
33
+ const slug = field.getValue( { item: data } ) || getSlug( data );
33
34
  const permalinkTemplate = data.permalink_template || '';
34
35
  const PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;
35
36
  const [ prefix, suffix ] = permalinkTemplate.split(
@@ -115,30 +116,26 @@ const SlugEdit = ( {
115
116
  }
116
117
  } }
117
118
  aria-describedby={ postUrlSlugDescriptionId }
118
- help={
119
- <>
120
- <p className="fields-controls__slug-help">
121
- <span className="fields-controls__slug-help-visual-label">
122
- { __( 'Permalink:' ) }
123
- </span>
124
- <ExternalLink
125
- className="fields-controls__slug-help-link"
126
- href={ permalink }
127
- >
128
- <span className="fields-controls__slug-help-prefix">
129
- { permalinkPrefix }
130
- </span>
131
- <span className="fields-controls__slug-help-slug">
132
- { slugToDisplay }
133
- </span>
134
- <span className="fields-controls__slug-help-suffix">
135
- { permalinkSuffix }
136
- </span>
137
- </ExternalLink>
138
- </p>
139
- </>
140
- }
141
119
  />
120
+ <div className="fields-controls__slug-help">
121
+ <span className="fields-controls__slug-help-visual-label">
122
+ { __( 'Permalink:' ) }
123
+ </span>
124
+ <ExternalLink
125
+ className="fields-controls__slug-help-link"
126
+ href={ permalink }
127
+ >
128
+ <span className="fields-controls__slug-help-prefix">
129
+ { permalinkPrefix }
130
+ </span>
131
+ <span className="fields-controls__slug-help-slug">
132
+ { slugToDisplay }
133
+ </span>
134
+ <span className="fields-controls__slug-help-suffix">
135
+ { permalinkSuffix }
136
+ </span>
137
+ </ExternalLink>
138
+ </div>
142
139
  </VStack>
143
140
  ) }
144
141
  { ! isEditable && (
@@ -7,9 +7,10 @@ import { useEffect, useRef } from '@wordpress/element';
7
7
  * Internal dependencies
8
8
  */
9
9
  import type { BasePost } from '../../types';
10
+ import { getSlug } from './utils';
10
11
 
11
12
  const SlugView = ( { item }: { item: BasePost } ) => {
12
- const slug = item.slug;
13
+ const slug = typeof item === 'object' ? getSlug( item ) : '';
13
14
  const originalSlugRef = useRef( slug );
14
15
 
15
16
  useEffect( () => {
@@ -20,7 +21,7 @@ const SlugView = ( { item }: { item: BasePost } ) => {
20
21
 
21
22
  const slugToDisplay = slug || originalSlugRef.current;
22
23
 
23
- return `/${ slugToDisplay ?? '' }`;
24
+ return `${ slugToDisplay }`;
24
25
  };
25
26
 
26
27
  export default SlugView;
@@ -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;
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'
@@ -37,6 +37,8 @@ export interface BasePost extends CommonPost {
37
37
  link?: string;
38
38
  slug?: string;
39
39
  permalink_template?: string;
40
+ date?: string;
41
+ modified?: string;
40
42
  }
41
43
 
42
44
  export interface Template extends CommonPost {
package/tsconfig.json CHANGED
@@ -8,24 +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" },
27
- { "path": "../media-utils" },
28
- { "path": "../router" }
29
+ { "path": "../warning" }
29
30
  ],
30
31
  "include": [ "src" ]
31
32
  }