@elementor/editor-editing-panel 4.1.0-826 → 4.1.0-828

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": "4.1.0-826",
3
+ "version": "4.1.0-828",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,31 +39,31 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.1.0-826",
43
- "@elementor/editor-canvas": "4.1.0-826",
44
- "@elementor/editor-controls": "4.1.0-826",
45
- "@elementor/editor-documents": "4.1.0-826",
46
- "@elementor/editor-elements": "4.1.0-826",
47
- "@elementor/editor-interactions": "4.1.0-826",
48
- "@elementor/editor-notifications": "4.1.0-826",
49
- "@elementor/editor-panels": "4.1.0-826",
50
- "@elementor/editor-props": "4.1.0-826",
51
- "@elementor/editor-responsive": "4.1.0-826",
52
- "@elementor/editor-styles": "4.1.0-826",
53
- "@elementor/editor-styles-repository": "4.1.0-826",
54
- "@elementor/editor-ui": "4.1.0-826",
55
- "@elementor/editor-v1-adapters": "4.1.0-826",
56
- "@elementor/http-client": "4.1.0-826",
42
+ "@elementor/editor": "4.1.0-828",
43
+ "@elementor/editor-canvas": "4.1.0-828",
44
+ "@elementor/editor-controls": "4.1.0-828",
45
+ "@elementor/editor-documents": "4.1.0-828",
46
+ "@elementor/editor-elements": "4.1.0-828",
47
+ "@elementor/editor-interactions": "4.1.0-828",
48
+ "@elementor/editor-notifications": "4.1.0-828",
49
+ "@elementor/editor-panels": "4.1.0-828",
50
+ "@elementor/editor-props": "4.1.0-828",
51
+ "@elementor/editor-responsive": "4.1.0-828",
52
+ "@elementor/editor-styles": "4.1.0-828",
53
+ "@elementor/editor-styles-repository": "4.1.0-828",
54
+ "@elementor/editor-ui": "4.1.0-828",
55
+ "@elementor/editor-v1-adapters": "4.1.0-828",
56
+ "@elementor/http-client": "4.1.0-828",
57
57
  "@elementor/icons": "^1.68.0",
58
- "@elementor/editor-variables": "4.1.0-826",
59
- "@elementor/locations": "4.1.0-826",
60
- "@elementor/menus": "4.1.0-826",
61
- "@elementor/query": "4.1.0-826",
62
- "@elementor/schema": "4.1.0-826",
63
- "@elementor/session": "4.1.0-826",
58
+ "@elementor/editor-variables": "4.1.0-828",
59
+ "@elementor/locations": "4.1.0-828",
60
+ "@elementor/menus": "4.1.0-828",
61
+ "@elementor/query": "4.1.0-828",
62
+ "@elementor/schema": "4.1.0-828",
63
+ "@elementor/session": "4.1.0-828",
64
64
  "@elementor/ui": "1.37.5",
65
- "@elementor/utils": "4.1.0-826",
66
- "@elementor/wp-media": "4.1.0-826",
65
+ "@elementor/utils": "4.1.0-828",
66
+ "@elementor/wp-media": "4.1.0-828",
67
67
  "@wordpress/i18n": "^5.13.0"
68
68
  },
69
69
  "peerDependencies": {
@@ -8,10 +8,17 @@ type SectionContentProps = PropsWithChildren< {
8
8
  pt?: number;
9
9
  };
10
10
  'aria-label'?: string;
11
+ className?: string;
11
12
  } >;
12
13
 
