@elementor/editor-editing-panel 1.31.0 → 1.32.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/CHANGELOG.md +14 -0
- package/dist/index.js +454 -355
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +366 -267
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/hooks/use-normalized-inheritance-chain-items.tsx +68 -0
- package/src/styles-inheritance/styles-inheritance-indicator.tsx +65 -19
- package/src/styles-inheritance/styles-inheritance-infotip.tsx +50 -0
- package/src/sync/get-experiments-config.ts +7 -0
- package/src/sync/types.ts +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-editing-panel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@elementor/editor": "0.19.1",
|
|
43
|
-
"@elementor/editor-canvas": "0.
|
|
44
|
-
"@elementor/editor-controls": "0.28.
|
|
45
|
-
"@elementor/editor-current-user": "0.3.
|
|
43
|
+
"@elementor/editor-canvas": "0.20.0",
|
|
44
|
+
"@elementor/editor-controls": "0.28.1",
|
|
45
|
+
"@elementor/editor-current-user": "0.3.1",
|
|
46
46
|
"@elementor/editor-elements": "0.8.1",
|
|
47
47
|
"@elementor/editor-panels": "0.15.1",
|
|
48
48
|
"@elementor/editor-props": "0.12.0",
|
|
@@ -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
|
-
|
|
31
|
-
style.id === currentStyleId &&
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 (
|
|
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
|
|
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
|
+
};
|
package/src/sync/types.ts
CHANGED