@elementor/editor-site-navigation 4.5.0-1237 → 4.5.0-1238

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-site-navigation",
3
- "version": "4.5.0-1237",
3
+ "version": "4.5.0-1238",
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-1237",
43
- "@elementor/editor-app-bar": "4.5.0-1237",
44
- "@elementor/editor-documents": "4.5.0-1237",
45
- "@elementor/editor-panels": "4.5.0-1237",
46
- "@elementor/editor-sidebar": "4.5.0-1237",
47
- "@elementor/editor-ui": "4.5.0-1237",
48
- "@elementor/editor-v1-adapters": "4.5.0-1237",
49
- "@elementor/env": "4.5.0-1237",
50
- "@elementor/events": "4.5.0-1237",
42
+ "@elementor/editor-controls": "4.5.0-1238",
43
+ "@elementor/editor-app-bar": "4.5.0-1238",
44
+ "@elementor/editor-documents": "4.5.0-1238",
45
+ "@elementor/editor-panels": "4.5.0-1238",
46
+ "@elementor/editor-sidebar": "4.5.0-1238",
47
+ "@elementor/editor-ui": "4.5.0-1238",
48
+ "@elementor/editor-v1-adapters": "4.5.0-1238",
49
+ "@elementor/env": "4.5.0-1238",
50
+ "@elementor/events": "4.5.0-1238",
51
51
  "@elementor/icons": "~1.78.1",
52
- "@elementor/locations": "4.5.0-1237",
53
- "@elementor/query": "4.5.0-1237",
52
+ "@elementor/locations": "4.5.0-1238",
53
+ "@elementor/query": "4.5.0-1238",
54
54
  "@elementor/ui": "1.41.4",
55
55
  "@wordpress/api-fetch": "^6.42.0",
56
56
  "@wordpress/i18n": "^5.13.0"
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ import { CheckIcon } from '@elementor/icons';
3
+ import { MenuItem, MenuList, Stack, Typography } from '@elementor/ui';
4
+
5
+ import { useSiteContentPanelSectionsFilter } from '../../contexts/site-content-panel-sections-filter';
6
+
7
+ const renderSectionMenuItemContent = ( label: string, selected: boolean ) => (
8
+ <Stack alignItems="center" direction="row" gap={ 1 } width="100%">
9
+ <Typography sx={ { color: 'text.secondary', flex: 1 } } variant="caption">
10
+ { label }
11
+ </Typography>
12
+ { selected ? <CheckIcon aria-hidden fontSize="tiny" /> : null }
13
+ </Stack>
14
+ );
15
+
16
+ export default function ContentPanelSectionsFilterList() {
17
+ const { descriptors, isSectionVisible, setSectionVisible } = useSiteContentPanelSectionsFilter();
18
+
19
+ return (
20
+ <MenuList dense>
21
+ { descriptors.map( ( descriptor ) => {
22
+ const selected = isSectionVisible( descriptor.id );
23
+
24
+ return (
25
+ <MenuItem
26
+ key={ descriptor.id }
27
+ dense
28
+ onClick={ () => setSectionVisible( descriptor.id, ! selected ) }
29
+ selected={ selected }
30
+ >
31
+ { renderSectionMenuItemContent( descriptor.label, selected ) }
32
+ </MenuItem>
33
+ );
34
+ } ) }
35
+ </MenuList>
36
+ );
37
+ }
@@ -0,0 +1,76 @@
1
+ import * as React from 'react';
2
+ import { PopoverBody, PopoverHeader } from '@elementor/editor-ui';
3
+ import { FilterIcon } from '@elementor/icons';
4
+ import { bindPopover, bindToggle, Divider, Popover, ToggleButton, Tooltip, usePopupState } from '@elementor/ui';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ import { useSiteContentPanelSectionsFilter } from '../../contexts/site-content-panel-sections-filter';
8
+ import { SITE_CONTENT_PANEL_SECTIONS_FILTER_POPOVER_WIDTH_PX } from '../../site-content-panel-sections';
9
+ import ContentPanelClearFiltersButton from './content-panel-clear-filters-button';
10
+ import ContentPanelSectionsFilterList from './content-panel-sections-filter-list';
11
+
12
+ export default function ContentPanelSectionsFilter() {
13
+ const { clearHiddenSections, hasHiddenSections, shouldShowSectionsFilter } = useSiteContentPanelSectionsFilter();
14
+ const popupState = usePopupState( {
15
+ variant: 'popover',
16
+ disableAutoFocus: true,
17
+ } );
18
+
19
+ if ( ! shouldShowSectionsFilter ) {
20
+ return null;
21
+ }
22
+
23
+ const filterLabel = __( 'Content types', 'elementor' );
24
+
25
+ return (
26
+ <>
27
+ <Tooltip placement="top" title={ filterLabel }>
28
+ <ToggleButton
29
+ aria-label={ filterLabel }
30
+ selected={ popupState.isOpen || hasHiddenSections }
31
+ size="tiny"
32
+ value="content-types"
33
+ { ...bindToggle( popupState ) }
34
+ >
35
+ <FilterIcon fontSize="tiny" />
36
+ </ToggleButton>
37
+ </Tooltip>
38
+ <Popover
39
+ anchorOrigin={ {
40
+ horizontal: 'right',
41
+ vertical: 'top',
42
+ } }
43
+ sx={ {
44
+ maxWidth: `${ SITE_CONTENT_PANEL_SECTIONS_FILTER_POPOVER_WIDTH_PX }px`,
45
+ } }
46
+ transformOrigin={ {
47
+ horizontal: -21,
48
+ vertical: 'top',
49
+ } }
50
+ { ...bindPopover( popupState ) }
51
+ >
52
+ <PopoverHeader
53
+ actions={
54
+ hasHiddenSections
55
+ ? [
56
+ <ContentPanelClearFiltersButton
57
+ ariaLabel={ __( 'Show all', 'elementor' ) }
58
+ key="show-all-content-types"
59
+ onClear={ clearHiddenSections }
60
+ tooltipText={ __( 'Show all', 'elementor' ) }
61
+ />,
62
+ ]
63
+ : []
64
+ }
65
+ icon={ <FilterIcon fontSize="tiny" /> }
66
+ onClose={ popupState.close }
67
+ title={ filterLabel }
68
+ />
69
+ <Divider sx={ { borderWidth: '1px 0 0 0' } } />
70
+ <PopoverBody height="auto" width={ SITE_CONTENT_PANEL_SECTIONS_FILTER_POPOVER_WIDTH_PX }>
71
+ <ContentPanelSectionsFilterList />
72
+ </PopoverBody>
73
+ </Popover>
74
+ </>
75
+ );
76
+ }
@@ -3,6 +3,7 @@ import { List, Skeleton, Stack } from '@elementor/ui';
3
3
 
