@elementor/editor-editing-panel 1.3.0 → 1.4.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.3.0",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -40,13 +40,14 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@elementor/editor": "0.17.2",
43
- "@elementor/editor-controls": "0.2.0",
44
- "@elementor/editor-elements": "0.3.2",
43
+ "@elementor/editor-controls": "0.3.0",
44
+ "@elementor/editor-elements": "0.3.3",
45
45
  "@elementor/menus": "0.1.2",
46
- "@elementor/editor-props": "0.4.0",
46
+ "@elementor/editor-props": "0.5.0",
47
47
  "@elementor/editor-panels": "0.10.2",
48
48
  "@elementor/editor-responsive": "0.12.4",
49
- "@elementor/editor-styles": "0.3.1",
49
+ "@elementor/editor-styles": "0.3.2",
50
+ "@elementor/editor-styles-repository": "0.2.0",
50
51
  "@elementor/editor-v1-adapters": "0.8.5",
51
52
  "@elementor/icons": "^1.20.0",
52
53
  "@elementor/schema": "0.1.2",
@@ -0,0 +1,52 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import * as React from 'react';
3
+ import { Box, Tooltip } from '@elementor/ui';
4
+
5
+ type ConditionalTooltipWrapperProps = {
6
+ maxWidth: React.CSSProperties[ 'maxWidth' ];
7
+ title: string;
8
+ };
9
+
10
+ export const ConditionalTooltipWrapper = ( { maxWidth, title }: ConditionalTooltipWrapperProps ) => {
11
+ const elRef = useRef< HTMLElement >( null );
12
+ const [ isOverflown, setIsOverflown ] = useState( false );
13
+
14
+ useEffect( () => {
15
+ const onResize = () => {
16
+ const element = elRef.current;
17
+
18
+ if ( element ) {
19
+ setIsOverflown( element.scrollWidth > element.clientWidth );
20
+ }
21
+ };
22
+
23
+ onResize();
24
+
25
+ window.addEventListener( 'resize', onResize );
26
+
27
+ return () => {
28
+ window.removeEventListener( 'resize', onResize );
29
+ };
30
+ }, [] );
31
+
32
+ if ( isOverflown ) {
33
+ return (
34
+ <Tooltip title={ title } placement="top">
35
+ <Content maxWidth={ maxWidth } ref={ elRef } title={ title } />
36
+ </Tooltip>
37
+ );
38
+ }
39
+
40
+ return <Content maxWidth={ maxWidth } ref={ elRef } title={ title } />;
41
+ };
42
+
43
+ const Content = React.forwardRef( ( { maxWidth, title, ...rest }: ConditionalTooltipWrapperProps, ref ) => (
44
+ <Box
45
+ ref={ ref }
46
+ position="relative"
47
+ sx={ { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth } }
48
+ { ...rest }
49
+ >
50
+ { title }
51
+ </Box>
52
+ ) );
@@ -1,32 +1,44 @@
1
1
  import * as React from 'react';
2
- import { updateSettings, useElementSetting, useElementStyles } from '@elementor/editor-elements';
2
+ import { updateSettings, useElementSetting } from '@elementor/editor-elements';
3
3
  import { classesPropTypeUtil, type ClassesPropValue } from '@elementor/editor-props';
4
4
  import { type StyleDefinitionID } from '@elementor/editor-styles';
5
+ import { ELEMENTS_STYLES_PROVIDER_KEY, useAllStylesByProvider } from '@elementor/editor-styles-repository';
5
6
  import { Chip, Stack, Typography } from '@elementor/ui';
6
7
  import { __ } from '@wordpress/i18n';
7
8
 
8
9
  import { useClassesProp } from '../contexts/classes-prop-context';
9
10
  import { useElement } from '../contexts/element-context';
10
11
  import { useStyle } from '../contexts/style-context';
12
+ import { ConditionalTooltipWrapper } from './conditional-tooltip-wrapper';
11
13
  import { MultiCombobox, type Option } from './multi-combobox';
12
14
 
13
15
  const ID = 'elementor-css-class-selector';
14
16
  const TAGS_LIMIT = 8;
15
17
 
