@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.
- package/CHANGELOG.md +2 -0
- package/README.md +44 -0
- package/build/actions/rename-post.cjs +0 -1
- package/build/actions/rename-post.cjs.map +2 -2
- package/build/components/create-template-part-modal/index.cjs +0 -1
- package/build/components/create-template-part-modal/index.cjs.map +2 -2
- package/build/components/media-edit/index.cjs.map +2 -2
- package/build/fields/description/index.cjs +70 -0
- package/build/fields/description/index.cjs.map +7 -0
- package/build/fields/index.cjs +24 -2
- package/build/fields/index.cjs.map +2 -2
- package/build/fields/last-edited/index.cjs +51 -0
- package/build/fields/last-edited/index.cjs.map +7 -0
- package/build/fields/last-edited/last-edited-date-view.cjs +40 -0
- package/build/fields/last-edited/last-edited-date-view.cjs.map +7 -0
- package/build/fields/parent/parent-edit.cjs +1 -1
- package/build/fields/parent/parent-edit.cjs.map +2 -2
- package/build/fields/password/edit.cjs +0 -1
- package/build/fields/password/edit.cjs.map +2 -2
- package/build/fields/pattern-title/view.cjs.map +2 -2
- package/build/fields/posts-page-title/index.cjs +47 -0
- package/build/fields/posts-page-title/index.cjs.map +7 -0
- package/build/fields/posts-per-page/index.cjs +42 -0
- package/build/fields/posts-per-page/index.cjs.map +7 -0
- package/build/fields/{date/scheduled → scheduled-date}/index.cjs +6 -6
- package/build/fields/scheduled-date/index.cjs.map +7 -0
- package/build/fields/site-discussion/index.cjs +58 -0
- package/build/fields/site-discussion/index.cjs.map +7 -0
- package/build/fields/template-author/index.cjs +81 -0
- package/build/fields/template-author/index.cjs.map +7 -0
- package/build/fields/template-author/view.cjs +101 -0
- package/build/fields/template-author/view.cjs.map +7 -0
- package/build/fields/template-title/index.cjs +1 -1
- package/build/fields/template-title/index.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build-module/actions/rename-post.mjs +0 -1
- package/build-module/actions/rename-post.mjs.map +2 -2
- package/build-module/components/create-template-part-modal/index.mjs +0 -1
- package/build-module/components/create-template-part-modal/index.mjs.map +2 -2
- package/build-module/components/media-edit/index.mjs.map +2 -2
- package/build-module/fields/description/index.mjs +45 -0
- package/build-module/fields/description/index.mjs.map +7 -0
- package/build-module/fields/index.mjs +33 -13
- package/build-module/fields/index.mjs.map +2 -2
- package/build-module/fields/last-edited/index.mjs +20 -0
- package/build-module/fields/last-edited/index.mjs.map +7 -0
- package/build-module/fields/last-edited/last-edited-date-view.mjs +19 -0
- package/build-module/fields/last-edited/last-edited-date-view.mjs.map +7 -0
- package/build-module/fields/parent/parent-edit.mjs +1 -1
- package/build-module/fields/parent/parent-edit.mjs.map +2 -2
- package/build-module/fields/password/edit.mjs +0 -1
- package/build-module/fields/password/edit.mjs.map +2 -2
- package/build-module/fields/pattern-title/view.mjs.map +2 -2
- package/build-module/fields/posts-page-title/index.mjs +26 -0
- package/build-module/fields/posts-page-title/index.mjs.map +7 -0
- package/build-module/fields/posts-per-page/index.mjs +21 -0
- package/build-module/fields/posts-per-page/index.mjs.map +7 -0
- package/build-module/fields/{date/scheduled → scheduled-date}/index.mjs +3 -3
- package/build-module/fields/scheduled-date/index.mjs.map +7 -0
- package/build-module/fields/site-discussion/index.mjs +37 -0
- package/build-module/fields/site-discussion/index.mjs.map +7 -0
- package/build-module/fields/template-author/index.mjs +45 -0
- package/build-module/fields/template-author/index.mjs.map +7 -0
- package/build-module/fields/template-author/view.mjs +75 -0
- package/build-module/fields/template-author/view.mjs.map +7 -0
- package/build-module/fields/template-title/index.mjs +1 -1
- package/build-module/fields/template-title/index.mjs.map +2 -2
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -1
- package/build-types/components/media-edit/index.d.ts.map +1 -1
- package/build-types/fields/description/index.d.ts +20 -0
- package/build-types/fields/description/index.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +7 -1
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/last-edited/index.d.ts +14 -0
- package/build-types/fields/last-edited/index.d.ts.map +1 -0
- package/build-types/fields/last-edited/last-edited-date-view.d.ts +8 -0
- package/build-types/fields/last-edited/last-edited-date-view.d.ts.map +1 -0
- package/build-types/fields/password/edit.d.ts.map +1 -1
- package/build-types/fields/pattern-title/view.d.ts.map +1 -1
- package/build-types/fields/posts-page-title/index.d.ts +14 -0
- package/build-types/fields/posts-page-title/index.d.ts.map +1 -0
- package/build-types/fields/posts-per-page/index.d.ts +14 -0
- package/build-types/fields/posts-per-page/index.d.ts.map +1 -0
- package/build-types/fields/{date/scheduled → scheduled-date}/index.d.ts +1 -1
- package/build-types/fields/scheduled-date/index.d.ts.map +1 -0
- package/build-types/fields/site-discussion/index.d.ts +14 -0
- package/build-types/fields/site-discussion/index.d.ts.map +1 -0
- package/build-types/fields/template-author/index.d.ts +14 -0
- package/build-types/fields/template-author/index.d.ts.map +1 -0
- package/build-types/fields/template-author/view.d.ts +8 -0
- package/build-types/fields/template-author/view.d.ts.map +1 -0
- package/build-types/types.d.ts +17 -2
- package/build-types/types.d.ts.map +1 -1
- package/package.json +33 -28
- package/src/actions/rename-post.tsx +0 -1
- package/src/components/create-template-part-modal/index.tsx +0 -1
- package/src/components/media-edit/index.tsx +0 -1
- package/src/fields/description/index.tsx +65 -0
- package/src/fields/index.ts +13 -1
- package/src/fields/last-edited/index.tsx +29 -0
- package/src/fields/last-edited/last-edited-date-view.tsx +26 -0
- package/src/fields/password/edit.tsx +0 -1
- package/src/fields/pattern-title/view.tsx +0 -1
- package/src/fields/posts-page-title/index.ts +35 -0
- package/src/fields/posts-per-page/index.ts +30 -0
- package/src/fields/{date/scheduled → scheduled-date}/index.tsx +1 -1
- package/src/fields/site-discussion/index.ts +48 -0
- package/src/fields/template-author/index.tsx +60 -0
- package/src/fields/template-author/view.tsx +95 -0
- package/src/fields/template-title/index.ts +1 -1
- package/src/types.ts +18 -2
- package/build/fields/date/scheduled/index.cjs.map +0 -7
- package/build-module/fields/date/scheduled/index.mjs.map +0 -7
- package/build-types/fields/date/scheduled/index.d.ts.map +0 -1
- package/build-types/index.native.d.ts +0 -1
- 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.
|
|
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
|
-
"@
|
|
51
|
-
"@wordpress/
|
|
52
|
-
"@wordpress/
|
|
53
|
-
"@wordpress/
|
|
54
|
-
"@wordpress/
|
|
55
|
-
"@wordpress/
|
|
56
|
-
"@wordpress/
|
|
57
|
-
"@wordpress/
|
|
58
|
-
"@wordpress/
|
|
59
|
-
"@wordpress/
|
|
60
|
-
"@wordpress/
|
|
61
|
-
"@wordpress/
|
|
62
|
-
"@wordpress/
|
|
63
|
-
"@wordpress/
|
|
64
|
-
"@wordpress/
|
|
65
|
-
"@wordpress/
|
|
66
|
-
"@wordpress/
|
|
67
|
-
"@wordpress/
|
|
68
|
-
"@wordpress/
|
|
69
|
-
"@wordpress/
|
|
70
|
-
"@wordpress/
|
|
71
|
-
"@wordpress/
|
|
72
|
-
"@wordpress/
|
|
73
|
-
"@wordpress/
|
|
74
|
-
"@wordpress/
|
|
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": "
|
|
92
|
+
"gitHead": "0e7112a4f4fde4ea15bd9060489b8f6fe11eb6ca"
|
|
88
93
|
}
|
|
@@ -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;
|
package/src/fields/index.ts
CHANGED
|
@@ -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
|
|
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
|
+
}
|
|
@@ -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;
|
|
@@ -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
|
-
|
|
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":""}
|