@wordpress/fields 0.33.0 → 0.33.1-next.v.202603102151.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/README.md +12 -0
- package/build/fields/author/author-view.cjs +4 -4
- package/build/fields/author/author-view.cjs.map +2 -2
- package/build/fields/date/scheduled/index.cjs +39 -0
- package/build/fields/date/scheduled/index.cjs.map +7 -0
- package/build/fields/featured-image/index.cjs +1 -0
- package/build/fields/featured-image/index.cjs.map +2 -2
- package/build/fields/format/index.cjs +69 -0
- package/build/fields/format/index.cjs.map +7 -0
- package/build/fields/index.cjs +9 -0
- package/build/fields/index.cjs.map +2 -2
- package/build/fields/post-content-info/index.cjs +49 -0
- package/build/fields/post-content-info/index.cjs.map +7 -0
- package/build/fields/post-content-info/post-content-info-view.cjs +76 -0
- package/build/fields/post-content-info/post-content-info-view.cjs.map +7 -0
- package/build/fields/status/status-view.cjs +1 -1
- package/build/fields/status/status-view.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build-module/fields/author/author-view.mjs +4 -4
- package/build-module/fields/author/author-view.mjs.map +2 -2
- package/build-module/fields/date/scheduled/index.mjs +18 -0
- package/build-module/fields/date/scheduled/index.mjs.map +7 -0
- package/build-module/fields/featured-image/index.mjs +1 -0
- package/build-module/fields/featured-image/index.mjs.map +2 -2
- package/build-module/fields/format/index.mjs +48 -0
- package/build-module/fields/format/index.mjs.map +7 -0
- package/build-module/fields/index.mjs +10 -4
- package/build-module/fields/index.mjs.map +2 -2
- package/build-module/fields/post-content-info/index.mjs +18 -0
- package/build-module/fields/post-content-info/index.mjs.map +7 -0
- package/build-module/fields/post-content-info/post-content-info-view.mjs +58 -0
- package/build-module/fields/post-content-info/post-content-info-view.mjs.map +7 -0
- package/build-module/fields/status/status-view.mjs +1 -1
- package/build-module/fields/status/status-view.mjs.map +2 -2
- package/build-style/style-rtl.css +50 -0
- package/build-style/style.css +50 -0
- package/build-types/fields/date/scheduled/index.d.ts +14 -0
- package/build-types/fields/date/scheduled/index.d.ts.map +1 -0
- package/build-types/fields/featured-image/index.d.ts.map +1 -1
- package/build-types/fields/format/index.d.ts +14 -0
- package/build-types/fields/format/index.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +3 -0
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/post-content-info/index.d.ts +14 -0
- package/build-types/fields/post-content-info/index.d.ts.map +1 -0
- package/build-types/fields/post-content-info/post-content-info-view.d.ts +8 -0
- package/build-types/fields/post-content-info/post-content-info-view.d.ts.map +1 -0
- package/build-types/types.d.ts +1 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/fields/author/author-view.tsx +7 -7
- package/src/fields/author/style.scss +46 -0
- package/src/fields/date/scheduled/index.tsx +27 -0
- package/src/fields/featured-image/index.tsx +1 -0
- package/src/fields/format/index.ts +62 -0
- package/src/fields/index.ts +3 -0
- package/src/fields/post-content-info/index.ts +27 -0
- package/src/fields/post-content-info/post-content-info-view.tsx +88 -0
- package/src/fields/status/status-view.tsx +1 -1
- package/src/fields/status/style.scss +10 -0
- package/src/style.scss +2 -0
- package/src/types.ts +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@use "@wordpress/base-styles/variables" as *;
|
|
2
|
+
|
|
3
|
+
.fields-controls__author-avatar {
|
|
4
|
+
flex-shrink: 0;
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
width: $grid-unit-30;
|
|
7
|
+
height: $grid-unit-30;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: left;
|
|
10
|
+
display: flex;
|
|
11
|
+
|
|
12
|
+
img {
|
|
13
|
+
width: $grid-unit-20;
|
|
14
|
+
height: $grid-unit-20;
|
|
15
|
+
object-fit: cover;
|
|
16
|
+
opacity: 0;
|
|
17
|
+
border-radius: 100%;
|
|
18
|
+
|
|
19
|
+
@media not (prefers-reduced-motion) {
|
|
20
|
+
transition: opacity 0.1s linear;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&.is-loaded {
|
|
25
|
+
img {
|
|
26
|
+
opacity: 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.fields-controls__author-icon {
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-shrink: 0;
|
|
34
|
+
width: $grid-unit-30;
|
|
35
|
+
height: $grid-unit-30;
|
|
36
|
+
|
|
37
|
+
svg {
|
|
38
|
+
margin-left: -$grid-unit-05;
|
|
39
|
+
fill: currentColor;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fields-controls__author-name {
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 scheduledDateField: Field< BasePost > = {
|
|
13
|
+
id: 'scheduled_date',
|
|
14
|
+
type: 'datetime',
|
|
15
|
+
label: __( 'Scheduled Date' ),
|
|
16
|
+
getValue: ( { item } ) => item.date,
|
|
17
|
+
setValue: ( { value } ) => ( { date: value } ),
|
|
18
|
+
isVisible: ( item ) => item.status === 'future',
|
|
19
|
+
enableHiding: false,
|
|
20
|
+
enableSorting: false,
|
|
21
|
+
filterBy: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* ScheduledDate Field.
|
|
26
|
+
*/
|
|
27
|
+
export default scheduledDateField;
|
|
@@ -15,6 +15,7 @@ const featuredImageField: Field< BasePostWithEmbeddedFeaturedMedia > = {
|
|
|
15
15
|
id: 'featured_media',
|
|
16
16
|
type: 'media',
|
|
17
17
|
label: __( 'Featured Image' ),
|
|
18
|
+
placeholder: __( 'Set featured image' ),
|
|
18
19
|
Edit: ( props ) => <MediaEdit { ...props } isExpanded />,
|
|
19
20
|
render: FeaturedImageView,
|
|
20
21
|
setValue: ( { value } ) => ( {
|
|
@@ -0,0 +1,62 @@
|
|
|
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 type { BasePost } from '../../types';
|
|
13
|
+
|
|
14
|
+
// All WP post formats, sorted alphabetically by translated name.
|
|
15
|
+
const POST_FORMATS = [
|
|
16
|
+
{ id: 'aside', caption: __( 'Aside' ) },
|
|
17
|
+
{ id: 'audio', caption: __( 'Audio' ) },
|
|
18
|
+
{ id: 'chat', caption: __( 'Chat' ) },
|
|
19
|
+
{ id: 'gallery', caption: __( 'Gallery' ) },
|
|
20
|
+
{ id: 'image', caption: __( 'Image' ) },
|
|
21
|
+
{ id: 'link', caption: __( 'Link' ) },
|
|
22
|
+
{ id: 'quote', caption: __( 'Quote' ) },
|
|
23
|
+
{ id: 'standard', caption: __( 'Standard' ) },
|
|
24
|
+
{ id: 'status', caption: __( 'Status' ) },
|
|
25
|
+
{ id: 'video', caption: __( 'Video' ) },
|
|
26
|
+
].sort( ( a, b ) => {
|
|
27
|
+
const normalizedA = a.caption.toUpperCase();
|
|
28
|
+
const normalizedB = b.caption.toUpperCase();
|
|
29
|
+
|
|
30
|
+
if ( normalizedA < normalizedB ) {
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
if ( normalizedA > normalizedB ) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
} );
|
|
38
|
+
|
|
39
|
+
const formatField: Field< BasePost > = {
|
|
40
|
+
id: 'format',
|
|
41
|
+
label: __( 'Format' ),
|
|
42
|
+
type: 'text',
|
|
43
|
+
Edit: 'radio',
|
|
44
|
+
enableSorting: false,
|
|
45
|
+
enableHiding: false,
|
|
46
|
+
filterBy: false,
|
|
47
|
+
getElements: async () => {
|
|
48
|
+
const themeSupports =
|
|
49
|
+
await resolveSelect( coreStore ).getThemeSupports();
|
|
50
|
+
return POST_FORMATS.filter(
|
|
51
|
+
( f ) =>
|
|
52
|
+
( themeSupports?.formats as string[] | undefined )?.includes(
|
|
53
|
+
f.id
|
|
54
|
+
)
|
|
55
|
+
).map( ( f ) => ( { value: f.id, label: f.caption } ) );
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Format field for BasePost.
|
|
61
|
+
*/
|
|
62
|
+
export default formatField;
|
package/src/fields/index.ts
CHANGED
|
@@ -13,5 +13,8 @@ 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
17
|
export { default as authorField } from './author';
|
|
17
18
|
export { default as notesField } from './notes';
|
|
19
|
+
export { default as formatField } from './format';
|
|
20
|
+
export { default as postContentInfoField } from './post-content-info';
|
|
@@ -0,0 +1,27 @@
|
|
|
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 PostContentInfoView from './post-content-info-view';
|
|
12
|
+
|
|
13
|
+
const postContentInfoField: Field< BasePost > = {
|
|
14
|
+
label: __( 'Post content information' ),
|
|
15
|
+
id: 'post-content-info',
|
|
16
|
+
type: 'text',
|
|
17
|
+
readOnly: true,
|
|
18
|
+
render: PostContentInfoView,
|
|
19
|
+
enableSorting: false,
|
|
20
|
+
enableHiding: false,
|
|
21
|
+
filterBy: false,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Post content information field for BasePost.
|
|
26
|
+
*/
|
|
27
|
+
export default postContentInfoField;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import {
|
|
5
|
+
__experimentalText as Text,
|
|
6
|
+
__experimentalVStack as VStack,
|
|
7
|
+
} from '@wordpress/components';
|
|
8
|
+
import { __, _x, _n, sprintf } from '@wordpress/i18n';
|
|
9
|
+
import { count as wordCount } from '@wordpress/wordcount';
|
|
10
|
+
import type { Strategy } from '@wordpress/wordcount';
|
|
11
|
+
import { humanTimeDiff } from '@wordpress/date';
|
|
12
|
+
import { useMemo } from '@wordpress/element';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal dependencies
|
|
16
|
+
*/
|
|
17
|
+
import type { BasePost } from '../../types';
|
|
18
|
+
|
|
19
|
+
// Taken from packages/editor/src/components/time-to-read/index.js.
|
|
20
|
+
const AVERAGE_READING_RATE = 189;
|
|
21
|
+
|
|
22
|
+
export default function PostContentInfoView( { item }: { item: BasePost } ) {
|
|
23
|
+
const content =
|
|
24
|
+
typeof item.content === 'string'
|
|
25
|
+
? item.content
|
|
26
|
+
: item.content?.raw || '';
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* translators: If your word count is based on single characters (e.g. East Asian characters),
|
|
30
|
+
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
|
|
31
|
+
* Do not translate into your own language.
|
|
32
|
+
*/
|
|
33
|
+
const wordCountType = _x(
|
|
34
|
+
'words',
|
|
35
|
+
'Word count type. Do not translate!'
|
|
36
|
+
) as Strategy;
|
|
37
|
+
const wordsCounted = useMemo(
|
|
38
|
+
() => ( content ? wordCount( content, wordCountType ) : 0 ),
|
|
39
|
+
[ content, wordCountType ]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const modified = item.modified;
|
|
43
|
+
|
|
44
|
+
if ( ! wordsCounted && ! modified ) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let contentInfoText: string | undefined;
|
|
49
|
+
if ( wordsCounted ) {
|
|
50
|
+
const readingTime = Math.round( wordsCounted / AVERAGE_READING_RATE );
|
|
51
|
+
const wordsCountText = sprintf(
|
|
52
|
+
// translators: %s: the number of words in the post.
|
|
53
|
+
_n( '%s word', '%s words', wordsCounted ),
|
|
54
|
+
wordsCounted.toLocaleString()
|
|
55
|
+
);
|
|
56
|
+
const minutesText =
|
|
57
|
+
readingTime <= 1
|
|
58
|
+
? __( '1 minute' )
|
|
59
|
+
: sprintf(
|
|
60
|
+
/* translators: %s: the number of minutes to read the post. */
|
|
61
|
+
_n( '%s minute', '%s minutes', readingTime ),
|
|
62
|
+
readingTime.toLocaleString()
|
|
63
|
+
);
|
|
64
|
+
contentInfoText = sprintf(
|
|
65
|
+
/* translators: 1: How many words a post has. 2: the number of minutes to read the post (e.g. 130 words, 2 minutes read time.) */
|
|
66
|
+
__( '%1$s, %2$s read time.' ),
|
|
67
|
+
wordsCountText,
|
|
68
|
+
minutesText
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<VStack spacing={ 1 }>
|
|
74
|
+
{ contentInfoText && (
|
|
75
|
+
<Text variant="muted">{ contentInfoText }</Text>
|
|
76
|
+
) }
|
|
77
|
+
{ modified && (
|
|
78
|
+
<Text variant="muted">
|
|
79
|
+
{ sprintf(
|
|
80
|
+
// translators: %s: Human-readable time difference, e.g. "2 days ago".
|
|
81
|
+
__( 'Last edited %s.' ),
|
|
82
|
+
humanTimeDiff( modified )
|
|
83
|
+
) }
|
|
84
|
+
</Text>
|
|
85
|
+
) }
|
|
86
|
+
</VStack>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -16,7 +16,7 @@ function StatusView( { item }: { item: BasePost } ) {
|
|
|
16
16
|
return (
|
|
17
17
|
<HStack alignment="left" spacing={ 0 }>
|
|
18
18
|
{ icon && (
|
|
19
|
-
<div className="
|
|
19
|
+
<div className="fields-controls__status-icon">
|
|
20
20
|
<Icon icon={ icon } />
|
|
21
21
|
</div>
|
|
22
22
|
) }
|
package/src/style.scss
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/default-custom-properties";
|
|
2
2
|
@use "./components/create-template-part-modal/style.scss" as *;
|
|
3
3
|
@use "./components/media-edit/style.scss" as *;
|
|
4
|
+
@use "./fields/author/style.scss" as *;
|
|
4
5
|
@use "./fields/slug/style.scss" as *;
|
|
5
6
|
@use "./fields/featured-image/style.scss" as *;
|
|
6
7
|
@use "./fields/parent/style.scss" as *;
|
|
7
8
|
@use "./fields/password/style.scss" as *;
|
|
9
|
+
@use "./fields/status/style.scss" as *;
|
|
8
10
|
@use "./fields/title/style.scss" as *;
|
|
9
11
|
@use "./fields/pattern-title/style.scss" as *;
|