@elementor/editor-editing-panel 1.31.0 → 1.33.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.31.0",
3
+ "version": "1.33.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -40,15 +40,15 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@elementor/editor": "0.19.1",
43
- "@elementor/editor-canvas": "0.19.1",
44
- "@elementor/editor-controls": "0.28.0",
45
- "@elementor/editor-current-user": "0.3.0",
46
- "@elementor/editor-elements": "0.8.1",
43
+ "@elementor/editor-canvas": "0.20.1",
44
+ "@elementor/editor-controls": "0.28.2",
45
+ "@elementor/editor-current-user": "0.3.2",
46
+ "@elementor/editor-elements": "0.8.2",
47
47
  "@elementor/editor-panels": "0.15.1",
48
48
  "@elementor/editor-props": "0.12.0",
49
49
  "@elementor/editor-responsive": "0.13.4",
50
50
  "@elementor/editor-styles": "0.6.6",
51
- "@elementor/editor-styles-repository": "0.8.5",
51
+ "@elementor/editor-styles-repository": "0.8.6",
52
52
  "@elementor/editor-ui": "0.8.1",
53
53
  "@elementor/editor-v1-adapters": "0.11.0",
54
54
  "@elementor/icons": "1.40.1",
@@ -2,11 +2,12 @@ import * as React from 'react';
2
2
  import { ControlFormLabel } from '@elementor/editor-controls';
3
3
  import { type Control } from '@elementor/editor-elements';
4
4
  import { SessionStorageProvider } from '@elementor/session';
5
+ import { Divider } from '@elementor/ui';
5
6
 
6
7
  import { useElement } from '../contexts/element-context';
7
8
  import { Control as BaseControl } from '../controls-registry/control';
8
9
  import { ControlTypeContainer } from '../controls-registry/control-type-container';
9
- import { type ControlType, getControlByType } from '../controls-registry/controls-registry';
10
+ import { type ControlType, getControl, getDefaultLayout } from '../controls-registry/controls-registry';
10
11
  import { SettingsField } from '../controls-registry/settings-field';
11
12
  import { Section } from './section';
12
13
  import { SectionsList } from './sections-list';
@@ -45,13 +46,16 @@ export const SettingsTab = () => {
45
46
  };
46
47
 
