@elementor/editor-editing-panel 1.34.0 → 1.35.0

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-editing-panel",
3
- "version": "1.34.0",
3
+ "version": "1.35.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,12 +39,12 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "0.19.1",
43
- "@elementor/editor-canvas": "0.21.1",
44
- "@elementor/editor-controls": "0.29.0",
42
+ "@elementor/editor": "0.19.2",
43
+ "@elementor/editor-canvas": "0.21.2",
44
+ "@elementor/editor-controls": "0.30.0",
45
45
  "@elementor/editor-current-user": "0.3.2",
46
46
  "@elementor/editor-elements": "0.8.2",
47
- "@elementor/editor-panels": "0.15.1",
47
+ "@elementor/editor-panels": "0.15.2",
48
48
  "@elementor/editor-props": "0.12.0",
49
49
  "@elementor/editor-responsive": "0.13.4",
50
50
  "@elementor/editor-styles": "0.6.6",
@@ -52,8 +52,8 @@
52
52
  "@elementor/editor-ui": "0.8.1",
53
53
  "@elementor/editor-v1-adapters": "0.11.0",
54
54
  "@elementor/icons": "1.40.1",
55
- "@elementor/locations": "0.7.7",
56
- "@elementor/menus": "0.1.4",
55
+ "@elementor/locations": "0.8.0",
56
+ "@elementor/menus": "0.1.5",
57
57
  "@elementor/schema": "0.1.2",
58
58
  "@elementor/session": "0.1.0",
59
59
  "@elementor/ui": "1.34.2",
@@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n';
5
5
 
6
6
  import { useElement } from '../contexts/element-context';
7
7
  import { ScrollProvider } from '../contexts/scroll-context';
8
+ import { useStateByElement } from '../hooks/use-state-by-element';
8
9
  import { SettingsTab } from './settings-tab';
9
10
  import { stickyHeaderStyles, StyleTab } from './style-tab';
10
11
 
@@ -12,30 +13,46 @@ type TabValue = 'settings' | 'style';
12
13
 
13
14
  export const EditingPanelTabs = () => {
14
15
  const { element } = useElement();
15
-
16
- const { getTabProps, getTabPanelProps, getTabsProps } = useTabs< TabValue >( 'settings' );
17
-
18
16
  return (
19
17
  // When switching between elements, the local states should be reset. We are using key to rerender the tabs.
20
18
  // Reference: https://react.dev/learn/preserving-and-resetting-state#resetting-a-form-with-a-key
21
19
  <Fragment key={ element.id }>
22
- <ScrollProvider>
23
- <Stack direction="column" sx={ { width: '100%' } }>
24
- <Stack sx={ { ...stickyHeaderStyles, top: 0 } }>
25
- <Tabs variant="fullWidth" size="small" sx={ { mt: 0.5 } } { ...getTabsProps() }>
26
- <Tab label={ __( 'General', 'elementor' ) } { ...getTabProps( 'settings' ) } />
27
- <Tab label={ __( 'Style', 'elementor' ) } { ...getTabProps( 'style' ) } />
28
- </Tabs>
29
- <Divider />
30
- </Stack>
31
- <TabPanel { ...getTabPanelProps( 'settings' ) } disablePadding>
32
- <SettingsTab />
33
- </TabPanel>
34
- <TabPanel { ...getTabPanelProps( 'style' ) } disablePadding>
35
- <StyleTab />
36
- </TabPanel>
37
- </Stack>
38
- </ScrollProvider>
20
+ <PanelTabContent />
39
21
  </Fragment>
40
22
  );
41
23
  };
24
+
25
+ const PanelTabContent = () => {
26
+ const defaultComponentTab = 'settings';
27
+
28
+ const [ currentTab, setCurrentTab ] = useStateByElement< TabValue >( 'tab', defaultComponentTab );
29
+ const { getTabProps, getTabPanelProps, getTabsProps } = useTabs< TabValue >( currentTab );
30
+ return (
31
+ <ScrollProvider>
32
+ <Stack direction="column" sx={ { width: '100%' } }>
33
+ <Stack sx={ { ...stickyHeaderStyles, top: 0 } }>
34
+ <Tabs
35
+ variant="fullWidth"
36
+ size="small"
37
+ sx={ { mt: 0.5 } }
38
+ { ...getTabsProps() }
39
+ onChange={ ( _: unknown, newValue: TabValue ) => {
40
+ getTabsProps().onChange( _, newValue );
41
+ setCurrentTab( newValue );
42
+ } }
43
+ >
44
+ <Tab label={ __( 'General', 'elementor' ) } { ...getTabProps( 'settings' ) } />
45
+ <Tab label={ __( 'Style', 'elementor' ) } { ...getTabProps( 'style' ) } />
46
+ </Tabs>
47
+ <Divider />
48
+ </Stack>
49
+ <TabPanel { ...getTabPanelProps( 'settings' ) } disablePadding>
50
+ <SettingsTab />
51
+ </TabPanel>
52
+ <TabPanel { ...getTabPanelProps( 'style' ) } disablePadding>
53
+ <StyleTab />
54
+ </TabPanel>
55
+ </Stack>
56
+ </ScrollProvider>
57
+ );
58
+ };
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
- import { type PropsWithChildren, useId, useState } from 'react';
2
+ import { type PropsWithChildren, useId } from 'react';
3
3
  import { Collapse, Divider, ListItemButton, ListItemText, Stack } from '@elementor/ui';
4
4
 
5
+ import { useStateByElement } from '../hooks/use-state-by-element';
5
6
  import { CollapseIcon } from './collapse-icon';
6
7
 
7
8
  type Props = PropsWithChildren< {
@@ -10,7 +11,7 @@ type Props = PropsWithChildren< {
10
11
  } >;
11
12
 
12
13
  export function Section( { title, children, defaultExpanded = false }: Props ) {
13
- const [ isOpen, setIsOpen ] = useState( !! defaultExpanded );
14
+ const [ isOpen, setIsOpen ] = useStateByElement( title, !! defaultExpanded );
14
15
 
15
16
  const id = useId();
16
17
  const labelId = `label-${ id }`;
@@ -21,7 +22,7 @@ export function Section( { title, children, defaultExpanded = false }: Props ) {
21
22
  <ListItemButton
22
23
  id={ labelId }
23
24
  aria-controls={ contentId }
24
- onClick={ () => setIsOpen( ( prev ) => ! prev ) }
25
+ onClick={ () => setIsOpen( ! isOpen ) }
25
26
  sx={ { '&:hover': { backgroundColor: 'transparent' } } }
26
27
  >
27
28
  <ListItemText
@@ -0,0 +1,18 @@
1
+ import { useState } from 'react';
2
+ import { getSessionStorageItem, setSessionStorageItem } from '@elementor/session';
3
+
4
+ import { useElement } from '../contexts/element-context';
5
+
6
+ export const useStateByElement = < T >( key: string, initialValue: T ) => {
7
+ const { element } = useElement();
8
+ const lookup = `elementor/editor-state/${ element.id }/${ key }`;
9
+ const storedValue = getSessionStorageItem< T >( lookup );
10
+ const [ value, setValue ] = useState( storedValue ?? initialValue );
11
+
12
+ const doUpdate = ( newValue: T ) => {
13
+ setSessionStorageItem( lookup, newValue );
14
+ setValue( newValue );
15
+ };
16
+
17
+ return [ value, doUpdate ] as const;
18
+ };