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