@wordpress/fields 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +16 -0
- package/build/actions/utils.js +2 -2
- package/build/actions/utils.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.map +1 -1
- package/build/fields/featured-image/featured-image-view.js.map +1 -1
- package/build/fields/featured-image/index.js +0 -3
- package/build/fields/featured-image/index.js.map +1 -1
- package/build/fields/index.js +28 -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 +0 -3
- package/build/fields/parent/index.js.map +1 -1
- package/build/fields/parent/parent-edit.js +6 -6
- package/build/fields/parent/parent-edit.js.map +1 -1
- package/build/fields/parent/parent-view.js +1 -1
- package/build/fields/parent/parent-view.js.map +1 -1
- 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 +0 -3
- package/build/fields/slug/index.js.map +1 -1
- package/build/fields/slug/slug-edit.js +23 -26
- package/build/fields/slug/slug-edit.js.map +1 -1
- package/build/fields/slug/slug-view.js +3 -2
- package/build/fields/slug/slug-view.js.map +1 -1
- 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/types.js.map +1 -1
- package/build-module/actions/utils.js +2 -2
- package/build-module/actions/utils.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 +1 -2
- package/build-module/fields/featured-image/featured-image-edit.js.map +1 -1
- package/build-module/fields/featured-image/featured-image-view.js.map +1 -1
- package/build-module/fields/featured-image/index.js +2 -4
- package/build-module/fields/featured-image/index.js.map +1 -1
- package/build-module/fields/index.js +4 -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 +2 -4
- package/build-module/fields/parent/index.js.map +1 -1
- package/build-module/fields/parent/parent-edit.js +10 -8
- package/build-module/fields/parent/parent-edit.js.map +1 -1
- package/build-module/fields/parent/parent-view.js +1 -1
- package/build-module/fields/parent/parent-view.js.map +1 -1
- 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 +2 -4
- package/build-module/fields/slug/index.js.map +1 -1
- package/build-module/fields/slug/slug-edit.js +25 -27
- package/build-module/fields/slug/slug-edit.js.map +1 -1
- package/build-module/fields/slug/slug-view.js +3 -2
- package/build-module/fields/slug/slug-view.js.map +1 -1
- 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/types.js.map +1 -1
- package/build-style/{styles-rtl.css → style-rtl.css} +79 -0
- package/build-style/{styles.css → style.css} +79 -0
- 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.map +1 -1
- package/build-types/fields/featured-image/featured-image-view.d.ts +1 -1
- package/build-types/fields/featured-image/featured-image-view.d.ts.map +1 -1
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/fields/index.d.ts +4 -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.map +1 -1
- package/build-types/fields/parent/parent-edit.d.ts +3 -0
- package/build-types/fields/parent/parent-edit.d.ts.map +1 -1
- package/build-types/fields/parent/parent-view.d.ts +1 -1
- package/build-types/fields/parent/parent-view.d.ts.map +1 -1
- 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.map +1 -1
- package/build-types/fields/slug/slug-edit.d.ts.map +1 -1
- package/build-types/fields/slug/slug-view.d.ts.map +1 -1
- 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 +3 -1
- package/build-types/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/actions/utils.ts +2 -2
- 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 +2 -1
- package/src/fields/featured-image/featured-image-view.tsx +1 -1
- package/src/fields/featured-image/index.ts +1 -2
- package/src/fields/index.ts +4 -0
- package/src/fields/order/index.ts +2 -1
- package/src/fields/parent/index.ts +1 -2
- package/src/fields/parent/parent-edit.tsx +9 -9
- package/src/fields/parent/parent-view.tsx +2 -2
- package/src/fields/password/edit.tsx +68 -0
- package/src/fields/password/index.tsx +24 -0
- package/src/fields/slug/index.ts +1 -2
- package/src/fields/slug/slug-edit.tsx +21 -24
- package/src/fields/slug/slug-view.tsx +3 -2
- 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/style.scss +2 -0
- package/src/types.ts +3 -1
- package/tsconfig.json +10 -9
- package/tsconfig.tsbuildinfo +1 -1
- package/src/styles.scss +0 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import removeAccents from 'remove-accents';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -12,21 +17,16 @@ import {
|
|
|
12
17
|
// @ts-ignore
|
|
13
18
|
import { store as coreStore } from '@wordpress/core-data';
|
|
14
19
|
import type { DataFormControlProps } from '@wordpress/dataviews';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import removeAccents from 'remove-accents';
|
|
20
|
+
import { debounce } from '@wordpress/compose';
|
|
21
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
22
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
23
|
+
import { filterURLForDisplay } from '@wordpress/url';
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* Internal dependencies
|
|
23
27
|
*/
|
|
24
|
-
import { debounce } from '@wordpress/compose';
|
|
25
|
-
import { decodeEntities } from '@wordpress/html-entities';
|
|
26
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
27
28
|
import type { BasePost } from '../../types';
|
|
28
29
|
import { getTitleWithFallbackName } from './utils';
|
|
29
|
-
import { filterURLForDisplay } from '@wordpress/url';
|
|
30
30
|
|
|
31
31
|
type TreeBase = {
|
|
32
32
|
id: number;
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
5
|
import { store as coreStore } from '@wordpress/core-data';
|
|
6
|
+
import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
|
|
7
|
+
import { __ } from '@wordpress/i18n';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Internal dependencies
|
|
9
11
|
*/
|
|
10
12
|
import type { BasePost } from '../../types';
|
|
11
|
-
import type { DataViewRenderFieldProps } from '@wordpress/dataviews';
|
|
12
13
|
import { getTitleWithFallbackName } from './utils';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
14
|
|
|
15
15
|
export const ParentView = ( {
|
|
16
16
|
item,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
CheckboxControl,
|
|
6
|
+
__experimentalVStack as VStack,
|
|
7
|
+
TextControl,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
import type { DataFormControlProps } from '@wordpress/dataviews';
|
|
10
|
+
import { useState } from '@wordpress/element';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import type { BasePost } from '../../types';
|
|
17
|
+
|
|
18
|
+
function PasswordEdit( {
|
|
19
|
+
data,
|
|
20
|
+
onChange,
|
|
21
|
+
field,
|
|
22
|
+
}: DataFormControlProps< BasePost > ) {
|
|
23
|
+
const [ showPassword, setShowPassword ] = useState(
|
|
24
|
+
!! field.getValue( { item: data } )
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const handleTogglePassword = ( value: boolean ) => {
|
|
28
|
+
setShowPassword( value );
|
|
29
|
+
if ( ! value ) {
|
|
30
|
+
onChange( { password: '' } );
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<VStack
|
|
36
|
+
as="fieldset"
|
|
37
|
+
spacing={ 4 }
|
|
38
|
+
className="fields-controls__password"
|
|
39
|
+
>
|
|
40
|
+
<CheckboxControl
|
|
41
|
+
__nextHasNoMarginBottom
|
|
42
|
+
label={ __( 'Password protected' ) }
|
|
43
|
+
help={ __( 'Only visible to those who know the password' ) }
|
|
44
|
+
checked={ showPassword }
|
|
45
|
+
onChange={ handleTogglePassword }
|
|
46
|
+
/>
|
|
47
|
+
{ showPassword && (
|
|
48
|
+
<div className="fields-controls__password-input">
|
|
49
|
+
<TextControl
|
|
50
|
+
label={ __( 'Password' ) }
|
|
51
|
+
onChange={ ( value ) =>
|
|
52
|
+
onChange( {
|
|
53
|
+
password: value,
|
|
54
|
+
} )
|
|
55
|
+
}
|
|
56
|
+
value={ field.getValue( { item: data } ) || '' }
|
|
57
|
+
placeholder={ __( 'Use a secure password' ) }
|
|
58
|
+
type="text"
|
|
59
|
+
__next40pxDefaultSize
|
|
60
|
+
__nextHasNoMarginBottom
|
|
61
|
+
maxLength={ 255 }
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
) }
|
|
65
|
+
</VStack>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
export default PasswordEdit;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Field } from '@wordpress/dataviews';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { BasePost } from '../../types';
|
|
10
|
+
import PasswordEdit from './edit';
|
|
11
|
+
|
|
12
|
+
const passwordField: Field< BasePost > = {
|
|
13
|
+
id: 'password',
|
|
14
|
+
type: 'text',
|
|
15
|
+
Edit: PasswordEdit,
|
|
16
|
+
enableSorting: false,
|
|
17
|
+
enableHiding: false,
|
|
18
|
+
isVisible: ( item ) => item.status !== 'private',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* This field is used to display the post password.
|
|
23
|
+
*/
|
|
24
|
+
export default passwordField;
|
package/src/fields/slug/index.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import type { Field } from '@wordpress/dataviews';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
10
|
import type { BasePost } from '../../types';
|
|
10
|
-
import { __ } from '@wordpress/i18n';
|
|
11
11
|
import SlugEdit from './slug-edit';
|
|
12
12
|
import SlugView from './slug-view';
|
|
13
13
|
|
|
@@ -15,7 +15,6 @@ const slugField: Field< BasePost > = {
|
|
|
15
15
|
id: 'slug',
|
|
16
16
|
type: 'text',
|
|
17
17
|
label: __( 'Slug' ),
|
|
18
|
-
getValue: ( { item } ) => item.slug,
|
|
19
18
|
Edit: SlugEdit,
|
|
20
19
|
render: SlugView,
|
|
21
20
|
};
|
|
@@ -21,6 +21,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
21
21
|
* Internal dependencies
|
|
22
22
|
*/
|
|
23
23
|
import type { BasePost } from '../../types';
|
|
24
|
+
import { getSlug } from './utils';
|
|
24
25
|
|
|
25
26
|
const SlugEdit = ( {
|
|
26
27
|
field,
|
|
@@ -29,7 +30,7 @@ const SlugEdit = ( {
|
|
|
29
30
|
}: DataFormControlProps< BasePost > ) => {
|
|
30
31
|
const { id } = field;
|
|
31
32
|
|
|
32
|
-
const slug = field.getValue( { item: data } )
|
|
33
|
+
const slug = field.getValue( { item: data } ) || getSlug( data );
|
|
33
34
|
const permalinkTemplate = data.permalink_template || '';
|
|
34
35
|
const PERMALINK_POSTNAME_REGEX = /%(?:postname|pagename)%/;
|
|
35
36
|
const [ prefix, suffix ] = permalinkTemplate.split(
|
|
@@ -115,30 +116,26 @@ const SlugEdit = ( {
|
|
|
115
116
|
}
|
|
116
117
|
} }
|
|
117
118
|
aria-describedby={ postUrlSlugDescriptionId }
|
|
118
|
-
help={
|
|
119
|
-
<>
|
|
120
|
-
<p className="fields-controls__slug-help">
|
|
121
|
-
<span className="fields-controls__slug-help-visual-label">
|
|
122
|
-
{ __( 'Permalink:' ) }
|
|
123
|
-
</span>
|
|
124
|
-
<ExternalLink
|
|
125
|
-
className="fields-controls__slug-help-link"
|
|
126
|
-
href={ permalink }
|
|
127
|
-
>
|
|
128
|
-
<span className="fields-controls__slug-help-prefix">
|
|
129
|
-
{ permalinkPrefix }
|
|
130
|
-
</span>
|
|
131
|
-
<span className="fields-controls__slug-help-slug">
|
|
132
|
-
{ slugToDisplay }
|
|
133
|
-
</span>
|
|
134
|
-
<span className="fields-controls__slug-help-suffix">
|
|
135
|
-
{ permalinkSuffix }
|
|
136
|
-
</span>
|
|
137
|
-
</ExternalLink>
|
|
138
|
-
</p>
|
|
139
|
-
</>
|
|
140
|
-
}
|
|
141
119
|
/>
|
|
120
|
+
<div className="fields-controls__slug-help">
|
|
121
|
+
<span className="fields-controls__slug-help-visual-label">
|
|
122
|
+
{ __( 'Permalink:' ) }
|
|
123
|
+
</span>
|
|
124
|
+
<ExternalLink
|
|
125
|
+
className="fields-controls__slug-help-link"
|
|
126
|
+
href={ permalink }
|
|
127
|
+
>
|
|
128
|
+
<span className="fields-controls__slug-help-prefix">
|
|
129
|
+
{ permalinkPrefix }
|
|
130
|
+
</span>
|
|
131
|
+
<span className="fields-controls__slug-help-slug">
|
|
132
|
+
{ slugToDisplay }
|
|
133
|
+
</span>
|
|
134
|
+
<span className="fields-controls__slug-help-suffix">
|
|
135
|
+
{ permalinkSuffix }
|
|
136
|
+
</span>
|
|
137
|
+
</ExternalLink>
|
|
138
|
+
</div>
|
|
142
139
|
</VStack>
|
|
143
140
|
) }
|
|
144
141
|
{ ! isEditable && (
|
|
@@ -7,9 +7,10 @@ import { useEffect, useRef } from '@wordpress/element';
|
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
9
|
import type { BasePost } from '../../types';
|
|
10
|
+
import { getSlug } from './utils';
|
|
10
11
|
|
|
11
12
|
const SlugView = ( { item }: { item: BasePost } ) => {
|
|
12
|
-
const slug = item
|
|
13
|
+
const slug = typeof item === 'object' ? getSlug( item ) : '';
|
|
13
14
|
const originalSlugRef = useRef( slug );
|
|
14
15
|
|
|
15
16
|
useEffect( () => {
|
|
@@ -20,7 +21,7 @@ const SlugView = ( { item }: { item: BasePost } ) => {
|
|
|
20
21
|
|
|
21
22
|
const slugToDisplay = slug || originalSlugRef.current;
|
|
22
23
|
|
|
23
|
-
return
|
|
24
|
+
return `${ slugToDisplay }`;
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
export default SlugView;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { cleanForSlug } from '@wordpress/url';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { BasePost } from '../../types';
|
|
9
|
+
import { getItemTitle } from '../../actions/utils';
|
|
10
|
+
|
|
11
|
+
export const getSlug = ( item: BasePost ): string => {
|
|
12
|
+
return (
|
|
13
|
+
item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString()
|
|
14
|
+
);
|
|
15
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Field } from '@wordpress/dataviews';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Internal dependencies
|
|
9
|
+
*/
|
|
10
|
+
import type { BasePost } from '../../types';
|
|
11
|
+
import StatusView from './status-view';
|
|
12
|
+
import STATUSES from './status-elements';
|
|
13
|
+
|
|
14
|
+
const OPERATOR_IS_ANY = 'isAny';
|
|
15
|
+
|
|
16
|
+
const statusField: Field< BasePost > = {
|
|
17
|
+
label: __( 'Status' ),
|
|
18
|
+
id: 'status',
|
|
19
|
+
type: 'text',
|
|
20
|
+
elements: STATUSES,
|
|
21
|
+
render: StatusView,
|
|
22
|
+
Edit: 'radio',
|
|
23
|
+
enableSorting: false,
|
|
24
|
+
filterBy: {
|
|
25
|
+
operators: [ OPERATOR_IS_ANY ],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Status field for BasePost.
|
|
31
|
+
*/
|
|
32
|
+
export default statusField;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
trash,
|
|
6
|
+
drafts,
|
|
7
|
+
published,
|
|
8
|
+
scheduled,
|
|
9
|
+
pending,
|
|
10
|
+
notAllowed,
|
|
11
|
+
} from '@wordpress/icons';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
|
|
14
|
+
// See https://github.com/WordPress/gutenberg/issues/55886
|
|
15
|
+
// We do not support custom statutes at the moment.
|
|
16
|
+
const STATUSES = [
|
|
17
|
+
{
|
|
18
|
+
value: 'draft',
|
|
19
|
+
label: __( 'Draft' ),
|
|
20
|
+
icon: drafts,
|
|
21
|
+
description: __( 'Not ready to publish.' ),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: 'future',
|
|
25
|
+
label: __( 'Scheduled' ),
|
|
26
|
+
icon: scheduled,
|
|
27
|
+
description: __( 'Publish automatically on a chosen date.' ),
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
value: 'pending',
|
|
31
|
+
label: __( 'Pending Review' ),
|
|
32
|
+
icon: pending,
|
|
33
|
+
description: __( 'Waiting for review before publishing.' ),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
value: 'private',
|
|
37
|
+
label: __( 'Private' ),
|
|
38
|
+
icon: notAllowed,
|
|
39
|
+
description: __( 'Only visible to site admins and editors.' ),
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
value: 'publish',
|
|
43
|
+
label: __( 'Published' ),
|
|
44
|
+
icon: published,
|
|
45
|
+
description: __( 'Visible to everyone.' ),
|
|
46
|
+
},
|
|
47
|
+
{ value: 'trash', label: __( 'Trash' ), icon: trash },
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export default STATUSES;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __experimentalHStack as HStack, Icon } from '@wordpress/components';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { BasePost } from '../../types';
|
|
10
|
+
import STATUSES from './status-elements';
|
|
11
|
+
|
|
12
|
+
function StatusView( { item }: { item: BasePost } ) {
|
|
13
|
+
const status = STATUSES.find( ( { value } ) => value === item.status );
|
|
14
|
+
const label = status?.label || item.status;
|
|
15
|
+
const icon = status?.icon;
|
|
16
|
+
return (
|
|
17
|
+
<HStack alignment="left" spacing={ 0 }>
|
|
18
|
+
{ icon && (
|
|
19
|
+
<div className="edit-site-post-list__status-icon">
|
|
20
|
+
<Icon icon={ icon } />
|
|
21
|
+
</div>
|
|
22
|
+
) }
|
|
23
|
+
<span>{ label }</span>
|
|
24
|
+
</HStack>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default StatusView;
|
|
@@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
9
9
|
*/
|
|
10
10
|
import type { BasePost } from '../../types';
|
|
11
11
|
import { getItemTitle } from '../../actions/utils';
|
|
12
|
+
import TitleView from './title-view';
|
|
12
13
|
|
|
13
14
|
const titleField: Field< BasePost > = {
|
|
14
15
|
type: 'text',
|
|
@@ -16,6 +17,8 @@ const titleField: Field< BasePost > = {
|
|
|
16
17
|
label: __( 'Title' ),
|
|
17
18
|
placeholder: __( 'No title' ),
|
|
18
19
|
getValue: ( { item } ) => getItemTitle( item ),
|
|
20
|
+
render: TitleView,
|
|
21
|
+
enableHiding: false,
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export default titleField;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __experimentalHStack as HStack } from '@wordpress/components';
|
|
5
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useSelect } from '@wordpress/data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import type { Settings } from '@wordpress/core-data';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import type { BasePost } from '../../types';
|
|
15
|
+
import { getItemTitle } from '../../actions/utils';
|
|
16
|
+
|
|
17
|
+
const TitleView = ( { item }: { item: BasePost } ) => {
|
|
18
|
+
const { frontPageId, postsPageId } = useSelect( ( select ) => {
|
|
19
|
+
const { getEntityRecord } = select( coreStore );
|
|
20
|
+
const siteSettings: Settings | undefined = getEntityRecord(
|
|
21
|
+
'root',
|
|
22
|
+
'site',
|
|
23
|
+
''
|
|
24
|
+
);
|
|
25
|
+
return {
|
|
26
|
+
frontPageId: siteSettings?.page_on_front,
|
|
27
|
+
postsPageId: siteSettings?.page_for_posts,
|
|
28
|
+
};
|
|
29
|
+
}, [] );
|
|
30
|
+
|
|
31
|
+
const renderedTitle = getItemTitle( item );
|
|
32
|
+
|
|
33
|
+
let suffix;
|
|
34
|
+
if ( item.id === frontPageId ) {
|
|
35
|
+
suffix = (
|
|
36
|
+
<span className="edit-site-post-list__title-badge">
|
|
37
|
+
{ __( 'Homepage' ) }
|
|
38
|
+
</span>
|
|
39
|
+
);
|
|
40
|
+
} else if ( item.id === postsPageId ) {
|
|
41
|
+
suffix = (
|
|
42
|
+
<span className="edit-site-post-list__title-badge">
|
|
43
|
+
{ __( 'Posts Page' ) }
|
|
44
|
+
</span>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<HStack
|
|
50
|
+
className="edit-site-post-list__title"
|
|
51
|
+
alignment="center"
|
|
52
|
+
justify="flex-start"
|
|
53
|
+
>
|
|
54
|
+
<span>
|
|
55
|
+
{ decodeEntities( renderedTitle ) || __( '(no title)' ) }
|
|
56
|
+
</span>
|
|
57
|
+
{ suffix }
|
|
58
|
+
</HStack>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default TitleView;
|
package/src/style.scss
ADDED
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type PostStatus =
|
|
2
|
-
| '
|
|
2
|
+
| 'publish'
|
|
3
3
|
| 'draft'
|
|
4
4
|
| 'pending'
|
|
5
5
|
| 'private'
|
|
@@ -37,6 +37,8 @@ export interface BasePost extends CommonPost {
|
|
|
37
37
|
link?: string;
|
|
38
38
|
slug?: string;
|
|
39
39
|
permalink_template?: string;
|
|
40
|
+
date?: string;
|
|
41
|
+
modified?: string;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export interface Template extends CommonPost {
|
package/tsconfig.json
CHANGED
|
@@ -8,24 +8,25 @@
|
|
|
8
8
|
},
|
|
9
9
|
"references": [
|
|
10
10
|
{ "path": "../api-fetch" },
|
|
11
|
+
{ "path": "../blob" },
|
|
11
12
|
{ "path": "../components" },
|
|
12
13
|
{ "path": "../compose" },
|
|
14
|
+
{ "path": "../core-data" },
|
|
13
15
|
{ "path": "../data" },
|
|
16
|
+
{ "path": "../dataviews" },
|
|
17
|
+
{ "path": "../date" },
|
|
14
18
|
{ "path": "../element" },
|
|
19
|
+
{ "path": "../hooks" },
|
|
20
|
+
{ "path": "../html-entities" },
|
|
15
21
|
{ "path": "../i18n" },
|
|
16
22
|
{ "path": "../icons" },
|
|
23
|
+
{ "path": "../media-utils" },
|
|
24
|
+
{ "path": "../notices" },
|
|
17
25
|
{ "path": "../primitives" },
|
|
18
26
|
{ "path": "../private-apis" },
|
|
19
|
-
{ "path": "../
|
|
27
|
+
{ "path": "../router" },
|
|
20
28
|
{ "path": "../url" },
|
|
21
|
-
{ "path": "../
|
|
22
|
-
{ "path": "../dataviews" },
|
|
23
|
-
{ "path": "../blob" },
|
|
24
|
-
{ "path": "../core-data" },
|
|
25
|
-
{ "path": "../hooks" },
|
|
26
|
-
{ "path": "../html-entities" },
|
|
27
|
-
{ "path": "../media-utils" },
|
|
28
|
-
{ "path": "../router" }
|
|
29
|
+
{ "path": "../warning" }
|
|
29
30
|
],
|
|
30
31
|
"include": [ "src" ]
|
|
31
32
|
}
|