@elementor/editor-editing-panel 1.40.0 → 1.42.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/index.d.mts +9 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +1227 -745
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1133 -628
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +7 -6
  9. package/src/action.tsx +26 -0
  10. package/src/components/add-or-remove-content.tsx +11 -3
  11. package/src/components/css-classes/css-class-item.tsx +3 -2
  12. package/src/components/css-classes/css-class-menu.tsx +15 -5
  13. package/src/components/css-classes/css-class-selector.tsx +1 -0
  14. package/src/components/css-classes/use-apply-and-unapply-class.ts +8 -4
  15. package/src/components/section-content.tsx +16 -6
  16. package/src/components/style-sections/background-section/background-section.tsx +6 -3
  17. package/src/components/style-sections/border-section/border-field.tsx +3 -0
  18. package/src/components/style-sections/layout-section/display-field.tsx +2 -1
  19. package/src/components/style-sections/layout-section/flex-order-field.tsx +5 -2
  20. package/src/components/style-sections/layout-section/flex-size-field.tsx +16 -12
  21. package/src/components/style-sections/size-section/object-fit-field.tsx +2 -6
  22. package/src/components/style-sections/size-section/object-position-field.tsx +2 -6
  23. package/src/components/style-sections/size-section/size-section.tsx +4 -10
  24. package/src/components/style-sections/typography-section/text-stroke-field.tsx +3 -0
  25. package/src/components/style-tab.tsx +1 -1
  26. package/src/contexts/style-context.tsx +11 -2
  27. package/src/contexts/styles-inheritance-context.tsx +9 -7
  28. package/src/controls-actions.ts +2 -0
  29. package/src/controls-registry/styles-field.tsx +3 -0
  30. package/src/init.ts +11 -1
  31. package/src/reset-style-props.tsx +31 -0
  32. package/src/styles-inheritance/components/action-icons.tsx +8 -0
  33. package/src/styles-inheritance/components/breakpoint-icon.tsx +47 -0
  34. package/src/styles-inheritance/components/index.ts +4 -0
  35. package/src/styles-inheritance/components/label-chip.tsx +48 -0
  36. package/src/styles-inheritance/components/value-component.tsx +25 -0
  37. package/src/styles-inheritance/consts.ts +17 -0
  38. package/src/styles-inheritance/create-styles-inheritance.ts +50 -12
  39. package/src/styles-inheritance/hooks/use-normalized-inheritance-chain-items.tsx +121 -0
  40. package/src/styles-inheritance/init-styles-inheritance-transformers.ts +38 -0
  41. package/src/styles-inheritance/init.ts +8 -0
  42. package/src/styles-inheritance/styles-inheritance-indicator.tsx +35 -32
  43. package/src/styles-inheritance/styles-inheritance-infotip.tsx +169 -20
  44. package/src/styles-inheritance/styles-inheritance-transformers-registry.tsx +3 -0
  45. package/src/styles-inheritance/transformers/background-color-overlay-transformer.tsx +27 -0
  46. package/src/styles-inheritance/transformers/background-gradient-overlay-transformer.tsx +50 -0
  47. package/src/styles-inheritance/transformers/background-image-overlay-transformer.tsx +79 -0
  48. package/src/styles-inheritance/transformers/background-overlay-transformer.tsx +20 -0
  49. package/src/styles-inheritance/types.ts +8 -2
  50. package/src/hooks/use-normalized-inheritance-chain-items.tsx +0 -75
@@ -1,43 +1,192 @@
1
1
  import * as React from 'react';
2
- import { useMemo } from 'react';
3
- import { createPropsResolver, type PropsResolver, styleTransformersRegistry } from '@elementor/editor-canvas';
2
+ import { useMemo, useState } from 'react';
3
+ import { createPropsResolver, type PropsResolver } from '@elementor/editor-canvas';
4
4
  import { type PropKey, type PropType } from '@elementor/editor-props';
5
- import { Card, CardContent, List, ListItem, ListItemText } from '@elementor/ui';
5
+ import {
6
+ Backdrop,
7
+ Box,
8
+ Card,
9
+ CardContent,
10
+ ClickAwayListener,
11
+ CloseButton,
12
+ IconButton,
13
+ Infotip,
14
+ Stack,
15
+ type Theme,
16
+ Tooltip,
17
+ Typography,
18
+ } from '@elementor/ui';
19
+ import { __ } from '@wordpress/i18n';
6
20
 
