@wordpress/fields 0.5.0 → 0.5.1-next.a9f418477.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 +52 -27
- package/build/actions/delete-post.js +4 -0
- package/build/actions/delete-post.js.map +1 -1
- package/build/actions/duplicate-pattern.js +4 -0
- package/build/actions/duplicate-pattern.js.map +1 -1
- package/build/actions/duplicate-post.js +7 -3
- package/build/actions/duplicate-post.js.map +1 -1
- package/build/actions/duplicate-template-part.js +71 -0
- package/build/actions/duplicate-template-part.js.map +1 -0
- package/build/actions/export-pattern.js +4 -0
- package/build/actions/export-pattern.js.map +1 -1
- package/build/actions/index.js +3 -17
- package/build/actions/index.js.map +1 -1
- package/build/actions/permanently-delete-post.js +4 -1
- package/build/actions/permanently-delete-post.js.map +1 -1
- package/build/actions/rename-post.js +6 -2
- package/build/actions/rename-post.js.map +1 -1
- package/build/actions/reorder-page.js +4 -0
- package/build/actions/reorder-page.js.map +1 -1
- package/build/actions/reset-post.js +7 -3
- package/build/actions/reset-post.js.map +1 -1
- package/build/actions/restore-post.js +4 -1
- package/build/actions/restore-post.js.map +1 -1
- package/build/actions/trash-post.js +4 -1
- package/build/actions/trash-post.js.map +1 -1
- package/build/actions/utils.js +4 -12
- package/build/actions/utils.js.map +1 -1
- package/build/actions/view-post-revisions.js +4 -0
- package/build/actions/view-post-revisions.js.map +1 -1
- package/build/actions/view-post.js +4 -0
- package/build/actions/view-post.js.map +1 -1
- package/build/components/create-template-part-modal/index.js +213 -0
- package/build/components/create-template-part-modal/index.js.map +1 -0
- package/build/components/create-template-part-modal/utils.js +64 -0
- package/build/components/create-template-part-modal/utils.js.map +1 -0
- package/build/fields/featured-image/index.js +4 -0
- 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 +4 -0
- package/build/fields/order/index.js.map +1 -1
- package/build/fields/page-title/index.js +36 -0
- package/build/fields/page-title/index.js.map +1 -0
- package/build/fields/page-title/view.js +45 -0
- package/build/fields/page-title/view.js.map +1 -0
- package/build/fields/parent/index.js +1 -1
- package/build/fields/parent/index.js.map +1 -1
- package/build/fields/password/index.js +1 -1
- package/build/fields/password/index.js.map +1 -1
- package/build/fields/pattern-title/index.js +36 -0
- package/build/fields/pattern-title/index.js.map +1 -0
- package/build/fields/pattern-title/view.js +45 -0
- package/build/fields/pattern-title/view.js.map +1 -0
- package/build/fields/slug/index.js +4 -0
- package/build/fields/slug/index.js.map +1 -1
- package/build/fields/slug/slug-view.js +1 -1
- package/build/fields/slug/slug-view.js.map +1 -1
- package/build/fields/slug/utils.js +3 -0
- package/build/fields/slug/utils.js.map +1 -1
- package/build/fields/template/index.js +29 -0
- package/build/fields/template/index.js.map +1 -0
- package/build/fields/template/template-edit.js +154 -0
- package/build/fields/template/template-edit.js.map +1 -0
- package/build/fields/template-title/index.js +36 -0
- package/build/fields/template-title/index.js.map +1 -0
- package/build/fields/title/index.js +10 -3
- package/build/fields/title/index.js.map +1 -1
- package/build/fields/title/view.js +48 -0
- package/build/fields/title/view.js.map +1 -0
- package/build/index.js +13 -0
- package/build/index.js.map +1 -1
- package/build/index.native.js +0 -26
- package/build/index.native.js.map +1 -1
- package/build/mutation/index.js +0 -1
- package/build/mutation/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build-module/actions/delete-post.js +4 -0
- package/build-module/actions/delete-post.js.map +1 -1
- package/build-module/actions/duplicate-pattern.js +4 -0
- package/build-module/actions/duplicate-pattern.js.map +1 -1
- package/build-module/actions/duplicate-post.js +7 -3
- package/build-module/actions/duplicate-post.js.map +1 -1
- package/build-module/actions/duplicate-template-part.js +66 -0
- package/build-module/actions/duplicate-template-part.js.map +1 -0
- package/build-module/actions/export-pattern.js +4 -0
- package/build-module/actions/export-pattern.js.map +1 -1
- package/build-module/actions/index.js +1 -3
- package/build-module/actions/index.js.map +1 -1
- package/build-module/actions/permanently-delete-post.js +4 -1
- package/build-module/actions/permanently-delete-post.js.map +1 -1
- package/build-module/actions/rename-post.js +7 -3
- package/build-module/actions/rename-post.js.map +1 -1
- package/build-module/actions/reorder-page.js +4 -0
- package/build-module/actions/reorder-page.js.map +1 -1
- package/build-module/actions/reset-post.js +8 -4
- package/build-module/actions/reset-post.js.map +1 -1
- package/build-module/actions/restore-post.js +4 -1
- package/build-module/actions/restore-post.js.map +1 -1
- package/build-module/actions/trash-post.js +4 -1
- package/build-module/actions/trash-post.js.map +1 -1
- package/build-module/actions/utils.js +4 -11
- package/build-module/actions/utils.js.map +1 -1
- package/build-module/actions/view-post-revisions.js +4 -0
- package/build-module/actions/view-post-revisions.js.map +1 -1
- package/build-module/actions/view-post.js +4 -0
- package/build-module/actions/view-post.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +204 -0
- package/build-module/components/create-template-part-modal/index.js.map +1 -0
- package/build-module/components/create-template-part-modal/utils.js +55 -0
- package/build-module/components/create-template-part-modal/utils.js.map +1 -0
- package/build-module/fields/featured-image/index.js +4 -0
- 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 +4 -0
- package/build-module/fields/order/index.js.map +1 -1
- package/build-module/fields/page-title/index.js +30 -0
- package/build-module/fields/page-title/index.js.map +1 -0
- package/build-module/fields/page-title/view.js +39 -0
- package/build-module/fields/page-title/view.js.map +1 -0
- package/build-module/fields/parent/index.js +1 -1
- package/build-module/fields/parent/index.js.map +1 -1
- package/build-module/fields/password/index.js +1 -1
- package/build-module/fields/password/index.js.map +1 -1
- package/build-module/fields/pattern-title/index.js +30 -0
- package/build-module/fields/pattern-title/index.js.map +1 -0
- package/build-module/fields/pattern-title/view.js +36 -0
- package/build-module/fields/pattern-title/view.js.map +1 -0
- package/build-module/fields/slug/index.js +4 -0
- package/build-module/fields/slug/index.js.map +1 -1
- package/build-module/fields/slug/slug-view.js +1 -1
- package/build-module/fields/slug/slug-view.js.map +1 -1
- package/build-module/fields/slug/utils.js +3 -0
- package/build-module/fields/slug/utils.js.map +1 -1
- package/build-module/fields/template/index.js +22 -0
- package/build-module/fields/template/index.js.map +1 -0
- package/build-module/fields/template/template-edit.js +144 -0
- package/build-module/fields/template/template-edit.js.map +1 -0
- package/build-module/fields/template-title/index.js +30 -0
- package/build-module/fields/template-title/index.js.map +1 -0
- package/build-module/fields/title/index.js +9 -2
- package/build-module/fields/title/index.js.map +1 -1
- package/build-module/fields/title/view.js +39 -0
- package/build-module/fields/title/view.js.map +1 -0
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +1 -2
- package/build-module/index.native.js.map +1 -1
- package/build-module/mutation/index.js +0 -1
- package/build-module/mutation/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-style/style-rtl.css +98 -0
- package/build-style/style.css +98 -0
- package/build-types/actions/delete-post.d.ts +3 -0
- package/build-types/actions/delete-post.d.ts.map +1 -1
- package/build-types/actions/duplicate-pattern.d.ts +3 -0
- package/build-types/actions/duplicate-pattern.d.ts.map +1 -1
- package/build-types/actions/duplicate-post.d.ts +3 -0
- package/build-types/actions/duplicate-post.d.ts.map +1 -1
- package/build-types/actions/duplicate-template-part.d.ts +14 -0
- package/build-types/actions/duplicate-template-part.d.ts.map +1 -0
- package/build-types/actions/export-pattern.d.ts +3 -0
- package/build-types/actions/export-pattern.d.ts.map +1 -1
- package/build-types/actions/index.d.ts +1 -3
- package/build-types/actions/index.d.ts.map +1 -1
- package/build-types/actions/permanently-delete-post.d.ts +3 -0
- package/build-types/actions/permanently-delete-post.d.ts.map +1 -1
- package/build-types/actions/rename-post.d.ts +3 -0
- package/build-types/actions/rename-post.d.ts.map +1 -1
- package/build-types/actions/reorder-page.d.ts +3 -0
- package/build-types/actions/reorder-page.d.ts.map +1 -1
- package/build-types/actions/reset-post.d.ts +3 -0
- package/build-types/actions/reset-post.d.ts.map +1 -1
- package/build-types/actions/restore-post.d.ts +3 -0
- package/build-types/actions/restore-post.d.ts.map +1 -1
- package/build-types/actions/trash-post.d.ts +3 -0
- package/build-types/actions/trash-post.d.ts.map +1 -1
- package/build-types/actions/utils.d.ts +7 -8
- package/build-types/actions/utils.d.ts.map +1 -1
- package/build-types/actions/view-post-revisions.d.ts +3 -0
- package/build-types/actions/view-post-revisions.d.ts.map +1 -1
- package/build-types/actions/view-post.d.ts +3 -0
- package/build-types/actions/view-post.d.ts.map +1 -1
- package/build-types/components/create-template-part-modal/index.d.ts +34 -0
- package/build-types/components/create-template-part-modal/index.d.ts.map +1 -0
- package/build-types/components/create-template-part-modal/utils.d.ts +4 -0
- package/build-types/components/create-template-part-modal/utils.d.ts.map +1 -0
- package/build-types/fields/featured-image/index.d.ts +3 -0
- 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 +3 -0
- package/build-types/fields/order/index.d.ts.map +1 -1
- package/build-types/fields/page-title/index.d.ts +14 -0
- package/build-types/fields/page-title/index.d.ts.map +1 -0
- package/build-types/fields/page-title/view.d.ts +8 -0
- package/build-types/fields/page-title/view.d.ts.map +1 -0
- package/build-types/fields/parent/index.d.ts +1 -1
- package/build-types/fields/password/index.d.ts +1 -1
- package/build-types/fields/pattern-title/index.d.ts +14 -0
- package/build-types/fields/pattern-title/index.d.ts.map +1 -0
- package/build-types/fields/pattern-title/view.d.ts +9 -0
- package/build-types/fields/pattern-title/view.d.ts.map +1 -0
- package/build-types/fields/slug/index.d.ts +3 -0
- package/build-types/fields/slug/index.d.ts.map +1 -1
- package/build-types/fields/slug/utils.d.ts.map +1 -1
- package/build-types/fields/template/index.d.ts +11 -0
- package/build-types/fields/template/index.d.ts.map +1 -0
- package/build-types/fields/template/template-edit.d.ts +4 -0
- package/build-types/fields/template/template-edit.d.ts.map +1 -0
- package/build-types/fields/template-title/index.d.ts +14 -0
- package/build-types/fields/template-title/index.d.ts.map +1 -0
- package/build-types/fields/title/index.d.ts +7 -2
- package/build-types/fields/title/index.d.ts.map +1 -1
- package/build-types/fields/title/view.d.ts +14 -0
- package/build-types/fields/title/view.d.ts.map +1 -0
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/index.native.d.ts +0 -2
- package/build-types/index.native.d.ts.map +1 -1
- 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 -0
- package/build-types/types.d.ts.map +1 -1
- package/package.json +24 -23
- package/src/actions/delete-post.tsx +3 -0
- package/src/actions/duplicate-pattern.tsx +3 -0
- package/src/actions/duplicate-post.tsx +6 -3
- package/src/actions/duplicate-template-part.tsx +74 -0
- package/src/actions/export-pattern.tsx +3 -0
- package/src/actions/index.ts +1 -3
- package/src/actions/permanently-delete-post.tsx +3 -0
- package/src/actions/rename-post.tsx +6 -6
- package/src/actions/reorder-page.tsx +3 -0
- package/src/actions/reset-post.tsx +7 -9
- package/src/actions/restore-post.tsx +3 -0
- package/src/actions/trash-post.tsx +3 -0
- package/src/actions/utils.ts +7 -15
- package/src/actions/view-post-revisions.tsx +3 -0
- package/src/actions/view-post.tsx +3 -0
- package/src/components/create-template-part-modal/index.tsx +274 -0
- package/src/components/create-template-part-modal/style.scss +63 -0
- package/src/components/create-template-part-modal/test/utils.js +60 -0
- package/src/components/create-template-part-modal/utils.js +68 -0
- package/src/fields/featured-image/index.ts +3 -0
- package/src/fields/index.ts +4 -0
- package/src/fields/order/index.ts +3 -0
- package/src/fields/page-title/index.ts +28 -0
- package/src/fields/page-title/style.scss +10 -0
- package/src/fields/page-title/view.tsx +38 -0
- package/src/fields/parent/index.ts +1 -1
- package/src/fields/password/index.tsx +1 -1
- package/src/fields/pattern-title/index.ts +28 -0
- package/src/fields/pattern-title/style.scss +3 -0
- package/src/fields/pattern-title/view.tsx +32 -0
- package/src/fields/slug/index.ts +3 -0
- package/src/fields/slug/slug-view.tsx +1 -1
- package/src/fields/slug/utils.ts +4 -0
- package/src/fields/template/index.ts +24 -0
- package/src/fields/template/style.scss +23 -0
- package/src/fields/template/template-edit.tsx +210 -0
- package/src/fields/template-title/index.ts +28 -0
- package/src/fields/title/index.ts +9 -3
- package/src/fields/title/style.scss +8 -0
- package/src/fields/title/view.tsx +43 -0
- package/src/index.native.ts +0 -2
- package/src/index.ts +2 -1
- package/src/style.scss +5 -0
- package/src/types.ts +3 -0
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/actions/duplicate-post.native.js +0 -9
- package/build/actions/duplicate-post.native.js.map +0 -1
- package/build/actions/export-pattern.native.js +0 -9
- package/build/actions/export-pattern.native.js.map +0 -1
- package/build/actions/reorder-page.native.js +0 -9
- package/build/actions/reorder-page.native.js.map +0 -1
- package/build/fields/title/title-view.js +0 -61
- package/build/fields/title/title-view.js.map +0 -1
- package/build-module/actions/duplicate-post.native.js +0 -3
- package/build-module/actions/duplicate-post.native.js.map +0 -1
- package/build-module/actions/export-pattern.native.js +0 -3
- package/build-module/actions/export-pattern.native.js.map +0 -1
- package/build-module/actions/reorder-page.native.js +0 -3
- package/build-module/actions/reorder-page.native.js.map +0 -1
- package/build-module/fields/title/title-view.js +0 -55
- package/build-module/fields/title/title-view.js.map +0 -1
- package/build-types/actions/duplicate-post.native.d.ts +0 -3
- package/build-types/actions/duplicate-post.native.d.ts.map +0 -1
- package/build-types/actions/export-pattern.native.d.ts +0 -3
- package/build-types/actions/export-pattern.native.d.ts.map +0 -1
- package/build-types/actions/reorder-page.native.d.ts +0 -3
- package/build-types/actions/reorder-page.native.d.ts.map +0 -1
- package/build-types/fields/title/title-view.d.ts +0 -9
- package/build-types/fields/title/title-view.d.ts.map +0 -1
- package/src/actions/duplicate-post.native.tsx +0 -3
- package/src/actions/export-pattern.native.tsx +0 -3
- package/src/actions/reorder-page.native.tsx +0 -3
- package/src/fields/title/title-view.tsx +0 -62
package/src/fields/index.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { default as slugField } from './slug';
|
|
2
2
|
export { default as titleField } from './title';
|
|
3
|
+
export { default as pageTitleField } from './page-title';
|
|
4
|
+
export { default as templateTitleField } from './template-title';
|
|
5
|
+
export { default as patternTitleField } from './pattern-title';
|
|
3
6
|
export { default as orderField } from './order';
|
|
4
7
|
export { default as featuredImageField } from './featured-image';
|
|
8
|
+
export { default as templateField } from './template';
|
|
5
9
|
export { default as parentField } from './parent';
|
|
6
10
|
export { default as passwordField } from './password';
|
|
7
11
|
export { default as statusField } from './status';
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { getItemTitle } from '../../actions/utils';
|
|
12
|
+
import PageTitleView from './view';
|
|
13
|
+
|
|
14
|
+
const pageTitleField: Field< BasePost > = {
|
|
15
|
+
type: 'text',
|
|
16
|
+
id: 'title',
|
|
17
|
+
label: __( 'Title' ),
|
|
18
|
+
placeholder: __( 'No title' ),
|
|
19
|
+
getValue: ( { item } ) => getItemTitle( item ),
|
|
20
|
+
render: PageTitleView,
|
|
21
|
+
enableHiding: false,
|
|
22
|
+
enableGlobalSearch: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Title for the page entity.
|
|
27
|
+
*/
|
|
28
|
+
export default pageTitleField;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import type { Settings } from '@wordpress/core-data';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Internal dependencies
|
|
11
|
+
*/
|
|
12
|
+
import type { CommonPost } from '../../types';
|
|
13
|
+
import { BaseTitleView } from '../title/view';
|
|
14
|
+
|
|
15
|
+
export default function PageTitleView( { item }: { item: CommonPost } ) {
|
|
16
|
+
const { frontPageId, postsPageId } = useSelect( ( select ) => {
|
|
17
|
+
const { getEntityRecord } = select( coreStore );
|
|
18
|
+
const siteSettings = getEntityRecord(
|
|
19
|
+
'root',
|
|
20
|
+
'site'
|
|
21
|
+
) as Partial< Settings >;
|
|
22
|
+
return {
|
|
23
|
+
frontPageId: siteSettings?.page_on_front,
|
|
24
|
+
postsPageId: siteSettings?.page_for_posts,
|
|
25
|
+
};
|
|
26
|
+
}, [] );
|
|
27
|
+
return (
|
|
28
|
+
<BaseTitleView item={ item } className="fields-field__page-title">
|
|
29
|
+
{ [ frontPageId, postsPageId ].includes( item.id as number ) && (
|
|
30
|
+
<span className="fields-field__page-title__badge">
|
|
31
|
+
{ item.id === frontPageId
|
|
32
|
+
? __( 'Homepage' )
|
|
33
|
+
: __( 'Posts Page' ) }
|
|
34
|
+
</span>
|
|
35
|
+
) }
|
|
36
|
+
</BaseTitleView>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { Pattern } from '../../types';
|
|
11
|
+
import { getItemTitle } from '../../actions/utils';
|
|
12
|
+
import PatternTitleView from './view';
|
|
13
|
+
|
|
14
|
+
const patternTitleField: Field< Pattern > = {
|
|
15
|
+
type: 'text',
|
|
16
|
+
id: 'title',
|
|
17
|
+
label: __( 'Title' ),
|
|
18
|
+
placeholder: __( 'No title' ),
|
|
19
|
+
getValue: ( { item } ) => getItemTitle( item ),
|
|
20
|
+
render: PatternTitleView,
|
|
21
|
+
enableHiding: false,
|
|
22
|
+
enableGlobalSearch: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Title for the pattern entity.
|
|
27
|
+
*/
|
|
28
|
+
export default patternTitleField;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
import { Icon, lockSmall } from '@wordpress/icons';
|
|
6
|
+
import { Tooltip } from '@wordpress/components';
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { privateApis as patternPrivateApis } from '@wordpress/patterns';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import type { CommonPost } from '../../types';
|
|
14
|
+
import { BaseTitleView } from '../title/view';
|
|
15
|
+
import { unlock } from '../../lock-unlock';
|
|
16
|
+
|
|
17
|
+
export const { PATTERN_TYPES } = unlock( patternPrivateApis );
|
|
18
|
+
|
|
19
|
+
export default function PatternTitleView( { item }: { item: CommonPost } ) {
|
|
20
|
+
return (
|
|
21
|
+
<BaseTitleView item={ item } className="fields-field__pattern-title">
|
|
22
|
+
{ item.type === PATTERN_TYPES.theme && (
|
|
23
|
+
<Tooltip
|
|
24
|
+
placement="top"
|
|
25
|
+
text={ __( 'This pattern cannot be edited.' ) }
|
|
26
|
+
>
|
|
27
|
+
<Icon icon={ lockSmall } size={ 24 } />
|
|
28
|
+
</Tooltip>
|
|
29
|
+
) }
|
|
30
|
+
</BaseTitleView>
|
|
31
|
+
);
|
|
32
|
+
}
|
package/src/fields/slug/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { BasePost } from '../../types';
|
|
|
10
10
|
import { getSlug } from './utils';
|
|
11
11
|
|
|
12
12
|
const SlugView = ( { item }: { item: BasePost } ) => {
|
|
13
|
-
const slug =
|
|
13
|
+
const slug = getSlug( item );
|
|
14
14
|
const originalSlugRef = useRef( slug );
|
|
15
15
|
|
|
16
16
|
useEffect( () => {
|
package/src/fields/slug/utils.ts
CHANGED
|
@@ -9,6 +9,10 @@ import type { BasePost } from '../../types';
|
|
|
9
9
|
import { getItemTitle } from '../../actions/utils';
|
|
10
10
|
|
|
11
11
|
export const getSlug = ( item: BasePost ): string => {
|
|
12
|
+
if ( typeof item !== 'object' ) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
return (
|
|
13
17
|
item.slug || cleanForSlug( getItemTitle( item ) ) || item.id.toString()
|
|
14
18
|
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Field } from '@wordpress/dataviews';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import type { BasePost } from '../../types';
|
|
11
|
+
import { TemplateEdit } from './template-edit';
|
|
12
|
+
|
|
13
|
+
const templateField: Field< BasePost > = {
|
|
14
|
+
id: 'template',
|
|
15
|
+
type: 'text',
|
|
16
|
+
label: __( 'Template' ),
|
|
17
|
+
Edit: TemplateEdit,
|
|
18
|
+
enableSorting: false,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Template field for BasePost.
|
|
23
|
+
*/
|
|
24
|
+
export default templateField;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.fields-controls__template-modal {
|
|
2
|
+
z-index: z-index(".fields-controls__template-modal");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.fields-controls__template-content .block-editor-block-patterns-list {
|
|
6
|
+
column-count: 2;
|
|
7
|
+
column-gap: $grid-unit-30;
|
|
8
|
+
|
|
9
|
+
// Small top padding required to avoid cutting off the visible outline when hovering items
|
|
10
|
+
padding-top: $border-width-focus-fallback;
|
|
11
|
+
|
|
12
|
+
@include break-medium() {
|
|
13
|
+
column-count: 3;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@include break-wide() {
|
|
17
|
+
column-count: 4;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.block-editor-block-patterns-list__list-item {
|
|
21
|
+
break-inside: avoid-column;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useMemo, useState } from '@wordpress/element';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { parse } from '@wordpress/blocks';
|
|
7
|
+
import type { WpTemplate } from '@wordpress/core-data';
|
|
8
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
9
|
+
import type { DataFormControlProps } from '@wordpress/dataviews';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
// @ts-expect-error block-editor is not typed correctly.
|
|
15
|
+
import { __experimentalBlockPatternsList as BlockPatternsList } from '@wordpress/block-editor';
|
|
16
|
+
import {
|
|
17
|
+
Button,
|
|
18
|
+
Dropdown,
|
|
19
|
+
MenuGroup,
|
|
20
|
+
MenuItem,
|
|
21
|
+
Modal,
|
|
22
|
+
} from '@wordpress/components';
|
|
23
|
+
import { useAsyncList } from '@wordpress/compose';
|
|
24
|
+
import { useSelect } from '@wordpress/data';
|
|
25
|
+
import { decodeEntities } from '@wordpress/html-entities';
|
|
26
|
+
import { __ } from '@wordpress/i18n';
|
|
27
|
+
import { getItemTitle } from '../../actions/utils';
|
|
28
|
+
import type { BasePost } from '../../types';
|
|
29
|
+
import { unlock } from '../../lock-unlock';
|
|
30
|
+
|
|
31
|
+
export const TemplateEdit = ( {
|
|
32
|
+
data,
|
|
33
|
+
field,
|
|
34
|
+
onChange,
|
|
35
|
+
}: DataFormControlProps< BasePost > ) => {
|
|
36
|
+
const { id } = field;
|
|
37
|
+
const postType = data.type;
|
|
38
|
+
const postId =
|
|
39
|
+
typeof data.id === 'number' ? data.id : parseInt( data.id, 10 );
|
|
40
|
+
const slug = data.slug;
|
|
41
|
+
|
|
42
|
+
const { availableTemplates, templates } = useSelect(
|
|
43
|
+
( select ) => {
|
|
44
|
+
const allTemplates =
|
|
45
|
+
select( coreStore ).getEntityRecords< WpTemplate >(
|
|
46
|
+
'postType',
|
|
47
|
+
'wp_template',
|
|
48
|
+
{
|
|
49
|
+
per_page: -1,
|
|
50
|
+
post_type: postType,
|
|
51
|
+
}
|
|
52
|
+
) ?? [];
|
|
53
|
+
|
|
54
|
+
const { getHomePage, getPostsPageId } = unlock(
|
|
55
|
+
select( coreStore )
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const isPostsPage = getPostsPageId() === +postId;
|
|
59
|
+
const isFrontPage =
|
|
60
|
+
postType === 'page' && getHomePage()?.postId === +postId;
|
|
61
|
+
|
|
62
|
+
const allowSwitchingTemplate = ! isPostsPage && ! isFrontPage;
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
templates: allTemplates,
|
|
66
|
+
availableTemplates: allowSwitchingTemplate
|
|
67
|
+
? allTemplates.filter(
|
|
68
|
+
( template ) =>
|
|
69
|
+
template.is_custom &&
|
|
70
|
+
template.slug !== data.template &&
|
|
71
|
+
!! template.content.raw // Skip empty templates.
|
|
72
|
+
)
|
|
73
|
+
: [],
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
[ data.template, postId, postType ]
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const templatesAsPatterns = useMemo(
|
|
80
|
+
() =>
|
|
81
|
+
availableTemplates.map( ( template ) => ( {
|
|
82
|
+
name: template.slug,
|
|
83
|
+
blocks: parse( template.content.raw ),
|
|
84
|
+
title: decodeEntities( template.title.rendered ),
|
|
85
|
+
id: template.id,
|
|
86
|
+
} ) ),
|
|
87
|
+
[ availableTemplates ]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const shownTemplates = useAsyncList( templatesAsPatterns );
|
|
91
|
+
|
|
92
|
+
const value = field.getValue( { item: data } );
|
|
93
|
+
|
|
94
|
+
const currentTemplate = useSelect(
|
|
95
|
+
( select ) => {
|
|
96
|
+
const foundTemplate = templates?.find(
|
|
97
|
+
( template ) => template.slug === value
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if ( foundTemplate ) {
|
|
101
|
+
return foundTemplate;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let slugToCheck;
|
|
105
|
+
// In `draft` status we might not have a slug available, so we use the `single`
|
|
106
|
+
// post type templates slug(ex page, single-post, single-product etc..).
|
|
107
|
+
// Pages do not need the `single` prefix in the slug to be prioritized
|
|
108
|
+
// through template hierarchy.
|
|
109
|
+
if ( slug ) {
|
|
110
|
+
slugToCheck =
|
|
111
|
+
postType === 'page'
|
|
112
|
+
? `${ postType }-${ slug }`
|
|
113
|
+
: `single-${ postType }-${ slug }`;
|
|
114
|
+
} else {
|
|
115
|
+
slugToCheck =
|
|
116
|
+
postType === 'page' ? 'page' : `single-${ postType }`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if ( postType ) {
|
|
120
|
+
const templateId = select( coreStore ).getDefaultTemplateId( {
|
|
121
|
+
slug: slugToCheck,
|
|
122
|
+
} );
|
|
123
|
+
|
|
124
|
+
return select( coreStore ).getEntityRecord(
|
|
125
|
+
'postType',
|
|
126
|
+
'wp_template',
|
|
127
|
+
templateId
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
[ postType, slug, templates, value ]
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const [ showModal, setShowModal ] = useState( false );
|
|
135
|
+
|
|
136
|
+
const onChangeControl = useCallback(
|
|
137
|
+
( newValue: string ) =>
|
|
138
|
+
onChange( {
|
|
139
|
+
[ id ]: newValue,
|
|
140
|
+
} ),
|
|
141
|
+
[ id, onChange ]
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<fieldset className="fields-controls__template">
|
|
146
|
+
<Dropdown
|
|
147
|
+
popoverProps={ { placement: 'bottom-start' } }
|
|
148
|
+
renderToggle={ ( { onToggle } ) => (
|
|
149
|
+
<Button
|
|
150
|
+
__next40pxDefaultSize
|
|
151
|
+
variant="tertiary"
|
|
152
|
+
size="compact"
|
|
153
|
+
onClick={ onToggle }
|
|
154
|
+
>
|
|
155
|
+
{ currentTemplate
|
|
156
|
+
? getItemTitle( currentTemplate )
|
|
157
|
+
: '' }
|
|
158
|
+
</Button>
|
|
159
|
+
) }
|
|
160
|
+
renderContent={ ( { onToggle } ) => (
|
|
161
|
+
<MenuGroup>
|
|
162
|
+
<MenuItem
|
|
163
|
+
onClick={ () => {
|
|
164
|
+
setShowModal( true );
|
|
165
|
+
onToggle();
|
|
166
|
+
} }
|
|
167
|
+
>
|
|
168
|
+
{ __( 'Swap template' ) }
|
|
169
|
+
</MenuItem>
|
|
170
|
+
{
|
|
171
|
+
// The default template in a post is indicated by an empty string
|
|
172
|
+
value !== '' && (
|
|
173
|
+
<MenuItem
|
|
174
|
+
onClick={ () => {
|
|
175
|
+
onChangeControl( '' );
|
|
176
|
+
onToggle();
|
|
177
|
+
} }
|
|
178
|
+
>
|
|
179
|
+
{ __( 'Use default template' ) }
|
|
180
|
+
</MenuItem>
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
</MenuGroup>
|
|
184
|
+
) }
|
|
185
|
+
/>
|
|
186
|
+
{ showModal && (
|
|
187
|
+
<Modal
|
|
188
|
+
title={ __( 'Choose a template' ) }
|
|
189
|
+
onRequestClose={ () => setShowModal( false ) }
|
|
190
|
+
overlayClassName="fields-controls__template-modal"
|
|
191
|
+
isFullScreen
|
|
192
|
+
>
|
|
193
|
+
<div className="fields-controls__template-content">
|
|
194
|
+
<BlockPatternsList
|
|
195
|
+
label={ __( 'Templates' ) }
|
|
196
|
+
blockPatterns={ templatesAsPatterns }
|
|
197
|
+
shownPatterns={ shownTemplates }
|
|
198
|
+
onClickPattern={ (
|
|
199
|
+
template: ( typeof templatesAsPatterns )[ 0 ]
|
|
200
|
+
) => {
|
|
201
|
+
onChangeControl( template.name );
|
|
202
|
+
setShowModal( false );
|
|
203
|
+
} }
|
|
204
|
+
/>
|
|
205
|
+
</div>
|
|
206
|
+
</Modal>
|
|
207
|
+
) }
|
|
208
|
+
</fieldset>
|
|
209
|
+
);
|
|
210
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { Template } from '../../types';
|
|
11
|
+
import { getItemTitle } from '../../actions/utils';
|
|
12
|
+
import TitleView from '../title/view';
|
|
13
|
+
|
|
14
|
+
const templateTitleField: Field< Template > = {
|
|
15
|
+
type: 'text',
|
|
16
|
+
label: __( 'Template' ),
|
|
17
|
+
placeholder: __( 'No title' ),
|
|
18
|
+
id: 'title',
|
|
19
|
+
getValue: ( { item } ) => getItemTitle( item ),
|
|
20
|
+
render: TitleView,
|
|
21
|
+
enableHiding: false,
|
|
22
|
+
enableGlobalSearch: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Title for the template entity.
|
|
27
|
+
*/
|
|
28
|
+
export default templateTitleField;
|
|
@@ -7,11 +7,11 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import type {
|
|
10
|
+
import type { CommonPost } from '../../types';
|
|
11
11
|
import { getItemTitle } from '../../actions/utils';
|
|
12
|
-
import TitleView from './
|
|
12
|
+
import TitleView from './view';
|
|
13
13
|
|
|
14
|
-
const titleField: Field<
|
|
14
|
+
const titleField: Field< CommonPost > = {
|
|
15
15
|
type: 'text',
|
|
16
16
|
id: 'title',
|
|
17
17
|
label: __( 'Title' ),
|
|
@@ -19,6 +19,12 @@ const titleField: Field< BasePost > = {
|
|
|
19
19
|
getValue: ( { item } ) => getItemTitle( item ),
|
|
20
20
|
render: TitleView,
|
|
21
21
|
enableHiding: false,
|
|
22
|
+
enableGlobalSearch: true,
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Title for the any entity with a `title` property.
|
|
27
|
+
* For patterns, pages or templates you should use the respective field
|
|
28
|
+
* because there are some differences in the rendering, labels, etc.
|
|
29
|
+
*/
|
|
24
30
|
export default titleField;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { __experimentalHStack as HStack } from '@wordpress/components';
|
|
11
|
+
import { __ } from '@wordpress/i18n';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import type { CommonPost } from '../../types';
|
|
17
|
+
import { getItemTitle } from '../../actions/utils';
|
|
18
|
+
|
|
19
|
+
export function BaseTitleView( {
|
|
20
|
+
item,
|
|
21
|
+
className,
|
|
22
|
+
children,
|
|
23
|
+
}: {
|
|
24
|
+
item: CommonPost;
|
|
25
|
+
className?: string;
|
|
26
|
+
children?: ReactNode;
|
|
27
|
+
} ) {
|
|
28
|
+
const renderedTitle = getItemTitle( item );
|
|
29
|
+
return (
|
|
30
|
+
<HStack
|
|
31
|
+
className={ clsx( 'fields-field__title', className ) }
|
|
32
|
+
alignment="center"
|
|
33
|
+
justify="flex-start"
|
|
34
|
+
>
|
|
35
|
+
<span>{ renderedTitle || __( '(no title)' ) }</span>
|
|
36
|
+
{ children }
|
|
37
|
+
</HStack>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function TitleView( { item }: { item: CommonPost } ) {
|
|
42
|
+
return <BaseTitleView item={ item } />;
|
|
43
|
+
}
|
package/src/index.native.ts
CHANGED
package/src/index.ts
CHANGED
package/src/style.scss
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
@import "./components/create-template-part-modal/style.scss";
|
|
1
2
|
@import "./fields/slug/style.scss";
|
|
2
3
|
@import "./fields/featured-image/style.scss";
|
|
4
|
+
@import "./fields/template/style.scss";
|
|
5
|
+
@import "./fields/title/style.scss";
|
|
6
|
+
@import "./fields/page-title/style.scss";
|
|
7
|
+
@import "./fields/pattern-title/style.scss";
|
package/src/types.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
{ "path": "../components" },
|
|
13
13
|
{ "path": "../compose" },
|
|
14
14
|
{ "path": "../core-data" },
|
|
15
|
+
{ "path": "../block-editor" },
|
|
15
16
|
{ "path": "../data" },
|
|
16
17
|
{ "path": "../dataviews" },
|
|
17
18
|
{ "path": "../date" },
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
{ "path": "../private-apis" },
|
|
27
28
|
{ "path": "../router" },
|
|
28
29
|
{ "path": "../url" },
|
|
30
|
+
{ "path": "../block-editor" },
|
|
29
31
|
{ "path": "../warning" }
|
|
30
32
|
],
|
|
31
33
|
"include": [ "src" ]
|