@elementor/editor-editing-panel 1.38.0 → 1.38.1

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.38.0",
3
+ "version": "1.38.1",
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.3",
43
- "@elementor/editor-canvas": "0.21.3",
44
- "@elementor/editor-controls": "0.30.1",
45
- "@elementor/editor-current-user": "0.3.2",
46
- "@elementor/editor-elements": "0.8.3",
43
+ "@elementor/editor-canvas": "0.22.0",
44
+ "@elementor/editor-controls": "0.31.0",
45
+ "@elementor/editor-current-user": "0.4.0",
46
+ "@elementor/editor-elements": "0.8.4",
47
47
  "@elementor/editor-panels": "0.15.3",
48
- "@elementor/editor-props": "0.12.0",
48
+ "@elementor/editor-props": "0.12.1",
49
49
  "@elementor/editor-responsive": "0.13.5",
50
- "@elementor/editor-styles": "0.6.7",
51
- "@elementor/editor-styles-repository": "0.8.8",
50
+ "@elementor/editor-styles": "0.6.8",
51
+ "@elementor/editor-styles-repository": "0.9.0",
52
52
  "@elementor/editor-ui": "0.8.2",
53
53
  "@elementor/editor-v1-adapters": "0.12.0",
54
54
  "@elementor/icons": "1.40.1",
@@ -4,7 +4,7 @@ import { isExperimentActive } from '@elementor/editor-v1-adapters';
4
4
  import { Stack } from '@elementor/ui';
5
5
  import { __ } from '@wordpress/i18n';
6
6
 
7
- import { useStylesInheritanceField } from '../../../contexts/styles-inheritance-context';
7
+ import { useStylesInheritanceChain } from '../../../contexts/styles-inheritance-context';
8
8
  import { StylesField } from '../../../controls-registry/styles-field';
9
9
  import { ControlLabel } from '../../control-label';
10
10
 
@@ -64,4 +64,4 @@ export const DisplayField = () => {
64
64
  };
65
65
 
66
66
  // TODO - placing this logic deliberately here, and will be removed once applied automatically to all style fields as part of ED-18491
67
- export const useDisplayPlaceholderValue = () => useStylesInheritanceField( 'display' )[ 0 ]?.value ?? undefined;
67
+ export const useDisplayPlaceholderValue = () => useStylesInheritanceChain( [ 'display' ] )[ 0 ]?.value ?? undefined;
@@ -7,51 +7,56 @@ import { stylesRepository } from '@elementor/editor-styles-repository';
7
7
 
8
8
  import { useStylesRerender } from '../hooks/use-styles-rerender';
9
9
  import { createStylesInheritance } from '../styles-inheritance/create-styles-inheritance';
10
- import { type SnapshotPropValue, type StylesInheritanceSnapshotGetter } from '../styles-inheritance/types';
10
+ import {
11
+ type SnapshotPropValue,
12
+ type StylesInheritanceAPI,
13
+ type StylesInheritanceSnapshot,
14
+ } from '../styles-inheritance/types';
11
15
  import { useClassesProp } from './classes-prop-context';
12
16
  import { useElement } from './element-context';
13
17
  import { useStyle } from './style-context';
14
18
 
15
- type ContextValue = {
16
- getSnapshot: StylesInheritanceSnapshotGetter;
17
- };
18
-
19
- const Context = createContext< ContextValue | null >( null );
19
+ const Context = createContext< StylesInheritanceAPI | null >( null );
20
20
 
21
21
  export function StyleInheritanceProvider( { children }: PropsWithChildren ) {
22
22
  const styleDefs = useAppliedStyles();
23
23
 
24
24
  const breakpointsTree = getBreakpointsTree();
25
25
 
26
- const getSnapshot = createStylesInheritance( styleDefs, breakpointsTree );
26
+ const { getSnapshot, getInheritanceChain } = createStylesInheritance( styleDefs, breakpointsTree );
27
27
 
28
- return <Context.Provider value={ { getSnapshot } }>{ children }</Context.Provider>;
28
+ return <Context.Provider value={ { getSnapshot, getInheritanceChain } }>{ children }</Context.Provider>;
29
29
  }
30
30
 
