@wordpress/fields 0.40.1 → 0.41.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 (117) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +44 -0
  3. package/build/actions/rename-post.cjs +0 -1
  4. package/build/actions/rename-post.cjs.map +2 -2
  5. package/build/components/create-template-part-modal/index.cjs +0 -1
  6. package/build/components/create-template-part-modal/index.cjs.map +2 -2
  7. package/build/components/media-edit/index.cjs.map +2 -2
  8. package/build/fields/description/index.cjs +70 -0
  9. package/build/fields/description/index.cjs.map +7 -0
  10. package/build/fields/index.cjs +24 -2
  11. package/build/fields/index.cjs.map +2 -2
  12. package/build/fields/last-edited/index.cjs +51 -0
  13. package/build/fields/last-edited/index.cjs.map +7 -0
  14. package/build/fields/last-edited/last-edited-date-view.cjs +40 -0
  15. package/build/fields/last-edited/last-edited-date-view.cjs.map +7 -0
  16. package/build/fields/parent/parent-edit.cjs +1 -1
  17. package/build/fields/parent/parent-edit.cjs.map +2 -2
  18. package/build/fields/password/edit.cjs +0 -1
  19. package/build/fields/password/edit.cjs.map +2 -2
  20. package/build/fields/pattern-title/view.cjs.map +2 -2
  21. package/build/fields/posts-page-title/index.cjs +47 -0
  22. package/build/fields/posts-page-title/index.cjs.map +7 -0
  23. package/build/fields/posts-per-page/index.cjs +42 -0
  24. package/build/fields/posts-per-page/index.cjs.map +7 -0
  25. package/build/fields/{date/scheduled → scheduled-date}/index.cjs +6 -6
  26. package/build/fields/scheduled-date/index.cjs.map +7 -0
  27. package/build/fields/site-discussion/index.cjs +58 -0
  28. package/build/fields/site-discussion/index.cjs.map +7 -0
  29. package/build/fields/template-author/index.cjs +81 -0
  30. package/build/fields/template-author/index.cjs.map +7 -0
  31. package/build/fields/template-author/view.cjs +101 -0
  32. package/build/fields/template-author/view.cjs.map +7 -0
  33. package/build/fields/template-title/index.cjs +1 -1
  34. package/build/fields/template-title/index.cjs.map +2 -2
  35. package/build/types.cjs.map +1 -1
  36. package/build-module/actions/rename-post.mjs +0 -1
  37. package/build-module/actions/rename-post.mjs.map +2 -2
  38. package/build-module/components/create-template-part-modal/index.mjs +0 -1
  39. package/build-module/components/create-template-part-modal/index.mjs.map +2 -2
  40. package/build-module/components/media-edit/index.mjs.map +2 -2
  41. package/build-module/fields/description/index.mjs +45 -0
  42. package/build-module/fields/description/index.mjs.map +7 -0
  43. package/build-module/fields/index.mjs +33 -13
  44. package/build-module/fields/index.mjs.map +2 -2
  45. package/build-module/fields/last-edited/index.mjs +20 -0
  46. package/build-module/fields/last-edited/index.mjs.map +7 -0
  47. package/build-module/fields/last-edited/last-edited-date-view.mjs +19 -0
  48. package/build-module/fields/last-edited/last-edited-date-view.mjs.map +7 -0
  49. package/build-module/fields/parent/parent-edit.mjs +1 -1
  50. package/build-module/fields/parent/parent-edit.mjs.map +2 -2
  51. package/build-module/fields/password/edit.mjs +0 -1
  52. package/build-module/fields/password/edit.mjs.map +2 -2
  53. package/build-module/fields/pattern-title/view.mjs.map +2 -2
  54. package/build-module/fields/posts-page-title/index.mjs +26 -0
  55. package/build-module/fields/posts-page-title/index.mjs.map +7 -0
  56. package/build-module/fields/posts-per-page/index.mjs +21 -0
  57. package/build-module/fields/posts-per-page/index.mjs.map +7 -0
  58. package/build-module/fields/{date/scheduled → scheduled-date}/index.mjs +3 -3
  59. package/build-module/fields/scheduled-date/index.mjs.map +7 -0
  60. package/build-module/fields/site-discussion/index.mjs +37 -0
  61. package/build-module/fields/site-discussion/index.mjs.map +7 -0
  62. package/build-module/fields/template-author/index.mjs +45 -0
  63. package/build-module/fields/template-author/index.mjs.map +7 -0
  64. package/build-module/fields/template-author/view.mjs +75 -0
  65. package/build-module/fields/template-author/view.mjs.map +7 -0
  66. package/build-module/fields/template-title/index.mjs +1 -1
  67. package/build-module/fields/template-title/index.mjs.map +2 -2
  68. package/build-types/actions/rename-post.d.ts.map +1 -1
  69. package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
  70. package/build-types/components/media-edit/index.d.ts.map +1 -1
  71. package/build-types/fields/description/index.d.ts +20 -0
  72. package/build-types/fields/description/index.d.ts.map +1 -0
  73. package/build-types/fields/index.d.ts +7 -1
  74. package/build-types/fields/index.d.ts.map +1 -1
  75. package/build-types/fields/last-edited/index.d.ts +14 -0
  76. package/build-types/fields/last-edited/index.d.ts.map +1 -0
  77. package/build-types/fields/last-edited/last-edited-date-view.d.ts +8 -0
  78. package/build-types/fields/last-edited/last-edited-date-view.d.ts.map +1 -0
  79. package/build-types/fields/password/edit.d.ts.map +1 -1
  80. package/build-types/fields/pattern-title/view.d.ts.map +1 -1
  81. package/build-types/fields/posts-page-title/index.d.ts +14 -0
  82. package/build-types/fields/posts-page-title/index.d.ts.map +1 -0
  83. package/build-types/fields/posts-per-page/index.d.ts +14 -0
  84. package/build-types/fields/posts-per-page/index.d.ts.map +1 -0
  85. package/build-types/fields/{date/scheduled → scheduled-date}/index.d.ts +1 -1
  86. package/build-types/fields/scheduled-date/index.d.ts.map +1 -0
  87. package/build-types/fields/site-discussion/index.d.ts +14 -0
  88. package/build-types/fields/site-discussion/index.d.ts.map +1 -0
  89. package/build-types/fields/template-author/index.d.ts +14 -0
  90. package/build-types/fields/template-author/index.d.ts.map +1 -0
  91. package/build-types/fields/template-author/view.d.ts +8 -0
  92. package/build-types/fields/template-author/view.d.ts.map +1 -0
  93. package/build-types/types.d.ts +17 -2
  94. package/build-types/types.d.ts.map +1 -1
  95. package/package.json +33 -28
  96. package/src/actions/rename-post.tsx +0 -1
  97. package/src/components/create-template-part-modal/index.tsx +0 -1
  98. package/src/components/media-edit/index.tsx +0 -1
  99. package/src/fields/description/index.tsx +65 -0
  100. package/src/fields/index.ts +13 -1
  101. package/src/fields/last-edited/index.tsx +29 -0
  102. package/src/fields/last-edited/last-edited-date-view.tsx +26 -0
  103. package/src/fields/password/edit.tsx +0 -1
  104. package/src/fields/pattern-title/view.tsx +0 -1
  105. package/src/fields/posts-page-title/index.ts +35 -0
  106. package/src/fields/posts-per-page/index.ts +30 -0
  107. package/src/fields/{date/scheduled → scheduled-date}/index.tsx +1 -1
  108. package/src/fields/site-discussion/index.ts +48 -0
  109. package/src/fields/template-author/index.tsx +60 -0
  110. package/src/fields/template-author/view.tsx +95 -0
  111. package/src/fields/template-title/index.ts +1 -1
  112. package/src/types.ts +18 -2
  113. package/build/fields/date/scheduled/index.cjs.map +0 -7
  114. package/build-module/fields/date/scheduled/index.mjs.map +0 -7
  115. package/build-types/fields/date/scheduled/index.d.ts.map +0 -1
  116. package/build-types/index.native.d.ts +0 -1
  117. package/build-types/index.native.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/fields",
