@wordpress/edit-site 5.12.9 → 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/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/patterns-list.js +1 -1
- 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/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-patterns/index.js +10 -14
- 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-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/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/patterns-list.js +1 -1
- 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/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-patterns/index.js +10 -14
- 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-style/style-rtl.css +5 -5
- package/build-style/style.css +5 -5
- 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/editor/index.js +15 -1
- package/src/components/layout/index.js +38 -43
- 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/patterns-list.js +12 -5
- package/src/components/page-patterns/use-patterns.js +11 -5
- package/src/components/sidebar-edit-mode/page-panels/page-status.js +1 -1
- package/src/components/sidebar-navigation-screen-patterns/index.js +10 -13
- 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/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
|
@@ -8,7 +8,7 @@ import { moreVertical } from '@wordpress/icons';
|
|
|
8
8
|
/**
|
|
9
9
|
* Internal dependencies
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
11
|
+
import TrashPageMenuItem from './trash-page-menu-item';
|
|
12
12
|
|
|
13
13
|
export default function PageActions( {
|
|
14
14
|
postId,
|
|
@@ -25,7 +25,7 @@ export default function PageActions( {
|
|
|
25
25
|
>
|
|
26
26
|
{ () => (
|
|
27
27
|
<MenuGroup>
|
|
28
|
-
<
|
|
28
|
+
<TrashPageMenuItem
|
|
29
29
|
postId={ postId }
|
|
30
30
|
onRemove={ onRemove }
|
|
31
31
|
/>
|
|
@@ -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
|
}
|
|
@@ -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`;
|
|
@@ -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
|
};
|
|
@@ -61,9 +61,6 @@ function TemplatePartGroup( { areas, currentArea, currentType } ) {
|
|
|
61
61
|
function ThemePatternsGroup( { categories, currentCategory, currentType } ) {
|
|
62
62
|
return (
|
|
63
63
|
<>
|
|
64
|
-
<div className="edit-site-sidebar-navigation-screen-patterns__group-header">
|
|
65
|
-
<Heading level={ 2 }>{ __( 'Theme patterns' ) }</Heading>
|
|
66
|
-
</div>
|
|
67
64
|
<ItemGroup className="edit-site-sidebar-navigation-screen-patterns__group">
|
|
68
65
|
{ categories.map( ( category ) => (
|
|
69
66
|
<CategoryItem
|
|
@@ -117,9 +114,6 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
117
114
|
const templatePartsLink = useLink( { path: '/wp_template_part/all' } );
|
|
118
115
|
const footer = ! isMobileViewport ? (
|
|
119
116
|
<ItemGroup>
|
|
120
|
-
<SidebarNavigationItem withChevron { ...templatePartsLink }>
|
|
121
|
-
{ __( 'Manage all template parts' ) }
|
|
122
|
-
</SidebarNavigationItem>
|
|
123
117
|
<SidebarNavigationItem
|
|
124
118
|
as="a"
|
|
125
119
|
href="edit.php?post_type=wp_block"
|
|
@@ -127,6 +121,9 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
127
121
|
>
|
|
128
122
|
{ __( 'Manage all of my patterns' ) }
|
|
129
123
|
</SidebarNavigationItem>
|
|
124
|
+
<SidebarNavigationItem withChevron { ...templatePartsLink }>
|
|
125
|
+
{ __( 'Manage all template parts' ) }
|
|
126
|
+
</SidebarNavigationItem>
|
|
130
127
|
</ItemGroup>
|
|
131
128
|
) : undefined;
|
|
132
129
|
|
|
@@ -172,13 +169,6 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
172
169
|
}
|
|
173
170
|
/>
|
|
174
171
|
</ItemGroup>
|
|
175
|
-
{ hasTemplateParts && (
|
|
176
|
-
<TemplatePartGroup
|
|
177
|
-
areas={ templatePartAreas }
|
|
178
|
-
currentArea={ currentCategory }
|
|
179
|
-
currentType={ currentType }
|
|
180
|
-
/>
|
|
181
|
-
) }
|
|
182
172
|
{ hasPatterns && (
|
|
183
173
|
<ThemePatternsGroup
|
|
184
174
|
categories={ patternCategories }
|
|
@@ -186,6 +176,13 @@ export default function SidebarNavigationScreenPatterns() {
|
|
|
186
176
|
currentType={ currentType }
|
|
187
177
|
/>
|
|
188
178
|
) }
|
|
179
|
+
{ hasTemplateParts && (
|
|
180
|
+
<TemplatePartGroup
|
|
181
|
+
areas={ templatePartAreas }
|
|
182
|
+
currentArea={ currentCategory }
|
|
183
|
+
currentType={ currentType }
|
|
184
|
+
/>
|
|
185
|
+
) }
|
|
189
186
|
</>
|
|
190
187
|
) }
|
|
191
188
|
</>
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
.edit-site-sidebar-navigation-screen-patterns__group {
|
|
2
|
-
margin-bottom: $grid-unit-
|
|
3
|
-
|
|
4
|
-
&:
|
|
2
|
+
margin-bottom: $grid-unit-30;
|
|
3
|
+
|
|
4
|
+
&:last-of-type {
|
|
5
5
|
border-bottom: 0;
|
|
6
6
|
padding-bottom: 0;
|
|
7
7
|
margin-bottom: 0;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
&:first-of-type {
|
|
11
|
-
margin-bottom: $grid-unit-40;
|
|
12
|
-
}
|
|
13
9
|
}
|
|
14
10
|
|
|
15
11
|
.edit-site-sidebar-navigation-screen-patterns__group-header {
|
|
12
|
+
margin-top: $grid-unit-20;
|
|
13
|
+
|
|
16
14
|
p {
|
|
17
15
|
color: $gray-600;
|
|
18
16
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useMemo } from '@wordpress/element';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
@@ -11,6 +12,10 @@ import useThemePatterns from './use-theme-patterns';
|
|
|
11
12
|
|
|
12
13
|
export default function usePatternCategories() {
|
|
13
14
|
const defaultCategories = useDefaultPatternCategories();
|
|
15
|
+
defaultCategories.push( {
|
|
16
|
+
name: 'uncategorized',
|
|
17
|
+
label: __( 'Uncategorized' ),
|
|
18
|
+
} );
|
|
14
19
|
const themePatterns = useThemePatterns();
|
|
15
20
|
|
|
16
21
|
const patternCategories = useMemo( () => {
|
|
@@ -31,6 +36,10 @@ export default function usePatternCategories() {
|
|
|
31
36
|
categoryMap[ category ].count += 1;
|
|
32
37
|
}
|
|
33
38
|
} );
|
|
39
|
+
// If the pattern has no categories, add it to uncategorized.
|
|
40
|
+
if ( ! pattern.categories?.length ) {
|
|
41
|
+
categoryMap.uncategorized.count += 1;
|
|
42
|
+
}
|
|
34
43
|
} );
|
|
35
44
|
|
|
36
45
|
// Filter categories so we only have those containing patterns.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/page-actions/delete-page-menu-item.js"],"names":["DeletePageMenuItem","postId","onRemove","isModalOpen","setIsModalOpen","createSuccessNotice","createErrorNotice","noticesStore","deleteEntityRecord","coreStore","page","select","getEntityRecord","removePage","throwOnError","title","rendered","type","id","error","errorMessage","message","code"],"mappings":";;;;;;;AAKA;;AAFA;;AACA;;AAEA;;AACA;;AACA;;AAIA;;AAZA;AACA;AACA;AAYe,SAASA,kBAAT,CAA6B;AAAEC,EAAAA,MAAF;AAAUC,EAAAA;AAAV,CAA7B,EAAoD;AAClE,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkC,uBAAU,KAAV,CAAxC;AACA,QAAM;AAAEC,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACL,uBAAaC,cAAb,CADD;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAAyB,uBAAaC,eAAb,CAA/B;AACA,QAAMC,IAAI,GAAG,qBACVC,MAAF,IACCA,MAAM,CAAEF,eAAF,CAAN,CAAoBG,eAApB,CAAqC,UAArC,EAAiD,MAAjD,EAAyDX,MAAzD,CAFW,EAGZ,CAAEA,MAAF,CAHY,CAAb;;AAKA,iBAAeY,UAAf,GAA4B;AAC3B,QAAI;AACH,YAAML,kBAAkB,CACvB,UADuB,EAEvB,MAFuB,EAGvBP,MAHuB,EAIvB,EAJuB,EAKvB;AAAEa,QAAAA,YAAY,EAAE;AAAhB,OALuB,CAAxB;AAOAT,MAAAA,mBAAmB,CAClB;AACC;AACA,oBAAI,eAAJ,CAFD,EAGC,kCAAgBK,IAAI,CAACK,KAAL,CAAWC,QAA3B,CAHD,CADkB,EAMlB;AACCC,QAAAA,IAAI,EAAE,UADP;AAECC,QAAAA,EAAE,EAAE;AAFL,OANkB,CAAnB;AAWAhB,MAAAA,QAAQ;AACR,KApBD,CAoBE,OAAQiB,KAAR,EAAgB;AACjB,YAAMC,YAAY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEG,cAAI,4CAAJ,CAHJ;AAKAf,MAAAA,iBAAiB,CAAEc,YAAF,EAAgB;AAAEH,QAAAA,IAAI,EAAE;AAAR,OAAhB,CAAjB;AACA,KA3BD,SA2BU;AACTb,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AACD;;AACD,SACC,qDACC,4BAAC,oBAAD;AAAU,IAAA,OAAO,EAAG,MAAMA,cAAc,CAAE,IAAF,CAAxC;AAAmD,IAAA,aAAa;AAAhE,KACG,cAAI,QAAJ,CADH,CADD,EAIC,4BAAC,uCAAD;AACC,IAAA,MAAM,EAAGD,WADV;AAEC,IAAA,SAAS,EAAGU,UAFb;AAGC,IAAA,QAAQ,EAAG,MAAMT,cAAc,CAAE,KAAF;AAHhC,KAKG,cAAI,4CAAJ,CALH,CAJD,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function DeletePageMenuItem( { postId, onRemove } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\tconst page = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'postType', 'page', postId ),\n\t\t[ postId ]\n\t);\n\tasync function removePage() {\n\t\ttry {\n\t\t\tawait deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'page',\n\t\t\t\tpostId,\n\t\t\t\t{},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: The page's title. */\n\t\t\t\t\t__( '\"%s\" deleted.' ),\n\t\t\t\t\tdecodeEntities( page.title.rendered )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'edit-site-page-removed',\n\t\t\t\t}\n\t\t\t);\n\t\t\tonRemove?.();\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while deleting the page.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t} finally {\n\t\t\tsetIsModalOpen( false );\n\t\t}\n\t}\n\treturn (\n\t\t<>\n\t\t\t<MenuItem onClick={ () => setIsModalOpen( true ) } isDestructive>\n\t\t\t\t{ __( 'Delete' ) }\n\t\t\t</MenuItem>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isModalOpen }\n\t\t\t\tonConfirm={ removePage }\n\t\t\t\tonCancel={ () => setIsModalOpen( false ) }\n\t\t\t>\n\t\t\t\t{ __( 'Are you sure you want to delete this page?' ) }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/page-actions/delete-page-menu-item.js"],"names":["useDispatch","useSelect","decodeEntities","useState","store","coreStore","__","sprintf","MenuItem","__experimentalConfirmDialog","ConfirmDialog","noticesStore","DeletePageMenuItem","postId","onRemove","isModalOpen","setIsModalOpen","createSuccessNotice","createErrorNotice","deleteEntityRecord","page","select","getEntityRecord","removePage","throwOnError","title","rendered","type","id","error","errorMessage","message","code"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,QAAuC,iBAAvC;AACA,SAASC,cAAT,QAA+B,0BAA/B;AACA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SACCC,QADD,EAECC,2BAA2B,IAAIC,aAFhC,QAGO,uBAHP;AAIA,SAASN,KAAK,IAAIO,YAAlB,QAAsC,oBAAtC;AAEA,eAAe,SAASC,kBAAT,CAA6B;AAAEC,EAAAA,MAAF;AAAUC,EAAAA;AAAV,CAA7B,EAAoD;AAClE,QAAM,CAAEC,WAAF,EAAeC,cAAf,IAAkCb,QAAQ,CAAE,KAAF,CAAhD;AACA,QAAM;AAAEc,IAAAA,mBAAF;AAAuBC,IAAAA;AAAvB,MACLlB,WAAW,CAAEW,YAAF,CADZ;AAEA,QAAM;AAAEQ,IAAAA;AAAF,MAAyBnB,WAAW,CAAEK,SAAF,CAA1C;AACA,QAAMe,IAAI,GAAGnB,SAAS,CACnBoB,MAAF,IACCA,MAAM,CAAEhB,SAAF,CAAN,CAAoBiB,eAApB,CAAqC,UAArC,EAAiD,MAAjD,EAAyDT,MAAzD,CAFoB,EAGrB,CAAEA,MAAF,CAHqB,CAAtB;;AAKA,iBAAeU,UAAf,GAA4B;AAC3B,QAAI;AACH,YAAMJ,kBAAkB,CACvB,UADuB,EAEvB,MAFuB,EAGvBN,MAHuB,EAIvB,EAJuB,EAKvB;AAAEW,QAAAA,YAAY,EAAE;AAAhB,OALuB,CAAxB;AAOAP,MAAAA,mBAAmB,CAClBV,OAAO;AACN;AACAD,MAAAA,EAAE,CAAE,eAAF,CAFI,EAGNJ,cAAc,CAAEkB,IAAI,CAACK,KAAL,CAAWC,QAAb,CAHR,CADW,EAMlB;AACCC,QAAAA,IAAI,EAAE,UADP;AAECC,QAAAA,EAAE,EAAE;AAFL,OANkB,CAAnB;AAWAd,MAAAA,QAAQ;AACR,KApBD,CAoBE,OAAQe,KAAR,EAAgB;AACjB,YAAMC,YAAY,GACjBD,KAAK,CAACE,OAAN,IAAiBF,KAAK,CAACG,IAAN,KAAe,eAAhC,GACGH,KAAK,CAACE,OADT,GAEGzB,EAAE,CAAE,4CAAF,CAHN;AAKAY,MAAAA,iBAAiB,CAAEY,YAAF,EAAgB;AAAEH,QAAAA,IAAI,EAAE;AAAR,OAAhB,CAAjB;AACA,KA3BD,SA2BU;AACTX,MAAAA,cAAc,CAAE,KAAF,CAAd;AACA;AACD;;AACD,SACC,8BACC,cAAC,QAAD;AAAU,IAAA,OAAO,EAAG,MAAMA,cAAc,CAAE,IAAF,CAAxC;AAAmD,IAAA,aAAa;AAAhE,KACGV,EAAE,CAAE,QAAF,CADL,CADD,EAIC,cAAC,aAAD;AACC,IAAA,MAAM,EAAGS,WADV;AAEC,IAAA,SAAS,EAAGQ,UAFb;AAGC,IAAA,QAAQ,EAAG,MAAMP,cAAc,CAAE,KAAF;AAHhC,KAKGV,EAAE,CAAE,4CAAF,CALL,CAJD,CADD;AAcA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState } from '@wordpress/element';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tMenuItem,\n\t__experimentalConfirmDialog as ConfirmDialog,\n} from '@wordpress/components';\nimport { store as noticesStore } from '@wordpress/notices';\n\nexport default function DeletePageMenuItem( { postId, onRemove } ) {\n\tconst [ isModalOpen, setIsModalOpen ] = useState( false );\n\tconst { createSuccessNotice, createErrorNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { deleteEntityRecord } = useDispatch( coreStore );\n\tconst page = useSelect(\n\t\t( select ) =>\n\t\t\tselect( coreStore ).getEntityRecord( 'postType', 'page', postId ),\n\t\t[ postId ]\n\t);\n\tasync function removePage() {\n\t\ttry {\n\t\t\tawait deleteEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'page',\n\t\t\t\tpostId,\n\t\t\t\t{},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t/* translators: The page's title. */\n\t\t\t\t\t__( '\"%s\" deleted.' ),\n\t\t\t\t\tdecodeEntities( page.title.rendered )\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t\tid: 'edit-site-page-removed',\n\t\t\t\t}\n\t\t\t);\n\t\t\tonRemove?.();\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while deleting the page.' );\n\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t} finally {\n\t\t\tsetIsModalOpen( false );\n\t\t}\n\t}\n\treturn (\n\t\t<>\n\t\t\t<MenuItem onClick={ () => setIsModalOpen( true ) } isDestructive>\n\t\t\t\t{ __( 'Delete' ) }\n\t\t\t</MenuItem>\n\t\t\t<ConfirmDialog\n\t\t\t\tisOpen={ isModalOpen }\n\t\t\t\tonConfirm={ removePage }\n\t\t\t\tonCancel={ () => setIsModalOpen( false ) }\n\t\t\t>\n\t\t\t\t{ __( 'Are you sure you want to delete this page?' ) }\n\t\t\t</ConfirmDialog>\n\t\t</>\n\t);\n}\n"]}
|