@elementor/editor-variables 4.1.0-785 → 4.1.0-786

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-variables",
3
- "version": "4.1.0-785",
3
+ "version": "4.1.0-786",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,22 +39,22 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.1.0-785",
43
- "@elementor/editor-canvas": "4.1.0-785",
44
- "@elementor/editor-controls": "4.1.0-785",
45
- "@elementor/editor-current-user": "4.1.0-785",
46
- "@elementor/editor-mcp": "4.1.0-785",
47
- "@elementor/editor-panels": "4.1.0-785",
48
- "@elementor/editor-props": "4.1.0-785",
49
- "@elementor/editor-ui": "4.1.0-785",
50
- "@elementor/editor-v1-adapters": "4.1.0-785",
51
- "@elementor/menus": "4.1.0-785",
52
- "@elementor/http-client": "4.1.0-785",
42
+ "@elementor/editor": "4.1.0-786",
43
+ "@elementor/editor-canvas": "4.1.0-786",
44
+ "@elementor/editor-controls": "4.1.0-786",
45
+ "@elementor/editor-current-user": "4.1.0-786",
46
+ "@elementor/editor-mcp": "4.1.0-786",
47
+ "@elementor/editor-panels": "4.1.0-786",
48
+ "@elementor/editor-props": "4.1.0-786",
49
+ "@elementor/editor-ui": "4.1.0-786",
50
+ "@elementor/editor-v1-adapters": "4.1.0-786",
51
+ "@elementor/menus": "4.1.0-786",
52
+ "@elementor/http-client": "4.1.0-786",
53
53
  "@elementor/icons": "^1.72.0",
54
- "@elementor/events": "4.1.0-785",
55
- "@elementor/schema": "4.1.0-785",
54
+ "@elementor/events": "4.1.0-786",
55
+ "@elementor/schema": "4.1.0-786",
56
56
  "@elementor/ui": "1.37.5",
57
- "@elementor/utils": "4.1.0-785",
57
+ "@elementor/utils": "4.1.0-786",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -6,9 +6,11 @@ import {
6
6
  type PropValue,
7
7
  selectionSizePropTypeUtil,
8
8
  type SelectionSizePropValue,
9
+ shadowPropTypeUtil,
9
10
  } from '@elementor/editor-props';
10
11
 
11
- import { useVariable } from '../hooks/use-prop-variables';
12
+ import { getVariable } from '../hooks/use-prop-variables';
13
+ import { sizeValue } from '../utils/size-value';
12
14
  import { ColorIndicator } from './ui/color-indicator';
13
15
 
