@elementor/editor-variables 3.33.0-165 → 3.33.0-166

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": "3.33.0-165",
3
+ "version": "3.33.0-166",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,20 +39,20 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.33.0-165",
43
- "@elementor/editor-canvas": "3.33.0-165",
44
- "@elementor/editor-controls": "3.33.0-165",
45
- "@elementor/editor-current-user": "3.33.0-165",
46
- "@elementor/editor-editing-panel": "3.33.0-165",
47
- "@elementor/editor-mcp": "3.33.0-165",
48
- "@elementor/editor-panels": "3.33.0-165",
49
- "@elementor/editor-props": "3.33.0-165",
50
- "@elementor/editor-ui": "3.33.0-165",
51
- "@elementor/editor-v1-adapters": "3.33.0-165",
52
- "@elementor/http-client": "3.33.0-165",
42
+ "@elementor/editor": "3.33.0-166",
43
+ "@elementor/editor-canvas": "3.33.0-166",
44
+ "@elementor/editor-controls": "3.33.0-166",
45
+ "@elementor/editor-current-user": "3.33.0-166",
46
+ "@elementor/editor-editing-panel": "3.33.0-166",
47
+ "@elementor/editor-mcp": "3.33.0-166",
48
+ "@elementor/editor-panels": "3.33.0-166",
49
+ "@elementor/editor-props": "3.33.0-166",
50
+ "@elementor/editor-ui": "3.33.0-166",
51
+ "@elementor/editor-v1-adapters": "3.33.0-166",
52
+ "@elementor/http-client": "3.33.0-166",
53
53
  "@elementor/icons": "1.53.0",
54
- "@elementor/mixpanel": "3.33.0-165",
55
- "@elementor/schema": "3.33.0-165",
54
+ "@elementor/mixpanel": "3.33.0-166",
55
+ "@elementor/schema": "3.33.0-166",
56
56
  "@elementor/ui": "1.36.14",
57
57
  "@wordpress/i18n": "^5.13.0"
58
58
  },
@@ -3,6 +3,7 @@ import { useRef, useState } from 'react';
3
3
  import { WarningInfotip } from '@elementor/editor-ui';
4
4
  import { TextField, type TextFieldProps } from '@elementor/ui';
5
5
 
6
+ import { type TVariablesList } from '../../storage';
6
7
  import { labelHint, validateLabel, VARIABLE_LABEL_MAX_LENGTH } from '../../utils/validations';
7
8
  function isLabelEqual( a: string, b: string ) {
8
9
  return a.trim().toLowerCase() === b.trim().toLowerCase();
@@ -32,6 +33,7 @@ export type LabelFieldProps = {
32
33
  focusOnShow?: boolean;
33
34
  selectOnShow?: boolean;
34
35
  showWarningInfotip?: boolean;
36
+ variables?: TVariablesList;
35
37
  };
36
38
 
37
39
  export const LabelField = ( {
@@ -44,15 +46,17 @@ export const LabelField = ( {
44
46
  focusOnShow = false,
45
47
  selectOnShow = false,
46
48
  showWarningInfotip = false,
49
+ variables,
47
50
  }: LabelFieldProps ) => {
48
51
  const [ label, setLabel ] = useState( value );
49
52
  const [ errorMessage, setErrorMessage ] = useState( '' );
53
+
50
54
  const fieldRef = useRef< HTMLElement >( null );
51
55
 
52
56
  const handleChange = ( newValue: string ) => {
53
57
  setLabel( newValue );
54
58
 
55
- const errorMsg = validateLabel( newValue );
59
+ const errorMsg = validateLabel( newValue, variables );
56
60
 
57
61
  setErrorMessage( errorMsg );
58
62
  onErrorChange?.( errorMsg );
@@ -216,6 +216,7 @@ export const VariablesManagerTable = ( {
216
216
  focusOnShow
217
217
  selectOnShow={ autoEditVariableId === row.id }
218
218
  showWarningInfotip={ true }
219
+ variables={ variables }
219
220
  />
220
221
  ) }
221
222
  autoEdit={ autoEditVariableId === row.id }
@@ -1,5 +1,7 @@
1
1
  import { __ } from '@wordpress/i18n';
2
2
 
3
+ import { type TVariable, type TVariablesList } from '../storage';
4
+
3
5
  export const ERROR_MESSAGES = {
4
6
  MISSING_VARIABLE_NAME: __( 'Give your variable a name.', 'elementor' ),
5
7
  MISSING_VARIABLE_VALUE: __( 'Add a value to complete your variable.', 'elementor' ),
@@ -36,7 +38,7 @@ export const mapServerError = ( error: ErrorResponse ): MappedError | undefined
36
38
  return undefined;
37
39
  };
38
40
 
39
- export const validateLabel = ( name: string ): string => {
41
+ export const validateLabel = ( name: string, variables?: TVariablesList ): string => {
40
42
  if ( ! name.trim() ) {
41
43
  return ERROR_MESSAGES.MISSING_VARIABLE_NAME;
42
44
  }
@@ -55,6 +57,10 @@ export const validateLabel = ( name: string ): string => {
55
57
  return ERROR_MESSAGES.VARIABLE_LABEL_MAX_LENGTH;
56
58
  }
57
59
 
60
+ if ( Object.values( variables ?? {} ).some( ( variable: TVariable ) => variable.label === name ) ) {
61
+ return ERROR_MESSAGES.DUPLICATED_LABEL;
62
+ }
63
+
58
64
  return '';
59
65
  };
60
66