31
- export function useStylesInheritanceFields< T extends readonly string[] >(
32
- fields: T
33
- ): { [ K in T[ number ] ]: SnapshotPropValue[] } | null {
31
+ export function useStylesInheritanceSnapshot(): StylesInheritanceSnapshot | null {
34
32
  const context = useContext( Context );
35
33
  const { meta } = useStyle();
36
34
 
37
35
  if ( ! context ) {
38
- throw new Error( 'useStylesInheritanceFields must be used within a StyleInheritanceProvider' );
36
+ throw new Error( 'useStylesInheritanceSnapshot must be used within a StyleInheritanceProvider' );
39
37
  }
40
38
 
41
39
  if ( ! meta ) {
42
40
  return null;
43
41
  }
44
42
 
45
- const snapshot = context.getSnapshot( meta );
46
-
47
- return fields.reduce(
48
- ( acc, key: T[ number ] ) => ( { ...acc, [ key ]: snapshot?.[ key ] ?? [] } ),
49
- {} as { [ K in T[ number ] ]: SnapshotPropValue[] }
50
- );
43
+ return context.getSnapshot( meta ) ?? null;
51
44
  }
52
45
 
53
- export function useStylesInheritanceField( field: string ): SnapshotPropValue[] {
54
- return useStylesInheritanceFields( [ field ] )?.[ field ] ?? [];
46
+ export function useStylesInheritanceChain( path: string[] ): SnapshotPropValue[] {
47
+ const context = useContext( Context );
48
+
49
+ if ( ! context ) {
50
+ throw new Error( 'useStylesInheritanceChain must be used within a StyleInheritanceProvider' );
51
+ }
52
+
53
+ const snapshot = useStylesInheritanceSnapshot();
54
+
55
+ if ( ! snapshot ) {
56
+ return [];
57
+ }
58
+
59
+ return context.getInheritanceChain( snapshot, path );
55
60
  }
56
61
 
57
62
  const useAppliedStyles = () => {
@@ -1,12 +1,19 @@
1
- import { useEffect, useState } from 'react';
1
+ import { type ReactNode, useEffect, useState } from 'react';
2
2
  import { type PropsResolver } from '@elementor/editor-canvas';
3
3
  import { type PropKey } from '@elementor/editor-props';
4
+ import { type StyleDefinitionVariant } from '@elementor/editor-styles';
4
5
 
5
- import { type NormalizedItem } from '../styles-inheritance/styles-inheritance-infotip';
6
6
  import { type SnapshotPropValue } from '../styles-inheritance/types';
7
7
 
8
8
  const MAXIMUM_ITEMS = 2;
9
9
 
10
+ type NormalizedItem = {
11
+ id: string | number;
12
+ breakpoint?: StyleDefinitionVariant[ 'meta' ][ 'breakpoint' ];
13
+ displayLabel: string;
14
+ value: ReactNode | string;
15
+ };
16
+
10
17
  export const useNormalizedInheritanceChainItems = (
11
18
  inheritanceChain: SnapshotPropValue[],
12
19
  bind: PropKey,
@@ -49,7 +56,7 @@ export const normalizeInheritanceItem = async (
49
56
  };
50
57
  };
51
58
 
52
- export const getTransformedValue = async (
59
+ const getTransformedValue = async (
53
60
  item: SnapshotPropValue,
54
61
  bind: PropKey,
55
62
  resolve: PropsResolver
@@ -1,21 +1,45 @@
1
+ import { isEmpty, isTransformable, type PropKey, type PropValue } from '@elementor/editor-props';
1
2
  import { type BreakpointNode } from '@elementor/editor-responsive';
2
3
  import { type StyleDefinition } from '@elementor/editor-styles';
3
4
 
4
5
  import { getProviderByStyleId } from '../contexts/style-context';
5
6
  import { createSnapshotsManager } from './create-snapshots-manager';
6
- import { type BreakpointsStatesStyles, type StyleInheritanceMetaProps, type StylesInheritanceSnapshot } from './types';
7
+ import {
8
+ type BreakpointsStatesStyles,
9
+ type StyleInheritanceMetaProps,
10
+ type StylesInheritanceAPI,
11
+ type StylesInheritanceSnapshot,
12
+ } from './types';
7
13
  import { getBreakpointKey, getStateKey } from './utils';
8
14
 
9
15
  export function createStylesInheritance(
10
16
  styleDefs: StyleDefinition[],
11
17
  breakpointsRoot: BreakpointNode
12
- ): ( meta: StyleInheritanceMetaProps ) => StylesInheritanceSnapshot | undefined {
18
+ ): StylesInheritanceAPI {
13
19
  const styleVariantsByMeta = buildStyleVariantsByMetaMapping( styleDefs );
14
20
 
15
21
  const getStyles = ( { breakpoint, state }: StyleInheritanceMetaProps ) =>
16
22
  styleVariantsByMeta?.[ getBreakpointKey( breakpoint ) ]?.[ getStateKey( state ) ] ?? [];
17
23
 
18
- return createSnapshotsManager( getStyles, breakpointsRoot );
24
+ return {
25
+ getSnapshot: createSnapshotsManager( getStyles, breakpointsRoot ),
26
+ getInheritanceChain: ( snapshot: StylesInheritanceSnapshot, path: string[] ) => {
27
+ const [ field, ...nextFields ] = path;
28
+
29
+ let inheritanceChain = snapshot[ field ] ?? [];
30
+
31
+ if ( nextFields.length > 0 ) {
32
+ inheritanceChain = inheritanceChain
33
+ .map( ( { value: styleValue, ...rest } ) => ( {
34
+ ...rest,
35
+ value: getValueByPath( styleValue, nextFields ),
36
+ } ) )
37
+ .filter( ( { value: styleValue } ) => ! isEmpty( styleValue ) );
38
+ }
39
+
40
+ return inheritanceChain;
41
+ },
42
+ };
19
43
  }
20
44
 
21
45
  function buildStyleVariantsByMetaMapping( styleDefs: StyleDefinition[] ): BreakpointsStatesStyles {
@@ -52,3 +76,25 @@ function buildStyleVariantsByMetaMapping( styleDefs: StyleDefinition[] ): Breakp
52
76
 
53
77
  return breakpointStateSlots;
54
78
  }
79
+
80
+ function getValueByPath( value: PropValue, path: PropKey[] ): PropValue {
81
+ if ( ! value || typeof value !== 'object' ) {
82
+ return null;
83
+ }
84
+
85
+ return path.reduce( ( currentScope: PropValue, key: PropKey ): PropValue | null => {
86
+ if ( ! currentScope ) {
87
+ return null;
88
+ }
89
+
90
+ if ( isTransformable( currentScope ) ) {
91
+ return currentScope.value?.[ key ];
92
+ }
93
+
94
+ if ( typeof currentScope === 'object' ) {
95
+ return currentScope[ key as keyof typeof currentScope ];
96
+ }
97
+
98
+ return null;
99
+ }, value );
100
+ }
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useState } from 'react';
3
3
  import { useBoundProp } from '@elementor/editor-controls';
4
+ import { isEmpty } from '@elementor/editor-props';
4
5
  import { ELEMENTS_BASE_STYLES_PROVIDER_KEY, isElementsStylesProvider } from '@elementor/editor-styles-repository';
5
6
  import { isExperimentActive } from '@elementor/editor-v1-adapters';
6
7
  import { IconButton, Infotip } from '@elementor/ui';
@@ -8,18 +9,20 @@ import { __ } from '@wordpress/i18n';
8
9
 
9
10
  import { StyleIndicator } from '../components/style-indicator';
10
11
  import { useStyle } from '../contexts/style-context';
11
- import { useStylesInheritanceField } from '../contexts/styles-inheritance-context';
12
+ import { useStylesInheritanceChain } from '../contexts/styles-inheritance-context';
12
13
  import { StyleIndicatorInfotip } from './styles-inheritance-infotip';
13
14
 
14
15
  export const StylesInheritanceIndicator = () => {
15
16
  const [ open, setOpen ] = useState( false );
16
17
 
17
- const { value, path } = useBoundProp();
18
+ const { value, path, propType } = useBoundProp();
18
19
  const { id: currentStyleId, provider: currentStyleProvider, meta: currentStyleMeta } = useStyle();
19
20
 
20
- // in the styles inheritance snapshot the keys are only those of the top level style schema attributes
21
- const [ bind ] = path;
22
- const inheritanceChain = useStylesInheritanceField( bind );
21
+ const isUsingNestedProps = isExperimentActive( 'e_v_3_30' );
22
+
23
+ const finalPath = isUsingNestedProps ? path : path.slice( 0, 1 );
24
+
25
+ const inheritanceChain = useStylesInheritanceChain( finalPath );
23
26
 
24
27
  if ( ! inheritanceChain.length ) {
25
28
  return null;
@@ -33,12 +36,12 @@ export const StylesInheritanceIndicator = () => {
33
36
 
34
37
  const { breakpoint, state } = variant.meta;
35
38
 
36
- const isFinalValue: boolean =
39
+ const isFinalValue =
37
40
  style.id === currentStyleId && breakpoint === currentStyleMeta.breakpoint && state === currentStyleMeta.state;
38
41
 
39
- const hasValue: boolean = value !== null && value !== undefined;
42
+ const hasValue = ! isEmpty( value );
40
43
 
41
- const label: string = getLabel( { isFinalValue, hasValue } );
44
+ const label = getLabel( { isFinalValue, hasValue } );
42
45
  const variantType = getVariant( { isFinalValue, hasValue, currentStyleProvider } );
43
46
 
44
47
  const eIndicationsPopover = isExperimentActive( 'e_indications_popover' );
@@ -52,7 +55,9 @@ export const StylesInheritanceIndicator = () => {
52
55
  return (
53
56
  <Infotip
54
57
  placement="top"
55
- content={ <StyleIndicatorInfotip inheritanceChain={ inheritanceChain } bind={ bind } /> }
58
+ content={
59
+ <StyleIndicatorInfotip inheritanceChain={ inheritanceChain } path={ finalPath } propType={ propType } />
60
+ }
56
61
  open={ open }
57
62
  onClose={ () => setOpen( false ) }
58
63
  trigger="manual"
@@ -1,8 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useMemo } from 'react';
3
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';
4
+ import { type PropKey, type PropType } from '@elementor/editor-props';
6
5
  import { Card, CardContent, List, ListItem, ListItemText } from '@elementor/ui';
7
6
 
8
7
  import { useNormalizedInheritanceChainItems } from '../hooks/use-normalized-inheritance-chain-items';
@@ -10,27 +9,21 @@ import { type SnapshotPropValue } from './types';
10
9
 
11
10
  type StyleIndicatorInfotipProps = {
12
11
  inheritanceChain: SnapshotPropValue[];
13
- bind: PropKey;
12
+ propType: PropType;
13
+ path: PropKey[];
14
14
  };
15
15
 
16
- export type NormalizedItem = {
17
- id: string | number;
18
- breakpoint?: StyleDefinitionVariant[ 'meta' ][ 'breakpoint' ];
19
- displayLabel: string;
20
- value: string;
21
- };
16
+ export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path }: StyleIndicatorInfotipProps ) => {
17
+ const key = path.join( '.' );
22
18
 
23
- export const StyleIndicatorInfotip = ( { inheritanceChain, bind }: StyleIndicatorInfotipProps ) => {
24
19
  const resolve = useMemo< PropsResolver >( () => {
25
- const stylesSchema = getStylesSchema();
26
-
27
20
  return createPropsResolver( {
28
21
  transformers: styleTransformersRegistry,
29
- schema: { [ bind ]: stylesSchema[ bind ] },
22
+ schema: { [ key ]: propType },
30
23
  } );
31
- }, [ bind ] );
24
+ }, [ key, propType ] );
32
25
 
33
- const items = useNormalizedInheritanceChainItems( inheritanceChain, bind, resolve );
26
+ const items = useNormalizedInheritanceChainItems( inheritanceChain, key, resolve );
34
27
 
35
28
  return (
36
29
  <Card elevation={ 0 } sx={ { maxWidth: 320 } }>
@@ -41,3 +41,8 @@ export type StyleInheritanceMetaProps = {
41
41
  export type StylesInheritanceSnapshotGetter = (
42
42
  meta: StyleInheritanceMetaProps
43
43
  ) => StylesInheritanceSnapshot | undefined;
44
+
45
+ export type StylesInheritanceAPI = {
46
+ getSnapshot: ( meta: StyleInheritanceMetaProps ) => StylesInheritanceSnapshot | undefined;
47
+ getInheritanceChain: ( snapshotField: StylesInheritanceSnapshot, path: string[] ) => SnapshotPropValue[];
48
+ };