@elementor/editor-editing-panel 0.16.0 → 0.17.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": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -42,7 +42,7 @@
42
42
  "@elementor/editor": "^0.14.0",
43
43
  "@elementor/editor-panels": "^0.7.0",
44
44
  "@elementor/editor-responsive": "^0.12.1",
45
- "@elementor/editor-style": "^0.3.0",
45
+ "@elementor/editor-style": "^0.4.0",
46
46
  "@elementor/editor-v1-adapters": "^0.8.2",
47
47
  "@elementor/icons": "^1.13.1",
48
48
  "@elementor/schema": "^0.1.0",
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ import { AlignLeftIcon, AlignCenterIcon, AlignRightIcon, AlignJustifiedIcon } from '@elementor/icons';
3
+ import { __ } from '@wordpress/i18n';
4
+ import { ControlContainer } from '../../../controls/components/control-container';
5
+ import { ToggleButtonGroupItem } from '../../../controls/components/control-toggle-button-group';
6
+ import { StyleControl } from '../../../controls/style-control';
7
+ import { ToggleControl } from '../../../controls/control-types/toggle-control';
8
+
9
+ type Alignments = 'left' | 'center' | 'right' | 'justify';
10
+
11
+ const options: ToggleButtonGroupItem< Alignments >[] = [
12
+ {
13
+ value: 'left',
14
+ label: __( 'Left', 'elementor' ),
15
+ icon: AlignLeftIcon,
16
+ },
17
+ {
18
+ value: 'center',
19
+ label: __( 'Center', 'elementor' ),
20
+ icon: AlignCenterIcon,
21
+ },
22
+ {
23
+ value: 'right',
24
+ label: __( 'Right', 'elementor' ),
25
+ icon: AlignRightIcon,
26
+ },
27
+ {
28
+ value: 'justify',
29
+ label: __( 'Justify', 'elementor' ),
30
+ icon: AlignJustifiedIcon,
31
+ },
32
+ ];
33
+
34
+ export const TextAlignmentControl = () => {
35
+ return (
36
+ <ControlContainer>
37
+ <StyleControl.Label>{ __( 'Alignment', 'elementor' ) }</StyleControl.Label>
38
+ <StyleControl bind={ 'text-align' }>
39
+ <ToggleControl options={ options } />
40
+ </StyleControl>
41
+ </ControlContainer>
42
+ );
43
+ };
@@ -10,6 +10,7 @@ import { LetterSpacingControl } from './letter-spacing-control';
10
10
  import { WordSpacingControl } from './word-spacing-control';
11
11
  import { CollapsibleContent } from '../../collapsible-content';
12
12
  import { TransformControl } from './transform-control';
13
+ import { TextAlignmentControl } from './text-alignment-control';
13
14
 
