@wordpress/edit-site 5.12.8 → 5.12.10
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/build/components/add-new-page/index.js +1 -6
- package/build/components/add-new-page/index.js.map +1 -1
- package/build/components/add-new-pattern/index.js +10 -2
- package/build/components/add-new-pattern/index.js.map +1 -1
- package/build/components/block-editor/index.js +0 -4
- package/build/components/block-editor/index.js.map +1 -1
- package/build/components/block-editor/use-site-editor-settings.js +12 -6
- package/build/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build/components/editor/index.js +10 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/layout/index.js +25 -22
- package/build/components/layout/index.js.map +1 -1
- package/build/components/page-actions/index.js +2 -2
- package/build/components/page-actions/index.js.map +1 -1
- package/build/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +8 -15
- package/build/components/page-actions/trash-page-menu-item.js.map +1 -0
- package/build/components/page-patterns/grid-item.js +1 -1
- package/build/components/page-patterns/grid-item.js.map +1 -1
- package/build/components/page-patterns/grid.js +72 -12
- package/build/components/page-patterns/grid.js.map +1 -1
- package/build/components/page-patterns/patterns-list.js +3 -4
- package/build/components/page-patterns/patterns-list.js.map +1 -1
- package/build/components/page-patterns/use-patterns.js +12 -4
- package/build/components/page-patterns/use-patterns.js.map +1 -1
- package/build/components/page-template-parts/add-new-template-part.js +74 -0
- package/build/components/page-template-parts/add-new-template-part.js.map +1 -0
- package/build/components/page-template-parts/index.js +2 -23
- package/build/components/page-template-parts/index.js.map +1 -1
- package/build/components/resizable-frame/index.js +75 -32
- package/build/components/resizable-frame/index.js.map +1 -1
- package/build/components/sidebar-edit-mode/page-panels/page-status.js +1 -1
- package/build/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
- package/build/components/sidebar-navigation-screen/index.js +13 -7
- package/build/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-main/template-part-hint.js +1 -1
- package/build/components/sidebar-navigation-screen-main/template-part-hint.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
- package/build/components/sidebar-navigation-screen-navigation-menu/more-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +3 -3
- package/build/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pages/index.js +33 -25
- package/build/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +3 -2
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +3 -2
- package/build/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/index.js +13 -18
- package/build/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +11 -1
- package/build/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build/components/site-hub/index.js +3 -1
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-sync-path-with-url.js +15 -12
- package/build/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-module/components/add-new-page/index.js +1 -6
- package/build-module/components/add-new-page/index.js.map +1 -1
- package/build-module/components/add-new-pattern/index.js +8 -2
- package/build-module/components/add-new-pattern/index.js.map +1 -1
- package/build-module/components/block-editor/index.js +0 -4
- package/build-module/components/block-editor/index.js.map +1 -1
- package/build-module/components/block-editor/use-site-editor-settings.js +13 -7
- package/build-module/components/block-editor/use-site-editor-settings.js.map +1 -1
- package/build-module/components/editor/index.js +10 -1
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/layout/index.js +25 -22
- package/build-module/components/layout/index.js.map +1 -1
- package/build-module/components/page-actions/index.js +2 -2
- package/build-module/components/page-actions/index.js.map +1 -1
- package/build-module/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +8 -16
- package/build-module/components/page-actions/trash-page-menu-item.js.map +1 -0
- package/build-module/components/page-patterns/grid-item.js +1 -1
- package/build-module/components/page-patterns/grid-item.js.map +1 -1
- package/build-module/components/page-patterns/grid.js +75 -15
- package/build-module/components/page-patterns/grid.js.map +1 -1
- package/build-module/components/page-patterns/patterns-list.js +4 -5
- package/build-module/components/page-patterns/patterns-list.js.map +1 -1
- package/build-module/components/page-patterns/use-patterns.js +12 -4
- package/build-module/components/page-patterns/use-patterns.js.map +1 -1
- package/build-module/components/page-template-parts/add-new-template-part.js +58 -0
- package/build-module/components/page-template-parts/add-new-template-part.js.map +1 -0
- package/build-module/components/page-template-parts/index.js +3 -22
- package/build-module/components/page-template-parts/index.js.map +1 -1
- package/build-module/components/resizable-frame/index.js +76 -35
- package/build-module/components/resizable-frame/index.js.map +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/page-status.js +1 -1
- package/build-module/components/sidebar-edit-mode/page-panels/page-status.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen/index.js +14 -8
- package/build-module/components/sidebar-navigation-screen/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js +1 -1
- package/build-module/components/sidebar-navigation-screen-main/template-part-hint.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
- package/build-module/components/sidebar-navigation-screen-navigation-menu/more-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +3 -3
- package/build-module/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pages/index.js +33 -25
- package/build-module/components/sidebar-navigation-screen-pages/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +3 -2
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +3 -2
- package/build-module/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/index.js +13 -18
- package/build-module/components/sidebar-navigation-screen-patterns/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +10 -1
- package/build-module/components/sidebar-navigation-screen-patterns/use-pattern-categories.js.map +1 -1
- package/build-module/components/site-hub/index.js +3 -1
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js +16 -12
- package/build-module/components/sync-state-with-url/use-sync-path-with-url.js.map +1 -1
- package/build-style/style-rtl.css +53 -15
- package/build-style/style.css +53 -15
- package/package.json +21 -21
- package/src/components/add-new-page/index.js +0 -3
- package/src/components/add-new-pattern/index.js +8 -2
- package/src/components/block-editor/index.js +0 -4
- package/src/components/block-editor/use-site-editor-settings.js +16 -11
- package/src/components/editor/index.js +15 -1
- package/src/components/layout/index.js +38 -43
- package/src/components/layout/style.scss +1 -0
- package/src/components/page-actions/index.js +2 -2
- package/src/components/page-actions/{delete-page-menu-item.js → trash-page-menu-item.js} +9 -21
- package/src/components/page-patterns/grid-item.js +1 -1
- package/src/components/page-patterns/grid.js +101 -16
- package/src/components/page-patterns/patterns-list.js +15 -9
- package/src/components/page-patterns/style.scss +21 -1
- package/src/components/page-patterns/use-patterns.js +11 -5
- package/src/components/page-template-parts/add-new-template-part.js +57 -0
- package/src/components/page-template-parts/index.js +3 -22
- package/src/components/resizable-frame/index.js +100 -31
- package/src/components/resizable-frame/style.scss +26 -9
- package/src/components/sidebar-edit-mode/page-panels/page-status.js +1 -1
- package/src/components/sidebar-navigation-item/style.scss +10 -1
- package/src/components/sidebar-navigation-screen/index.js +13 -6
- package/src/components/sidebar-navigation-screen-main/template-part-hint.js +1 -3
- package/src/components/sidebar-navigation-screen-navigation-menu/more-menu.js +1 -0
- package/src/components/sidebar-navigation-screen-navigation-menu/single-navigation-menu.js +1 -1
- package/src/components/sidebar-navigation-screen-pages/index.js +39 -29
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menu.js +2 -1
- package/src/components/sidebar-navigation-screen-pattern/template-part-navigation-menus.js +2 -1
- package/src/components/sidebar-navigation-screen-patterns/index.js +29 -30
- package/src/components/sidebar-navigation-screen-patterns/style.scss +5 -7
- package/src/components/sidebar-navigation-screen-patterns/use-pattern-categories.js +9 -0
- package/src/components/site-hub/index.js +5 -1
- package/src/components/site-hub/style.scss +5 -0
- package/src/components/sync-state-with-url/use-sync-path-with-url.js +73 -66
- package/build/components/page-actions/delete-page-menu-item.js.map +0 -1
- package/build-module/components/page-actions/delete-page-menu-item.js.map +0 -1
|
@@ -3,17 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
5
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
6
|
-
import { useState } from '@wordpress/element';
|
|
7
6
|
import { store as coreStore } from '@wordpress/core-data';
|
|
8
7
|
import { __, sprintf } from '@wordpress/i18n';
|
|
9
|
-
import {
|
|
10
|
-
MenuItem,
|
|
11
|
-
__experimentalConfirmDialog as ConfirmDialog,
|
|
12
|
-
} from '@wordpress/components';
|
|
8
|
+
import { MenuItem } from '@wordpress/components';
|
|
13
9
|
import { store as noticesStore } from '@wordpress/notices';
|
|
14
10
|
|
|
15
|
-
export default function
|
|
16
|
-
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
11
|
+
export default function TrashPageMenuItem( { postId, onRemove } ) {
|
|
17
12
|
const { createSuccessNotice, createErrorNotice } =
|
|
18
13
|
useDispatch( noticesStore );
|
|
19
14
|
const { deleteEntityRecord } = useDispatch( coreStore );
|
|
@@ -34,12 +29,12 @@ export default function DeletePageMenuItem( { postId, onRemove } ) {
|
|
|
34
29
|
createSuccessNotice(
|
|
35
30
|
sprintf(
|
|
36
31
|
/* translators: The page's title. */
|
|
37
|
-
__( '"%s"
|
|
32
|
+
__( '"%s" moved to the Trash.' ),
|
|
38
33
|
decodeEntities( page.title.rendered )
|
|
39
34
|
),
|
|
40
35
|
{
|
|
41
36
|
type: 'snackbar',
|
|
42
|
-
id: 'edit-site-page-
|
|
37
|
+
id: 'edit-site-page-trashed',
|
|
43
38
|
}
|
|
44
39
|
);
|
|
45
40
|
onRemove?.();
|
|
@@ -47,25 +42,18 @@ export default function DeletePageMenuItem( { postId, onRemove } ) {
|
|
|
47
42
|
const errorMessage =
|
|
48
43
|
error.message && error.code !== 'unknown_error'
|
|
49
44
|
? error.message
|
|
50
|
-
: __(
|
|
45
|
+
: __(
|
|
46
|
+
'An error occurred while moving the page to the trash.'
|
|
47
|
+
);
|
|
51
48
|
|
|
52
49
|
createErrorNotice( errorMessage, { type: 'snackbar' } );
|
|
53
|
-
} finally {
|
|
54
|
-
setIsModalOpen( false );
|
|
55
50
|
}
|
|
56
51
|
}
|
|
57
52
|
return (
|
|
58
53
|
<>
|
|
59
|
-
<MenuItem onClick={ () =>
|
|
60
|
-
{ __( '
|
|
54
|
+
<MenuItem onClick={ () => removePage() } isDestructive>
|
|
55
|
+
{ __( 'Move to Trash' ) }
|
|
61
56
|
</MenuItem>
|
|
62
|
-
<ConfirmDialog
|
|
63
|
-
isOpen={ isModalOpen }
|
|
64
|
-
onConfirm={ removePage }
|
|
65
|
-
onCancel={ () => setIsModalOpen( false ) }
|
|
66
|
-
>
|
|
67
|
-
{ __( 'Are you sure you want to delete this page?' ) }
|
|
68
|
-
</ConfirmDialog>
|
|
69
57
|
</>
|
|
70
58
|
);
|
|
71
59
|
}
|
|
@@ -1,26 +1,115 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
__experimentalHStack as HStack,
|
|
6
|
+
__experimentalText as Text,
|
|
7
|
+
Button,
|
|
8
|
+
} from '@wordpress/components';
|
|
9
|
+
import { useRef, useState, useMemo } from '@wordpress/element';
|
|
10
|
+
import { __, _x, _n, sprintf } from '@wordpress/i18n';
|
|
11
|
+
import { useAsyncList } from '@wordpress/compose';
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Internal dependencies
|
|
10
15
|
*/
|
|
11
16
|
import GridItem from './grid-item';
|
|
12
17
|
|
|
13
|
-
const PAGE_SIZE =
|
|
18
|
+
const PAGE_SIZE = 20;
|
|
19
|
+
|
|
20
|
+
function Pagination( { currentPage, numPages, changePage, totalItems } ) {
|
|
21
|
+
return (
|
|
22
|
+
<HStack
|
|
23
|
+
expanded={ false }
|
|
24
|
+
spacing={ 3 }
|
|
25
|
+
className="edit-site-patterns__grid-pagination"
|
|
26
|
+
>
|
|
27
|
+
<Text variant="muted">
|
|
28
|
+
{
|
|
29
|
+
// translators: %s: Total number of patterns.
|
|
30
|
+
sprintf(
|
|
31
|
+
// translators: %s: Total number of patterns.
|
|
32
|
+
_n( '%s item', '%s items', totalItems ),
|
|
33
|
+
totalItems
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
</Text>
|
|
37
|
+
<HStack expanded={ false } spacing={ 1 }>
|
|
38
|
+
<Button
|
|
39
|
+
variant="tertiary"
|
|
40
|
+
onClick={ () => changePage( 1 ) }
|
|
41
|
+
disabled={ currentPage === 1 }
|
|
42
|
+
aria-label={ __( 'First page' ) }
|
|
43
|
+
>
|
|
44
|
+
«
|
|
45
|
+
</Button>
|
|
46
|
+
<Button
|
|
47
|
+
variant="tertiary"
|
|
48
|
+
onClick={ () => changePage( currentPage - 1 ) }
|
|
49
|
+
disabled={ currentPage === 1 }
|
|
50
|
+
aria-label={ __( 'Previous page' ) }
|
|
51
|
+
>
|
|
52
|
+
‹
|
|
53
|
+
</Button>
|
|
54
|
+
</HStack>
|
|
55
|
+
<Text variant="muted">
|
|
56
|
+
{ sprintf(
|
|
57
|
+
// translators: %1$s: Current page number, %2$s: Total number of pages.
|
|
58
|
+
_x( '%1$s of %2$s', 'paging' ),
|
|
59
|
+
currentPage,
|
|
60
|
+
numPages
|
|
61
|
+
) }
|
|
62
|
+
</Text>
|
|
63
|
+
<HStack expanded={ false } spacing={ 1 }>
|
|
64
|
+
<Button
|
|
65
|
+
variant="tertiary"
|
|
66
|
+
onClick={ () => changePage( currentPage + 1 ) }
|
|
67
|
+
disabled={ currentPage === numPages }
|
|
68
|
+
aria-label={ __( 'Next page' ) }
|
|
69
|
+
>
|
|
70
|
+
›
|
|
71
|
+
</Button>
|
|
72
|
+
<Button
|
|
73
|
+
variant="tertiary"
|
|
74
|
+
onClick={ () => changePage( numPages ) }
|
|
75
|
+
disabled={ currentPage === numPages }
|
|
76
|
+
aria-label={ __( 'Last page' ) }
|
|
77
|
+
>
|
|
78
|
+
»
|
|
79
|
+
</Button>
|
|
80
|
+
</HStack>
|
|
81
|
+
</HStack>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
14
84
|
|
|
15
85
|
export default function Grid( { categoryId, items, ...props } ) {
|
|
86
|
+
const [ currentPage, setCurrentPage ] = useState( 1 );
|
|
16
87
|
const gridRef = useRef();
|
|
88
|
+
const totalItems = items.length;
|
|
89
|
+
const pageIndex = currentPage - 1;
|
|
17
90
|
|
|
18
|
-
|
|
91
|
+
const list = useMemo(
|
|
92
|
+
() =>
|
|
93
|
+
items.slice(
|
|
94
|
+
pageIndex * PAGE_SIZE,
|
|
95
|
+
pageIndex * PAGE_SIZE + PAGE_SIZE
|
|
96
|
+
),
|
|
97
|
+
[ pageIndex, items ]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const asyncList = useAsyncList( list, { step: 10 } );
|
|
101
|
+
|
|
102
|
+
if ( ! list?.length ) {
|
|
19
103
|
return null;
|
|
20
104
|
}
|
|
21
105
|
|
|
22
|
-
const
|
|
23
|
-
const
|
|
106
|
+
const numPages = Math.ceil( items.length / PAGE_SIZE );
|
|
107
|
+
const changePage = ( page ) => {
|
|
108
|
+
const scrollContainer = document.querySelector( '.edit-site-patterns' );
|
|
109
|
+
scrollContainer?.scrollTo( 0, 0 );
|
|
110
|
+
|
|
111
|
+
setCurrentPage( page );
|
|
112
|
+
};
|
|
24
113
|
|
|
25
114
|
return (
|
|
26
115
|
<>
|
|
@@ -30,7 +119,7 @@ export default function Grid( { categoryId, items, ...props } ) {
|
|
|
30
119
|
{ ...props }
|
|
31
120
|
ref={ gridRef }
|
|
32
121
|
>
|
|
33
|
-
{
|
|
122
|
+
{ asyncList.map( ( item ) => (
|
|
34
123
|
<GridItem
|
|
35
124
|
key={ item.name }
|
|
36
125
|
item={ item }
|
|
@@ -38,14 +127,10 @@ export default function Grid( { categoryId, items, ...props } ) {
|
|
|
38
127
|
/>
|
|
39
128
|
) ) }
|
|
40
129
|
</ul>
|
|
41
|
-
{
|
|
42
|
-
<
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
__( '+ %d more patterns discoverable by searching' ),
|
|
46
|
-
restLength
|
|
47
|
-
) }
|
|
48
|
-
</Text>
|
|
130
|
+
{ numPages > 1 && (
|
|
131
|
+
<Pagination
|
|
132
|
+
{ ...{ currentPage, numPages, changePage, totalItems } }
|
|
133
|
+
/>
|
|
49
134
|
) }
|
|
50
135
|
</>
|
|
51
136
|
);
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { __, isRTL } from '@wordpress/i18n';
|
|
16
16
|
import { chevronLeft, chevronRight } from '@wordpress/icons';
|
|
17
17
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
18
|
-
import { useViewportMatch
|
|
18
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Internal dependencies
|
|
@@ -57,11 +57,18 @@ export default function PatternsList( { categoryId, type } ) {
|
|
|
57
57
|
|
|
58
58
|
const [ syncFilter, setSyncFilter ] = useState( 'all' );
|
|
59
59
|
const deferredSyncedFilter = useDeferredValue( syncFilter );
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
|
|
61
|
+
const { patterns, isResolving } = usePatterns(
|
|
62
|
+
type,
|
|
63
|
+
categoryId !== 'uncategorized' ? categoryId : '',
|
|
64
|
+
{
|
|
65
|
+
search: deferredFilterValue,
|
|
66
|
+
syncStatus:
|
|
67
|
+
deferredSyncedFilter === 'all'
|
|
68
|
+
? undefined
|
|
69
|
+
: deferredSyncedFilter,
|
|
70
|
+
}
|
|
71
|
+
);
|
|
65
72
|
|
|
66
73
|
const id = useId();
|
|
67
74
|
const titleId = `${ id }-title`;
|
|
@@ -70,7 +77,6 @@ export default function PatternsList( { categoryId, type } ) {
|
|
|
70
77
|
const hasPatterns = patterns.length;
|
|
71
78
|
const title = SYNC_FILTERS[ syncFilter ];
|
|
72
79
|
const description = SYNC_DESCRIPTIONS[ syncFilter ];
|
|
73
|
-
const shownPatterns = useAsyncList( patterns );
|
|
74
80
|
|
|
75
81
|
return (
|
|
76
82
|
<VStack spacing={ 6 }>
|
|
@@ -132,7 +138,7 @@ export default function PatternsList( { categoryId, type } ) {
|
|
|
132
138
|
</Flex>
|
|
133
139
|
{ syncFilter !== 'all' && (
|
|
134
140
|
<VStack className="edit-site-patterns__section-header">
|
|
135
|
-
<Heading as="h3" level={
|
|
141
|
+
<Heading as="h3" level={ 5 } id={ titleId }>
|
|
136
142
|
{ title }
|
|
137
143
|
</Heading>
|
|
138
144
|
{ description ? (
|
|
@@ -145,7 +151,7 @@ export default function PatternsList( { categoryId, type } ) {
|
|
|
145
151
|
{ hasPatterns && (
|
|
146
152
|
<Grid
|
|
147
153
|
categoryId={ categoryId }
|
|
148
|
-
items={
|
|
154
|
+
items={ patterns }
|
|
149
155
|
aria-labelledby={ titleId }
|
|
150
156
|
aria-describedby={ descriptionId }
|
|
151
157
|
/>
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
.edit-site-patterns {
|
|
2
|
-
|
|
2
|
+
border: 1px solid $gray-800;
|
|
3
|
+
background: none;
|
|
3
4
|
margin: $header-height 0 0;
|
|
5
|
+
border-radius: 0;
|
|
4
6
|
.components-base-control {
|
|
5
7
|
width: 100%;
|
|
6
8
|
@include break-medium {
|
|
@@ -59,6 +61,23 @@
|
|
|
59
61
|
background: $gray-700;
|
|
60
62
|
color: $gray-100;
|
|
61
63
|
}
|
|
64
|
+
|
|
65
|
+
.edit-site-patterns__grid-pagination {
|
|
66
|
+
width: fit-content;
|
|
67
|
+
.components-button.is-tertiary {
|
|
68
|
+
width: $button-size-compact;
|
|
69
|
+
height: $button-size-compact;
|
|
70
|
+
color: $gray-100;
|
|
71
|
+
background-color: $gray-800;
|
|
72
|
+
&:disabled {
|
|
73
|
+
color: $gray-600;
|
|
74
|
+
background: none;
|
|
75
|
+
}
|
|
76
|
+
&:hover:not(:disabled) {
|
|
77
|
+
background-color: $gray-700;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
62
81
|
}
|
|
63
82
|
|
|
64
83
|
.edit-site-patterns__section-header {
|
|
@@ -74,6 +93,7 @@
|
|
|
74
93
|
// Small top padding required to avoid cutting off the visible outline
|
|
75
94
|
// when hovering items.
|
|
76
95
|
padding-top: $border-width-focus-fallback;
|
|
96
|
+
margin-top: 0;
|
|
77
97
|
margin-bottom: $grid-unit-40;
|
|
78
98
|
@include break-large {
|
|
79
99
|
grid-template-columns: 1fr 1fr;
|
|
@@ -93,11 +93,17 @@ const selectThemePatterns = ( select, { categoryId, search = '' } = {} ) => {
|
|
|
93
93
|
blocks: parse( pattern.content ),
|
|
94
94
|
} ) );
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
if ( categoryId ) {
|
|
97
|
+
patterns = searchItems( patterns, search, {
|
|
98
|
+
categoryId,
|
|
99
|
+
hasCategory: ( item, currentCategory ) =>
|
|
100
|
+
item.categories?.includes( currentCategory ),
|
|
101
|
+
} );
|
|
102
|
+
} else {
|
|
103
|
+
patterns = searchItems( patterns, search, {
|
|
104
|
+
hasCategory: ( item ) => ! item.hasOwnProperty( 'categories' ),
|
|
105
|
+
} );
|
|
106
|
+
}
|
|
101
107
|
|
|
102
108
|
return { patterns, isResolving: false };
|
|
103
109
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
import { store as coreStore } from '@wordpress/core-data';
|
|
7
|
+
import { useState } from '@wordpress/element';
|
|
8
|
+
import { Button } from '@wordpress/components';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import { unlock } from '../../lock-unlock';
|
|
14
|
+
import { store as editSiteStore } from '../../store';
|
|
15
|
+
import CreateTemplatePartModal from '../create-template-part-modal';
|
|
16
|
+
|
|
17
|
+
const { useHistory } = unlock( routerPrivateApis );
|
|
18
|
+
|
|
19
|
+
export default function AddNewTemplatePart() {
|
|
20
|
+
const { canCreate, postType } = useSelect( ( select ) => {
|
|
21
|
+
const { supportsTemplatePartsMode } =
|
|
22
|
+
select( editSiteStore ).getSettings();
|
|
23
|
+
return {
|
|
24
|
+
canCreate: ! supportsTemplatePartsMode,
|
|
25
|
+
postType: select( coreStore ).getPostType( 'wp_template_part' ),
|
|
26
|
+
};
|
|
27
|
+
}, [] );
|
|
28
|
+
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
29
|
+
const history = useHistory();
|
|
30
|
+
|
|
31
|
+
if ( ! canCreate || ! postType ) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<Button variant="primary" onClick={ () => setIsModalOpen( true ) }>
|
|
38
|
+
{ postType.labels.add_new_item }
|
|
39
|
+
</Button>
|
|
40
|
+
{ isModalOpen && (
|
|
41
|
+
<CreateTemplatePartModal
|
|
42
|
+
closeModal={ () => setIsModalOpen( false ) }
|
|
43
|
+
blocks={ [] }
|
|
44
|
+
onCreate={ ( templatePart ) => {
|
|
45
|
+
setIsModalOpen( false );
|
|
46
|
+
history.push( {
|
|
47
|
+
postId: templatePart.id,
|
|
48
|
+
postType: 'wp_template_part',
|
|
49
|
+
canvas: 'edit',
|
|
50
|
+
} );
|
|
51
|
+
} }
|
|
52
|
+
onError={ () => setIsModalOpen( false ) }
|
|
53
|
+
/>
|
|
54
|
+
) }
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -7,8 +7,7 @@ import {
|
|
|
7
7
|
__experimentalVStack as VStack,
|
|
8
8
|
} from '@wordpress/components';
|
|
9
9
|
import { __ } from '@wordpress/i18n';
|
|
10
|
-
import {
|
|
11
|
-
import { store as coreStore, useEntityRecords } from '@wordpress/core-data';
|
|
10
|
+
import { useEntityRecords } from '@wordpress/core-data';
|
|
12
11
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
12
|
|
|
14
13
|
/**
|
|
@@ -19,8 +18,7 @@ import Table from '../table';
|
|
|
19
18
|
import Link from '../routes/link';
|
|
20
19
|
import AddedBy from '../list/added-by';
|
|
21
20
|
import TemplateActions from '../template-actions';
|
|
22
|
-
import
|
|
23
|
-
import { store as editSiteStore } from '../../store';
|
|
21
|
+
import AddNewTemplatePart from './add-new-template-part';
|
|
24
22
|
|
|
25
23
|
export default function PageTemplateParts() {
|
|
26
24
|
const { records: templateParts } = useEntityRecords(
|
|
@@ -31,15 +29,6 @@ export default function PageTemplateParts() {
|
|
|
31
29
|
}
|
|
32
30
|
);
|
|
33
31
|
|
|
34
|
-
const { canCreate } = useSelect( ( select ) => {
|
|
35
|
-
const { supportsTemplatePartsMode } =
|
|
36
|
-
select( editSiteStore ).getSettings();
|
|
37
|
-
return {
|
|
38
|
-
postType: select( coreStore ).getPostType( 'wp_template_part' ),
|
|
39
|
-
canCreate: ! supportsTemplatePartsMode,
|
|
40
|
-
};
|
|
41
|
-
} );
|
|
42
|
-
|
|
43
32
|
const columns = [
|
|
44
33
|
{
|
|
45
34
|
header: __( 'Template Part' ),
|
|
@@ -87,15 +76,7 @@ export default function PageTemplateParts() {
|
|
|
87
76
|
return (
|
|
88
77
|
<Page
|
|
89
78
|
title={ __( 'Template Parts' ) }
|
|
90
|
-
actions={
|
|
91
|
-
canCreate && (
|
|
92
|
-
<AddNewTemplate
|
|
93
|
-
templateType={ 'wp_template_part' }
|
|
94
|
-
showIcon={ false }
|
|
95
|
-
toggleProps={ { variant: 'primary' } }
|
|
96
|
-
/>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
79
|
+
actions={ <AddNewTemplatePart /> }
|
|
99
80
|
>
|
|
100
81
|
{ templateParts && (
|
|
101
82
|
<Table data={ templateParts } columns={ columns } />
|
|
@@ -9,9 +9,12 @@ import classnames from 'classnames';
|
|
|
9
9
|
import { useState, useRef, useEffect } from '@wordpress/element';
|
|
10
10
|
import {
|
|
11
11
|
ResizableBox,
|
|
12
|
+
Tooltip,
|
|
12
13
|
__unstableMotion as motion,
|
|
13
14
|
} from '@wordpress/components';
|
|
14
|
-
import {
|
|
15
|
+
import { useInstanceId } from '@wordpress/compose';
|
|
16
|
+
import { useDispatch, useSelect } from '@wordpress/data';
|
|
17
|
+
import { __ } from '@wordpress/i18n';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Internal dependencies
|
|
@@ -33,7 +36,7 @@ const HANDLE_STYLES_OVERRIDE = {
|
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
// The minimum width of the frame (in px) while resizing.
|
|
36
|
-
const FRAME_MIN_WIDTH =
|
|
39
|
+
const FRAME_MIN_WIDTH = 320;
|
|
37
40
|
// The reference width of the frame (in px) used to calculate the aspect ratio.
|
|
38
41
|
const FRAME_REFERENCE_WIDTH = 1300;
|
|
39
42
|
// 9 : 19.5 is the target aspect ratio enforced (when possible) while resizing.
|
|
@@ -42,6 +45,8 @@ const FRAME_TARGET_ASPECT_RATIO = 9 / 19.5;
|
|
|
42
45
|
// viewport's edge. If the frame is resized to be closer to the viewport's edge
|
|
43
46
|
// than this distance, then "canvas mode" will be enabled.
|
|
44
47
|
const SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD = 200;
|
|
48
|
+
// Default size for the `frameSize` state.
|
|
49
|
+
const INITIAL_FRAME_SIZE = { width: '100%', height: '100%' };
|
|
45
50
|
|
|
46
51
|
function calculateNewHeight( width, initialAspectRatio ) {
|
|
47
52
|
const lerp = ( a, b, amount ) => {
|
|
@@ -78,22 +83,27 @@ function ResizableFrame( {
|
|
|
78
83
|
oversizedClassName,
|
|
79
84
|
innerContentStyle,
|
|
80
85
|
} ) {
|
|
81
|
-
const [ frameSize, setFrameSize ] = useState(
|
|
82
|
-
width: '100%',
|
|
83
|
-
height: '100%',
|
|
84
|
-
} );
|
|
86
|
+
const [ frameSize, setFrameSize ] = useState( INITIAL_FRAME_SIZE );
|
|
85
87
|
// The width of the resizable frame when a new resize gesture starts.
|
|
86
88
|
const [ startingWidth, setStartingWidth ] = useState();
|
|
87
89
|
const [ isResizing, setIsResizing ] = useState( false );
|
|
88
|
-
const [
|
|
90
|
+
const [ shouldShowHandle, setShouldShowHandle ] = useState( false );
|
|
89
91
|
const [ isOversized, setIsOversized ] = useState( false );
|
|
90
92
|
const [ resizeRatio, setResizeRatio ] = useState( 1 );
|
|
93
|
+
const canvasMode = useSelect(
|
|
94
|
+
( select ) => unlock( select( editSiteStore ) ).getCanvasMode(),
|
|
95
|
+
[]
|
|
96
|
+
);
|
|
91
97
|
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
|
|
92
98
|
const initialAspectRatioRef = useRef( null );
|
|
93
99
|
// The width of the resizable frame on initial render.
|
|
94
100
|
const initialComputedWidthRef = useRef( null );
|
|
95
101
|
const FRAME_TRANSITION = { type: 'tween', duration: isResizing ? 0 : 0.5 };
|
|
96
102
|
const frameRef = useRef( null );
|
|
103
|
+
const resizableHandleHelpId = useInstanceId(
|
|
104
|
+
ResizableFrame,
|
|
105
|
+
'edit-site-resizable-frame-handle-help'
|
|
106
|
+
);
|
|
97
107
|
|
|
98
108
|
// Remember frame dimensions on initial render.
|
|
99
109
|
useEffect( () => {
|
|
@@ -154,13 +164,40 @@ function ResizableFrame( {
|
|
|
154
164
|
if ( remainingWidth > SNAP_TO_EDIT_CANVAS_MODE_THRESHOLD ) {
|
|
155
165
|
// Reset the initial aspect ratio if the frame is resized slightly
|
|
156
166
|
// above the sidebar but not far enough to trigger full screen.
|
|
157
|
-
setFrameSize(
|
|
167
|
+
setFrameSize( INITIAL_FRAME_SIZE );
|
|
158
168
|
} else {
|
|
159
169
|
// Trigger full screen if the frame is resized far enough to the left.
|
|
160
170
|
setCanvasMode( 'edit' );
|
|
161
171
|
}
|
|
162
172
|
};
|
|
163
173
|
|
|
174
|
+
// Handle resize by arrow keys
|
|
175
|
+
const handleResizableHandleKeyDown = ( event ) => {
|
|
176
|
+
if ( ! [ 'ArrowLeft', 'ArrowRight' ].includes( event.key ) ) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
|
|
182
|
+
const step = 20 * ( event.shiftKey ? 5 : 1 );
|
|
183
|
+
const delta = step * ( event.key === 'ArrowLeft' ? 1 : -1 );
|
|
184
|
+
const newWidth = Math.min(
|
|
185
|
+
Math.max(
|
|
186
|
+
FRAME_MIN_WIDTH,
|
|
187
|
+
frameRef.current.resizable.offsetWidth + delta
|
|
188
|
+
),
|
|
189
|
+
initialComputedWidthRef.current
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
setFrameSize( {
|
|
193
|
+
width: newWidth,
|
|
194
|
+
height: calculateNewHeight(
|
|
195
|
+
newWidth,
|
|
196
|
+
initialAspectRatioRef.current
|
|
197
|
+
),
|
|
198
|
+
} );
|
|
199
|
+
};
|
|
200
|
+
|
|
164
201
|
const frameAnimationVariants = {
|
|
165
202
|
default: {
|
|
166
203
|
flexGrow: 0,
|
|
@@ -173,16 +210,26 @@ function ResizableFrame( {
|
|
|
173
210
|
};
|
|
174
211
|
|
|
175
212
|
const resizeHandleVariants = {
|
|
176
|
-
|
|
213
|
+
hidden: {
|
|
214
|
+
opacity: 0,
|
|
215
|
+
left: 0,
|
|
216
|
+
},
|
|
217
|
+
visible: {
|
|
177
218
|
opacity: 1,
|
|
178
219
|
left: -16,
|
|
179
220
|
},
|
|
180
|
-
|
|
221
|
+
active: {
|
|
181
222
|
opacity: 1,
|
|
182
223
|
left: -16,
|
|
183
224
|
scaleY: 1.3,
|
|
184
225
|
},
|
|
185
226
|
};
|
|
227
|
+
const currentResizeHandleVariant = ( () => {
|
|
228
|
+
if ( isResizing ) {
|
|
229
|
+
return 'active';
|
|
230
|
+
}
|
|
231
|
+
return shouldShowHandle ? 'visible' : 'hidden';
|
|
232
|
+
} )();
|
|
186
233
|
|
|
187
234
|
return (
|
|
188
235
|
<ResizableBox
|
|
@@ -217,28 +264,50 @@ function ResizableFrame( {
|
|
|
217
264
|
minWidth={ FRAME_MIN_WIDTH }
|
|
218
265
|
maxWidth={ isFullWidth ? '100%' : '150%' }
|
|
219
266
|
maxHeight={ '100%' }
|
|
220
|
-
|
|
221
|
-
|
|
267
|
+
onFocus={ () => setShouldShowHandle( true ) }
|
|
268
|
+
onBlur={ () => setShouldShowHandle( false ) }
|
|
269
|
+
onMouseOver={ () => setShouldShowHandle( true ) }
|
|
270
|
+
onMouseOut={ () => setShouldShowHandle( false ) }
|
|
222
271
|
handleComponent={ {
|
|
223
|
-
left:
|
|
224
|
-
|
|
225
|
-
<
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
272
|
+
left: canvasMode === 'view' && (
|
|
273
|
+
<>
|
|
274
|
+
<Tooltip text={ __( 'Drag to resize' ) }>
|
|
275
|
+
{ /* Disable reason: role="separator" does in fact support aria-valuenow */ }
|
|
276
|
+
{ /* eslint-disable-next-line jsx-a11y/role-supports-aria-props */ }
|
|
277
|
+
<motion.button
|
|
278
|
+
key="handle"
|
|
279
|
+
role="separator"
|
|
280
|
+
aria-orientation="vertical"
|
|
281
|
+
className={ classnames(
|
|
282
|
+
'edit-site-resizable-frame__handle',
|
|
283
|
+
{ 'is-resizing': isResizing }
|
|
284
|
+
) }
|
|
285
|
+
variants={ resizeHandleVariants }
|
|
286
|
+
animate={ currentResizeHandleVariant }
|
|
287
|
+
aria-label={ __( 'Drag to resize' ) }
|
|
288
|
+
aria-describedby={ resizableHandleHelpId }
|
|
289
|
+
aria-valuenow={
|
|
290
|
+
frameRef.current?.resizable?.offsetWidth ||
|
|
291
|
+
undefined
|
|
292
|
+
}
|
|
293
|
+
aria-valuemin={ FRAME_MIN_WIDTH }
|
|
294
|
+
aria-valuemax={
|
|
295
|
+
initialComputedWidthRef.current
|
|
296
|
+
}
|
|
297
|
+
onKeyDown={ handleResizableHandleKeyDown }
|
|
298
|
+
initial="hidden"
|
|
299
|
+
exit="hidden"
|
|
300
|
+
whileFocus="active"
|
|
301
|
+
whileHover="active"
|
|
302
|
+
/>
|
|
303
|
+
</Tooltip>
|
|
304
|
+
<div hidden id={ resizableHandleHelpId }>
|
|
305
|
+
{ __(
|
|
306
|
+
'Use left and right arrow keys to resize the canvas. Hold shift to resize in larger increments.'
|
|
307
|
+
) }
|
|
308
|
+
</div>
|
|
309
|
+
</>
|
|
310
|
+
),
|
|
242
311
|
} }
|
|
243
312
|
onResizeStart={ handleResizeStart }
|
|
244
313
|
onResize={ handleResize }
|