13
- export const SectionContent: FC< SectionContentProps > = ( { gap = 2, sx, children, 'aria-label': ariaLabel } ) => (
14
- <Stack gap={ gap } sx={ { ...sx } } aria-label={ ariaLabel }>
14
+ export const SectionContent: FC< SectionContentProps > = ( {
15
+ gap = 2,
16
+ sx,
17
+ children,
18
+ 'aria-label': ariaLabel,
19
+ className,
20
+ } ) => (
21
+ <Stack gap={ gap } sx={ { ...sx } } aria-label={ ariaLabel } className={ className }>
15
22
  { children }
16
23
  </Stack>
17
24
  );
@@ -15,15 +15,11 @@ const positionOptions = [
15
15
  { label: __( 'Sticky', 'elementor' ), value: 'sticky' },
16
16
  ];
17
17
 
18
- type Props = {
19
- onChange?: ( newValue: string | null, previousValue: string | null | undefined ) => void;
20
- };
21
-
22
- export const PositionField = ( { onChange }: Props ) => {
18
+ export const PositionField = () => {
23
19
  return (
24
20
  <StylesField bind="position" propDisplayName={ POSITION_LABEL }>
25
21
  <StylesFieldLayout label={ POSITION_LABEL }>
26
- <SelectControl options={ positionOptions } onChange={ onChange } />
22
+ <SelectControl options={ positionOptions } />
27
23
  </StylesFieldLayout>
28
24
  </StylesField>
29
25
  );
@@ -1,7 +1,8 @@
1
1
  import * as React from 'react';
2
- import { useCallback, useEffect, useRef } from 'react';
3
- import { type StringPropValue } from '@elementor/editor-props';
2
+ import { useEffect, useRef } from 'react';
3
+ import { type NumberPropValue, type SizePropValue, type StringPropValue } from '@elementor/editor-props';
4
4
  import { useSessionStorage } from '@elementor/session';
5
+ import { styled } from '@elementor/ui';
5
6
  import { __ } from '@wordpress/i18n';
6
7
 
7
8
  import { useStyle } from '../../../contexts/style-context';
@@ -14,112 +15,62 @@ import { OffsetField } from './offset-field';
14
15
  import { PositionField } from './position-field';
15
16
  import { ZIndexField } from './z-index-field';
16
17
 
17
- type DimensionValue =
18
- | {
19
- $$type: 'size';
20
- value: number;
21
- }
22
- | undefined
23
- | null;
24
-
25
- type DimensionsValues = {
26
- 'inset-block-start': DimensionValue;
27
- 'inset-block-end': DimensionValue;
28
- 'inset-inline-start': DimensionValue;
29
- 'inset-inline-end': DimensionValue;
18
+ type DependentValues = {
19
+ 'inset-block-start'?: SizePropValue | null;
20
+ 'inset-block-end'?: SizePropValue | null;
21
+ 'inset-inline-start'?: SizePropValue | null;
22
+ 'inset-inline-end'?: SizePropValue | null;
23
+ 'z-index'?: NumberPropValue | null;
30
24
  };
31
25
 
32
- type PositionDependentValues = DimensionsValues & {
33
- 'z-index': number | undefined | null;
34
- };
35
-
36
- const POSITION_STATIC = 'static' as const;
26
+ const POSITION_STATIC = 'static';
37
27
 
38
28
  const POSITION_LABEL = __( 'Position', 'elementor' );
39
29
  const DIMENSIONS_LABEL = __( 'Dimensions', 'elementor' );
40
30
 
41
- const POSITION_DEPENDENT_PROP_NAMES = [
31
+ const DEPENDENT_PROP_NAMES: Array< keyof DependentValues > = [
42
32
  'inset-block-start',
43
33
  'inset-block-end',
44
34
  'inset-inline-start',
45
35
  'inset-inline-end',
46
36
  'z-index',
47
- ] as const;
48
-
49
- const CLEARED_POSITION_DEPENDENT_VALUES: Record< ( typeof POSITION_DEPENDENT_PROP_NAMES )[ number ], null > = {
50
- 'inset-block-start': null,
51
- 'inset-block-end': null,
52
- 'inset-inline-start': null,
53
- 'inset-inline-end': null,
54
- 'z-index': null,
55
- };
37
+ ];
56
38
 
57
39
  export const PositionSection = () => {
58
- const { value: positionValue } = useStylesField< StringPropValue >( 'position', {
59
- history: { propDisplayName: POSITION_LABEL },
60
- } );
61
- const { values: positionDependentValues, setValues: setPositionDependentValues } =
62
- useStylesFields< PositionDependentValues >( [ ...POSITION_DEPENDENT_PROP_NAMES ] );
63
-
64
- const [ dimensionsValuesFromHistory, updateDimensionsHistory, clearDimensionsHistory ] = usePersistDimensions();
65
-
66
- const clearPositionDependentProps = useCallback( () => {
67
- const dimensions: DimensionsValues = {
68
- 'inset-block-start': positionDependentValues?.[ 'inset-block-start' ],
69
- 'inset-block-end': positionDependentValues?.[ 'inset-block-end' ],
70
- 'inset-inline-start': positionDependentValues?.[ 'inset-inline-start' ],
71
- 'inset-inline-end': positionDependentValues?.[ 'inset-inline-end' ],
72
- };
73
- const meta = { history: { propDisplayName: DIMENSIONS_LABEL } };
74
- const hasValuesToClear =
75
- Object.values( dimensions ).some( ( v ) => v !== null ) || positionDependentValues?.[ 'z-index' ] !== null;
40
+ const { value: position } = useStylesField< StringPropValue >( 'position', withHistoryLabel( POSITION_LABEL ) );
41
+ const positionPrevRef = useRef( position );
42
+ const { values: dependentValues, setValues: setDependentValues } =
43
+ useStylesFields< DependentValues >( DEPENDENT_PROP_NAMES );
44
+
45
+ const [ savedDependentValues, saveToHistory, clearHistory ] = usePersistDimensions();
76
46
 
77
- if ( hasValuesToClear ) {
78
- updateDimensionsHistory( dimensions );
79
- setPositionDependentValues( CLEARED_POSITION_DEPENDENT_VALUES, meta );
47
+ useEffect( () => {
48
+ if ( position && position?.value === POSITION_STATIC && hasDependentValues( dependentValues ) ) {
49
+ saveToHistory( extractDimensions( dependentValues ) );
80
50
  }
81
- }, [ positionDependentValues, updateDimensionsHistory, setPositionDependentValues ] );
82
51
 
83
- const clearPositionDependentPropsRef = useRef( clearPositionDependentProps );
84
- clearPositionDependentPropsRef.current = clearPositionDependentProps;
52
+ if ( positionPrevRef.current?.value === POSITION_STATIC ) {
53
+ setDependentValues( { ...savedDependentValues }, withHistoryLabel( DIMENSIONS_LABEL ) );
85
54
 
86
- useEffect( () => {
87
- if ( positionValue?.value === POSITION_STATIC || positionValue === null ) {
88
- clearPositionDependentPropsRef.current();
55
+ clearHistory();
89
56
  }
90
- }, [ positionValue ] );
91
-
92
- const onPositionChange = ( newPosition: string | null, previousPosition: string | null | undefined ) => {
93
- const meta = { history: { propDisplayName: DIMENSIONS_LABEL } };
94
-
95
- if ( newPosition === POSITION_STATIC ) {
96
- clearPositionDependentProps();
97
- } else if ( previousPosition === POSITION_STATIC ) {
98
- if ( dimensionsValuesFromHistory ) {
99
- setPositionDependentValues(
100
- { ...dimensionsValuesFromHistory, 'z-index': undefined } as PositionDependentValues,
101
- meta
102
- );
103
- clearDimensionsHistory();
104
- }
57
+
58
+ if ( ( ! position || position?.value === POSITION_STATIC ) && dependentValues?.[ 'z-index' ] ) {
59
+ setDependentValues( { 'z-index': null }, withHistoryLabel( DIMENSIONS_LABEL ) );
105
60
  }
106
- };
107
61
 
108
- const isNotStatic = positionValue && positionValue?.value !== POSITION_STATIC;
62
+ positionPrevRef.current = position;
63
+ // eslint-disable-next-line react-hooks/exhaustive-deps
64
+ }, [ position?.value ] );
109
65
 
110
66
  return (
111
- <SectionContent>
112
- <PositionField onChange={ onPositionChange } />
113
- { isNotStatic ? (
114
- <>
115
- <DimensionsField />
116
- </>
117
- ) : null }
118
-
119
- <ZIndexField disabled={ ! isNotStatic } />
67
+ <StyledSectionContent>
68
+ <PositionField />
69
+ <DimensionsField />
70
+ <ZIndexField disabled={ ! position || position?.value === POSITION_STATIC } />
120
71
  <PanelDivider />
121
72
  <OffsetField />
122
- </SectionContent>
73
+ </StyledSectionContent>
123
74
  );
124
75
  };
125
76
 
@@ -128,5 +79,51 @@ const usePersistDimensions = () => {
128
79
  const styleVariantPath = `styles/${ styleDefID }/${ meta.breakpoint || 'desktop' }/${ meta.state || 'null' }`;
129
80
  const dimensionsPath = `${ styleVariantPath }/dimensions`;
130
81
 
131
- return useSessionStorage< DimensionsValues >( dimensionsPath );
82
+ return useSessionStorage< DependentValues >( dimensionsPath );
83
+ };
84
+
85
+ const withHistoryLabel = ( name: string ) => {
86
+ return {
87
+ history: { propDisplayName: name },
88
+ };
89
+ };
90
+
91
+ const hasDependentValues = ( values?: DependentValues | null ) => {
92
+ if ( ! values ) {
93
+ return false;
94
+ }
95
+
96
+ const dimensions = extractDimensions( values );
97
+
98
+ return Object.values( dimensions ).some( ( v ) => v !== null );
132
99
  };
100
+
101
+ const extractDimensions = ( values: DependentValues | null ): DependentValues => {
102
+ return DEPENDENT_PROP_NAMES.reduce( ( acc, key ) => {
103
+ return {
104
+ ...acc,
105
+ [ key ]: values?.[ key ] ?? null,
106
+ };
107
+ }, {} );
108
+ };
109
+
110
+ const StyledSectionContent = styled( SectionContent, {
111
+ shouldForwardProp: ( prop ) => prop !== 'gap',
112
+ } )< { gap?: number } >( ( { gap = 2, theme } ) => ( {
113
+ gap: 0,
114
+ '& > *': {
115
+ marginBottom: theme.spacing( gap ),
116
+ },
117
+ '& > *:last-child': {
118
+ marginBottom: 0,
119
+ },
120
+ '& > .MuiStack-root': {
121
+ marginBottom: 0,
122
+ },
123
+ '& > .MuiStack-root:has(> *)': {
124
+ marginBottom: theme.spacing( gap ),
125
+ },
126
+ '& > .MuiDivider-root': {
127
+ marginBottom: theme.spacing( gap ),
128
+ },
129
+ } ) );
@@ -53,7 +53,10 @@ function useSyncDepsWithInherited( {
53
53
  useEffect( () => {
54
54
  const { hasSynced, prevDepValues } = syncRef.current;
55
55
 
56
- if ( hasSynced && value && wasDepsCleared( prevDepValues, depValues ) ) {
56
+ if (
57
+ ( hasSynced && value && wasDepsCleared( prevDepValues, depValues ) ) ||
58
+ ( isHidden && depValues && value )
59
+ ) {
57
60
  resetValue();
58
61
  }
59
62