3
- "version": "0.40.1",
3
+ "version": "0.41.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",
@@ -47,42 +47,47 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@react-spring/web": "^9.4.5",
50
- "@types/react": "^18.3.27",
51
- "@wordpress/api-fetch": "^7.48.1",
52
- "@wordpress/base-styles": "^10.0.1",
53
- "@wordpress/blob": "^4.48.1",
54
- "@wordpress/blocks": "^15.21.1",
55
- "@wordpress/components": "^35.0.1",
56
- "@wordpress/compose": "^8.1.1",
57
- "@wordpress/core-data": "^7.48.1",
58
- "@wordpress/data": "^10.48.1",
59
- "@wordpress/dataviews": "^16.0.1",
60
- "@wordpress/date": "^5.48.1",
61
- "@wordpress/element": "^8.0.1",
62
- "@wordpress/hooks": "^4.48.1",
63
- "@wordpress/html-entities": "^4.48.1",
64
- "@wordpress/i18n": "^6.21.1",
65
- "@wordpress/icons": "^14.0.1",
66
- "@wordpress/media-utils": "^5.48.1",
67
- "@wordpress/notices": "^5.48.1",
68
- "@wordpress/patterns": "^2.48.1",
69
- "@wordpress/primitives": "^4.48.1",
70
- "@wordpress/private-apis": "^1.48.1",
71
- "@wordpress/router": "^1.48.1",
72
- "@wordpress/ui": "^0.15.1",
73
- "@wordpress/url": "^4.48.1",
74
- "@wordpress/warning": "^3.48.1",
75
- "@wordpress/wordcount": "^4.48.1",
50
+ "@wordpress/api-fetch": "^7.49.0",
51
+ "@wordpress/base-styles": "^10.1.0",
52
+ "@wordpress/blob": "^4.49.0",
53
+ "@wordpress/blocks": "^15.22.0",
54
+ "@wordpress/components": "^36.0.0",
55
+ "@wordpress/compose": "^8.2.0",
56
+ "@wordpress/core-data": "^7.49.0",
57
+ "@wordpress/data": "^10.49.0",
58
+ "@wordpress/dataviews": "^17.0.0",
59
+ "@wordpress/date": "^5.49.0",
60
+ "@wordpress/element": "^8.1.0",
61
+ "@wordpress/hooks": "^4.49.0",
62
+ "@wordpress/html-entities": "^4.49.0",
63
+ "@wordpress/i18n": "^6.22.0",
64
+ "@wordpress/icons": "^15.0.0",
65
+ "@wordpress/media-utils": "^5.49.0",
66
+ "@wordpress/notices": "^5.49.0",
67
+ "@wordpress/patterns": "^2.49.0",
68
+ "@wordpress/primitives": "^4.49.0",
69
+ "@wordpress/private-apis": "^1.49.0",
70
+ "@wordpress/router": "^1.49.0",
71
+ "@wordpress/ui": "^0.16.0",
72
+ "@wordpress/url": "^4.49.0",
73
+ "@wordpress/warning": "^3.49.0",
74
+ "@wordpress/wordcount": "^4.49.0",
76
75
  "change-case": "^4.1.2",
