@elementor/editor-site-navigation 4.5.0-1233 → 4.5.0-1235

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.
Files changed (27) hide show
  1. package/dist/index.d.mts +83 -15
  2. package/dist/index.d.ts +83 -15
  3. package/dist/index.js +975 -822
  4. package/dist/index.mjs +938 -800
  5. package/package.json +12 -12
  6. package/src/components/panel/content-panel-active-filters.tsx +2 -2
  7. package/src/components/panel/content-panel-chrome.ts +47 -21
  8. package/src/components/panel/content-panel-search.tsx +9 -4
  9. package/src/components/panel/{content-panel-toolbar.tsx → content-panel-section-toolbar.tsx} +9 -2
  10. package/src/components/panel/content-panel-sort-list.tsx +2 -2
  11. package/src/components/panel/content-panel-sort.tsx +2 -2
  12. package/src/components/panel/content-panel-status-filter-list.tsx +25 -10
  13. package/src/components/panel/content-panel-status-filter.tsx +2 -2
  14. package/src/components/panel/posts-list/collapsible-list.tsx +3 -0
  15. package/src/components/panel/posts-list/list-items/edit-mode-template.tsx +6 -0
  16. package/src/components/panel/posts-list/list-items/list-item-create.tsx +1 -0
  17. package/src/components/panel/posts-list/list-items/list-item-duplicate.tsx +1 -0
  18. package/src/components/panel/posts-list/list-items/list-item-view.tsx +15 -3
  19. package/src/components/panel/posts-list/posts-collapsible-list.tsx +42 -18
  20. package/src/components/panel/shell.tsx +0 -3
  21. package/src/components/shared/page-title-and-status.tsx +4 -3
  22. package/src/contexts/content-panel-coordinator.tsx +2 -65
  23. package/src/contexts/site-content-section-toolbar.tsx +61 -0
  24. package/src/hooks/use-homepage-actions.ts +12 -1
  25. package/src/hooks/use-site-content-section-list-controls.ts +64 -0
  26. package/src/index.ts +28 -1
  27. package/src/site-content-status-filter.ts +11 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-site-navigation",
3
- "version": "4.5.0-1233",
3
+ "version": "4.5.0-1235",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,18 +39,18 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor-controls": "4.5.0-1233",
43
- "@elementor/editor-app-bar": "4.5.0-1233",
44
- "@elementor/editor-documents": "4.5.0-1233",
45
- "@elementor/editor-panels": "4.5.0-1233",
46
- "@elementor/editor-sidebar": "4.5.0-1233",
47
- "@elementor/editor-ui": "4.5.0-1233",
48
- "@elementor/editor-v1-adapters": "4.5.0-1233",
49
- "@elementor/env": "4.5.0-1233",
50
- "@elementor/events": "4.5.0-1233",
42
+ "@elementor/editor-controls": "4.5.0-1235",
43
+ "@elementor/editor-app-bar": "4.5.0-1235",
44
+ "@elementor/editor-documents": "4.5.0-1235",
45
+ "@elementor/editor-panels": "4.5.0-1235",
46
+ "@elementor/editor-sidebar": "4.5.0-1235",
47
+ "@elementor/editor-ui": "4.5.0-1235",
48
+ "@elementor/editor-v1-adapters": "4.5.0-1235",
49
+ "@elementor/env": "4.5.0-1235",
50
+ "@elementor/events": "4.5.0-1235",
51
51
  "@elementor/icons": "~1.78.1",
52
- "@elementor/locations": "4.5.0-1233",
53
- "@elementor/query": "4.5.0-1233",
52
+ "@elementor/locations": "4.5.0-1235",
53
+ "@elementor/query": "4.5.0-1235",
54
54
  "@elementor/ui": "1.41.4",
55
55
  "@wordpress/api-fetch": "^6.42.0",
56
56
  "@wordpress/i18n": "^5.13.0"
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { Chip, Stack } from '@elementor/ui';
3
3
  import { __ } from '@wordpress/i18n';
4
4
 
