@elementor/editor-app-bar 4.3.0-986 → 4.3.0-988
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/README.md +62 -3
- package/dist/index.js +174 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +171 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/app-bar.tsx +41 -19
- package/src/components/locations/tools-menu-location.tsx +4 -4
- package/src/components/locations/utilities-menu-location.tsx +6 -6
- package/src/constants.ts +14 -0
- package/src/contexts/app-bar-size-context.tsx +14 -0
- package/src/hooks/use-container-width.ts +29 -0
- package/src/utils/get-max-toolbar-actions.ts +25 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-app-bar",
|
|
3
3
|
"description": "App Bar extension for @elementor/editor",
|
|
4
|
-
"version": "4.3.0-
|
|
4
|
+
"version": "4.3.0-988",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elementor/editor-current-user": "4.3.0-
|
|
44
|
-
"@elementor/editor-ui": "4.3.0-
|
|
45
|
-
"@elementor/http-client": "4.3.0-
|
|
46
|
-
"@elementor/editor": "4.3.0-
|
|
47
|
-
"@elementor/editor-documents": "4.3.0-
|
|
48
|
-
"@elementor/editor-mcp": "4.3.0-
|
|
49
|
-
"@elementor/editor-responsive": "4.3.0-
|
|
50
|
-
"@elementor/editor-v1-adapters": "4.3.0-
|
|
43
|
+
"@elementor/editor-current-user": "4.3.0-988",
|
|
44
|
+
"@elementor/editor-ui": "4.3.0-988",
|
|
45
|
+
"@elementor/http-client": "4.3.0-988",
|
|
46
|
+
"@elementor/editor": "4.3.0-988",
|
|
47
|
+
"@elementor/editor-documents": "4.3.0-988",
|
|
48
|
+
"@elementor/editor-mcp": "4.3.0-988",
|
|
49
|
+
"@elementor/editor-responsive": "4.3.0-988",
|
|
50
|
+
"@elementor/editor-v1-adapters": "4.3.0-988",
|
|
51
51
|
"@elementor/icons": "~1.75.1",
|
|
52
|
-
"@elementor/locations": "4.3.0-
|
|
53
|
-
"@elementor/menus": "4.3.0-
|
|
54
|
-
"@elementor/events": "4.3.0-
|
|
52
|
+
"@elementor/locations": "4.3.0-988",
|
|
53
|
+
"@elementor/menus": "4.3.0-988",
|
|
54
|
+
"@elementor/events": "4.3.0-988",
|
|
55
55
|
"@elementor/ui": "1.37.5",
|
|
56
56
|
"@wordpress/i18n": "^5.13.0"
|
|
57
57
|
},
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { useRef } from 'react';
|
|
2
3
|
import { __useActiveDocument as useActiveDocument } from '@elementor/editor-documents';
|
|
3
4
|
import { AppBar as BaseAppBar, Box, Divider, Grid, ThemeProvider, Toolbar } from '@elementor/ui';
|
|
4
5
|
|
|
6
|
+
import { MIN_APP_BAR_WIDTH } from '../constants';
|
|
7
|
+
import { AppBarSizeProvider } from '../contexts/app-bar-size-context';
|
|
8
|
+
import { useContainerWidth } from '../hooks/use-container-width';
|
|
9
|
+
import { getMaxToolbarActions } from '../utils/get-max-toolbar-actions';
|
|
5
10
|
import MainMenuLocation from './locations/main-menu-location';
|
|
6
11
|
import PageIndicationLocation from './locations/page-indication-location';
|
|
7
12
|
import PrimaryActionLocation from './locations/primary-action-location';
|
|
@@ -12,28 +17,45 @@ import ToolbarMenu from './ui/toolbar-menu';
|
|
|
12
17
|
|
|
13
18
|
export default function AppBar() {
|
|
14
19
|
const document = useActiveDocument();
|
|
20
|
+
const containerRef = useRef< HTMLDivElement >( null );
|
|
21
|
+
const containerWidth = useContainerWidth( containerRef );
|
|
22
|
+
const maxToolbarActions = getMaxToolbarActions( containerWidth );
|
|
23
|
+
|
|
15
24
|
return (
|
|
16
25
|
<ThemeProvider colorScheme="dark">
|
|
17
26
|
<BaseAppBar position="sticky">
|
|
18
|
-
<Toolbar disableGutters variant="dense">
|
|
19
|
-
<Box
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
<Toolbar disableGutters variant="dense" sx={ { overflowX: 'auto' } }>
|
|
28
|
+
<Box
|
|
29
|
+
ref={ containerRef }
|
|
30
|
+
display="grid"
|
|
31
|
+
gridTemplateColumns="minmax(0, 1fr) auto minmax(0, 1fr)"
|
|
32
|
+
flexGrow={ 1 }
|
|
33
|
+
minWidth={ `${ MIN_APP_BAR_WIDTH }px` }
|
|
34
|
+
>
|
|
35
|
+
<AppBarSizeProvider value={ maxToolbarActions }>
|
|
36
|
+
<Grid container flexWrap="nowrap" sx={ { minWidth: 0, overflow: 'hidden' } }>
|
|
37
|
+
<MainMenuLocation />
|
|
38
|
+
{ document?.permissions?.allowAddingWidgets && <ToolsMenuLocation /> }
|
|
39
|
+
</Grid>
|
|
40
|
+
<Grid container justifyContent="center">
|
|
41
|
+
<ToolbarMenu spacing={ 1.5 }>
|
|
42
|
+
<Divider orientation="vertical" />
|
|
43
|
+
<PageIndicationLocation />
|
|
44
|
+
<Divider orientation="vertical" />
|
|
45
|
+
<ResponsiveLocation />
|
|
46
|
+
<Divider orientation="vertical" />
|
|
47
|
+
</ToolbarMenu>
|
|
48
|
+
</Grid>
|
|
49
|
+
<Grid
|
|
50
|
+
container
|
|
51
|
+
justifyContent="flex-end"
|
|
52
|
+
flexWrap="nowrap"
|
|
53
|
+
sx={ { minWidth: 0, overflow: 'hidden' } }
|
|
54
|
+
>
|
|
55
|
+
<UtilitiesMenuLocation />
|
|
56
|
+
<PrimaryActionLocation />
|
|
57
|
+
</Grid>
|
|
58
|
+
</AppBarSizeProvider>
|
|
37
59
|
</Box>
|
|
38
60
|
</Toolbar>
|
|
39
61
|
</BaseAppBar>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
+
import { useMaxToolbarActions } from '../../contexts/app-bar-size-context';
|
|
3
4
|
import { AngieGuideLocation } from '../../extensions/angie/components/angie-guide-location';
|
|
4
5
|
import { toolsMenu } from '../../locations';
|
|
5
6
|
import ToolbarMenu from '../ui/toolbar-menu';
|
|
@@ -7,15 +8,14 @@ import ToolbarMenuMore from '../ui/toolbar-menu-more';
|
|
|
7
8
|
import IntegrationsMenuLocation from './integrations-menu-location';
|
|
8
9
|
import SendFeedbackPopupLocation from './send-feedback-popup-location';
|
|
9
10
|
|
|
10
|
-
const MAX_TOOLBAR_ACTIONS = 5;
|
|
11
|
-
|
|
12
11
|
const { useMenuItems } = toolsMenu;
|
|
13
12
|
|
|
14
13
|
export default function ToolsMenuLocation() {
|
|
15
14
|
const menuItems = useMenuItems();
|
|
15
|
+
const { tools: maxToolbarActions } = useMaxToolbarActions();
|
|
16
16
|
|
|
17
|
-
const toolbarMenuItems = menuItems.default.slice( 0,
|
|
18
|
-
const popoverMenuItems = menuItems.default.slice(
|
|
17
|
+
const toolbarMenuItems = menuItems.default.slice( 0, maxToolbarActions );
|
|
18
|
+
const popoverMenuItems = menuItems.default.slice( maxToolbarActions );
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<ToolbarMenu>
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
3
|
|
|
4
|
+
import { useMaxToolbarActions } from '../../contexts/app-bar-size-context';
|
|
4
5
|
import { utilitiesMenu } from '../../locations';
|
|
5
6
|
import ToolbarMenu from '../ui/toolbar-menu';
|
|
6
7
|
import ToolbarMenuMore from '../ui/toolbar-menu-more';
|
|
7
8
|
|
|
8
|
-
const MAX_TOOLBAR_ACTIONS = 4;
|
|
9
|
-
|
|
10
9
|
const { useMenuItems } = utilitiesMenu;
|
|
11
10
|
|
|
12
11
|
export default function UtilitiesMenuLocation() {
|
|
13
12
|
const menuItems = useMenuItems();
|
|
13
|
+
const { utilities: maxToolbarActions } = useMaxToolbarActions();
|
|
14
14
|
|
|
15
|
-
// If there are more than
|
|
15
|
+
// If there are more items than the allowed max, show the max inline and the rest in the popover.
|
|
16
16
|
// Otherwise, display all items inline.
|
|
17
|
-
const shouldUsePopover = menuItems.default.length >
|
|
17
|
+
const shouldUsePopover = menuItems.default.length > maxToolbarActions + 1;
|
|
18
18
|
|
|
19
|
-
const toolbarMenuItems = shouldUsePopover ? menuItems.default.slice( 0,
|
|
20
|
-
const popoverMenuItems = shouldUsePopover ? menuItems.default.slice(
|
|
19
|
+
const toolbarMenuItems = shouldUsePopover ? menuItems.default.slice( 0, maxToolbarActions ) : menuItems.default;
|
|
20
|
+
const popoverMenuItems = shouldUsePopover ? menuItems.default.slice( maxToolbarActions ) : [];
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
23
|
<ToolbarMenu>
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Below this width the app bar stops shrinking and scrolls horizontally instead, since the
|
|
2
|
+
// center section (document title, breakpoints switcher) can't shrink further without becoming
|
|
3
|
+
// unusable.
|
|
4
|
+
export const MIN_APP_BAR_WIDTH = 800;
|
|
5
|
+
|
|
6
|
+
export type MaxToolbarActions = {
|
|
7
|
+
tools: number;
|
|
8
|
+
utilities: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_MAX_TOOLBAR_ACTIONS: MaxToolbarActions = {
|
|
12
|
+
tools: 5,
|
|
13
|
+
utilities: 4,
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createContext, type PropsWithChildren, useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
import { DEFAULT_MAX_TOOLBAR_ACTIONS, type MaxToolbarActions } from '../constants';
|
|
5
|
+
|
|
6
|
+
const AppBarSizeContext = createContext< MaxToolbarActions >( DEFAULT_MAX_TOOLBAR_ACTIONS );
|
|
7
|
+
|
|
8
|
+
export function AppBarSizeProvider( { value, children }: PropsWithChildren< { value: MaxToolbarActions } > ) {
|
|
9
|
+
return <AppBarSizeContext.Provider value={ value }>{ children }</AppBarSizeContext.Provider>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useMaxToolbarActions() {
|
|
13
|
+
return useContext( AppBarSizeContext );
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RefObject, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useContainerWidth( ref: RefObject< HTMLElement | null > ) {
|
|
4
|
+
const [ width, setWidth ] = useState( 0 );
|
|
5
|
+
|
|
6
|
+
useEffect( () => {
|
|
7
|
+
const element = ref.current;
|
|
8
|
+
|
|
9
|
+
if ( ! element || typeof ResizeObserver === 'undefined' ) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const observer = new ResizeObserver( ( entries ) => {
|
|
14
|
+
const entry = entries[ 0 ];
|
|
15
|
+
|
|
16
|
+
if ( entry ) {
|
|
17
|
+
setWidth( entry.contentRect.width );
|
|
18
|
+
}
|
|
19
|
+
} );
|
|
20
|
+
|
|
21
|
+
setWidth( element.getBoundingClientRect().width );
|
|
22
|
+
|
|
23
|
+
observer.observe( element );
|
|
24
|
+
|
|
25
|
+
return () => observer.disconnect();
|
|
26
|
+
}, [ ref ] );
|
|
27
|
+
|
|
28
|
+
return width;
|
|
29
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DEFAULT_MAX_TOOLBAR_ACTIONS, type MaxToolbarActions, MIN_APP_BAR_WIDTH } from '../constants';
|
|
2
|
+
|
|
3
|
+
// Breakpoints are checked from the widest to the narrowest, so items in the left ("tools") and
|
|
4
|
+
// right ("utilities") sections of the app bar collapse into their "More" popover as the app bar
|
|
5
|
+
// narrows, freeing up space for the center section (document title, breakpoints switcher).
|
|
6
|
+
//
|
|
7
|
+
// The utilities section also holds the primary action (e.g. "Publish"), which has a fixed
|
|
8
|
+
// minimum width and can't shrink, so it gets fewer inline items than tools at the same width.
|
|
9
|
+
const BREAKPOINTS: Array< { minWidth: number } & MaxToolbarActions > = [
|
|
10
|
+
{ minWidth: 1200, ...DEFAULT_MAX_TOOLBAR_ACTIONS },
|
|
11
|
+
{ minWidth: 950, tools: 3, utilities: 2 },
|
|
12
|
+
{ minWidth: MIN_APP_BAR_WIDTH, tools: 1, utilities: 0 },
|
|
13
|
+
{ minWidth: 0, tools: 0, utilities: 0 },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
export function getMaxToolbarActions( containerWidth: number ): MaxToolbarActions {
|
|
17
|
+
// Avoid collapsing the toolbar before its width has been measured.
|
|
18
|
+
if ( ! containerWidth ) {
|
|
19
|
+
return DEFAULT_MAX_TOOLBAR_ACTIONS;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const breakpoint = BREAKPOINTS.find( ( { minWidth } ) => containerWidth >= minWidth ) ?? BREAKPOINTS.at( -1 );
|
|
23
|
+
|
|
24
|
+
return { tools: breakpoint?.tools ?? 0, utilities: breakpoint?.utilities ?? 0 };
|
|
25
|
+
}
|