14
15
  export const TypographySection = () => {
15
16
  return (
@@ -24,6 +25,7 @@ export const TypographySection = () => {
24
25
  <LetterSpacingControl />
25
26
  <WordSpacingControl />
26
27
  <Divider />
28
+ <TextAlignmentControl />
27
29
  <TextStyleControl />
28
30
  <TransformControl />
29
31
  </Stack>
@@ -28,11 +28,13 @@ import {
28
28
  TabPanel,
29
29
  } from '@elementor/ui';
30
30
  import { __ } from '@wordpress/i18n';
31
+ import { usePropValueHistory } from '../hooks/use-prop-value-history';
31
32
 
32
33
  const SIZE = 'tiny';
33
34
 
34
35
  export const DynamicSelectionControl = () => {
35
36
  const { bind, value, setValue } = useControl< DynamicPropValue | null >();
37
+ const [ propValueFromHistory ] = usePropValueHistory( bind );
36
38
  const { name: tagName = '' } = value?.value || {};
37
39
 
38
40
  const selectionPopoverId = useId();
@@ -41,8 +43,7 @@ export const DynamicSelectionControl = () => {
41
43
  const dynamicTag = useDynamicTag( bind, tagName );
42
44
 
43
45
  const removeDynamicTag = () => {
44
- // TODO: Implement static value restoration.
45
- setValue( null );
46
+ setValue( propValueFromHistory ?? null );
46
47
  };
47
48
 
48
49
  if ( ! dynamicTag ) {
@@ -18,7 +18,9 @@ import {
18
18
  Typography,
19
19
  } from '@elementor/ui';
20
20
  import { __ } from '@wordpress/i18n';
21
- import { PropKey } from '../../types';
21
+ import { PropKey, PropValue } from '../../types';
22
+ import { isDynamicPropValue } from '../utils';
23
+ import { usePropValueHistory } from '../hooks/use-prop-value-history';
22
24
 
23
25
  type Option = {
24
26
  label: string;
@@ -35,9 +37,11 @@ export type DynamicSelectionProps = {
35
37
 
36
38
  export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
37
39
  const [ searchValue, setSearchValue ] = useState( '' );
38
-
39
40
  const { groups: dynamicGroups } = getAtomicDynamicTags() || {};
40
- const { bind, value: dynamicValue, setValue } = useControl< DynamicPropValue >();
41
+ const { bind, value: currentValue, setValue } = useControl< DynamicPropValue | PropValue >();
42
+ const [ , updatePropValueHistory ] = usePropValueHistory( bind );
43
+
44
+ const isCurrentValueDynamic = isDynamicPropValue( currentValue );
41
45
 
42
46
  const options = useFilteredOptions( bind, searchValue );
43
47
 
@@ -45,6 +49,16 @@ export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
45
49
  setSearchValue( event.target.value );
46
50
  };
47
51
 
52
+ const handleSetDynamicTag = ( value: string ) => {
53
+ if ( ! isCurrentValueDynamic ) {
54
+ updatePropValueHistory( currentValue );
55
+ }
56
+
57
+ setValue( { $$type: 'dynamic', value: { name: value } } );
58
+
59
+ onSelect?.();
60
+ };
61
+
48
62
  return (
49
63
  <Stack>
50
64
  <Box px={ 1.5 } pb={ 1 }>
@@ -73,7 +87,7 @@ export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
73
87
  { dynamicGroups?.[ category ]?.title || category }
74
88
  </ListSubheader>
75
89
  { items.map( ( { value, label: tagLabel } ) => {
76
- const isSelected = value === dynamicValue?.value?.name;
90
+ const isSelected = isCurrentValueDynamic && value === currentValue?.value?.name;
77
91
 
78
92
  return (
79
93
  <MenuItem
@@ -82,10 +96,7 @@ export const DynamicSelection = ( { onSelect }: DynamicSelectionProps ) => {
82
96
  // eslint-disable-next-line jsx-a11y/no-autofocus
83
97
  autoFocus={ isSelected }
84
98
  sx={ { typography: 'caption' } }
85
- onClick={ () => {
86
- setValue( { $$type: 'dynamic', value: { name: value } } );
87
- onSelect?.();
88
- } }
99
+ onClick={ () => handleSetDynamicTag( value ) }
89
100
  >
90
101
  { tagLabel }
91
102
  </MenuItem>
@@ -0,0 +1,26 @@
1
+ import { useElementContext } from '../../contexts/element-context';
2
+ import { PropValue } from '../../types';
3
+
4
+ export const PROPS_VALUES_HISTORY_KEY = 'elementor/dynamic/non-dynamic-values-history';
5
+
6
+ export const usePropValueHistory = ( path: string ) => {
7
+ const valuesHistory = getValues();
8
+ const { element } = useElementContext();
9
+ const key = `${ element.id }-${ path }`;
10
+
11
+ const value = valuesHistory[ key ] ?? null;
12
+
13
+ const setValue = ( newValue: PropValue ) => {
14
+ setValues( { ...valuesHistory, [ key ]: newValue } );
15
+ };
16
+
17
+ return [ value, setValue ] as const;
18
+ };
19
+
20
+ const getValues = () => {
21
+ return JSON.parse( sessionStorage.getItem( PROPS_VALUES_HISTORY_KEY ) || '{}' );
22
+ };
23
+
24
+ const setValues = ( values: Record< string, PropValue > ) => {
25
+ sessionStorage.setItem( PROPS_VALUES_HISTORY_KEY, JSON.stringify( values ) );
26
+ };
@@ -1,9 +1,9 @@
1
1
  import { AdditionalPropType, PropValue } from '../types';
2
- import { DynamicPropType } from './types';
2
+ import { DynamicPropType, DynamicPropValue } from './types';
3
3
  import { isTransformable } from '../props/is-transformable';
4
4
 
5
5
  export const isDynamicType = ( prop: AdditionalPropType ): prop is DynamicPropType => prop.key === 'dynamic';
6
6
 
7
- export const isDynamicPropValue = ( prop: PropValue ) => {
7
+ export const isDynamicPropValue = ( prop: PropValue ): prop is DynamicPropValue => {
8
8
  return isTransformable( prop ) && prop.$$type === 'dynamic';
9
9
  };