@wordpress/fields 0.34.0 → 0.35.1-next.v.202604091042.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 +9 -1
- package/build/components/media-edit/index.cjs +8 -1
- package/build/components/media-edit/index.cjs.map +2 -2
- package/build/fields/date/scheduled/index.cjs +4 -0
- package/build/fields/date/scheduled/index.cjs.map +2 -2
- package/build/fields/excerpt/index.cjs +61 -0
- package/build/fields/excerpt/index.cjs.map +7 -0
- package/build/fields/index.cjs +6 -0
- package/build/fields/index.cjs.map +2 -2
- package/build/fields/post-content-info/index.cjs.map +2 -2
- package/build/fields/post-content-info/post-content-info-view.cjs +9 -2
- package/build/fields/post-content-info/post-content-info-view.cjs.map +2 -2
- package/build/fields/sticky/index.cjs +38 -0
- package/build/fields/sticky/index.cjs.map +7 -0
- package/build/types.cjs.map +1 -1
- package/build-module/components/media-edit/index.mjs +8 -1
- package/build-module/components/media-edit/index.mjs.map +2 -2
- package/build-module/fields/date/scheduled/index.mjs +4 -0
- package/build-module/fields/date/scheduled/index.mjs.map +2 -2
- package/build-module/fields/excerpt/index.mjs +43 -0
- package/build-module/fields/excerpt/index.mjs.map +7 -0
- package/build-module/fields/index.mjs +8 -4
- package/build-module/fields/index.mjs.map +2 -2
- package/build-module/fields/post-content-info/index.mjs.map +2 -2
- package/build-module/fields/post-content-info/post-content-info-view.mjs +9 -2
- package/build-module/fields/post-content-info/post-content-info-view.mjs.map +2 -2
- package/build-module/fields/sticky/index.mjs +17 -0
- package/build-module/fields/sticky/index.mjs.map +7 -0
- package/build-style/style-rtl.css +4 -0
- package/build-style/style.css +4 -0
- package/build-types/components/media-edit/index.d.ts +1 -1
- package/build-types/components/media-edit/index.d.ts.map +1 -1
- package/build-types/fields/date/scheduled/index.d.ts.map +1 -1
- package/build-types/fields/excerpt/index.d.ts +14 -0
- package/build-types/fields/excerpt/index.d.ts.map +1 -0
- package/build-types/fields/index.d.ts +2 -0
- package/build-types/fields/index.d.ts.map +1 -1
- package/build-types/fields/post-content-info/index.d.ts +2 -2
- package/build-types/fields/post-content-info/index.d.ts.map +1 -1
- package/build-types/fields/post-content-info/post-content-info-view.d.ts +3 -3
- package/build-types/fields/post-content-info/post-content-info-view.d.ts.map +1 -1
- package/build-types/fields/status/status-elements.d.ts +11 -11
- package/build-types/fields/sticky/index.d.ts +14 -0
- package/build-types/fields/sticky/index.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts.map +1 -1
- package/build-types/types.d.ts +6 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +26 -26
- package/src/components/media-edit/index.tsx +5 -2
- package/src/components/media-edit/style.scss +5 -0
- package/src/fields/date/scheduled/index.tsx +4 -0
- package/src/fields/excerpt/index.tsx +57 -0
- package/src/fields/index.ts +2 -0
- package/src/fields/post-content-info/index.ts +2 -2
- package/src/fields/post-content-info/post-content-info-view.tsx +12 -6
- package/src/fields/sticky/index.tsx +26 -0
- package/src/stories/index.story.tsx +2 -2
- package/src/types.ts +9 -0
- package/build/fields/template/utils.cjs +0 -91
- package/build/fields/template/utils.cjs.map +0 -7
- package/build-module/fields/template/utils.mjs +0 -65
- package/build-module/fields/template/utils.mjs.map +0 -7
- package/build-types/fields/template/utils.d.ts +0 -28
- package/build-types/fields/template/utils.d.ts.map +0 -1
- package/src/fields/template/utils.ts +0 -119
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
5
|
-
/**
|
|
6
|
-
* Compute the template slug to look up in the template hierarchy.
|
|
7
|
-
*
|
|
8
|
-
* In `draft` status we might not have a slug available, so we use the
|
|
9
|
-
* `single` post type template slug (e.g. page, single-post,
|
|
10
|
-
* single-product, etc.). Pages do not need the `single` prefix to be
|
|
11
|
-
* prioritised through template hierarchy.
|
|
12
|
-
*
|
|
13
|
-
* @param postType The post type.
|
|
14
|
-
* @param slug The post slug.
|
|
15
|
-
*/
|
|
16
|
-
export declare function getTemplateSlugToCheck(postType: string, slug: string | undefined): string;
|
|
17
|
-
/**
|
|
18
|
-
* Resolve the human-readable label for the default template that would
|
|
19
|
-
* apply to a post, given its type, ID and slug. Meant to be called inside a
|
|
20
|
-
* `useSelect` callback (receives `select` as its first argument).
|
|
21
|
-
*
|
|
22
|
-
* @param select The `select` function from a `useSelect` callback.
|
|
23
|
-
* @param postType The post type.
|
|
24
|
-
* @param postId The post ID.
|
|
25
|
-
* @param slug The post slug.
|
|
26
|
-
*/
|
|
27
|
-
export declare function getDefaultTemplateLabel(select: (store: typeof coreStore) => any, postType: string | undefined, postId: string | number | undefined, slug: string | undefined): string;
|
|
28
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/fields/template/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAU1D;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GAAG,SAAS,GACtB,MAAM,CAOR;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,CAAE,KAAK,EAAE,OAAO,SAAS,KAAM,GAAG,EAC1C,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,EACnC,IAAI,EAAE,MAAM,GAAG,SAAS,GACtB,MAAM,CAmER"}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { store as coreStore } from '@wordpress/core-data';
|
|
5
|
-
import type { WpTemplate } from '@wordpress/core-data';
|
|
6
|
-
import { __ } from '@wordpress/i18n';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
import { getItemTitle } from '../../actions/utils';
|
|
12
|
-
import { unlock } from '../../lock-unlock';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Compute the template slug to look up in the template hierarchy.
|
|
16
|
-
*
|
|
17
|
-
* In `draft` status we might not have a slug available, so we use the
|
|
18
|
-
* `single` post type template slug (e.g. page, single-post,
|
|
19
|
-
* single-product, etc.). Pages do not need the `single` prefix to be
|
|
20
|
-
* prioritised through template hierarchy.
|
|
21
|
-
*
|
|
22
|
-
* @param postType The post type.
|
|
23
|
-
* @param slug The post slug.
|
|
24
|
-
*/
|
|
25
|
-
export function getTemplateSlugToCheck(
|
|
26
|
-
postType: string,
|
|
27
|
-
slug: string | undefined
|
|
28
|
-
): string {
|
|
29
|
-
if ( slug ) {
|
|
30
|
-
return postType === 'page'
|
|
31
|
-
? `${ postType }-${ slug }`
|
|
32
|
-
: `single-${ postType }-${ slug }`;
|
|
33
|
-
}
|
|
34
|
-
return postType === 'page' ? 'page' : `single-${ postType }`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Resolve the human-readable label for the default template that would
|
|
39
|
-
* apply to a post, given its type, ID and slug. Meant to be called inside a
|
|
40
|
-
* `useSelect` callback (receives `select` as its first argument).
|
|
41
|
-
*
|
|
42
|
-
* @param select The `select` function from a `useSelect` callback.
|
|
43
|
-
* @param postType The post type.
|
|
44
|
-
* @param postId The post ID.
|
|
45
|
-
* @param slug The post slug.
|
|
46
|
-
*/
|
|
47
|
-
export function getDefaultTemplateLabel(
|
|
48
|
-
select: ( store: typeof coreStore ) => any,
|
|
49
|
-
postType: string | undefined,
|
|
50
|
-
postId: string | number | undefined,
|
|
51
|
-
slug: string | undefined
|
|
52
|
-
): string {
|
|
53
|
-
if ( ! postType || ! postId ) {
|
|
54
|
-
return __( 'Default template' );
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// For the front page, we always use the front page template if existing.
|
|
58
|
-
const homePage = unlock( select( coreStore ) ).getHomePage();
|
|
59
|
-
if (
|
|
60
|
-
postType === 'page' &&
|
|
61
|
-
homePage?.postType === 'page' &&
|
|
62
|
-
homePage?.postId === String( postId )
|
|
63
|
-
) {
|
|
64
|
-
// The /lookup endpoint cannot currently handle a lookup
|
|
65
|
-
// when a page is set as the front page, so specifically in
|
|
66
|
-
// that case, we want to check if there is a front page
|
|
67
|
-
// template, and instead of falling back to the home
|
|
68
|
-
// template, we want to fall back to the page template.
|
|
69
|
-
const templates = select( coreStore ).getEntityRecords(
|
|
70
|
-
'postType',
|
|
71
|
-
'wp_template',
|
|
72
|
-
{ per_page: -1 }
|
|
73
|
-
);
|
|
74
|
-
const frontPage = templates?.find(
|
|
75
|
-
( t: WpTemplate ) => t.slug === 'front-page'
|
|
76
|
-
);
|
|
77
|
-
if ( frontPage ) {
|
|
78
|
-
return getItemTitle( frontPage );
|
|
79
|
-
}
|
|
80
|
-
// If no front page template is found, continue with the
|
|
81
|
-
// logic below (fetching the page template).
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const postsPageId = unlock( select( coreStore ) ).getPostsPageId();
|
|
85
|
-
// Check if the current page is the posts page.
|
|
86
|
-
if ( postType === 'page' && postsPageId === String( postId ) ) {
|
|
87
|
-
const templateId = select( coreStore ).getDefaultTemplateId( {
|
|
88
|
-
slug: 'home',
|
|
89
|
-
} );
|
|
90
|
-
if ( templateId ) {
|
|
91
|
-
const template = select( coreStore ).getEntityRecord(
|
|
92
|
-
'postType',
|
|
93
|
-
'wp_template',
|
|
94
|
-
templateId
|
|
95
|
-
);
|
|
96
|
-
if ( template ) {
|
|
97
|
-
return getItemTitle( template );
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return __( 'Default template' );
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const slugToCheck = getTemplateSlugToCheck( postType, slug );
|
|
104
|
-
const templateId = select( coreStore ).getDefaultTemplateId( {
|
|
105
|
-
slug: slugToCheck,
|
|
106
|
-
} );
|
|
107
|
-
|
|
108
|
-
if ( ! templateId ) {
|
|
109
|
-
return __( 'Default template' );
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const template = select( coreStore ).getEntityRecord(
|
|
113
|
-
'postType',
|
|
114
|
-
'wp_template',
|
|
115
|
-
templateId
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
return template ? getItemTitle( template ) : __( 'Default template' );
|
|
119
|
-
}
|