7
- import { useNormalizedInheritanceChainItems } from '../hooks/use-normalized-inheritance-chain-items';
21
+ import { useSectionContentRef } from '../components/section-content';
22
+ import { useDirection } from '../hooks/use-direction';
23
+ import { ActionIcons, BreakpointIcon, LabelChip, ValueComponent } from './components';
24
+ import { useNormalizedInheritanceChainItems } from './hooks/use-normalized-inheritance-chain-items';
25
+ import { stylesInheritanceTransformersRegistry } from './styles-inheritance-transformers-registry';
8
26
  import { type SnapshotPropValue } from './types';
9
27
 
10
- type StyleIndicatorInfotipProps = {
28
+ type Props = {
11
29
  inheritanceChain: SnapshotPropValue[];
12
30
  propType: PropType;
13
31
  path: PropKey[];
32
+ label: string;
33
+ children: React.ReactNode;
14
34
  };
15
35
 
16
- export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path }: StyleIndicatorInfotipProps ) => {
36
+ const SIZE = 'tiny';
37
+
38
+ export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path, label, children }: Props ) => {
39
+ const [ showInfotip, setShowInfotip ] = useState< boolean >( false );
40
+ const toggleInfotip = () => setShowInfotip( ( prev ) => ! prev );
41
+ const closeInfotip = () => setShowInfotip( false );
42
+
17
43
  const key = path.join( '.' );
18
44
 
45
+ const sectionContentRef = useSectionContentRef();
46
+ const sectionContentWidth = sectionContentRef?.current?.offsetWidth ?? 320;
47
+
19
48
  const resolve = useMemo< PropsResolver >( () => {
20
49
  return createPropsResolver( {
21
- transformers: styleTransformersRegistry,
50
+ transformers: stylesInheritanceTransformersRegistry,
22
51
  schema: { [ key ]: propType },
23
52
  } );
24
53
  }, [ key, propType ] );
25
54
 
26
55
  const items = useNormalizedInheritanceChainItems( inheritanceChain, key, resolve );
27
56
 
57
+ const infotipContent = (
58
+ <ClickAwayListener onClickAway={ closeInfotip }>
59
+ <Card
60
+ elevation={ 0 }
61
+ sx={ {
62
+ width: `${ sectionContentWidth }px`,
63
+ maxWidth: 500,
64
+ overflowX: 'hidden',
65
+ } }
66
+ >
67
+ <CardContent
68
+ sx={ {
69
+ display: 'flex',
70
+ gap: 0.5,
71
+ flexDirection: 'column',
72
+ p: 0,
73
+ '&:last-child': {
74
+ pb: 0,
75
+ },
76
+ } }
77
+ >
78
+ <Stack direction="row" alignItems="center" sx={ { pl: 1.5, pr: 0.5, minHeight: 36, py: 0.5 } }>
79
+ <Typography variant="subtitle2" color="secondary" sx={ { fontSize: 12, fontWeight: '500' } }>
80
+ { __( 'Style origin', 'elementor' ) }
81
+ </Typography>
82
+ <CloseButton
83
+ slotProps={ { icon: { fontSize: SIZE } } }
84
+ sx={ { ml: 'auto' } }
85
+ onClick={ closeInfotip }
86
+ />
87
+ </Stack>
88
+ <Stack
89
+ gap={ 1.5 }
90
+ sx={ { pl: 2, pr: 1, pb: 2, overflowX: 'hidden', overflowY: 'auto' } }
91
+ role="list"
92
+ >
93
+ { items.map( ( item, index ) => {
94
+ return (
95
+ <Box
96
+ key={ item.id }
97
+ display="flex"
98
+ gap={ 0.5 }
99
+ role="listitem"
100
+ /* translators: %s: Label of the inheritance item */
101
+ aria-label={ __( 'Inheritance item: %s', 'elementor' ).replace(
102
+ '%s',
103
+ item.displayLabel
104
+ ) }
105
+ >
106
+ <Box display="flex" gap={ 0.5 } sx={ { flexWrap: 'wrap', width: '100%' } }>
107
+ <BreakpointIcon breakpoint={ item.breakpoint } />
108
+ <LabelChip
109
+ displayLabel={ item.displayLabel }
110
+ provider={ item.provider }
111
+ chipColor={ item.chipColor }
112
+ />
113
+ <ValueComponent index={ index } value={ item.value } />
114
+ </Box>
115
+ <ActionIcons />
116
+ </Box>
117
+ );
118
+ } ) }
119
+ </Stack>
120
+ </CardContent>
121
+ </Card>
122
+ </ClickAwayListener>
123
+ );
124
+
28
125
  return (
29
- <Card elevation={ 0 } sx={ { maxWidth: 320 } }>
30
- <CardContent sx={ { p: 1.5, pb: 2.5 } }>
31
- <List>
32
- { items.map( ( item ) => (
33
- <ListItem key={ item.id }>
34
- <ListItemText
35
- primary={ `${ item.breakpoint } | ${ item.displayLabel }. ${ item.value }` }
36
- />
37
- </ListItem>
38
- ) ) }
39
- </List>
40
- </CardContent>
41
- </Card>
126
+ <TooltipOrInfotip showInfotip={ showInfotip } onClose={ closeInfotip } infotipContent={ infotipContent }>
127
+ <IconButton onClick={ toggleInfotip } aria-label={ label } sx={ { my: '-1px' } }>
128
+ { children }
129
+ </IconButton>
130
+ </TooltipOrInfotip>
42
131
  );
43
132
  };