18
+ const EMPTY_OPTION = {
19
+ label: __( 'local', 'elementor' ),
20
+ value: '',
21
+ fixed: true,
22
+ color: 'primary',
23
+ provider: ELEMENTS_STYLES_PROVIDER_KEY,
24
+ } satisfies Option;
25
+
26
+ /**
27
+ * Applied - Classes applied to an element.
28
+ * Active - Class that is currently on edit mode.
29
+ */
30
+
16
31
  export function CssClassSelector() {
17
32
  const options = useOptions();
33
+ const [ appliedIds, setAppliedIds ] = useAppliedClassesIds();
18
34
 
19
35
  const { id: activeId, setId: setActiveId } = useStyle();
20
- const [ appliedIds ] = useAppliedClassesIds();
21
36
 
22
- const handleApply = useHandleApply();
37
+ const handleApply = useHandleApply( appliedIds, setAppliedIds );
23
38
  const handleActivate = ( { value }: Option ) => setActiveId( value );
24
39
 
25
- const active = options.find( ( option ) => option.value === activeId ) || null;
26
-
27
- const applied = appliedIds
28
- .map( ( id ) => options.find( ( option ) => option.value === id ) )
29
- .filter( ( option ) => !! option );
40
+ const applied = useAppliedOptions( options, appliedIds );
41
+ const active = applied.find( ( option ) => option.value === activeId ) ?? EMPTY_OPTION;
30
42
 
31
43
  return (
32
44
  <Stack gap={ 1 } p={ 2 }>
@@ -51,11 +63,12 @@ export function CssClassSelector() {
51
63
  { ...chipProps }
52
64
  key={ chipProps.key }
53
65
  size="small"
54
- label={ value.label }
66
+ label={ <ConditionalTooltipWrapper maxWidth="10ch" title={ value.label } /> }
55
67
  variant={ isActive ? 'filled' : 'standard' }
56
68
  color={ isActive && value.color ? value.color : 'default' }
57
69
  onClick={ () => handleActivate( value ) }
58
70
  onDelete={ null }
71
+ aria-pressed={ isActive }
59
72
  />
60
73
  );
61
74
  } )
