@elementor/editor-editing-panel 1.39.0 → 1.41.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 +44 -0
  2. package/dist/index.d.mts +9 -0
  3. package/dist/index.d.ts +9 -0
  4. package/dist/index.js +1182 -735
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1075 -617
  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/creatable-autocomplete/creatable-autocomplete.tsx +6 -2
  12. package/src/components/css-classes/css-class-item.tsx +3 -2
  13. package/src/components/css-classes/css-class-menu.tsx +15 -5
  14. package/src/components/css-classes/css-class-selector.tsx +2 -1
  15. package/src/components/css-classes/use-apply-and-unapply-class.ts +8 -4
  16. package/src/components/section-content.tsx +16 -6
  17. package/src/components/style-sections/background-section/background-section.tsx +6 -3
  18. package/src/components/style-sections/border-section/border-field.tsx +3 -0
  19. package/src/components/style-sections/layout-section/display-field.tsx +2 -1
  20. package/src/components/style-sections/layout-section/flex-order-field.tsx +5 -2
  21. package/src/components/style-sections/layout-section/flex-size-field.tsx +16 -12
  22. package/src/components/style-sections/size-section/object-fit-field.tsx +1 -1
  23. package/src/components/style-sections/size-section/object-position-field.tsx +1 -1
  24. package/src/components/style-sections/size-section/size-section.tsx +12 -11
  25. package/src/components/style-sections/typography-section/text-stroke-field.tsx +3 -0
  26. package/src/components/style-tab.tsx +1 -1
  27. package/src/contexts/style-context.tsx +11 -2
  28. package/src/contexts/styles-inheritance-context.tsx +9 -7
  29. package/src/controls-actions.ts +2 -0
  30. package/src/controls-registry/styles-field.tsx +3 -0
  31. package/src/init.ts +11 -1
  32. package/src/reset-style-props.tsx +31 -0
  33. package/src/styles-inheritance/components/action-icons.tsx +8 -0
  34. package/src/styles-inheritance/components/breakpoint-icon.tsx +47 -0
  35. package/src/styles-inheritance/components/index.ts +4 -0
  36. package/src/styles-inheritance/components/label-chip.tsx +43 -0
  37. package/src/styles-inheritance/components/value-component.tsx +25 -0
  38. package/src/styles-inheritance/consts.ts +17 -0
  39. package/src/styles-inheritance/create-styles-inheritance.ts +50 -12
  40. package/src/{hooks → styles-inheritance/hooks}/use-normalized-inheritance-chain-items.tsx +41 -11
  41. package/src/styles-inheritance/init-styles-inheritance-transformers.ts +38 -0
  42. package/src/styles-inheritance/init.ts +8 -0
  43. package/src/styles-inheritance/styles-inheritance-indicator.tsx +35 -32
  44. package/src/styles-inheritance/styles-inheritance-infotip.tsx +113 -19
  45. package/src/styles-inheritance/styles-inheritance-transformers-registry.tsx +3 -0
  46. package/src/styles-inheritance/transformers/background-color-overlay-transformer.tsx +27 -0
  47. package/src/styles-inheritance/transformers/background-gradient-overlay-transformer.tsx +50 -0
  48. package/src/styles-inheritance/transformers/background-image-overlay-transformer.tsx +79 -0
  49. package/src/styles-inheritance/transformers/background-overlay-transformer.tsx +20 -0
  50. package/src/styles-inheritance/types.ts +6 -2
@@ -1,43 +1,137 @@
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 { Box, Card, CardContent, CloseButton, IconButton, Infotip, Stack, Typography } from '@elementor/ui';
6
+ import { __ } from '@wordpress/i18n';
6
7
 
7
- import { useNormalizedInheritanceChainItems } from '../hooks/use-normalized-inheritance-chain-items';
8
+ import { useSectionContentRef } from '../components/section-content';
9
+ import { useDirection } from '../hooks/use-direction';
10
+ import { ActionIcons, BreakpointIcon, LabelChip, ValueComponent } from './components';
11
+ import { useNormalizedInheritanceChainItems } from './hooks/use-normalized-inheritance-chain-items';
12
+ import { stylesInheritanceTransformersRegistry } from './styles-inheritance-transformers-registry';
8
13
  import { type SnapshotPropValue } from './types';
9
14
 
