@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.
- package/dist/index.d.mts +83 -15
- package/dist/index.d.ts +83 -15
- package/dist/index.js +975 -822
- package/dist/index.mjs +938 -800
- package/package.json +12 -12
- package/src/components/panel/content-panel-active-filters.tsx +2 -2
- package/src/components/panel/content-panel-chrome.ts +47 -21
- package/src/components/panel/content-panel-search.tsx +9 -4
- package/src/components/panel/{content-panel-toolbar.tsx → content-panel-section-toolbar.tsx} +9 -2
- package/src/components/panel/content-panel-sort-list.tsx +2 -2
- package/src/components/panel/content-panel-sort.tsx +2 -2
- package/src/components/panel/content-panel-status-filter-list.tsx +25 -10
- package/src/components/panel/content-panel-status-filter.tsx +2 -2
- package/src/components/panel/posts-list/collapsible-list.tsx +3 -0
- package/src/components/panel/posts-list/list-items/edit-mode-template.tsx +6 -0
- package/src/components/panel/posts-list/list-items/list-item-create.tsx +1 -0
- package/src/components/panel/posts-list/list-items/list-item-duplicate.tsx +1 -0
- package/src/components/panel/posts-list/list-items/list-item-view.tsx +15 -3
- package/src/components/panel/posts-list/posts-collapsible-list.tsx +42 -18
- package/src/components/panel/shell.tsx +0 -3
- package/src/components/shared/page-title-and-status.tsx +4 -3
- package/src/contexts/content-panel-coordinator.tsx +2 -65
- package/src/contexts/site-content-section-toolbar.tsx +61 -0
- package/src/hooks/use-homepage-actions.ts +12 -1
- package/src/hooks/use-site-content-section-list-controls.ts +64 -0
- package/src/index.ts +28 -1
- package/src/site-content-status-filter.ts +11 -0
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createContext, type ReactNode, useCallback, useContext, useMemo, useRef
|
|
2
|
+
import { createContext, type ReactNode, useCallback, useContext, useMemo, useRef } from 'react';
|
|
3
3
|
|
|
4
4
|
import { type Slug } from '../api/post';
|
|
5
|
-
import { DEFAULT_SITE_CONTENT_SORT, type SiteContentSortOption } from '../site-content-sort';
|
|
6
|
-
import {
|
|
7
|
-
EMPTY_SITE_CONTENT_STATUS_FILTERS,
|
|
8
|
-
type SiteContentSelectableStatus,
|
|
9
|
-
type SiteContentStatusFilters,
|
|
10
|
-
toggleSiteContentStatusFilter,
|
|
11
|
-
} from '../site-content-status-filter';
|
|
12
5
|
|
|
13
6
|
export type ContentPanelSectionId = Slug | ( string & {} );
|
|
14
7
|
|
|
@@ -18,17 +11,8 @@ type SectionHandlers = {
|
|
|
18
11
|
};
|
|
19
12
|
|
|
20
13
|
type ContentPanelCoordinatorValue = {
|
|
21
|
-
clearActiveToolbarFilters: () => void;
|
|
22
|
-
clearSiteContentSort: () => void;
|
|
23
|
-
clearStatusFilters: () => void;
|
|
24
14
|
registerSection: ( type: ContentPanelSectionId, handlers: SectionHandlers ) => void;
|
|
25
15
|
requestCreate: ( type: ContentPanelSectionId ) => void;
|
|
26
|
-
searchQuery: string;
|
|
27
|
-
setSearchQuery: ( query: string ) => void;
|
|
28
|
-
setSiteContentSort: ( sort: SiteContentSortOption ) => void;
|
|
29
|
-
siteContentSort: SiteContentSortOption;
|
|
30
|
-
statusFilters: SiteContentStatusFilters;
|
|
31
|
-
toggleStatusFilter: ( filter: SiteContentSelectableStatus ) => void;
|
|
32
16
|
unregisterSection: ( type: ContentPanelSectionId ) => void;
|
|
33
17
|
};
|
|
34
18
|
|
|
@@ -36,11 +20,6 @@ const ContentPanelCoordinatorContext = createContext< ContentPanelCoordinatorVal
|
|
|
36
20
|
|
|
37
21
|
export function ContentPanelCoordinatorProvider( { children }: { children: ReactNode } ) {
|
|
38
22
|
const sectionsRef = useRef( new Map< ContentPanelSectionId, SectionHandlers >() );
|
|
39
|
-
const [ searchQuery, setSearchQuery ] = useState( '' );
|
|
40
|
-
const [ siteContentSort, setSiteContentSortState ] = useState< SiteContentSortOption >( DEFAULT_SITE_CONTENT_SORT );
|
|
41
|
-
const [ statusFilters, setStatusFilters ] = useState< SiteContentStatusFilters >(
|
|
42
|
-
EMPTY_SITE_CONTENT_STATUS_FILTERS
|
|
43
|
-
);
|
|
44
23
|
|
|
45
24
|
const registerSection = useCallback( ( type: ContentPanelSectionId, handlers: SectionHandlers ) => {
|
|
46
25
|
sectionsRef.current.set( type, handlers );
|
|
@@ -61,55 +40,13 @@ export function ContentPanelCoordinatorProvider( { children }: { children: React
|
|
|
61
40
|
handlers.startCreate();
|
|
62
41
|
}, [] );
|
|
63
42
|
|
|
64
|
-
const clearActiveToolbarFilters = useCallback( () => {
|
|
65
|
-
setSiteContentSortState( DEFAULT_SITE_CONTENT_SORT );
|
|
66
|
-
setStatusFilters( EMPTY_SITE_CONTENT_STATUS_FILTERS );
|
|
67
|
-
}, [] );
|
|
68
|
-
|
|
69
|
-
const clearSiteContentSort = useCallback( () => {
|
|
70
|
-
setSiteContentSortState( DEFAULT_SITE_CONTENT_SORT );
|
|
71
|
-
}, [] );
|
|
72
|
-
|
|
73
|
-
const clearStatusFilters = useCallback( () => {
|
|
74
|
-
setStatusFilters( EMPTY_SITE_CONTENT_STATUS_FILTERS );
|
|
75
|
-
}, [] );
|
|
76
|
-
|
|
77
|
-
const setSiteContentSort = useCallback( ( sort: SiteContentSortOption ) => {
|
|
78
|
-
setSiteContentSortState( sort );
|
|
79
|
-
}, [] );
|
|
80
|
-
|
|
81
|
-
const toggleStatusFilter = useCallback( ( filter: SiteContentSelectableStatus ) => {
|
|
82
|
-
setStatusFilters( ( current ) => toggleSiteContentStatusFilter( current, filter ) );
|
|
83
|
-
}, [] );
|
|
84
|
-
|
|
85
43
|
const value = useMemo(
|
|
86
44
|
() => ( {
|
|
87
|
-
clearActiveToolbarFilters,
|
|
88
|
-
clearSiteContentSort,
|
|
89
|
-
clearStatusFilters,
|
|
90
45
|
registerSection,
|
|
91
46
|
requestCreate,
|
|
92
|
-
searchQuery,
|
|
93
|
-
setSearchQuery,
|
|
94
|
-
setSiteContentSort,
|
|
95
|
-
siteContentSort,
|
|
96
|
-
statusFilters,
|
|
97
|
-
toggleStatusFilter,
|
|
98
47
|
unregisterSection,
|
|
99
48
|
} ),
|
|
100
|
-
[
|
|
101
|
-
clearActiveToolbarFilters,
|
|
102
|
-
clearSiteContentSort,
|
|
103
|
-
clearStatusFilters,
|
|
104
|
-
registerSection,
|
|
105
|
-
requestCreate,
|
|
106
|
-
searchQuery,
|
|
107
|
-
siteContentSort,
|
|
108
|
-
setSiteContentSort,
|
|
109
|
-
statusFilters,
|
|
110
|
-
toggleStatusFilter,
|
|
111
|
-
unregisterSection,
|
|
112
|
-
]
|
|
49
|
+
[ registerSection, requestCreate, unregisterSection ]
|
|
113
50
|
);
|
|
114
51
|
|
|
115
52
|
return (
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createContext, type ReactNode, useContext, useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
import { type Slug } from '../api/post';
|
|
5
|
+
import {
|
|
6
|
+
type SiteContentSectionListControls,
|
|
7
|
+
useSiteContentSectionListControls,
|
|
8
|
+
} from '../hooks/use-site-content-section-list-controls';
|
|
9
|
+
import { type SiteContentSelectableStatus } from '../site-content-status-filter';
|
|
10
|
+
|
|
11
|
+
type SiteContentSectionToolbarContextValue = SiteContentSectionListControls & {
|
|
12
|
+
statusFilterCountSlugs: Slug[];
|
|
13
|
+
statusFilterCounts?: Partial< Record< SiteContentSelectableStatus, number > >;
|
|
14
|
+
statusFilterCountsPending?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const SiteContentSectionToolbarContext = createContext< SiteContentSectionToolbarContextValue | null >( null );
|
|
18
|
+
|
|
19
|
+
type ProviderProps = {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
statusFilterCountSlugs?: Slug[];
|
|
22
|
+
statusFilterCounts?: Partial< Record< SiteContentSelectableStatus, number > >;
|
|
23
|
+
statusFilterCountsPending?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function SiteContentSectionToolbarProvider( {
|
|
27
|
+
children,
|
|
28
|
+
statusFilterCountSlugs = [],
|
|
29
|
+
statusFilterCounts,
|
|
30
|
+
statusFilterCountsPending = false,
|
|
31
|
+
}: ProviderProps ) {
|
|
32
|
+
const controls = useSiteContentSectionListControls();
|
|
33
|
+
|
|
34
|
+
const value = useMemo(
|
|
35
|
+
() => ( {
|
|
36
|
+
...controls,
|
|
37
|
+
statusFilterCountSlugs,
|
|
38
|
+
statusFilterCounts,
|
|
39
|
+
statusFilterCountsPending,
|
|
40
|
+
} ),
|
|
41
|
+
[ controls, statusFilterCountSlugs, statusFilterCounts, statusFilterCountsPending ]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<SiteContentSectionToolbarContext.Provider value={ value }>
|
|
46
|
+
{ children }
|
|
47
|
+
</SiteContentSectionToolbarContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function useSiteContentSectionToolbar() {
|
|
52
|
+
const context = useContext( SiteContentSectionToolbarContext );
|
|
53
|
+
|
|
54
|
+
if ( ! context ) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'The `useSiteContentSectionToolbar()` hook must be used within a `<SiteContentSectionToolbarProvider />`'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return context;
|
|
61
|
+
}
|
|
@@ -4,9 +4,20 @@ import { type UpdateReadingSettings, updateSettings } from '../api/settings';
|
|
|
4
4
|
import { settingsQueryKey } from './use-homepage';
|
|
5
5
|
|
|
6
6
|
export function useHomepageActions() {
|
|
7
|
+
const queryClient = useQueryClient();
|
|
7
8
|
const invalidateSettings = useInvalidateSettings();
|
|
8
9
|
|
|
9
|
-
const onSuccess = async (
|
|
10
|
+
const onSuccess = async ( _data: unknown, settings: UpdateReadingSettings ) => {
|
|
11
|
+
const homepageQueryKey = settingsQueryKey();
|
|
12
|
+
|
|
13
|
+
if ( 'page' === settings.show_on_front ) {
|
|
14
|
+
queryClient.setQueryData( homepageQueryKey, settings.page_on_front );
|
|
15
|
+
} else {
|
|
16
|
+
queryClient.setQueryData( homepageQueryKey, 0 );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await invalidateSettings( { exact: true } );
|
|
20
|
+
};
|
|
10
21
|
|
|
11
22
|
const updateSettingsMutation = useMutation( {
|
|
12
23
|
mutationFn: ( settings: UpdateReadingSettings ) => updateSettings( settings ),
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { DEFAULT_SITE_CONTENT_SORT, type SiteContentSortOption } from '../site-content-sort';
|
|
4
|
+
import {
|
|
5
|
+
EMPTY_SITE_CONTENT_STATUS_FILTERS,
|
|
6
|
+
type SiteContentSelectableStatus,
|
|
7
|
+
type SiteContentStatusFilters,
|
|
8
|
+
toggleSiteContentStatusFilter,
|
|
9
|
+
} from '../site-content-status-filter';
|
|
10
|
+
|
|
11
|
+
const SEARCH_DEBOUNCE_MS = 300;
|
|
12
|
+
|
|
13
|
+
export function useSiteContentSectionListControls() {
|
|
14
|
+
const [ searchQuery, setSearchQuery ] = useState( '' );
|
|
15
|
+
const [ debouncedSearch, setDebouncedSearch ] = useState( '' );
|
|
16
|
+
const [ siteContentSort, setSiteContentSortState ] = useState< SiteContentSortOption >( DEFAULT_SITE_CONTENT_SORT );
|
|
17
|
+
const [ statusFilters, setStatusFilters ] = useState< SiteContentStatusFilters >(
|
|
18
|
+
EMPTY_SITE_CONTENT_STATUS_FILTERS
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const trimmedSearch = searchQuery.trim();
|
|
22
|
+
|
|
23
|
+
useEffect( () => {
|
|
24
|
+
const handle = window.setTimeout( () => setDebouncedSearch( trimmedSearch ), SEARCH_DEBOUNCE_MS );
|
|
25
|
+
|
|
26
|
+
return () => window.clearTimeout( handle );
|
|
27
|
+
}, [ trimmedSearch ] );
|
|
28
|
+
|
|
29
|
+
const clearActiveToolbarFilters = useCallback( () => {
|
|
30
|
+
setSiteContentSortState( DEFAULT_SITE_CONTENT_SORT );
|
|
31
|
+
setStatusFilters( EMPTY_SITE_CONTENT_STATUS_FILTERS );
|
|
32
|
+
}, [] );
|
|
33
|
+
|
|
34
|
+
const clearSiteContentSort = useCallback( () => {
|
|
35
|
+
setSiteContentSortState( DEFAULT_SITE_CONTENT_SORT );
|
|
36
|
+
}, [] );
|
|
37
|
+
|
|
38
|
+
const clearStatusFilters = useCallback( () => {
|
|
39
|
+
setStatusFilters( EMPTY_SITE_CONTENT_STATUS_FILTERS );
|
|
40
|
+
}, [] );
|
|
41
|
+
|
|
42
|
+
const setSiteContentSort = useCallback( ( sort: SiteContentSortOption ) => {
|
|
43
|
+
setSiteContentSortState( sort );
|
|
44
|
+
}, [] );
|
|
45
|
+
|
|
46
|
+
const toggleStatusFilter = useCallback( ( filter: SiteContentSelectableStatus ) => {
|
|
47
|
+
setStatusFilters( ( current ) => toggleSiteContentStatusFilter( current, filter ) );
|
|
48
|
+
}, [] );
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
clearActiveToolbarFilters,
|
|
52
|
+
clearSiteContentSort,
|
|
53
|
+
clearStatusFilters,
|
|
54
|
+
debouncedSearch,
|
|
55
|
+
searchQuery,
|
|
56
|
+
setSearchQuery,
|
|
57
|
+
setSiteContentSort,
|
|
58
|
+
siteContentSort,
|
|
59
|
+
statusFilters,
|
|
60
|
+
toggleStatusFilter,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type SiteContentSectionListControls = ReturnType< typeof useSiteContentSectionListControls >;
|
package/src/index.ts
CHANGED
|
@@ -18,13 +18,40 @@ export {
|
|
|
18
18
|
useContentPanelCoordinator,
|
|
19
19
|
type ContentPanelSectionId,
|
|
20
20
|
} from './contexts/content-panel-coordinator';
|
|
21
|
+
export {
|
|
22
|
+
SiteContentSectionToolbarProvider,
|
|
23
|
+
useSiteContentSectionToolbar,
|
|
24
|
+
} from './contexts/site-content-section-toolbar';
|
|
25
|
+
export { default as SiteContentSectionToolbar } from './components/panel/content-panel-section-toolbar';
|
|
26
|
+
export {
|
|
27
|
+
DEFAULT_SITE_CONTENT_SORT,
|
|
28
|
+
getRestOrderForSiteContentSort,
|
|
29
|
+
type SiteContentSortOption,
|
|
30
|
+
} from './site-content-sort';
|
|
31
|
+
export {
|
|
32
|
+
EMPTY_SITE_CONTENT_STATUS_FILTERS,
|
|
33
|
+
getRestStatusForSiteContentFilters,
|
|
34
|
+
getSiteContentStatusFilterForCount,
|
|
35
|
+
hasActiveSiteContentStatusFilters,
|
|
36
|
+
isSiteContentListNarrowed,
|
|
37
|
+
isSiteContentTrashFilterActive,
|
|
38
|
+
serializeSiteContentStatusFilters,
|
|
39
|
+
SITE_CONTENT_SELECTABLE_STATUS_FILTERS,
|
|
40
|
+
type SiteContentSelectableStatus,
|
|
41
|
+
type SiteContentStatusFilters,
|
|
42
|
+
} from './site-content-status-filter';
|
|
21
43
|
export { default as SiteContentCollapsibleList } from './components/panel/posts-list/collapsible-list';
|
|
22
44
|
export { default as SiteContentListErrorState } from './components/panel/posts-list/error-state';
|
|
23
45
|
export { default as SiteContentPaginationActions } from './components/panel/posts-list/post-list-pagination-actions';
|
|
24
46
|
export { usePostListPagination } from './hooks/use-post-list-pagination';
|
|
25
47
|
export { POST_PER_PAGE } from './api/post';
|
|
26
48
|
export { type Post } from './types';
|
|
27
|
-
export {
|
|
49
|
+
export {
|
|
50
|
+
contentPanelListItemButtonSx,
|
|
51
|
+
contentPanelListRowPaddingSx,
|
|
52
|
+
getContentPanelListItemRowStateSx,
|
|
53
|
+
getContentPanelListItemSx,
|
|
54
|
+
} from './components/panel/content-panel-chrome';
|
|
28
55
|
export { default as ContentPanelAddIconButton } from './components/panel/content-panel-add-icon-button';
|
|
29
56
|
export { default as SiteContentPageTitleAndStatus } from './components/shared/page-title-and-status';
|
|
30
57
|
export { default as SiteContentEditModeTemplate } from './components/panel/posts-list/list-items/edit-mode-template';
|
|
@@ -94,6 +94,17 @@ export function toggleSiteContentStatusFilter(
|
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
export function getSiteContentStatusFilterForCount( status: SiteContentSelectableStatus ): SiteContentStatusFilters {
|
|
98
|
+
if ( 'trash' === status ) {
|
|
99
|
+
return { ...EMPTY_SITE_CONTENT_STATUS_FILTERS, trash: true };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
...EMPTY_SITE_CONTENT_STATUS_FILTERS,
|
|
104
|
+
[ status ]: true,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
97
108
|
export function shouldShowSiteContentStatusFilterRow(
|
|
98
109
|
count: number | undefined,
|
|
99
110
|
isLoadingCounts: boolean,
|