47
48
  const Control = ( { control }: { control: Control[ 'value' ] } ) => {
48
- if ( ! getControlByType( control.type as ControlType ) ) {
49
+ if ( ! getControl( control.type as ControlType ) ) {
49
50
  return null;
50
51
  }
51
52
 
53
+ const layout = control.meta?.layout || getDefaultLayout( control.type as ControlType );
54
+
52
55
  return (
53
56
  <SettingsField bind={ control.bind }>
54
- <ControlTypeContainer controlType={ control.type as ControlType }>
57
+ { control.meta?.topDivider && <Divider /> }
58
+ <ControlTypeContainer layout={ layout }>
55
59
  { control.label ? <ControlFormLabel>{ control.label }</ControlFormLabel> : null }
56
60
  <BaseControl type={ control.type as ControlType } props={ control.props } />
57
61
  </ControlTypeContainer>
@@ -1,14 +1,8 @@
1
1
  import * as React from 'react';
2
+ import { type ControlLayout } from '@elementor/editor-elements';
2
3
  import { Box, type BoxProps, styled } from '@elementor/ui';
3
4
 
4
- import { type ControlLayout, type ControlType, getLayoutByType } from './controls-registry';
5
-
6
- export const ControlTypeContainer = ( {
7
- controlType,
8
- children,
9
- }: React.PropsWithChildren< { controlType: ControlType } > ) => {
10
- const layout = getLayoutByType( controlType );
11
-
5
+ export const ControlTypeContainer = ( { children, layout }: React.PropsWithChildren< { layout?: ControlLayout } > ) => {
12
6
  return <StyledContainer layout={ layout }>{ children }</StyledContainer>;
13
7
  };
14
8
 
@@ -3,7 +3,7 @@ import type { ComponentProps } from 'react';
3
3
 
4
4
  import { useElement } from '../contexts/element-context';
5
5
  import { ControlTypeNotFoundError } from '../errors';
6
- import { type ControlType, type ControlTypes, getControlByType } from './controls-registry';
6
+ import { type ControlType, type ControlTypes, getControl } from './controls-registry';
7
7
 
8
8
  type IsRequired< T, K extends keyof T > = object extends Pick< T, K > ? false : true;
9
9
 
@@ -24,7 +24,7 @@ type ControlProps< T extends ControlType > = AnyPropertyRequired< ComponentProps
24
24
  };
25
25
 
26
26
  export const Control = < T extends ControlType >( { props, type }: ControlProps< T > ) => {
27
- const ControlByType = getControlByType( type );
27
+ const ControlByType = getControl( type );
28
28
  const { element } = useElement();
29
29
 
30
30
  if ( ! ControlByType ) {
@@ -9,8 +9,7 @@ import {
9
9
  TextControl,
10
10
  UrlControl,
11
11
  } from '@elementor/editor-controls';
12
-
13
- export type ControlLayout = 'full' | 'two-columns';
12
+ import { type ControlLayout } from '@elementor/editor-elements';
14
13
 
15
14
  type ControlRegistry = Record< string, { component: ControlComponent; layout: ControlLayout } >;
16
15
 
@@ -31,6 +30,6 @@ export type ControlTypes = {
31
30
  [ key in ControlType ]: ( typeof controlTypes )[ key ][ 'component' ];
32
31
  };
33
32
 
34
- export const getControlByType = ( type: ControlType ) => controlTypes[ type ]?.component;
33
+ export const getControl = ( type: ControlType ) => controlTypes[ type ]?.component;
35
34
 
36
- export const getLayoutByType = ( type: ControlType ) => controlTypes[ type ].layout;
35
+ export const getDefaultLayout = ( type: ControlType ) => controlTypes[ type ].layout;
@@ -24,7 +24,7 @@ import { __ } from '@wordpress/i18n';
24
24
 
25
25
  import { PopoverContent } from '../../components/popover-content';
26
26
  import { Control as BaseControl } from '../../controls-registry/control';
27
- import { type ControlType, getControlByType } from '../../controls-registry/controls-registry';
27
+ import { type ControlType, getControl } from '../../controls-registry/controls-registry';
28
28
  import { usePersistDynamicValue } from '../../hooks/use-persist-dynamic-value';
29
29
  import { DynamicControl } from '../dynamic-control';
30
30
  import { useDynamicTag } from '../hooks/use-dynamic-tag';
@@ -167,7 +167,7 @@ const DynamicSettings = ( { controls }: { controls: DynamicTag[ 'atomic_controls
167
167
  };
168
168
 
169
169
  const Control = ( { control }: { control: Control[ 'value' ] } ) => {
170
- if ( ! getControlByType( control.type as ControlType ) ) {
170
+ if ( ! getControl( control.type as ControlType ) ) {
171
171
  return null;
172
172
  }
173
173
 
@@ -0,0 +1,68 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { type PropsResolver } from '@elementor/editor-canvas';
3
+ import { type PropKey } from '@elementor/editor-props';
4
+
5
+ import { type NormalizedItem } from '../styles-inheritance/styles-inheritance-infotip';
6
+ import { type SnapshotPropValue } from '../styles-inheritance/types';
7
+
8
+ const MAXIMUM_ITEMS = 2;
9
+
10
+ export const useNormalizedInheritanceChainItems = (
11
+ inheritanceChain: SnapshotPropValue[],
12
+ bind: PropKey,
13
+ resolve: PropsResolver
14
+ ) => {
15
+ const [ items, setItems ] = useState< NormalizedItem[] >( [] );
16
+
17
+ useEffect( () => {
18
+ ( async () => {
19
+ const normalizedItems = await Promise.all(
20
+ inheritanceChain
21
+ .filter( ( item ) => item.style?.label )
22
+ .map( ( item, index ) => normalizeInheritanceItem( item, index, bind, resolve ) )
23
+ );
24
+
25
+ const validItems = normalizedItems.filter( ( item ) => item.value !== '' ).slice( 0, MAXIMUM_ITEMS );
26
+
27
+ setItems( validItems );
28
+ } )();
29
+ }, [ inheritanceChain, bind, resolve ] );
30
+
31
+ return items;
32
+ };
33
+
34
+ export const normalizeInheritanceItem = async (
35
+ item: SnapshotPropValue,
36
+ index: number,
37
+ bind: PropKey,
38
+ resolve: PropsResolver
39
+ ): Promise< NormalizedItem > => {
40
+ const state = item.variant?.meta?.state || '';
41
+ const label = item.style?.label || '';
42
+ const displayLabel = state ? `${ label }:${ state }` : label;
43
+
44
+ return {
45
+ id: item.style?.id ? item.style?.id + state : index,
46
+ breakpoint: item.variant?.meta?.breakpoint,
47
+ displayLabel,
48
+ value: await getTransformedValue( item, bind, resolve ),
49
+ };
50
+ };
51
+
52
+ export const getTransformedValue = async (
53
+ item: SnapshotPropValue,
54
+ bind: PropKey,
55
+ resolve: PropsResolver
56
+ ): Promise< string > => {
57
+ try {
58
+ const result = await resolve( {
59
+ props: {
60
+ [ bind ]: item.value,
61
+ },
62
+ } );
63
+
64
+ return Object.values( result ).join( ' ' );
65
+ } catch {
66
+ return '';
67
+ }
68
+ };
@@ -1,13 +1,19 @@
1
1
  import * as React from 'react';
2
+ import { useState } from 'react';
2
3
  import { useBoundProp } from '@elementor/editor-controls';
3
4
  import { ELEMENTS_BASE_STYLES_PROVIDER_KEY, isElementsStylesProvider } from '@elementor/editor-styles-repository';
5
+ import { IconButton, Infotip } from '@elementor/ui';
4
6
  import { __ } from '@wordpress/i18n';
5
7
 
6
8
  import { StyleIndicator } from '../components/style-indicator';
7
9
  import { useStyle } from '../contexts/style-context';
8
10
  import { useStylesInheritanceField } from '../contexts/styles-inheritance-context';
11
+ import { getExperimentsConfig } from '../sync/get-experiments-config';
12
+ import { StyleIndicatorInfotip } from './styles-inheritance-infotip';
9
13
 
10
14
  export const StylesInheritanceIndicator = () => {
15
+ const [ open, setOpen ] = useState( false );
16
+
11
17
  const { value, path } = useBoundProp();
12
18
  const { id: currentStyleId, provider: currentStyleProvider, meta: currentStyleMeta } = useStyle();
13
19
 
@@ -27,27 +33,67 @@ export const StylesInheritanceIndicator = () => {
27
33
 
28
34
  const { breakpoint, state } = variant.meta;
29
35
 
30
- if (
31
- style.id === currentStyleId &&
32
- breakpoint === currentStyleMeta.breakpoint &&
33
- state === currentStyleMeta.state
34
- ) {
35
- return (
36
- <StyleIndicator
37
- aria-label={ __( 'This is the final value', 'elementor' ) }
38
- variant={ isElementsStylesProvider( currentStyleProvider?.getKey() ) ? 'local' : 'global' }
39
- />
40
- );
36
+ const isFinalValue: boolean =
37
+ style.id === currentStyleId && breakpoint === currentStyleMeta.breakpoint && state === currentStyleMeta.state;
38
+
39
+ const hasValue: boolean = value !== null && value !== undefined;
40
+
41
+ const label: string = getLabel( { isFinalValue, hasValue } );
42
+ const variantType = getVariant( { isFinalValue, hasValue, currentStyleProvider } );
43
+
44
+ const { e_indications_popover: eIndicationsPopover } = getExperimentsConfig();
45
+
46
+ if ( ! eIndicationsPopover ) {
47
+ return <StyleIndicator variant={ variantType } aria-label={ label } />;
48
+ }
49
+
50
+ const toggleOpen = () => setOpen( ( prev ) => ! prev );
51
+
52
+ return (
53
+ <Infotip
54
+ placement="top"
55
+ content={ <StyleIndicatorInfotip inheritanceChain={ inheritanceChain } bind={ bind } /> }
56
+ open={ open }
57
+ onClose={ () => setOpen( false ) }
58
+ trigger="manual"
59
+ >
60
+ <IconButton onClick={ toggleOpen } aria-label={ label }>
61
+ <StyleIndicator variant={ variantType } />
62
+ </IconButton>
63
+ </Infotip>
64
+ );
65
+ };
66
+
67
+ const getLabel = ( { isFinalValue, hasValue }: { isFinalValue: boolean; hasValue: boolean } ) => {
68
+ if ( isFinalValue ) {
69
+ return __( 'This is the final value', 'elementor' );
70
+ }
71
+
72
+ if ( hasValue ) {
73
+ return __( 'This value is overridden by another style', 'elementor' );
74
+ }
75
+
76
+ return __( 'This has value from another style', 'elementor' );
77
+ };
78
+
79
+ const getVariant = ( {
80
+ isFinalValue,
81
+ hasValue,
82
+ currentStyleProvider,
83
+ }: {
84
+ isFinalValue: boolean;
85
+ hasValue: boolean;
86
+ currentStyleProvider: object | null;
87
+ } ): 'local' | 'global' | 'overridden' | undefined => {
88
+ if ( isFinalValue ) {
89
+ return isElementsStylesProvider( ( currentStyleProvider as { getKey: () => string } )?.getKey?.() )
90
+ ? 'local'
91
+ : 'global';
41
92
  }
42
93
 
43
- if ( value !== null && value !== undefined ) {
44
- return (
45
- <StyleIndicator
46
- aria-label={ __( 'This value is overridden by another style', 'elementor' ) }
47
- variant="overridden"
48
- />
49
- );
94
+ if ( hasValue ) {
95
+ return 'overridden';
50
96
  }
51
97
 
52
- return <StyleIndicator aria-label={ __( 'This has value from another style', 'elementor' ) } />;
98
+ return undefined;
53
99
  };
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { useMemo } from 'react';
3
+ import { createPropsResolver, type PropsResolver, styleTransformersRegistry } from '@elementor/editor-canvas';
4
+ import { type PropKey } from '@elementor/editor-props';
5
+ import { getStylesSchema, type StyleDefinitionVariant } from '@elementor/editor-styles';
6
+ import { Card, CardContent, List, ListItem, ListItemText } from '@elementor/ui';
7
+
8
+ import { useNormalizedInheritanceChainItems } from '../hooks/use-normalized-inheritance-chain-items';
9
+ import { type SnapshotPropValue } from './types';
10
+
11
+ type StyleIndicatorInfotipProps = {
12
+ inheritanceChain: SnapshotPropValue[];
13
+ bind: PropKey;
14
+ };
15
+
16
+ export type NormalizedItem = {
17
+ id: string | number;
18
+ breakpoint?: StyleDefinitionVariant[ 'meta' ][ 'breakpoint' ];
19
+ displayLabel: string;
20
+ value: string;
21
+ };
22
+
23
+ export const StyleIndicatorInfotip = ( { inheritanceChain, bind }: StyleIndicatorInfotipProps ) => {
24
+ const resolve = useMemo< PropsResolver >( () => {
25
+ const stylesSchema = getStylesSchema();
26
+
27
+ return createPropsResolver( {
28
+ transformers: styleTransformersRegistry,
29
+ schema: { [ bind ]: stylesSchema[ bind ] },
30
+ } );
31
+ }, [ bind ] );
32
+
33
+ const items = useNormalizedInheritanceChainItems( inheritanceChain, bind, resolve );
34
+
35
+ return (
36
+ <Card elevation={ 0 } sx={ { maxWidth: 320 } }>
37
+ <CardContent sx={ { p: 1.5, pb: 2.5 } }>
38
+ <List>
39
+ { items.map( ( item ) => (
40
+ <ListItem key={ item.id }>
41
+ <ListItemText
42
+ primary={ `${ item.breakpoint } | ${ item.displayLabel }. ${ item.value }` }
43
+ />
44
+ </ListItem>
45
+ ) ) }
46
+ </List>
47
+ </CardContent>
48
+ </Card>
49
+ );
50
+ };
@@ -0,0 +1,7 @@
1
+ import { type ExtendedWindow } from './types';
2
+
3
+ export const getExperimentsConfig = () => {
4
+ const extendedWindow = window as unknown as ExtendedWindow;
5
+
6
+ return extendedWindow.elementorCommon?.config?.experimentalFeatures ?? {};
7
+ };
package/src/sync/types.ts CHANGED
@@ -31,6 +31,13 @@ export type ExtendedWindow = Window & {
31
31
  };
32
32
  };
33
33
  };
34
+ elementorCommon?: {
35
+ config?: {
36
+ experimentalFeatures?: {
37
+ e_indications_popover?: boolean;
38
+ };
39
+ };
40
+ };
34
41
  elementorFrontend?: {
35
42
  config?: {
36
43
  is_rtl?: boolean;