10
- type StyleIndicatorInfotipProps = {
15
+ type Props = {
11
16
  inheritanceChain: SnapshotPropValue[];
12
17
  propType: PropType;
13
18
  path: PropKey[];
19
+ label: string;
20
+ children: React.ReactNode;
14
21
  };
15
22
 
16
- export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path }: StyleIndicatorInfotipProps ) => {
23
+ const SIZE = 'tiny';
24
+
25
+ export const StyleIndicatorInfotip = ( { inheritanceChain, propType, path, label, children }: Props ) => {
26
+ const [ open, setOpen ] = useState( false );
27
+ const { isSiteRtl } = useDirection();
17
28
  const key = path.join( '.' );
18
29
 
30
+ const sectionContentRef = useSectionContentRef();
31
+ const sectionContentWidth = sectionContentRef?.current?.offsetWidth ?? 320;
32
+
19
33
  const resolve = useMemo< PropsResolver >( () => {
20
34
  return createPropsResolver( {
21
- transformers: styleTransformersRegistry,
35
+ transformers: stylesInheritanceTransformersRegistry,
22
36
  schema: { [ key ]: propType },
23
37
  } );
24
38
  }, [ key, propType ] );
25
39
 
26
40
  const items = useNormalizedInheritanceChainItems( inheritanceChain, key, resolve );
27
41
 
28
- 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>
42
+ const toggleOpen = () => setOpen( ( prev ) => ! prev );
43
+ const closeInfotip = () => {
44
+ setOpen( false );
45
+ };
46
+
47
+ const forceInfotipAlignLeft = isSiteRtl ? 9999999 : -9999999;
48
+
49
+ const infotipContent = (
50
+ <Card
51
+ elevation={ 0 }
52
+ sx={ {
53
+ width: `${ sectionContentWidth }px`,
54
+ maxWidth: 500,
55
+ overflowX: 'hidden',
56
+ } }
57
+ >
58
+ <CardContent
59
+ sx={ {
60
+ display: 'flex',
61
+ gap: 0.5,
62
+ flexDirection: 'column',
63
+ p: 0,
64
+ '&:last-child': {
65
+ pb: 0,
66
+ },
67
+ } }
68
+ >
69
+ <Stack direction="row" alignItems="center" sx={ { pl: 1.5, pr: 0.5, minHeight: 36, py: 0.5 } }>
70
+ <Typography variant="subtitle2" color="secondary" sx={ { fontSize: 12, fontWeight: '500' } }>
71
+ { __( 'Style origin', 'elementor' ) }
72
+ </Typography>
73
+ <CloseButton
74
+ slotProps={ { icon: { fontSize: SIZE } } }
75
+ sx={ { ml: 'auto' } }
76
+ onClick={ closeInfotip }
77
+ />
78
+ </Stack>
79
+ <Stack gap={ 1.5 } sx={ { pl: 2, pr: 1, pb: 2, overflowX: 'hidden', overflowY: 'auto' } } role="list">
80
+ { items.map( ( item, index ) => {
81
+ return (
82
+ <Box
83
+ key={ item.id }
84
+ display="flex"
85
+ gap={ 0.5 }
86
+ role="listitem"
87
+ /* translators: %s: Label of the inheritance item */
88
+ aria-label={ __( 'Inheritance item: %s', 'elementor' ).replace(
89
+ '%s',
90
+ item.displayLabel
91
+ ) }
92
+ >
93
+ <Box display="flex" gap={ 0.5 } sx={ { flexWrap: 'wrap', width: '100%' } }>
94
+ <BreakpointIcon breakpoint={ item.breakpoint } />
95
+ <LabelChip displayLabel={ item.displayLabel } provider={ item.provider } />
96
+ <ValueComponent index={ index } value={ item.value } />
97
+ </Box>
98
+ <ActionIcons />
99
+ </Box>
100
+ );
101
+ } ) }
102
+ </Stack>
40
103
  </CardContent>
41
104
  </Card>
42
105
  );
106
+
107
+ return (
108
+ <Infotip
109
+ placement="top"
110
+ content={ infotipContent }
111
+ open={ open }
112
+ onClose={ closeInfotip }
113
+ disableHoverListener={ true }
114
+ componentsProps={ {
115
+ tooltip: {
116
+ sx: {
117
+ mx: 2,
118
+ },
119
+ },
120
+ } }
121
+ slotProps={ {
122
+ popper: {
123
+ modifiers: [
124
+ {
125
+ name: 'offset',
126
+ options: { offset: [ forceInfotipAlignLeft, 0 ] },
127
+ },
128
+ ],
129
+ },
130
+ } }
131
+ >
132
+ <IconButton onClick={ toggleOpen } aria-label={ label } sx={ { my: '-1px' } }>
133
+ { children }
134
+ </IconButton>
135
+ </Infotip>
136
+ );
43
137
  };
@@ -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,9 @@ 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
  };