4
4
  import { type Slug } from '../../api/post';
5
5
  import { PostListContextProvider } from '../../contexts/post-list-context';
6
+ import { useSiteContentPanelSectionsFilter } from '../../contexts/site-content-panel-sections-filter';
6
7
  import { getSiteContentSections } from '../../site-content-sections';
7
8
  import PostsCollapsibleList from './posts-list/posts-collapsible-list';
8
9
  import UserLoadError from './user-load-error';
@@ -33,16 +34,29 @@ export default function ShellPanelBodyContent( {
33
34
  return <UserLoadError />;
34
35
  }
35
36
 
37
+ return <ShellPanelBodySections accessiblePostTypes={ accessiblePostTypes } onListError={ onListError } />;
38
+ }
39
+
40
+ function ShellPanelBodySections( {
41
+ accessiblePostTypes,
42
+ onListError,
43
+ }: {
44
+ accessiblePostTypes: Slug[];
45
+ onListError: () => void;
46
+ } ) {
47
+ const { isSectionVisible } = useSiteContentPanelSectionsFilter();
36
48
  const extraSections = getSiteContentSections();
49
+ const visiblePostTypes = accessiblePostTypes.filter( ( postTypeSlug ) => isSectionVisible( postTypeSlug ) );
50
+ const visibleSections = extraSections.filter( ( section ) => isSectionVisible( section.id ) );
37
51
 
38
52
  return (
39
53
  <List dense disablePadding sx={ { py: 0, width: '100%' } }>
40
- { accessiblePostTypes.map( ( postTypeSlug, index ) => (
54
+ { visiblePostTypes.map( ( postTypeSlug, index ) => (
41
55
  <PostListContextProvider key={ postTypeSlug } type={ postTypeSlug } setError={ onListError }>
42
56
  <PostsCollapsibleList isOpenByDefault={ index === 0 } />
43
57
  </PostListContextProvider>
44
58
  ) ) }
45
- { extraSections.map( ( section ) => (
59
+ { visibleSections.map( ( section ) => (
46
60
  <React.Fragment key={ section.id }>{ section.render() }</React.Fragment>
47
61
  ) ) }
48
62
  </List>
@@ -6,9 +6,11 @@ import { Divider, Stack } from '@elementor/ui';
6
6
  import { __ } from '@wordpress/i18n';
7
7
 
8
8
  import { ContentPanelCoordinatorProvider } from '../../contexts/content-panel-coordinator';
9
+ import { SiteContentPanelSectionsFilterProvider } from '../../contexts/site-content-panel-sections-filter';
9
10
  import useAccessiblePanelPostTypes from '../../hooks/use-accessible-panel-post-types';
10
11
  import { contentPanelHeaderStackSx } from './content-panel-chrome';
11
12
  import ContentPanelHeaderAdd from './content-panel-header-add';
13
+ import ContentPanelSectionsFilter from './content-panel-sections-filter';
12
14
  import ErrorSnackbar from './error-snackbar';
13
15
  import ShellPanelBodyContent from './shell-panel-body-content';
14
16
 
@@ -19,34 +21,37 @@ const Shell = () => {
19
21
 
20
22
  return (
21
23
  <ContentPanelCoordinatorProvider>
22
- <Panel>
23
- <PanelHeader>
24
- <Stack
25
- alignItems="center"
26
- direction="row"
27
- spacing={ 0.5 }
28
- sx={ {
29
- ...contentPanelHeaderStackSx,
30
- ...( sidebarPanelChrome ? {} : { p: 1, pl: 2 } ),
31
- } }
32
- >
33
- <PanelHeaderTitle sx={ { flex: 1, minWidth: 0, textAlign: 'start' } }>
34
- { __( 'Site content', 'elementor' ) }
35
- </PanelHeaderTitle>
36
- <ContentPanelHeaderAdd />
37
- </Stack>
38
- </PanelHeader>
39
- <Divider />
40
- <PanelBody>
41
- <ShellPanelBodyContent
42
- accessiblePostTypes={ accessiblePostTypes }
43
- isUserPending={ isUserPending }
44
- onListError={ () => setIsErrorSnackbarOpen( true ) }
45
- showUserLoadError={ showUserLoadError }
46
- />
47
- <ErrorSnackbar open={ isErrorSnackbarOpen } onClose={ () => setIsErrorSnackbarOpen( false ) } />
48
- </PanelBody>
49
- </Panel>
24
+ <SiteContentPanelSectionsFilterProvider>
25
+ <Panel>
26
+ <PanelHeader>
27
+ <Stack
28
+ alignItems="center"
29
+ direction="row"
30
+ spacing={ 0.5 }
31
+ sx={ {
32
+ ...contentPanelHeaderStackSx,
33
+ ...( sidebarPanelChrome ? {} : { p: 1, pl: 2 } ),
34
+ } }
35
+ >
36
+ <PanelHeaderTitle sx={ { flex: 1, minWidth: 0, textAlign: 'start' } }>
37
+ { __( 'Site content', 'elementor' ) }
38
+ </PanelHeaderTitle>
39
+ <ContentPanelSectionsFilter />
40
+ <ContentPanelHeaderAdd />
41
+ </Stack>
42
+ </PanelHeader>
43
+ <Divider />
44
+ <PanelBody>
45
+ <ShellPanelBodyContent
46
+ accessiblePostTypes={ accessiblePostTypes }
47
+ isUserPending={ isUserPending }
48
+ onListError={ () => setIsErrorSnackbarOpen( true ) }
49
+ showUserLoadError={ showUserLoadError }
50
+ />
51
+ <ErrorSnackbar open={ isErrorSnackbarOpen } onClose={ () => setIsErrorSnackbarOpen( false ) } />
52
+ </PanelBody>
53
+ </Panel>
54
+ </SiteContentPanelSectionsFilterProvider>
50
55
  </ContentPanelCoordinatorProvider>
51
56
  );
52
57
  };
@@ -0,0 +1,111 @@
1
+ import * as React from 'react';
2
+ import { createContext, type ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react';
3
+
4
+ import useAccessiblePanelPostTypes from '../hooks/use-accessible-panel-post-types';
5
+ import {
6
+ getSiteContentPanelSectionDescriptors,
7
+ hasHiddenSiteContentPanelSections,
8
+ type SiteContentPanelSectionDescriptor,
9
+ } from '../site-content-panel-sections';
10
+
11
+ type SiteContentPanelSectionsFilterContextValue = {
12
+ clearHiddenSections: () => void;
13
+ descriptors: SiteContentPanelSectionDescriptor[];
14
+ hasHiddenSections: boolean;
15
+ hiddenSectionIds: ReadonlySet< string >;
16
+ isSectionVisible: ( sectionId: string ) => boolean;
17
+ setSectionVisible: ( sectionId: string, visible: boolean ) => void;
18
+ shouldShowSectionsFilter: boolean;
19
+ };
20
+
21
+ const SiteContentPanelSectionsFilterContext = createContext< SiteContentPanelSectionsFilterContextValue | null >(
22
+ null
23
+ );
24
+
25
+ export function SiteContentPanelSectionsFilterProvider( { children }: { children: ReactNode } ) {
26
+ const { accessiblePostTypes } = useAccessiblePanelPostTypes();
27
+ const descriptors = useMemo(
28
+ () => getSiteContentPanelSectionDescriptors( accessiblePostTypes ),
29
+ [ accessiblePostTypes ]
30
+ );
31
+ const [ hiddenSectionIds, setHiddenSectionIds ] = useState< ReadonlySet< string > >( () => new Set() );
32
+
33
+ useEffect( () => {
34
+ const validIds = new Set( descriptors.map( ( descriptor ) => descriptor.id ) );
35
+
36
+ setHiddenSectionIds( ( current ) => {
37
+ const nextHidden = new Set( [ ...current ].filter( ( id ) => validIds.has( id ) ) );
38
+
39
+ return nextHidden.size === current.size ? current : nextHidden;
40
+ } );
41
+ }, [ descriptors ] );
42
+
43
+ const setSectionVisible = useCallback(
44
+ ( sectionId: string, visible: boolean ) => {
45
+ setHiddenSectionIds( ( current ) => {
46
+ if ( visible ) {
47
+ if ( ! current.has( sectionId ) ) {
48
+ return current;
49
+ }
50
+
51
+ const next = new Set( current );
52
+ next.delete( sectionId );
53
+
54
+ return next;
55
+ }
56
+
57
+ const visibleSectionCount = descriptors.length - current.size;
58
+
59
+ if ( current.has( sectionId ) || visibleSectionCount <= 1 ) {
60
+ return current;
61
+ }
62
+
63
+ const next = new Set( current );
64
+ next.add( sectionId );
65
+
66
+ return next;
67
+ } );
68
+ },
69
+ [ descriptors.length ]
70
+ );
71
+
72
+ const isSectionVisible = useCallback(
73
+ ( sectionId: string ) => ! hiddenSectionIds.has( sectionId ),
74
+ [ hiddenSectionIds ]
75
+ );
76
+
77
+ const clearHiddenSections = useCallback( () => {
78
+ setHiddenSectionIds( () => new Set() );
79
+ }, [] );
80
+
81
+ const value = useMemo(
82
+ () => ( {
83
+ clearHiddenSections,
84
+ descriptors,
85
+ hasHiddenSections: hasHiddenSiteContentPanelSections( hiddenSectionIds ),
86
+ hiddenSectionIds,
87
+ isSectionVisible,
88
+ setSectionVisible,
89
+ shouldShowSectionsFilter: descriptors.length > 1,
90
+ } ),
91
+ [ clearHiddenSections, descriptors, hiddenSectionIds, isSectionVisible, setSectionVisible ]
92
+ );
93
+
94
+ return (
95
+ <SiteContentPanelSectionsFilterContext.Provider value={ value }>
96
+ { children }
97
+ </SiteContentPanelSectionsFilterContext.Provider>
98
+ );
99
+ }
100
+
101
+ export function useSiteContentPanelSectionsFilter() {
102
+ const context = useContext( SiteContentPanelSectionsFilterContext );
103
+
104
+ if ( ! context ) {
105
+ throw new Error(
106
+ 'useSiteContentPanelSectionsFilter() must be used within a SiteContentPanelSectionsFilterProvider'
107
+ );
108
+ }
109
+
110
+ return context;
111
+ }
@@ -0,0 +1,29 @@
1
+ import { postTypesMap, type Slug } from './api/post';
2
+ import { getSiteContentSections } from './site-content-sections';
3
+
4
+ export type SiteContentPanelSectionDescriptor = {
5
+ id: string;
6
+ label: string;
7
+ };
8
+
9
+ export const SITE_CONTENT_PANEL_SECTIONS_FILTER_POPOVER_WIDTH_PX = 280;
10
+
11
+ export function getSiteContentPanelSectionDescriptors(
12
+ accessiblePostTypes: Slug[]
13
+ ): SiteContentPanelSectionDescriptor[] {
14
+ const postTypeSections = accessiblePostTypes.map( ( slug ) => ( {
15
+ id: slug,
16
+ label: postTypesMap[ slug ].labels.plural_name,
17
+ } ) );
18
+
19
+ const registeredSections = getSiteContentSections().map( ( section ) => ( {
20
+ id: section.id,
21
+ label: section.label ?? section.id,
22
+ } ) );
23
+
24
+ return [ ...postTypeSections, ...registeredSections ];
25
+ }
26
+
27
+ export function hasHiddenSiteContentPanelSections( hiddenSectionIds: ReadonlySet< string > ): boolean {
28
+ return hiddenSectionIds.size > 0;
29
+ }
@@ -2,6 +2,7 @@ import type { ReactNode } from 'react';
2
2
 
3
3
  export type SiteContentSection = {
4
4
  id: string;
5
+ label?: string;
5
6
  priority?: number;
6
7
  render: () => ReactNode;
7
8
  };