@@ -68,14 +81,40 @@ export function CssClassSelector() {
68
81
  function useOptions() {
69
82
  const { element } = useElement();
70
83
 
71
- const styleDefs = useElementStyles( element.id );
84
+ return useAllStylesByProvider( { elementId: element.id } ).flatMap< Option >( ( [ providerKey, styleDefs ] ) => {
85
+ const isElements = providerKey === ELEMENTS_STYLES_PROVIDER_KEY;
86
+
87
+ // Add empty local option for elements, as fallback.
88
+ if ( isElements && styleDefs.length === 0 ) {
89
+ return [ EMPTY_OPTION ];
90
+ }
91
+
92
+ return styleDefs.map( ( styleDef ) => {
93
+ return {
94
+ label: styleDef.label,
95
+ value: styleDef.id,
96
+ fixed: isElements,
97
+ color: isElements ? 'primary' : 'global',
98
+ provider: providerKey,
99
+ };
100
+ } );
101
+ } );
102
+ }
103
+
104
+ function useAppliedOptions( options: Option[], appliedIds: StyleDefinitionID[] ) {
105
+ const applied = appliedIds
106
+ .map( ( id ) => options.find( ( option ) => option.value === id ) )
107
+ .filter( ( option ) => !! option );
108
+
109
+ const hasElementsProviderStyleApplied = applied.some(
110
+ ( option ) => option.provider === ELEMENTS_STYLES_PROVIDER_KEY
111
+ );
72
112
 
73
- return Object.values( styleDefs ).map< Option >( ( styleDef ) => ( {
74
- label: styleDef.label,
75
- value: styleDef.id,
76
- fixed: true,
77
- color: 'primary',
78
- } ) );
113
+ if ( ! hasElementsProviderStyleApplied ) {
114
+ applied.unshift( EMPTY_OPTION );
115
+ }
116
+
117
+ return applied;
79
118
  }
80
119
 
81
120
  function useAppliedClassesIds() {
@@ -96,12 +135,13 @@ function useAppliedClassesIds() {
96
135
  return [ value, setValue ] as const;
97
136
  }
98
137
 
99
- function useHandleApply() {
138
+ function useHandleApply( appliedIds: StyleDefinitionID[], setAppliedIds: ( ids: StyleDefinitionID[] ) => void ) {
100
139
  const { id: activeId, setId: setActiveId } = useStyle();
101
- const [ appliedIds, setAppliedIds ] = useAppliedClassesIds();
102
140
 
103
141
  return ( selectedOptions: Option[] ) => {
104
- const selectedValues = selectedOptions.map( ( { value } ) => value );
142
+ const selectedValues = selectedOptions
143
+ .map( ( { value } ) => value )
144
+ .filter( ( value ) => value !== EMPTY_OPTION.value );
105
145
 
106
146
  const isSameClassesAlreadyApplied =
107
147
  selectedValues.length === appliedIds.length &&
@@ -4,6 +4,7 @@ export type Option = {
4
4
  fixed?: boolean;
5
5
  // TODO: Should be remove from here or use some kind of `meta`
6
6
  color?: 'primary' | 'global';
7
+ provider?: string;
7
8
  };
8
9
 
9
10
  export type Action = {
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+ import { GapControl } from '@elementor/editor-controls';
3
+ import { Stack } from '@elementor/ui';
4
+ import { __ } from '@wordpress/i18n';
5
+
6
+ import { StylesField } from '../../../controls-registry/styles-field';
7
+
8
+ export type Gap = 'column' | 'row';
9
+
10
+ export const GapControlField = () => {
11
+ return (
12
+ <Stack gap={ 1 }>
13
+ <StylesField bind={ 'gap' }>
14
+ <GapControl label={ __( 'Gaps', 'elementor' ) } />
15
+ </StylesField>
16
+ </Stack>
17
+ );
18
+ };
@@ -11,6 +11,7 @@ import { DisplayField } from './display-field';
11
11
  import { FlexDirectionField } from './flex-direction-field';
12
12
  import { FlexOrderField } from './flex-order-field';
13
13
  import { FlexSizeField } from './flex-size-field';
14
+ import { GapControlField } from './gap-control-field';
14
15
  import { JustifyContentField } from './justify-content-field';
15
16
  import { WrapField } from './wrap-field';
16
17
 
@@ -31,6 +32,7 @@ const FlexFields = () => (
31
32
  <JustifyContentField />
32
33
  <AlignItemsField />
33
34
  <Divider />
35
+ <GapControlField />
34
36
  <WrapField />
35
37
  <Divider />
36
38
  <ControlLabel>{ __( 'Flex child', 'elementor' ) }</ControlLabel>
@@ -3,7 +3,7 @@ import { useState } from 'react';
3
3
  import { useElementSetting, useElementStyles } from '@elementor/editor-elements';
4
4
  import { type ClassesPropValue, type PropKey } from '@elementor/editor-props';
5
5
  import { useActiveBreakpoint } from '@elementor/editor-responsive';
6
- import { generateId, type StyleDefinition } from '@elementor/editor-styles';
6
+ import { type StyleDefinition } from '@elementor/editor-styles';
7
7
  import { Divider } from '@elementor/ui';
8
8
  import { __ } from '@wordpress/i18n';
9
9
 
@@ -70,9 +70,7 @@ function useActiveStyleDefId( currentClassesProp: PropKey ) {
70
70
 
71
71
  const fallback = useFirstElementStyleDef( currentClassesProp );
72
72
 
73
- const newId = useGeneratedId();
74
-
75
- return [ activeStyledDefId || fallback?.id || newId, setActiveStyledDefId ] as const;
73
+ return [ activeStyledDefId || fallback?.id || null, setActiveStyledDefId ] as const;
76
74
  }
77
75
 
78
76
  function useFirstElementStyleDef( currentClassesProp: PropKey ) {
@@ -84,13 +82,6 @@ function useFirstElementStyleDef( currentClassesProp: PropKey ) {
84
82
  return Object.values( stylesDefs ).find( ( styleDef ) => classesIds.includes( styleDef.id ) );
85
83
  }
86
84
 
87
- function useGeneratedId() {
88
- const { element } = useElement();
89
- const stylesDefs = useElementStyles( element.id );
90
-
91
- return generateId( `e-${ element.id }-`, Object.keys( stylesDefs ) );
92
- }
93
-
94
85
  function useCurrentClassesProp(): string {
95
86
  const { elementType } = useElement();
96
87
 
@@ -3,8 +3,8 @@ import { createContext, type Dispatch, type PropsWithChildren, useContext } from
3
3
  import { type StyleDefinition, type StyleVariant } from '@elementor/editor-styles';
4
4
 
5
5
  type ContextValue = {
6
- id: StyleDefinition[ 'id' ];
7
- setId: Dispatch< StyleDefinition[ 'id' ] >;
6
+ id: StyleDefinition[ 'id' ] | null;
7
+ setId: Dispatch< StyleDefinition[ 'id' ] | null >;
8
8
  meta: StyleVariant[ 'meta' ];
9
9
  };
10
10
 
@@ -11,7 +11,7 @@ export const useStylePropsHistory = ( props: PropKey[] ) => {
11
11
  const { id: styleDefID, meta } = useStyle();
12
12
  const { getPropValue, setPropValue, removeProp } = usePropValueHistory();
13
13
 
14
- const styleDef = getElementStyles( element.id )?.[ styleDefID ];
14
+ const styleDef = styleDefID ? getElementStyles( element.id )?.[ styleDefID ] : null;
15
15
  const styleVariant = styleDef ? getVariantByMeta( styleDef, meta ) : null;
16
16
  const styleVariantPath = `${ styleDefID }-${ styleVariant?.meta.breakpoint }-${ styleVariant?.meta.state }`;
17
17
 
@@ -1,6 +1,7 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import { updateStyle, useElementStyleProp } from '@elementor/editor-elements';
3
3
  import type { PropKey, PropValue } from '@elementor/editor-props';
4
+ import { __ } from '@wordpress/i18n';
4
5
 
5
6
  import { useClassesProp } from '../contexts/classes-prop-context';
6
7
  import { useElement } from '../contexts/element-context';
@@ -33,6 +34,7 @@ export const useStylesField = < T extends PropValue >(
33
34
  props: { [ propName ]: newValue },
34
35
  meta,
35
36
  bind: classesProp,
37
+ label: __( 'local', 'elementor' ),
36
38
  } );
37
39
  };
38
40