133
+
134
+ function TooltipOrInfotip( {
135
+ children,
136
+ showInfotip,
137
+ onClose,
138
+ infotipContent,
139
+ }: {
140
+ children: React.ReactNode;
141
+ showInfotip: boolean;
142
+ onClose: () => void;
143
+ infotipContent: React.ReactNode;
144
+ } ) {
145
+ const { isSiteRtl } = useDirection();
146
+ const forceInfotipAlignLeft = isSiteRtl ? 9999999 : -9999999;
147
+
148
+ if ( showInfotip ) {
149
+ return (
150
+ <>
151
+ <Backdrop
152
+ open={ showInfotip }
153
+ onClick={ onClose }
154
+ sx={ {
155
+ backgroundColor: 'transparent',
156
+ zIndex: ( theme: Theme ) => theme.zIndex.modal - 1,
157
+ } }
158
+ />
159
+ <Infotip
160
+ placement="top"
161
+ content={ infotipContent }
162
+ open={ showInfotip }
163
+ onClose={ onClose }
164
+ disableHoverListener
165
+ componentsProps={ {
166
+ tooltip: {
167
+ sx: { mx: 2 },
168
+ },
169
+ } }
170
+ slotProps={ {
171
+ popper: {
172
+ modifiers: [
173
+ {
174
+ name: 'offset',
175
+ options: { offset: [ forceInfotipAlignLeft, 0 ] },
176
+ },
177
+ ],
178
+ },
179
+ } }
180
+ >
181
+ { children }
182
+ </Infotip>
183
+ </>
184
+ );
185
+ }
186
+
187
+ return (
188
+ <Tooltip title={ __( 'Style origin', 'elementor' ) } placement="top">
189
+ { children }
190
+ </Tooltip>
191
+ );
192
+ }
@@ -0,0 +1,3 @@
1
+ import { createTransformersRegistry } from '@elementor/editor-canvas';
2
+
3
+ export const stylesInheritanceTransformersRegistry = createTransformersRegistry();
@@ -0,0 +1,27 @@
1
+ import * as React from 'react';
2
+ import { createTransformer } from '@elementor/editor-canvas';
3
+ import { Stack, styled, UnstableColorIndicator } from '@elementor/ui';
4
+
5
+ export type Color = {
6
+ color: string;
7
+ };
8
+
9
+ export const backgroundColorOverlayTransformer = createTransformer( ( value: Color ) => (
10
+ <Stack direction="row" gap={ 10 }>
11
+ <ItemIconColor value={ value } />
12
+ <ItemLabelColor value={ value } />
13
+ </Stack>
14
+ ) );
15
+
16
+ const ItemIconColor = ( { value }: { value: Color } ) => {
17
+ const { color } = value;
18
+ return <StyledUnstableColorIndicator size="inherit" component="span" value={ color } />;
19
+ };
20
+
21
+ const ItemLabelColor = ( { value: { color } }: { value: Color } ) => {
22
+ return <span>{ color }</span>;
23
+ };
24
+
25
+ export const StyledUnstableColorIndicator = styled( UnstableColorIndicator )( ( { theme } ) => ( {
26
+ borderRadius: `${ theme.shape.borderRadius / 2 }px`,
27
+ } ) );
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import { createTransformer } from '@elementor/editor-canvas';
3
+ import { Stack } from '@elementor/ui';
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ import { type Color, StyledUnstableColorIndicator } from './background-color-overlay-transformer';
7
+
8
+ type ColorStop = Color & {
9
+ offset: number;
10
+ };
11
+
12
+ type Gradient = {
13
+ type: string;
14
+ angle?: number;
15
+ positions?: string;
16
+ stops: ColorStop[];
17
+ };
18
+
19
+ export const backgroundGradientOverlayTransformer = createTransformer( ( value: Gradient ) => (
20
+ <Stack direction="row" gap={ 10 }>
21
+ <ItemIconGradient value={ value } />
22
+ <ItemLabelGradient value={ value } />
23
+ </Stack>
24
+ ) );
25
+
26
+ const ItemIconGradient = ( { value }: { value: Gradient } ) => {
27
+ const gradient = getGradientValue( value );
28
+
29
+ return <StyledUnstableColorIndicator size="inherit" component="span" value={ gradient } />;
30
+ };
31
+
32
+ const ItemLabelGradient = ( { value }: { value: Gradient } ) => {
33
+ if ( value.type === 'linear' ) {
34
+ return <span>{ __( 'Linear Gradient', 'elementor' ) }</span>;
35
+ }
36
+
37
+ return <span>{ __( 'Radial Gradient', 'elementor' ) }</span>;
38
+ };
39
+
40
+ const getGradientValue = ( gradient: Gradient ) => {
41
+ const stops = gradient.stops
42
+ ?.map( ( { color, offset }: ColorStop ) => `${ color } ${ offset ?? 0 }%` )
43
+ ?.join( ',' );
44
+
45
+ if ( gradient.type === 'linear' ) {
46
+ return `linear-gradient(${ gradient.angle }deg, ${ stops })`;
47
+ }
48
+
49
+ return `radial-gradient(circle at ${ gradient.positions }, ${ stops })`;
50
+ };
@@ -0,0 +1,79 @@
1
+ import * as React from 'react';
2
+ import { createTransformer } from '@elementor/editor-canvas';
3
+ import { EllipsisWithTooltip } from '@elementor/editor-ui';
4
+ import { CardMedia, Stack, type Theme } from '@elementor/ui';
5
+ import { useWpMediaAttachment } from '@elementor/wp-media';
6
+
7
+ type ImageSrcAttachment = { id: number; url: null };
8
+
9
+ type ImageSrcUrl = { url: string; id: null };
10
+
11
+ type Image = {
12
+ image: {
13
+ src: ImageSrcAttachment | ImageSrcUrl;
14
+ size: 'thumbnail' | 'medium' | 'large' | 'full';
15
+ };
16
+ };
17
+
18
+ export const backgroundImageOverlayTransformer = createTransformer( ( value: Image ) => (
19
+ <Stack direction="row" gap={ 10 }>
20
+ <ItemIconImage value={ value } />
21
+ <ItemLabelImage value={ value } />
22
+ </Stack>
23
+ ) );
24
+
25
+ const ItemIconImage = ( { value }: { value: Image } ) => {
26
+ const { imageUrl } = useImage( value );
27
+
28
+ return (
29
+ <CardMedia
30
+ image={ imageUrl }
31
+ sx={ ( theme: Theme ) => ( {
32
+ height: '1em',
33
+ width: '1em',
34
+ borderRadius: `${ theme.shape.borderRadius / 2 }px`,
35
+ outline: `1px solid ${ theme.palette.action.disabled }`,
36
+ } ) }
37
+ />
38
+ );
39
+ };
40
+
41
+ const ItemLabelImage = ( { value }: { value: Image } ) => {
42
+ const { imageTitle } = useImage( value );
43
+
44
+ return (
45
+ <EllipsisWithTooltip title={ imageTitle }>
46
+ <span>{ imageTitle }</span>
47
+ </EllipsisWithTooltip>
48
+ );
49
+ };
50
+
51
+ const useImage = ( image: Image ) => {
52
+ let imageTitle,
53
+ imageUrl: string | null = null;
54
+
55
+ const imageSrc = image?.image.src;
56
+ const { data: attachment } = useWpMediaAttachment( imageSrc.id || null );
57
+
58
+ if ( imageSrc.id ) {
59
+ const imageFileTypeExtension = getFileExtensionFromFilename( attachment?.filename );
60
+ imageTitle = `${ attachment?.title }${ imageFileTypeExtension }` || null;
61
+ imageUrl = attachment?.url || null;
62
+ } else if ( imageSrc.url ) {
63
+ imageUrl = imageSrc.url;
64
+ imageTitle = imageUrl?.substring( imageUrl.lastIndexOf( '/' ) + 1 ) || null;
65
+ }
66
+
67
+ return { imageTitle, imageUrl };
68
+ };
69
+
70
+ const getFileExtensionFromFilename = ( filename?: string ) => {
71
+ if ( ! filename ) {
72
+ return '';
73
+ }
74
+
75
+ // get the substring after the last . in the filename
76
+ const extension = filename.substring( filename.lastIndexOf( '.' ) + 1 );
77
+
78
+ return `.${ extension }`;
79
+ };
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import { type ReactNode } from 'react';
3
+ import { createTransformer } from '@elementor/editor-canvas';
4
+ import { Stack } from '@elementor/ui';
5
+
6
+ type BackgroundOverlay = ReactNode[];
7
+
8
+ export const backgroundOverlayTransformer = createTransformer( ( values: BackgroundOverlay[] ) => {
9
+ if ( ! values || values.length === 0 ) {
10
+ return null;
11
+ }
12
+
13
+ return (
14
+ <Stack direction="column">
15
+ { values.map( ( item, index ) => (
16
+ <Stack key={ index }>{ item }</Stack>
17
+ ) ) }
18
+ </Stack>
19
+ );
20
+ } );
@@ -1,4 +1,4 @@
1
- import { type PropValue } from '@elementor/editor-props';
1
+ import { type PropKey, type PropType, type PropValue } from '@elementor/editor-props';
2
2
  import { type BreakpointId } from '@elementor/editor-responsive';