77
76
  "client-zip": "^2.4.5",
78
77
  "clsx": "^2.1.1",
79
78
  "remove-accents": "^0.5.0"
80
79
  },
81
80
  "peerDependencies": {
81
+ "@types/react": "^18.3.27",
82
82
  "react": "^18.0.0"
83
83
  },
84
+ "peerDependenciesMeta": {
85
+ "@types/react": {
86
+ "optional": true
87
+ }
88
+ },
84
89
  "publishConfig": {
85
90
  "access": "public"
86
91
  },
87
- "gitHead": "99df7432c5c7cb83ba41146fd1f57f3c19004305"
92
+ "gitHead": "0e7112a4f4fde4ea15bd9060489b8f6fe11eb6ca"
88
93
  }
@@ -119,7 +119,6 @@ const renamePost: Action< PostWithPermissions > = {
119
119
  <form onSubmit={ onRename }>
120
120
  <VStack spacing="5">
121
121
  <TextControl
122
- __next40pxDefaultSize
123
122
  label={ __( 'Name' ) }
124
123
  value={ title }
125
124
  onChange={ setTitle }
@@ -195,7 +195,6 @@ export function CreateTemplatePartModalContents( {
195
195
  >
196
196
  <VStack spacing="4">
197
197
  <TextControl
198
- __next40pxDefaultSize
199
198
  label={ __( 'Name' ) }
200
199
  value={ title }
201
200
  onChange={ setTitle }
@@ -40,7 +40,6 @@ import {
40
40
  chevronLeft,
41
41
  chevronRight,
42
42
  } from '@wordpress/icons';
43
- // eslint-disable-next-line @wordpress/use-recommended-components -- `Tooltip` is not yet on the recommended `@wordpress/ui` allow-list; landing as a migration step ahead of the wider rollout.
44
43
  import { VisuallyHidden, Tooltip } from '@wordpress/ui';
45
44
  import {
46
45
  MediaUpload,
@@ -0,0 +1,65 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { decodeEntities } from '@wordpress/html-entities';
6
+ import { __ } from '@wordpress/i18n';
7
+ import { Text } from '@wordpress/ui';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import type { Template } from '../../types';
13
+
14
+ // A template is editable only when it's a user-created custom template.
15
+ // Theme-provided templates surface a read-only description instead.
16
+ const isCustomTemplate = ( item: Template ) =>
17
+ item.source === 'custom' && ! item.has_theme_file && item.is_custom;
18
+
19
+ const getValue = ( { item }: { item: Template } ) =>
20
+ decodeEntities( item.description || '' );
21
+
22
+ const render = ( { item }: { item: Template } ) => {
23
+ const { description } = item;
24
+ return description && <Text>{ decodeEntities( description ) }</Text>;
25
+ };
26
+
27
+ const descriptionField: Field< Template > = {
28
+ id: 'description',
29
+ type: 'text',
30
+ label: __( 'Description' ),
31
+ placeholder: __( 'Add a description' ),
32
+ getValue,
33
+ render,
34
+ Edit: {
35
+ control: 'textarea',
36
+ rows: 4,
37
+ },
38
+ isVisible: isCustomTemplate,
39
+ enableSorting: false,
40
+ filterBy: false,
41
+ enableGlobalSearch: true,
42
+ };
43
+
44
+ /**
45
+ * Read-only description field for theme-provided templates, which can't be
46
+ * edited. Shares the display config with `descriptionField` but renders as
47
+ * read-only and is only visible when a description exists.
48
+ */
49
+ export const readOnlyDescriptionField: Field< Template > = {
50
+ id: 'description_readonly',
51
+ type: 'text',
52
+ label: __( 'Description' ),
53
+ getValue,
54
+ render,
55
+ readOnly: true,
56
+ isVisible: ( item ) => ! isCustomTemplate( item ) && !! item.description,
57
+ enableSorting: false,
58
+ enableHiding: false,
59
+ filterBy: false,
60
+ };
61
+
62
+ /**
63
+ * Description field for templates.
64
+ */
65
+ export default descriptionField;
@@ -13,10 +13,22 @@ export { default as commentStatusField } from './comment-status';
13
13
  export { default as pingStatusField } from './ping-status';
14
14
  export { default as discussionField } from './discussion';
15
15
  export { default as dateField } from './date';
16
- export { default as scheduledDateField } from './date/scheduled';
16
+ export { default as scheduledDateField } from './scheduled-date';
17
+ export { default as lastEditedDateField } from './last-edited';
17
18
  export { default as authorField } from './author';
19
+ export {
20
+ templateAuthorField,
21
+ templatePartAuthorField,
22
+ } from './template-author';
18
23
  export { default as notesField } from './notes';
19
24
  export { default as excerptField } from './excerpt';
25
+ export {
26
+ default as descriptionField,
27
+ readOnlyDescriptionField,
28
+ } from './description';
20
29
  export { default as formatField } from './format';
21
30
  export { default as postContentInfoField } from './post-content-info';
22
31
  export { default as stickyField } from './sticky';
32
+ export { default as postsPerPageField } from './posts-per-page';
33
+ export { default as siteDiscussionField } from './site-discussion';
34
+ export { default as postsPageTitleField } from './posts-page-title';
@@ -0,0 +1,29 @@
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 LastEditedDateView from './last-edited-date-view';
12
+
13
+ const lastEditedDateField: Field< BasePost > = {
14
+ id: 'last_edited_date',
15
+ type: 'datetime',
16
+ label: __( 'Last edited' ),
17
+ render: LastEditedDateView,
18
+ getValue: ( { item } ) => item.modified,
19
+ isVisible: ( item ) => !! item.modified,
20
+ readOnly: true,
21
+ enableHiding: false,
22
+ enableSorting: false,
23
+ filterBy: false,
24
+ };
25
+
26
+ /**
27
+ * Last edited date field for BasePost.
28
+ */
29
+ export default lastEditedDateField;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { Text } from '@wordpress/ui';
5
+ import { __, sprintf } from '@wordpress/i18n';
6
+ import { humanTimeDiff } from '@wordpress/date';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import type { BasePost } from '../../types';
12
+
13
+ export default function LastEditedDateView( { item }: { item: BasePost } ) {
14
+ if ( ! item.modified ) {
15
+ return null;
16
+ }
17
+ return (
18
+ <Text>
19
+ { sprintf(
20
+ // translators: %s: Human-readable time difference, e.g. "2 days ago".
21
+ __( 'Last edited %s.' ),
22
+ humanTimeDiff( item.modified )
23
+ ) }
24
+ </Text>
25
+ );
26
+ }
@@ -55,7 +55,6 @@ function PasswordEdit( {
55
55
  value={ field.getValue( { item: data } ) || '' }
56
56
  placeholder={ __( 'Use a secure password' ) }
57
57
  type="text"
58
- __next40pxDefaultSize
59
58
  maxLength={ 255 }
60
59
  />
61
60
  </div>
@@ -5,7 +5,6 @@ import { __ } from '@wordpress/i18n';
5
5
  import { Icon, lockSmall } from '@wordpress/icons';
6
6
  // @ts-ignore
7
7
  import { privateApis as patternPrivateApis } from '@wordpress/patterns';
8
- // eslint-disable-next-line @wordpress/use-recommended-components -- `Tooltip` is not yet on the recommended `@wordpress/ui` allow-list; landing as a migration step ahead of the wider rollout.
9
8
  import { Tooltip, VisuallyHidden } from '@wordpress/ui';
10
9
 
11
10
  /**
@@ -0,0 +1,35 @@
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 { PostsPage } from '../../types';
11
+
12
+ const postsPageTitleField: Field< PostsPage > = {
13
+ id: 'posts_page_title',
14
+ type: 'text',
15
+ label: __( 'Blog title' ),
16
+ description: __(
17
+ 'Set the Posts Page title. Appears in search results, and when the page is shared on social media.'
18
+ ),
19
+ getValue: ( { item } ) => {
20
+ const title = item.title;
21
+ if ( typeof title === 'string' ) {
22
+ return title;
23
+ }
24
+ return title?.raw ?? '';
25
+ },
26
+ setValue: ( { value } ) => ( { title: value } ),
27
+ enableSorting: false,
28
+ enableHiding: false,
29
+ filterBy: false,
30
+ };
31
+
32
+ /**
33
+ * Title field for the posts page (the `page` assigned as `page_for_posts`).
34
+ */
35
+ export default postsPageTitleField;
@@ -0,0 +1,30 @@
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 { SiteSettings } from '../../types';
11
+
12
+ const postsPerPageField: Field< SiteSettings > = {
13
+ id: 'posts_per_page',
14
+ type: 'integer',
15
+ label: __( 'Posts per page' ),
16
+ description: __(
17
+ 'Set the default number of posts to display on blog pages, including categories and tags. Some templates may override this setting.'
18
+ ),
19
+ getValue: ( { item } ) => item.posts_per_page ?? 1,
20
+ setValue: ( { value } ) => ( { posts_per_page: value } ),
21
+ isValid: { min: 1 },
22
+ enableSorting: false,
23
+ enableHiding: false,
24
+ filterBy: false,
25
+ };
26
+
27
+ /**
28
+ * Posts per page field for the `root/site` entity.
29
+ */
30
+ export default postsPerPageField;
@@ -7,7 +7,7 @@ import { __ } from '@wordpress/i18n';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import type { BasePost } from '../../../types';
10
+ import type { BasePost } from '../../types';
11
11
 
12
12
  const scheduledDateField: Field< BasePost > = {
13
13
  id: 'scheduled_date',
@@ -0,0 +1,48 @@
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 { SiteSettings } from '../../types';
11
+
12
+ const siteDiscussionField: Field< SiteSettings > = {
13
+ id: 'default_comment_status',
14
+ type: 'text',
15
+ label: __( 'Discussion' ),
16
+ Edit: 'radio',
17
+ getValue: ( { item } ) => item.default_comment_status || '',
18
+ setValue: ( { value } ) => ( {
19
+ default_comment_status: value || null,
20
+ } ),
21
+ render: ( { item } ) => {
22
+ return item.default_comment_status === 'open'
23
+ ? __( 'Comments open' )
24
+ : __( 'Comments closed' );
25
+ },
26
+ elements: [
27
+ {
28
+ value: 'open',
29
+ label: __( 'Open' ),
30
+ description: __( 'Visitors can add new comments and replies.' ),
31
+ },
32
+ {
33
+ value: '',
34
+ label: __( 'Closed' ),
35
+ description: __(
36
+ 'Visitors cannot add new comments or replies. Existing comments remain visible.'
37
+ ),
38
+ },
39
+ ],
40
+ enableSorting: false,
41
+ enableHiding: false,
42
+ filterBy: false,
43
+ };
44
+
45
+ /**
46
+ * Discussion field for the `root/site` entity.
47
+ */
48
+ export default siteDiscussionField;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import type { Field } from '@wordpress/dataviews';
5
+ import { __ } from '@wordpress/i18n';
6
+ import { resolveSelect } from '@wordpress/data';
7
+ import { store as coreStore } from '@wordpress/core-data';
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import TemplateAuthorView from './view';
13
+ import type { Template, TemplatePart } from '../../types';
14
+
15
+ async function getAuthorElements(
16
+ postType: 'wp_template' | 'wp_template_part'
17
+ ) {
18
+ const records = ( await resolveSelect( coreStore ).getEntityRecords(
19
+ 'postType',
20
+ postType,
21
+ { per_page: -1, _fields: 'id,author_text' }
22
+ ) ) as ( Template | TemplatePart )[] | null;
23
+
24
+ const seen = new Set< string >();
25
+ const elements: { value: string; label: string }[] = [];
26
+ for ( const record of records ?? [] ) {
27
+ const value = record.author_text;
28
+ if ( value && ! seen.has( value ) ) {
29
+ seen.add( value );
30
+ elements.push( { value, label: value } );
31
+ }
32
+ }
33
+ return elements;
34
+ }
35
+
36
+ /**
37
+ * Author field for templates.
38
+ */
39
+ export const templateAuthorField: Field< Template > = {
40
+ label: __( 'Author' ),
41
+ id: 'author',
42
+ getValue: ( { item } ) => item.author_text,
43
+ render: TemplateAuthorView,
44
+ getElements: () => getAuthorElements( 'wp_template' ),
45
+ };
46
+
47
+ /**
48
+ * Author field for template parts.
49
+ */
50
+ export const templatePartAuthorField: Field< TemplatePart > = {
51
+ label: __( 'Author' ),
52
+ id: 'author',
53
+ getValue: ( { item } ) => item.author_text,
54
+ render: TemplateAuthorView,
55
+ enableSorting: false,
56
+ filterBy: {
57
+ isPrimary: true,
58
+ },
59
+ getElements: () => getAuthorElements( 'wp_template_part' ),
60
+ };
@@ -0,0 +1,95 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import clsx from 'clsx';
5
+
6
+ /**
7
+ * WordPress dependencies
8
+ */
9
+ import { useState } from '@wordpress/element';
10
+ import { useSelect } from '@wordpress/data';
11
+ import { store as coreStore } from '@wordpress/core-data';
12
+ import {
13
+ commentAuthorAvatar as authorIcon,
14
+ layout as themeIcon,
15
+ plugins as pluginIcon,
16
+ globe as globeIcon,
17
+ } from '@wordpress/icons';
18
+ import { Icon, Stack } from '@wordpress/ui';
19
+
20
+ /**
21
+ * Internal dependencies
22
+ */
23
+ import type { Template, TemplatePart } from '../../types';
24
+
25
+ function getIconForSource( originalSource: Template[ 'original_source' ] ) {
26
+ switch ( originalSource ) {
27
+ case 'theme':
28
+ return themeIcon;
29
+ case 'plugin':
30
+ return pluginIcon;
31
+ case 'site':
32
+ return globeIcon;
33
+ default:
34
+ return authorIcon;
35
+ }
36
+ }
37
+
38
+ export default function TemplateAuthorView( {
39
+ item,
40
+ }: {
41
+ item: Template | TemplatePart;
42
+ } ) {
43
+ const [ isImageLoaded, setIsImageLoaded ] = useState( false );
44
+ const originalSource = item.original_source;
45
+ const icon = getIconForSource( originalSource );
46
+ const text = item.author_text;
47
+ const authorId = item.author;
48
+
49
+ const imageUrl = useSelect(
50
+ ( select ) => {
51
+ if ( originalSource === 'site' ) {
52
+ const siteData = select( coreStore ).getEntityRecord< {
53
+ site_logo?: number;
54
+ } >( 'root', '__unstableBase' );
55
+ const logoId = siteData?.site_logo;
56
+ if ( ! logoId ) {
57
+ return undefined;
58
+ }
59
+ return select( coreStore ).getEntityRecord< {
60
+ source_url: string;
61
+ } >( 'postType', 'attachment', logoId )?.source_url;
62
+ }
63
+
64
+ if ( originalSource !== 'user' || ! authorId ) {
65
+ return undefined;
66
+ }
67
+ return select( coreStore ).getUser( authorId )?.avatar_urls?.[ 48 ];
68
+ },
69
+ [ originalSource, authorId ]
70
+ );
71
+
72
+ return (
73
+ <Stack direction="row" align="center">
74
+ { imageUrl && (
75
+ <div
76
+ className={ clsx( 'fields-controls__author-avatar', {
77
+ 'is-loaded': isImageLoaded,
78
+ } ) }
79
+ >
80
+ <img
81
+ onLoad={ () => setIsImageLoaded( true ) }
82
+ alt=""
83
+ src={ imageUrl }
84
+ />
85
+ </div>
86
+ ) }
87
+ { ! imageUrl && (
88
+ <div className="fields-controls__author-icon">
89
+ <Icon icon={ icon } />
90
+ </div>
91
+ ) }
92
+ <span className="fields-controls__author-name">{ text }</span>
93
+ </Stack>
94
+ );
95
+ }
@@ -12,10 +12,10 @@ import { getItemTitle } from '../../actions/utils';
12
12
  import TitleView from '../title/view';
13
13
 
14
14
  const templateTitleField: Field< Template > = {
15
+ id: 'title',
15
16
  type: 'text',
16
17
  label: __( 'Template' ),
17
18
  placeholder: __( 'No title' ),
18
- id: 'title',
19
19
  getValue: ( { item } ) => getItemTitle( item ),
20
20
  render: TitleView,
21
21
  enableHiding: false,
package/src/types.ts CHANGED
@@ -89,7 +89,13 @@ export interface BasePostWithEmbeddedFeaturedMedia extends BasePost {
89
89
  _embedded: EmbeddedFeaturedMedia;
90
90
  }
91
91
 
92
- export interface Template extends CommonPost {
92
+ interface TemplateAuthorFields {
93
+ author?: number;
94
+ author_text: string;
95
+ original_source?: 'theme' | 'plugin' | 'site' | 'user';
96
+ }
97
+
98
+ export interface Template extends CommonPost, TemplateAuthorFields {
93
99
  type: 'wp_template';
94
100
  is_custom: boolean;
95
101
  source: string;
@@ -97,9 +103,10 @@ export interface Template extends CommonPost {
97
103
  plugin?: string;
98
104
  has_theme_file: boolean;
99
105
  id: string;
106
+ description?: string;
100
107
  }
101
108
 
102
- export interface TemplatePart extends CommonPost {
109
+ export interface TemplatePart extends CommonPost, TemplateAuthorFields {
103
110
  type: 'wp_template_part';
104
111
  source: string;
105
112
  origin: string;
@@ -115,6 +122,15 @@ export interface Pattern extends CommonPost {
115
122
  wp_pattern_sync_status: string;
116
123
  }
117
124
 
125
+ export interface SiteSettings {
126
+ posts_per_page?: number;
127
+ default_comment_status?: string | null;
128
+ }
129
+
130
+ export interface PostsPage {
131
+ title?: { raw?: string } | string;
132
+ }
133
+
118
134
  export type Post = Template | TemplatePart | Pattern | BasePost;
119
135
 
120
136
  export type PostWithPermissions = Post & {
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/fields/date/scheduled/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../../types';\n\nconst scheduledDateField: Field< BasePost > = {\n\tid: 'scheduled_date',\n\ttype: 'datetime',\n\tlabel: __( 'Scheduled Date' ),\n\tgetValue: ( { item } ) => item.date,\n\tsetValue: ( { value } ) => ( { date: value } ),\n\tisVisible: ( item ) => item.status === 'future',\n\tEdit: {\n\t\tcontrol: 'datetime',\n\t\tcompact: true,\n\t},\n\tenableHiding: false,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\n/**\n * ScheduledDate Field.\n */\nexport default scheduledDateField;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAmB;AAOnB,IAAM,qBAAwC;AAAA,EAC7C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,WAAO,gBAAI,gBAAiB;AAAA,EAC5B,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,EAC/B,UAAU,CAAE,EAAE,MAAM,OAAS,EAAE,MAAM,MAAM;AAAA,EAC3C,WAAW,CAAE,SAAU,KAAK,WAAW;AAAA,EACvC,MAAM;AAAA,IACL,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAAA,EACA,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AACX;AAKA,IAAO,oBAAQ;",
6
- "names": []
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/fields/date/scheduled/index.tsx"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport type { Field } from '@wordpress/dataviews';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport type { BasePost } from '../../../types';\n\nconst scheduledDateField: Field< BasePost > = {\n\tid: 'scheduled_date',\n\ttype: 'datetime',\n\tlabel: __( 'Scheduled Date' ),\n\tgetValue: ( { item } ) => item.date,\n\tsetValue: ( { value } ) => ( { date: value } ),\n\tisVisible: ( item ) => item.status === 'future',\n\tEdit: {\n\t\tcontrol: 'datetime',\n\t\tcompact: true,\n\t},\n\tenableHiding: false,\n\tenableSorting: false,\n\tfilterBy: false,\n};\n\n/**\n * ScheduledDate Field.\n */\nexport default scheduledDateField;\n"],
5
- "mappings": ";AAIA,SAAS,UAAU;AAOnB,IAAM,qBAAwC;AAAA,EAC7C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO,GAAI,gBAAiB;AAAA,EAC5B,UAAU,CAAE,EAAE,KAAK,MAAO,KAAK;AAAA,EAC/B,UAAU,CAAE,EAAE,MAAM,OAAS,EAAE,MAAM,MAAM;AAAA,EAC3C,WAAW,CAAE,SAAU,KAAK,WAAW;AAAA,EACvC,MAAM;AAAA,IACL,SAAS;AAAA,IACT,SAAS;AAAA,EACV;AAAA,EACA,cAAc;AAAA,EACd,eAAe;AAAA,EACf,UAAU;AACX;AAKA,IAAO,oBAAQ;",
6
- "names": []
7
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/fields/date/scheduled/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,QAAA,MAAM,kBAAkB,EAAE,KAAK,CAAE,QAAQ,CAcxC,CAAC;AAEF;;GAEG;eACY,kBAAkB"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../src/index.native.ts"],"names":[],"mappings":""}