5
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
5
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
6
6
  import { DEFAULT_SITE_CONTENT_SORT, getSiteContentSortLabel, hasActiveSiteContentSort } from '../../site-content-sort';
7
7
  import {
8
8
  getActiveSiteContentStatusFilterKeys,
@@ -23,7 +23,7 @@ const contentPanelFilterChipSx = {
23
23
 
24
24
  export default function ContentPanelActiveFilters() {
25
25
  const { clearActiveToolbarFilters, setSiteContentSort, siteContentSort, statusFilters, toggleStatusFilter } =
26
- useContentPanelCoordinator();
26
+ useSiteContentSectionToolbar();
27
27
 
28
28
  const hasStatusFilters = hasActiveSiteContentStatusFilters( statusFilters );
29
29
  const hasSort = hasActiveSiteContentSort( siteContentSort );
@@ -1,10 +1,7 @@
1
1
  const CONTENT_PANEL_INSET_SPACING = 2;
2
2
  const CONTENT_PANEL_LIST_ROW_GAP = 0.5;
3
3
  const CONTENT_PANEL_LIST_ROW_INSET_INLINE = 0.75;
4
- const CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_ACTIONS_COUNT = 2;
5
- const CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_ACTION_SLOT_WIDTH = 5.5;
6
- const CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_INSET =
7
- CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_ACTIONS_COUNT * CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_ACTION_SLOT_WIDTH;
4
+ const CONTENT_PANEL_LIST_ROW_SECONDARY_ACTION_SLOT_WIDTH = 5.5;
8
5
  const CONTENT_PANEL_LIST_ROW_TITLE_FONT_SIZE = '0.75rem';
9
6
  const CONTENT_PANEL_LIST_SECTION_BOTTOM_SPACING = 1;
10
7
 
@@ -20,21 +17,42 @@ export const contentPanelListRowPaddingSx = {
20
17
  ...contentPanelInsetPaddingSx,
21
18
  };
22
19
 
23
- const contentPanelListItemActiveActionsInsetSx = {
20
+ const contentPanelListItemSecondaryInsetSx = ( trailingActionCount: number ) => ( {
24
21
  '&& > .MuiListItemButton-root': {
25
- paddingInlineEnd: CONTENT_PANEL_LIST_ROW_ACTIVE_SECONDARY_INSET,
22
+ paddingInlineEnd: trailingActionCount * CONTENT_PANEL_LIST_ROW_SECONDARY_ACTION_SLOT_WIDTH,
26
23
  paddingRight: 'unset',
27
24
  },
28
- };
25
+ } );
26
+
27
+ export function getContentPanelListItemSx( trailingActionCount: number ) {
28
+ return {
29
+ ...contentPanelListRowPaddingSx,
30
+ ...contentPanelListItemSecondaryInsetSx( trailingActionCount ),
31
+ };
32
+ }
29
33
 
30
- export function getContentPanelListItemSx( hasActiveRowActions: boolean ) {
31
- if ( ! hasActiveRowActions ) {
32
- return contentPanelListRowPaddingSx;
34
+ export function getContentPanelListItemRowStateSx( isActive: boolean, allowRowHover: boolean ) {
35
+ if ( isActive ) {
36
+ return {
37
+ borderRadius: 1,
38
+ backgroundColor: 'action.selected',
39
+ '&:hover': {
40
+ backgroundColor: 'action.selected',
41
+ },
42
+ };
43
+ }
44
+
45
+ if ( ! allowRowHover ) {
46
+ return {
47
+ borderRadius: 1,
48
+ };
33
49
  }
34
50
 
35
51
  return {
36
- ...contentPanelListRowPaddingSx,
37
- ...contentPanelListItemActiveActionsInsetSx,
52
+ borderRadius: 1,
53
+ '&:hover': {
54
+ backgroundColor: 'action.hover',
55
+ },
38
56
  };
39
57
  }
40
58
 
@@ -70,18 +88,26 @@ export const contentPanelListSectionListSx = {
70
88
  paddingBlockEnd: CONTENT_PANEL_LIST_SECTION_BOTTOM_SPACING,
71
89
  };
72
90
 
73
- export const contentPanelListItemButtonSx = {
74
- justifyContent: 'flex-start',
75
- paddingInline: CONTENT_PANEL_LIST_ROW_INSET_INLINE,
76
- textAlign: 'start',
77
- width: '100%',
91
+ const contentPanelListItemButtonTransparentSx = {
92
+ backgroundColor: 'transparent',
78
93
  '&.Mui-selected': {
79
- backgroundColor: 'action.selected',
94
+ backgroundColor: 'transparent',
80
95
  },
81
96
  '&.Mui-selected:hover': {
82
- backgroundColor: 'action.selected',
97
+ backgroundColor: 'transparent',
83
98
  },
84
- '&:hover:not(.Mui-disabled)': {
85
- backgroundColor: 'action.hover',
99
+ '&:hover': {
100
+ backgroundColor: 'transparent',
86
101
  },
102
+ '&.Mui-disabled': {
103
+ backgroundColor: 'transparent',
104
+ },
105
+ };
106
+
107
+ export const contentPanelListItemButtonSx = {
108
+ ...contentPanelListItemButtonTransparentSx,
109
+ justifyContent: 'flex-start',
110
+ paddingInline: CONTENT_PANEL_LIST_ROW_INSET_INLINE,
111
+ textAlign: 'start',
112
+ width: '100%',
87
113
  };
@@ -3,13 +3,18 @@ import { SearchIcon } from '@elementor/icons';
3
3
  import { Box, InputAdornment, TextField } from '@elementor/ui';
4
4
  import { __ } from '@wordpress/i18n';
5
5
 
6
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
6
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
7
7
 
8
- export default function ContentPanelSearch() {
9
- const { searchQuery, setSearchQuery } = useContentPanelCoordinator();
8
+ type Props = {
9
+ searchAriaLabel?: string;
10
+ };
11
+
12
+ export default function ContentPanelSearch( { searchAriaLabel }: Props ) {
13
+ const { searchQuery, setSearchQuery } = useSiteContentSectionToolbar();
14
+ const ariaLabel = searchAriaLabel ?? __( 'Search site content', 'elementor' );
10
15
 
11
16
  return (
12
- <Box component="search" aria-label={ __( 'Search site content', 'elementor' ) }>
17
+ <Box component="search" aria-label={ ariaLabel }>
13
18
  <TextField
14
19
  fullWidth
15
20
  size="tiny"
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { type ReactNode } from 'react';
2
3
  import { Box, Stack } from '@elementor/ui';
3
4
 
4
5
  import ContentPanelActiveFilters from './content-panel-active-filters';
@@ -7,16 +8,22 @@ import ContentPanelSearch from './content-panel-search';
7
8
  import ContentPanelSort from './content-panel-sort';
8
9
  import ContentPanelStatusFilter from './content-panel-status-filter';
9
10
 
10
- export default function ContentPanelToolbar() {
11
+ type Props = {
12
+ addAction?: ReactNode;
13
+ searchAriaLabel?: string;
14
+ };
15
+
16
+ export default function ContentPanelSectionToolbar( { addAction, searchAriaLabel }: Props ) {
11
17
  return (
12
18
  <Box sx={ contentPanelSearchBoxSx }>
13
19
  <Stack gap={ 0.75 } width="100%">
14
20
  <Stack alignItems="center" direction="row" gap={ 0.5 } width="100%">
15
21
  <Box sx={ { flexGrow: 1, minWidth: 0 } }>
16
- <ContentPanelSearch />
22
+ <ContentPanelSearch searchAriaLabel={ searchAriaLabel } />
17
23
  </Box>
18
24
  <ContentPanelStatusFilter />
19
25
  <ContentPanelSort />
26
+ { addAction }
20
27
  </Stack>
21
28
  <ContentPanelActiveFilters />
22
29
  </Stack>
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import { CheckIcon } from '@elementor/icons';
3
3
  import { MenuItem, MenuList, Stack, Typography } from '@elementor/ui';
4
4
 
5
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
5
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
6
6
  import { getSiteContentSortLabel, SITE_CONTENT_SORT_OPTIONS } from '../../site-content-sort';
7
7
 
8
8
  const renderSortMenuItemContent = ( label: string, selected: boolean ) => (
@@ -15,7 +15,7 @@ const renderSortMenuItemContent = ( label: string, selected: boolean ) => (
15
15
  );
16
16
 
17
17
  export default function ContentPanelSortList() {
18
- const { setSiteContentSort, siteContentSort } = useContentPanelCoordinator();
18
+ const { setSiteContentSort, siteContentSort } = useSiteContentSectionToolbar();
19
19
 
20
20
  return (
21
21
  <MenuList dense>
@@ -4,13 +4,13 @@ import { ArrowsSortIcon } from '@elementor/icons';
4
4
  import { bindPopover, bindToggle, Divider, Popover, ToggleButton, Tooltip, usePopupState } from '@elementor/ui';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
7
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
8
8
  import { hasActiveSiteContentSort, SITE_CONTENT_SORT_POPOVER_WIDTH_PX } from '../../site-content-sort';
9
9
  import ContentPanelClearFiltersButton from './content-panel-clear-filters-button';
10
10
  import ContentPanelSortList from './content-panel-sort-list';
11
11
 
12
12
  export default function ContentPanelSort() {
13
- const { clearSiteContentSort, siteContentSort } = useContentPanelCoordinator();
13
+ const { clearSiteContentSort, siteContentSort } = useSiteContentSectionToolbar();
14
14
  const popupState = usePopupState( {
15
15
  variant: 'popover',
16
16
  disableAutoFocus: true,
@@ -2,8 +2,7 @@ import * as React from 'react';
2
2
  import { CheckIcon } from '@elementor/icons';
3
3
  import { MenuItem, MenuList, Stack, Typography } from '@elementor/ui';
4
4
 
5
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
6
- import useAccessiblePanelPostTypes from '../../hooks/use-accessible-panel-post-types';
5
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
7
6
  import { useSiteContentStatusFilterCounts } from '../../hooks/use-site-content-status-filter-counts';
8
7
  import {
9
8
  getSiteContentStatusFilterLabel,
@@ -27,18 +26,34 @@ type Props = {
27
26
  };
28
27
 
29
28
  export default function ContentPanelStatusFilterList( { loadCounts }: Props ) {
30
- const { clearStatusFilters, statusFilters, toggleStatusFilter } = useContentPanelCoordinator();
31
- const { accessiblePostTypes } = useAccessiblePanelPostTypes();
32
- const { data: statusCounts, isPending: isLoadingCounts } = useSiteContentStatusFilterCounts(
33
- accessiblePostTypes,
34
- loadCounts
29
+ const {
30
+ clearStatusFilters,
31
+ statusFilterCountSlugs,
32
+ statusFilterCounts: presetStatusCounts,
33
+ statusFilterCountsPending,
34
+ statusFilters,
35
+ toggleStatusFilter,
36
+ } = useSiteContentSectionToolbar();
37
+ const shouldLoadPostTypeCounts = loadCounts && statusFilterCountSlugs.length > 0 && ! presetStatusCounts;
38
+ const { data: fetchedStatusCounts, isPending: isFetchingStatusCounts } = useSiteContentStatusFilterCounts(
39
+ statusFilterCountSlugs,
40
+ shouldLoadPostTypeCounts
35
41
  );
42
+ const statusCounts = presetStatusCounts ?? fetchedStatusCounts;
43
+ const isLoadingCounts = Boolean( presetStatusCounts ? statusFilterCountsPending : isFetchingStatusCounts );
36
44
 
37
45
  const isAllSelected = ! hasActiveSiteContentStatusFilters( statusFilters );
38
46
 
39
- const visibleFilters = SITE_CONTENT_SELECTABLE_STATUS_FILTERS.filter( ( filter ) =>
40
- shouldShowSiteContentStatusFilterRow( statusCounts?.[ filter ], isLoadingCounts, statusFilters[ filter ] )
41
- );
47
+ const visibleFilters =
48
+ statusFilterCountSlugs.length === 0
49
+ ? SITE_CONTENT_SELECTABLE_STATUS_FILTERS
50
+ : SITE_CONTENT_SELECTABLE_STATUS_FILTERS.filter( ( filter ) =>
51
+ shouldShowSiteContentStatusFilterRow(
52
+ statusCounts?.[ filter ],
53
+ isLoadingCounts,
54
+ statusFilters[ filter ]
55
+ )
56
+ );
42
57
 
43
58
  return (
44
59
  <MenuList dense>
@@ -4,7 +4,7 @@ import { FilterIcon } from '@elementor/icons';
4
4
  import { bindPopover, bindToggle, Divider, Popover, ToggleButton, Tooltip, usePopupState } from '@elementor/ui';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
- import { useContentPanelCoordinator } from '../../contexts/content-panel-coordinator';
7
+ import { useSiteContentSectionToolbar } from '../../contexts/site-content-section-toolbar';
8
8
  import {
9
9
  hasActiveSiteContentStatusFilters,
10
10
  SITE_CONTENT_FILTER_POPOVER_WIDTH_PX,
@@ -13,7 +13,7 @@ import ContentPanelClearFiltersButton from './content-panel-clear-filters-button
13
13
  import ContentPanelStatusFilterList from './content-panel-status-filter-list';
14
14
 
15
15
  export default function ContentPanelStatusFilter() {
16
- const { clearStatusFilters, statusFilters } = useContentPanelCoordinator();
16
+ const { clearStatusFilters, statusFilters } = useSiteContentSectionToolbar();
17
17
  const popupState = usePopupState( {
18
18
  variant: 'popover',
19
19
  disableAutoFocus: true,
@@ -15,6 +15,7 @@ type Props = {
15
15
  headerRef?: Ref< HTMLDivElement >;
16
16
  isOpen: boolean;
17
17
  onOpenChange: ( isOpen: boolean ) => void;
18
+ sectionToolbar?: ReactNode;
18
19
  title: string;
19
20
  trailingActions?: ReactNode;
20
21
  };
@@ -39,6 +40,7 @@ export default function CollapsibleList( {
39
40
  headerRef,
40
41
  isOpen,
41
42
  onOpenChange,
43
+ sectionToolbar,
42
44
  title,
43
45
  trailingActions,
44
46
  children,
@@ -102,6 +104,7 @@ export default function CollapsibleList( {
102
104
  </Stack>
103
105
  ) }
104
106
  </Box>
107
+ { isOpen && sectionToolbar }
105
108
  <Collapse aria-labelledby={ labelId } id={ contentId } in={ isOpen } timeout="auto" unmountOnExit>
106
109
  <List dense disablePadding sx={ contentPanelListSectionListSx }>
107
110
  { children }
@@ -65,6 +65,7 @@ export default function EditModeTemplate( { postTitle, isLoading, callback, onDi
65
65
  const [ touched, setTouched ] = useState( false );
66
66
  const [ inputError, setInputError ] = useState< string | null >( null );
67
67
  const closeButton = useRef< HTMLButtonElement >();
68
+ const hasSubmittedRef = useRef( false );
68
69
 
69
70
  const onBlur = ( e: FocusEvent ) => {
70
71
  if ( closeButton.current === e.relatedTarget ) {
@@ -89,10 +90,15 @@ export default function EditModeTemplate( { postTitle, isLoading, callback, onDi
89
90
  };
90
91
 
91
92
  const runCallback = () => {
93
+ if ( hasSubmittedRef.current || isLoading ) {
94
+ return;
95
+ }
96
+
92
97
  if ( ! validateInput( title ) ) {
93
98
  return;
94
99
  }
95
100
 
101
+ hasSubmittedRef.current = true;
96
102
  callback( title );
97
103
  };
98
104
 
@@ -20,6 +20,7 @@ export default function ListItemCreate() {
20
20
  status: 'draft',
21
21
  } );
22
22
 
23
+ resetEditMode();
23
24
  navigateToDocument( id );
24
25
  } catch {
25
26
  setError();
@@ -23,6 +23,7 @@ export default function ListItemDuplicate() {
23
23
  title: inputValue,
24
24
  } );
25
25
 
26
+ resetEditMode();
26
27
  navigateToDocument( postId );
27
28
  } catch {
28
29
  setError();
@@ -32,7 +32,11 @@ import Rename from '../../actions-menu/actions/rename';
32
32
  import Restore from '../../actions-menu/actions/restore';
33
33
  import SetHome, { RemoveHomepageDialog } from '../../actions-menu/actions/set-home';
34
34
  import View from '../../actions-menu/actions/view';
35
- import { contentPanelListItemButtonSx, getContentPanelListItemSx } from '../../content-panel-chrome';
35
+ import {
36
+ contentPanelListItemButtonSx,
37
+ getContentPanelListItemRowStateSx,
38
+ getContentPanelListItemSx,
39
+ } from '../../content-panel-chrome';
36
40
  import {
37
41
  SiteContentListItemActionsSlot,
38
42
  useSiteContentListItemActionsInjections,
@@ -88,14 +92,23 @@ export default function ListItemView( { post }: { post: Post } ) {
88
92
  const menuTriggerProps = bindTrigger( popupState );
89
93
  const hasListItemActions = useSiteContentListItemActionsInjections().length > 0;
90
94
  const showListItemActions = isActive && post.user_can.edit && ! isTrashed && hasListItemActions;
95
+ const isHome = Boolean( post.isHome );
96
+ const trailingActionCount = 1 + ( showListItemActions ? 1 : 0 ) + ( isHome ? 1 : 0 );
97
+ const allowRowHover = ! isEditBlocked;
91
98
 
92
99
  const listRow = (
93
100
  <ListItem
94
101
  disablePadding
95
- sx={ getContentPanelListItemSx( showListItemActions ) }
102
+ sx={ {
103
+ ...getContentPanelListItemSx( trailingActionCount ),
104
+ ...getContentPanelListItemRowStateSx( isActive, allowRowHover ),
105
+ } }
96
106
  secondaryAction={
97
107
  <Stack alignItems="center" direction="row" spacing={ 0 }>
98
108
  { showListItemActions && <SiteContentListItemActionsSlot post={ post } title={ title } /> }
109
+ { isHome && (
110
+ <HomeIcon color="disabled" fontSize="tiny" titleAccess={ __( 'Homepage', 'elementor' ) } />
111
+ ) }
99
112
  <IconButton
100
113
  aria-label={ __( 'More actions', 'elementor' ) }
101
114
  size="tiny"
@@ -128,7 +141,6 @@ export default function ListItemView( { post }: { post: Post } ) {
128
141
  <ListItemText disableTypography sx={ { flex: 1, minWidth: 0 } }>
129
142
  <PageTitleAndStatus title={ title } status={ status } />
130
143
  </ListItemText>
131
- { post.isHome && <HomeIcon titleAccess={ __( 'Homepage', 'elementor' ) } color="disabled" /> }
132
144
  </ListItemButton>
133
145
  </ListItem>
134
146
  );
@@ -1,11 +1,15 @@
1
1
  import * as React from 'react';
2
2
  import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { Box, Skeleton, Typography } from '@elementor/ui';
4
- import { __ } from '@wordpress/i18n';
4
+ import { __, sprintf } from '@wordpress/i18n';
5
5
 
6
6
  import { postTypesMap } from '../../../api/post';
7
7
  import { useContentPanelCoordinator } from '../../../contexts/content-panel-coordinator';
8
8
  import { usePostListContext } from '../../../contexts/post-list-context';
9
+ import {
10
+ SiteContentSectionToolbarProvider,
11
+ useSiteContentSectionToolbar,
12
+ } from '../../../contexts/site-content-section-toolbar';
9
13
  import { useHomepage } from '../../../hooks/use-homepage';
10
14
  import { usePostListPagination } from '../../../hooks/use-post-list-pagination';
11
15
  import { usePosts } from '../../../hooks/use-posts';
@@ -17,36 +21,27 @@ import {
17
21
  isSiteContentTrashFilterActive,
18
22
  serializeSiteContentStatusFilters,
19
23
  } from '../../../site-content-status-filter';
24
+ import ContentPanelSectionToolbar from '../content-panel-section-toolbar';
20
25
  import SectionAddButton from '../section-add-button';
21
26
  import CollapsibleList from './collapsible-list';
22
27
  import ErrorState from './error-state';
23
28
  import PostListItem from './post-list-item';
24
29
  import PostListPaginationActions from './post-list-pagination-actions';
25
30
 
26
- const SEARCH_DEBOUNCE_MS = 300;
27
-
28
31
  type Props = {
29
32
  isOpenByDefault?: boolean;
30
33
  };
31
34
 
32
- export default function PostsCollapsibleList( { isOpenByDefault = false }: Props ) {
35
+ function PostsCollapsibleListContent( { isOpenByDefault = false }: Props ) {
33
36
  const { type, editMode, resetEditMode, setEditMode } = usePostListContext();
34
- const { registerSection, searchQuery, siteContentSort, statusFilters, unregisterSection } =
35
- useContentPanelCoordinator();
37
+ const { registerSection, unregisterSection } = useContentPanelCoordinator();
38
+ const { clearStatusFilters, debouncedSearch, siteContentSort, statusFilters } = useSiteContentSectionToolbar();
36
39
  const [ isOpen, setIsOpen ] = useState( isOpenByDefault );
37
- const trimmedSearch = searchQuery.trim();
38
- const [ debouncedSearch, setDebouncedSearch ] = useState( trimmedSearch );
39
40
  const focusAfterShowLessRef = useRef( false );
40
41
  const listTopRef = useRef< HTMLDivElement | null >( null );
41
42
  const loadMoreButtonRef = useRef< HTMLButtonElement | null >( null );
42
43
  const sectionHeaderRef = useRef< HTMLDivElement | null >( null );
43
44
 
44
- useEffect( () => {
45
- const handle = window.setTimeout( () => setDebouncedSearch( trimmedSearch ), SEARCH_DEBOUNCE_MS );
46
-
47
- return () => window.clearTimeout( handle );
48
- }, [ trimmedSearch ] );
49
-
50
45
  const {
51
46
  data: { posts, total },
52
47
  isError: postsError,
@@ -72,11 +67,17 @@ export default function PostsCollapsibleList( { isOpenByDefault = false }: Props
72
67
  useEffect( () => {
73
68
  registerSection( type, {
74
69
  setExpanded: setIsOpen,
75
- startCreate: () => setEditMode( { mode: 'create', details: {} } ),
70
+ startCreate: () => {
71
+ if ( isSiteContentTrashFilterActive( statusFilters ) ) {
72
+ clearStatusFilters();
73
+ }
74
+
75
+ setEditMode( { mode: 'create', details: {} } );
76
+ },
76
77
  } );
77
78
 
78
79
  return () => unregisterSection( type );
79
- }, [ registerSection, unregisterSection, type, setEditMode ] );
80
+ }, [ clearStatusFilters, registerSection, setEditMode, statusFilters, type, unregisterSection ] );
80
81
 
81
82
  const filteredPosts = useMemo( () => {
82
83
  if ( ! posts ) {
@@ -84,7 +85,7 @@ export default function PostsCollapsibleList( { isOpenByDefault = false }: Props
84
85
  }
85
86
 
86
87
  const mappedPosts = isPageType
87
- ? posts.map( ( post ) => ( post.id === homepageId ? { ...post, isHome: true } : post ) )
88
+ ? posts.map( ( post ) => ( { ...post, isHome: post.id === homepageId } ) )
88
89
  : posts;
89
90
 
90
91
  const shouldPinHomepage = isPageType && shouldPinHomepageForSiteContentSort( siteContentSort );
@@ -177,6 +178,12 @@ export default function PostsCollapsibleList( { isOpenByDefault = false }: Props
177
178
  ( debouncedSearch || hasActiveSiteContentStatusFilters( statusFilters ) ) && filteredPosts.length === 0;
178
179
  const countChipLabel = isNarrowed && baselineTotal !== undefined ? `${ total } / ${ baselineTotal }` : undefined;
179
180
 
181
+ const searchAriaLabel = sprintf(
182
+ /* translators: %s: document type plural label. */
183
+ __( 'Search %s', 'elementor' ),
184
+ sectionTitle
185
+ );
186
+
180
187
  return (
181
188
  <CollapsibleList
182
189
  count={ displayCount }
@@ -184,8 +191,15 @@ export default function PostsCollapsibleList( { isOpenByDefault = false }: Props
184
191
  headerRef={ sectionHeaderRef }
185
192
  isOpen={ isOpen }
186
193
  onOpenChange={ setIsOpen }
194
+ sectionToolbar={
195
+ <ContentPanelSectionToolbar
196
+ addAction={
197
+ isTrashFilter ? undefined : <SectionAddButton onBeforeCreate={ () => setIsOpen( true ) } />
198
+ }
199
+ searchAriaLabel={ searchAriaLabel }
200
+ />
201
+ }
187
202
  title={ sectionTitle }
188
- trailingActions={ isTrashFilter ? null : <SectionAddButton onBeforeCreate={ () => setIsOpen( true ) } /> }
189
203
  >
190
204
  { showNoResults && (
191
205
  <Box sx={ { py: 2, px: 2 } }>
@@ -210,3 +224,13 @@ export default function PostsCollapsibleList( { isOpenByDefault = false }: Props
210
224
  </CollapsibleList>
211
225
  );
212
226
  }
227
+
228
+ export default function PostsCollapsibleList( props: Props ) {
229
+ const { type } = usePostListContext();
230
+
231
+ return (
232
+ <SiteContentSectionToolbarProvider statusFilterCountSlugs={ [ type ] }>
233
+ <PostsCollapsibleListContent { ...props } />
234
+ </SiteContentSectionToolbarProvider>
235
+ );
236
+ }
@@ -9,7 +9,6 @@ import { ContentPanelCoordinatorProvider } from '../../contexts/content-panel-co
9
9
  import useAccessiblePanelPostTypes from '../../hooks/use-accessible-panel-post-types';
10
10
  import { contentPanelHeaderStackSx } from './content-panel-chrome';
11
11
  import ContentPanelHeaderAdd from './content-panel-header-add';
12
- import ContentPanelToolbar from './content-panel-toolbar';
13
12
  import ErrorSnackbar from './error-snackbar';
14
13
  import ShellPanelBodyContent from './shell-panel-body-content';
15
14
 
@@ -39,8 +38,6 @@ const Shell = () => {
39
38
  </PanelHeader>
40
39
  <Divider />
41
40
  <PanelBody>
42
- <ContentPanelToolbar />
43
- <Divider />
44
41
  <ShellPanelBodyContent
45
42
  accessiblePostTypes={ accessiblePostTypes }
46
43
  isUserPending={ isUserPending }
@@ -81,14 +81,15 @@ const PageStatus = ( { status }: { status: string } ) => {
81
81
  );
82
82
  };
83
83
 
84
- const PageTitle = ( { title }: { title: string } ) => {
84
+ const PageTitle = ( { status, title }: { status: string; title: string } ) => {
85
85
  const modifiedTitle = useReverseHtmlEntities( title );
86
+ const titleColor = 'trash' === status ? 'text.disabled' : 'text.secondary';
86
87
 
87
88
  return (
88
89
  <Typography
89
90
  component="span"
90
91
  variant="body2"
91
- color="text.secondary"
92
+ color={ titleColor }
92
93
  noWrap
93
94
  sx={ {
94
95
  ...contentPanelListRowTitleSx,
@@ -107,7 +108,7 @@ const PageTitle = ( { title }: { title: string } ) => {
107
108
  export default function PageTitleAndStatus( { title, status }: { title: string; status: string } ) {
108
109
  return (
109
110
  <Box alignItems="center" display="flex" minWidth={ 0 } sx={ { overflow: 'hidden' } }>
110
- <PageTitle title={ title } />
111
+ <PageTitle status={ status } title={ title } />
111
112
  <PageStatus status={ status } />
112
113
  </Box>
113
114
  );