@elementor/editor-editing-panel 1.18.0 → 1.19.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.18.0",
3
+ "version": "1.19.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -40,14 +40,14 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@elementor/editor": "0.18.3",
43
- "@elementor/editor-controls": "0.17.0",
43
+ "@elementor/editor-controls": "0.18.0",
44
44
  "@elementor/editor-current-user": "0.3.0",
45
- "@elementor/editor-elements": "0.6.3",
45
+ "@elementor/editor-elements": "0.6.4",
46
46
  "@elementor/editor-panels": "0.13.0",
47
47
  "@elementor/editor-props": "0.11.0",
48
48
  "@elementor/editor-responsive": "0.13.3",
49
49
  "@elementor/editor-styles": "0.6.3",
50
- "@elementor/editor-styles-repository": "0.7.6",
50
+ "@elementor/editor-styles-repository": "0.7.7",
51
51
  "@elementor/editor-ui": "0.4.2",
52
52
  "@elementor/editor-v1-adapters": "0.11.0",
53
53
  "@elementor/icons": "1.37.0",
@@ -0,0 +1,13 @@
1
+ import * as React from 'react';
2
+ import { type PropsWithChildren } from 'react';
3
+ import { ControlAdornments, ControlLabel } from '@elementor/editor-controls';
4
+ import { Stack } from '@elementor/ui';
5
+
6
+ export const ControlLabelWithAdornments = ( { children }: PropsWithChildren< object > ) => {
7
+ return (
8
+ <Stack direction="row" alignItems="center" justifyItems="start" gap={ 1 }>
9
+ <ControlLabel>{ children }</ControlLabel>
10
+ <ControlAdornments />
11
+ </Stack>
12
+ );
13
+ };
@@ -1,10 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { createContext, type PropsWithChildren, useContext } from 'react';
3
- import { useElementSetting } from '@elementor/editor-elements';
3
+ import { getWidgetsCache, useElementSetting } from '@elementor/editor-elements';
4
4
  import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
5
5
  import { getBreakpointsTree } from '@elementor/editor-responsive';
6
6
  import { stylesRepository } from '@elementor/editor-styles-repository';
7
7
 
8
+ import { useStylesRerender } from '../hooks/use-styles-rerender';
8
9
  import { createStylesInheritance } from '../styles-inheritance/create-styles-inheritance';
9
10
  import { type SnapshotPropValue, type StylesInheritanceSnapshotGetter } from '../styles-inheritance/types';
10
11
  import { useClassesProp } from './classes-prop-context';
@@ -56,10 +57,24 @@ export function useStylesInheritanceField( field: string ): SnapshotPropValue[]
56
57
  const useAppliedStyles = () => {
57
58
  const { element } = useElement();
58
59
  const currentClassesProp = useClassesProp();
60
+ const baseStyles = useBaseStyles();
61
+
62
+ useStylesRerender();
63
+
59
64
  const classesProp = useElementSetting< ClassesPropValue >( element.id, currentClassesProp );
60
65
 
61
66
  const appliedStyles = classesPropTypeUtil.extract( classesProp );
62
- const allStyles = stylesRepository.all();
63
67
 
64
- return allStyles.filter( ( style ) => appliedStyles?.includes( style.id ) );
68
+ return stylesRepository
69
+ .all()
70
+ .filter( ( style ) => appliedStyles?.includes( style.id ) )
71
+ .concat( baseStyles );
72
+ };
73
+
74
+ const useBaseStyles = () => {
75
+ const { elementType } = useElement();
76
+ const widgetsCache = getWidgetsCache();
77
+ const widgetCache = widgetsCache?.[ elementType.key ];
78
+
79
+ return Object.values( widgetCache?.base_styles ?? {} );
65
80
  };
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
- import { PropKeyProvider, PropProvider } from '@elementor/editor-controls';
2
+ import { ControlAdornmentsProvider, PropKeyProvider, PropProvider } from '@elementor/editor-controls';
3
3
  import { type PropKey, type PropValue } from '@elementor/editor-props';
4
4
  import { getStylesSchema } from '@elementor/editor-styles';
5
5
 
6
6
  import { useStylesField } from '../hooks/use-styles-field';
7
+ import { StylesInheritanceIndicator } from '../styles-inheritance/styles-inheritance-indicator';
7
8
  import { createTopLevelOjectType } from './create-top-level-object-type';
8
9
 