3
3
  import { type StyleDefinition, type StyleDefinitionState, type StyleDefinitionVariant } from '@elementor/editor-styles';
4
4
 
@@ -44,5 +44,11 @@ export type StylesInheritanceSnapshotGetter = (
44
44
 
45
45
  export type StylesInheritanceAPI = {
46
46
  getSnapshot: ( meta: StyleInheritanceMetaProps ) => StylesInheritanceSnapshot | undefined;
47
- getInheritanceChain: ( snapshotField: StylesInheritanceSnapshot, path: string[] ) => SnapshotPropValue[];
47
+ getInheritanceChain: (
48
+ snapshotField: StylesInheritanceSnapshot,
49
+ path: PropKey[],
50
+ basePropType: PropType
51
+ ) => SnapshotPropValue[];
48
52
  };
53
+
54
+ export type ChipColors = 'default' | 'global' | 'accent';
@@ -1,75 +0,0 @@
1
- import { type ReactNode, useEffect, useState } from 'react';
2
- import { type PropsResolver } from '@elementor/editor-canvas';
3
- import { type PropKey } from '@elementor/editor-props';
4
- import { type StyleDefinitionVariant } from '@elementor/editor-styles';
5
-
6
- import { type SnapshotPropValue } from '../styles-inheritance/types';
7
-
8
- const MAXIMUM_ITEMS = 2;
9
-
10
- type NormalizedItem = {
11
- id: string | number;
12
- breakpoint?: StyleDefinitionVariant[ 'meta' ][ 'breakpoint' ];
13
- displayLabel: string;
14
- value: ReactNode | string;
15
- };
16
-
17
- export const useNormalizedInheritanceChainItems = (
18
- inheritanceChain: SnapshotPropValue[],
19
- bind: PropKey,
20
- resolve: PropsResolver
21
- ) => {
22
- const [ items, setItems ] = useState< NormalizedItem[] >( [] );
23
-
24
- useEffect( () => {
25
- ( async () => {
26
- const normalizedItems = await Promise.all(
27
- inheritanceChain
28
- .filter( ( item ) => item.style?.label )
29
- .map( ( item, index ) => normalizeInheritanceItem( item, index, bind, resolve ) )
30
- );
31
-
32
- const validItems = normalizedItems.filter( ( item ) => item.value !== '' ).slice( 0, MAXIMUM_ITEMS );
33
-
34
- setItems( validItems );
35
- } )();
36
- }, [ inheritanceChain, bind, resolve ] );
37
-
38
- return items;
39
- };
40
-
41
- export const normalizeInheritanceItem = async (
42
- item: SnapshotPropValue,
43
- index: number,
44
- bind: PropKey,
45
- resolve: PropsResolver
46
- ): Promise< NormalizedItem > => {
47
- const state = item.variant?.meta?.state || '';
48
- const label = item.style?.label || '';
49
- const displayLabel = state ? `${ label }:${ state }` : label;
50
-
51
- return {
52
- id: item.style?.id ? item.style?.id + state : index,
53
- breakpoint: item.variant?.meta?.breakpoint,
54
- displayLabel,
55
- value: await getTransformedValue( item, bind, resolve ),
56
- };
57
- };
58
-
59
- const getTransformedValue = async (
60
- item: SnapshotPropValue,
61
- bind: PropKey,
62
- resolve: PropsResolver
63
- ): Promise< string > => {
64
- try {
65
- const result = await resolve( {
66
- props: {
67
- [ bind ]: item.value,
68
- },
69
- } );
70
-
71
- return Object.values( result ).join( ' ' );
72
- } catch {
73
- return '';
74
- }
75
- };