14
16
  type Props = {
@@ -18,7 +20,7 @@ type Props = {
18
20
  const useColorVariable = ( value: BackgroundColorOverlayPropValue | BoxShadowPropValue ) => {
19
21
  const variableId = value?.value?.color?.value;
20
22
 
21
- return useVariable( variableId || '' );
23
+ return getVariable( variableId || '' );
22
24
  };
23
25
 
24
26
  export const BackgroundRepeaterColorIndicator = ( { value }: Props ) => {
@@ -39,11 +41,32 @@ export const BoxShadowRepeaterColorIndicator = ( { value }: Props ) => {
39
41
  return <ColorIndicator component="span" size="inherit" value={ colorVariable?.value } />;
40
42
  };
41
43
 
44
+ export const BoxShadowRepeaterLabel = ( { value }: Props ) => {
45
+ const shadowPropValue = shadowPropTypeUtil.extract( value ) || {};
46
+
47
+ const labels: string[] = [];
48
+
49
+ for ( const key of [ 'hOffset', 'vOffset', 'blur', 'spread' ] ) {
50
+ const rendered = sizeValue( shadowPropValue[ key as keyof typeof shadowPropValue ] );
51
+ if ( rendered ) {
52
+ labels.push( rendered );
53
+ }
54
+ }
55
+
56
+ const positionLabel = shadowPropValue.position?.value || 'outset';
57
+
58
+ return (
59
+ <span style={ { textTransform: 'capitalize' } }>
60
+ { positionLabel }: { labels.join( ' ' ) }
61
+ </span>
62
+ );
63
+ };
64
+
42
65
  export const TransitionsSizeVariableLabel = ( { value: prop }: Props ) => {
43
66
  let label = '';
44
67
 
45
68
  const variableId = ( prop as SelectionSizePropValue )?.value?.size?.value || '';
46
- const variable = useVariable( variableId );
69
+ const variable = getVariable( variableId );
47
70
 
48
71
  if ( variable && selectionSizePropTypeUtil.isValid( prop ) ) {
49
72
  const selection = ( prop.value?.selection as KeyValuePropValue )?.value?.key?.value;
@@ -23,7 +23,15 @@ export const hasVariable = ( key: string ) => {
23
23
  return getVariables()[ key ] !== undefined;
24
24
  };
25
25
 
26
+ /**
27
+ * @param key
28
+ * @deprecated Use getVariable instead
29
+ */
26
30
  export const useVariable = ( key: string ) => {
31
+ return getVariable( key );
32
+ };
33
+
34
+ export function getVariable( key: string ) {
27
35
  const variables = getVariables();
28
36
 
29
37
  if ( ! variables?.[ key ] ) {
@@ -34,13 +42,14 @@ export const useVariable = ( key: string ) => {
34
42
  ...variables[ key ],
35
43
  key,
36
44
  };
37
- };
45
+ }
38
46
 
39
47
  export const useFilteredVariables = ( searchValue: string, propTypeKey: string ) => {
40
48
  const baseVariables = usePropVariables( propTypeKey );
41
49
 
42
50
  const typeFilteredVariables = useVariableSelectionFilter( baseVariables );
43
51
  const searchFilteredVariables = filterBySearch( typeFilteredVariables, searchValue );
52
+
44
53
  const sortedVariables = searchFilteredVariables.sort( ( a, b ) => {
45
54
  const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
46
55
  const orderB = b.order ?? Number.MAX_SAFE_INTEGER;
@@ -10,6 +10,7 @@ import {
10
10
  BackgroundRepeaterColorIndicator,
11
11
  BackgroundRepeaterLabel,
12
12
  BoxShadowRepeaterColorIndicator,
13
+ BoxShadowRepeaterLabel,
13
14
  TransitionsSizeVariableLabel,
14
15
  } from './components/variables-repeater-item-slot';
15
16
  import { colorVariablePropTypeUtil, customSizeVariablePropTypeUtil, sizeVariablePropTypeUtil } from './prop-types';
@@ -47,7 +48,23 @@ const boxShadowRepeaterInjections = () => {
47
48
  id: 'color-variables-box-shadow-icon',
48
49
  component: BoxShadowRepeaterColorIndicator,
49
50
  condition: ( { value }: Args ) => {
50
- return hasAssignedColorVariable( shadowPropTypeUtil.extract( value )?.color );
51
+ const { color } = shadowPropTypeUtil.extract( value ) || {};
52
+ return hasAssignedColorVariable( color );
53
+ },
54
+ } );
55
+
56
+ injectIntoRepeaterItemLabel( {
57
+ id: 'color-variables-box-shadow-label',
58
+ component: BoxShadowRepeaterLabel,
59
+ condition: ( { value }: Args ) => {
60
+ const { hOffset, vOffset, blur, spread } = shadowPropTypeUtil.extract( value ) || {};
61
+
62
+ return (
63
+ hasAssignedSizeVariable( hOffset ) ||
64
+ hasAssignedSizeVariable( vOffset ) ||
65
+ hasAssignedSizeVariable( blur ) ||
66
+ hasAssignedSizeVariable( spread )
67
+ );
51
68
  },
52
69
  } );
53
70
  };
@@ -0,0 +1,30 @@
1
+ import { type PropValue, sizePropTypeUtil } from '@elementor/editor-props';
2
+
3
+ import { getVariable } from '../hooks/use-prop-variables';
4
+ import { customSizeVariablePropTypeUtil, sizeVariablePropTypeUtil } from '../prop-types';
5
+
6
+ const DEFAULT_UNIT = 'px';
7
+ const CUSTOM_SIZE_LABEL = 'fx';
8
+
9
+ export function sizeValue( value: PropValue ) {
10
+ if ( sizeVariablePropTypeUtil.isValid( value ) || customSizeVariablePropTypeUtil.isValid( value ) ) {
11
+ const variable = getVariable( value?.value );
12
+ return variable?.value;
13
+ }
14
+
15
+ if ( sizePropTypeUtil.isValid( value ) ) {
16
+ const { size, unit } = value.value;
17
+
18
+ if ( 'custom' !== unit ) {
19
+ return `${ size ?? 0 }${ unit ?? DEFAULT_UNIT }`;
20
+ }
21
+
22
+ if ( ! size ) {
23
+ return CUSTOM_SIZE_LABEL;
24
+ }
25
+
26
+ return size;
27
+ }
28
+
29
+ return '';
30
+ }