9
10
  export type StylesFieldProps = {
@@ -25,8 +26,17 @@ export const StylesField = ( { bind, children }: StylesFieldProps ) => {
25
26
  };
26
27
 
27
28
  return (
28
- <PropProvider propType={ propType } value={ values } setValue={ setValues }>
29
- <PropKeyProvider bind={ bind }>{ children }</PropKeyProvider>
30
- </PropProvider>
29
+ <ControlAdornmentsProvider
30
+ items={ [
31
+ {
32
+ id: 'styles-inheritance',
33
+ Adornment: StylesInheritanceIndicator,
34
+ },
35
+ ] }
36
+ >
37
+ <PropProvider propType={ propType } value={ values } setValue={ setValues }>
38
+ <PropKeyProvider bind={ bind }>{ children }</PropKeyProvider>
39
+ </PropProvider>
40
+ </ControlAdornmentsProvider>
31
41
  );
32
42
  };
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useReducer } from 'react';
1
+ import { useMemo } from 'react';
2
2
  import {
3
3
  createElementStyle,
4
4
  type CreateElementStyleArgs,
@@ -17,6 +17,7 @@ import { useClassesProp } from '../contexts/classes-prop-context';
17
17
  import { useElement } from '../contexts/element-context';
18
18
  import { useStyle } from '../contexts/style-context';
19
19
  import { StyleNotFoundUnderProviderError, StylesProviderCannotUpdatePropsError } from '../errors';
20
+ import { useStylesRerender } from './use-styles-rerender';
20
21
 
21
22
  export function useStylesFields< T extends Props >( propNames: ( keyof T & string )[] ) {
22
23
  const { element } = useElement();
@@ -26,9 +27,7 @@ export function useStylesFields< T extends Props >( propNames: ( keyof T & strin
26
27
  const undoableUpdateStyle = useUndoableUpdateStyle();
27
28
  const undoableCreateElementStyle = useUndoableCreateElementStyle();
28
29
 
29
- const [ , reRender ] = useReducer( ( p ) => ! p, false );
30
-
31
- useEffect( () => provider?.subscribe( reRender ), [ provider ] );
30
+ useStylesRerender();
32
31
 
33
32
  const value = getProps< T >( {
34
33
  elementId: element.id,
@@ -0,0 +1,10 @@
1
+ import { useEffect, useReducer } from 'react';
2
+
3
+ import { useStyle } from '../contexts/style-context';
4
+
5
+ export const useStylesRerender = () => {
6
+ const { provider } = useStyle();
7
+ const [ , reRender ] = useReducer( ( p ) => ! p, false );
8
+
9
+ useEffect( () => provider?.subscribe( reRender ), [ provider ] );
10
+ };
@@ -0,0 +1,70 @@
1
+ import * as React from 'react';
2
+ import { useBoundProp } from '@elementor/editor-controls';
3
+ import { ELEMENTS_STYLES_PROVIDER_KEY } from '@elementor/editor-styles-repository';
4
+ import { styled } from '@elementor/ui';
5
+ import { __ } from '@wordpress/i18n';
6
+
7
+ import { useStyle } from '../contexts/style-context';
8
+ import { useStylesInheritanceField } from '../contexts/styles-inheritance-context';
9
+ import { useStylesField } from '../hooks/use-styles-field';
10
+
11
+ const Circle = styled( 'div', {
12
+ shouldForwardProp: ( prop ) => prop !== 'variant',
13
+ } )< { variant?: 'overridden' | 'local-affects' | 'global-affects' } >`
14
+ width: 5px;
15
+ height: 5px;
16
+ border-radius: 50%;
17
+ background-color: ${ ( { theme, variant } ) => {
18
+ switch ( variant ) {
19
+ case 'overridden':
20
+ return theme.palette.warning.main;
21
+ case 'global-affects':
22
+ return theme.palette.global.main;
23
+ case 'local-affects':
24
+ return theme.palette.primary.main;
25
+ default:
26
+ return theme.palette.text.secondary;
27
+ }
28
+ } };
29
+ `;
30
+
31
+ export const StylesInheritanceIndicator = () => {
32
+ const { bind } = useBoundProp();
33
+ const { id: currentStyleId, provider: currentStyleProvider, meta: currentStyleMeta } = useStyle();
34
+ const [ value ] = useStylesField( bind );
35
+ const inheritanceChain = useStylesInheritanceField( bind );
36
+
37
+ if ( ! inheritanceChain.length ) {
38
+ return null;
39
+ }
40
+
41
+ const [ { styleId, styleVariant } ] = inheritanceChain;
42
+
43
+ const { breakpoint, state } = styleVariant.meta;
44
+
45
+ if (
46
+ styleId === currentStyleId &&
47
+ breakpoint === currentStyleMeta.breakpoint &&
48
+ state === currentStyleMeta.state
49
+ ) {
50
+ return (
51
+ <Circle
52
+ aria-label={ __( 'This is the final value', 'elementor' ) }
53
+ variant={
54
+ currentStyleProvider?.key === ELEMENTS_STYLES_PROVIDER_KEY ? 'local-affects' : 'global-affects'
55
+ }
56
+ />
57
+ );
58
+ }
59
+
60
+ if ( value !== null && value !== undefined ) {
61
+ return (
62
+ <Circle
63
+ aria-label={ __( 'This value is overridden by another style', 'elementor' ) }
64
+ variant="overridden"
65
+ />
66
+ );
67
+ }
68
+
69
+ return <Circle aria-label={ __( 'This has value from another style', 'elementor' ) } />;
70
+ };