@elementor/editor-variables 3.32.0-28 → 3.32.0-30

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.32.0-28",
3
+ "version": "3.32.0-30",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,18 +39,18 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.32.0-28",
43
- "@elementor/editor-canvas": "3.32.0-28",
44
- "@elementor/editor-controls": "3.32.0-28",
45
- "@elementor/editor-current-user": "3.32.0-28",
46
- "@elementor/editor-editing-panel": "3.32.0-28",
47
- "@elementor/editor-panels": "3.32.0-28",
48
- "@elementor/editor-props": "3.32.0-28",
49
- "@elementor/editor-ui": "3.32.0-28",
50
- "@elementor/editor-v1-adapters": "3.32.0-28",
51
- "@elementor/http-client": "3.32.0-28",
42
+ "@elementor/editor": "3.32.0-30",
43
+ "@elementor/editor-canvas": "3.32.0-30",
44
+ "@elementor/editor-controls": "3.32.0-30",
45
+ "@elementor/editor-current-user": "3.32.0-30",
46
+ "@elementor/editor-editing-panel": "3.32.0-30",
47
+ "@elementor/editor-panels": "3.32.0-30",
48
+ "@elementor/editor-props": "3.32.0-30",
49
+ "@elementor/editor-ui": "3.32.0-30",
50
+ "@elementor/editor-v1-adapters": "3.32.0-30",
51
+ "@elementor/http-client": "3.32.0-30",
52
52
  "@elementor/icons": "1.46.0",
53
- "@elementor/schema": "3.32.0-28",
53
+ "@elementor/schema": "3.32.0-30",
54
54
  "@elementor/ui": "1.36.2",
55
55
  "@wordpress/i18n": "^5.13.0"
56
56
  },
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useRef, useState } from 'react';
3
- import { FormHelperText, FormLabel, Grid, UnstableColorField } from '@elementor/ui';
4
- import { __ } from '@wordpress/i18n';
3
+ import { UnstableColorField } from '@elementor/ui';
5
4
 
6
5
  import { usePopoverContentRef } from '../../context/variable-selection-popover.context';
7
6
  import { validateValue } from '../../utils/validations';
@@ -9,9 +8,10 @@ import { validateValue } from '../../utils/validations';
9
8
  type ColorFieldProps = {
10
9
  value: string;
11
10
  onChange: ( value: string ) => void;
11
+ onValidationChange?: ( errorMessage: string ) => void;
12
12
  };
13
13
 
14
- export const ColorField = ( { value, onChange }: ColorFieldProps ) => {
14
+ export const ColorField = ( { value, onChange, onValidationChange }: ColorFieldProps ) => {
15
15
  const [ color, setColor ] = useState( value );
16
16
  const [ errorMessage, setErrorMessage ] = useState( '' );
17
17
 
@@ -23,32 +23,25 @@ export const ColorField = ( { value, onChange }: ColorFieldProps ) => {
23
23
 
24
24
  const errorMsg = validateValue( newValue );
25
25
  setErrorMessage( errorMsg );
26
+ onValidationChange?.( errorMsg );
26
27
 
27
28
  onChange( errorMsg ? '' : newValue );
28
29
  };
29
30
 
30
31
  return (
31
- <Grid container gap={ 0.75 } alignItems="center">
32
- <Grid item xs={ 12 }>
33
- <FormLabel size="tiny">{ __( 'Value', 'elementor' ) }</FormLabel>
34
- </Grid>
35
- <Grid item xs={ 12 }>
36
- <UnstableColorField
37
- size="tiny"
38
- fullWidth
39
- value={ color }
40
- onChange={ handleChange }
41
- error={ errorMessage ?? undefined }
42
- slotProps={ {
43
- colorPicker: {
44
- anchorEl: anchorRef,
45
- anchorOrigin: { vertical: 'top', horizontal: 'right' },
46
- transformOrigin: { vertical: 'top', horizontal: -10 },
47
- },
48
- } }
49
- />
50
- { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
51
- </Grid>
52
- </Grid>
32
+ <UnstableColorField
33
+ size="tiny"
34
+ fullWidth
35
+ value={ color }
36
+ onChange={ handleChange }
37
+ error={ errorMessage || undefined }
38
+ slotProps={ {
39
+ colorPicker: {
40
+ anchorEl: anchorRef,
41
+ anchorOrigin: { vertical: 'top', horizontal: 'right' },
42
+ transformOrigin: { vertical: 'top', horizontal: -10 },
43
+ },
44
+ } }
45
+ />
53
46
  );
54
47
  };
@@ -1,18 +1,9 @@
1
1
  import * as React from 'react';
2
- import { useRef, useState } from 'react';
2
+ import { useId, useRef, useState } from 'react';
3
3
  import { enqueueFont, ItemSelector } from '@elementor/editor-controls';
4
4
  import { useFontFamilies, useSectionWidth } from '@elementor/editor-editing-panel';
5
5
  import { ChevronDownIcon, TextIcon } from '@elementor/icons';
6
- import {
7
- bindPopover,
8
- bindTrigger,
9
- FormHelperText,
10
- FormLabel,
11
- Grid,
12
- Popover,
13
- UnstableTag,
14
- usePopupState,
15
- } from '@elementor/ui';
6
+ import { bindPopover, bindTrigger, Popover, UnstableTag, usePopupState } from '@elementor/ui';
16
7
  import { __ } from '@wordpress/i18n';
17
8
 
18
9
  import { usePopoverContentRef } from '../../context/variable-selection-popover.context';
@@ -21,11 +12,11 @@ import { validateValue } from '../../utils/validations';
21
12
  type FontFieldProps = {
22
13
  value: string;
23
14
  onChange: ( value: string ) => void;
15
+ onValidationChange?: ( errorMessage: string ) => void;
24
16
  };
25
17
 
26
- export const FontField = ( { value, onChange }: FontFieldProps ) => {
18
+ export const FontField = ( { value, onChange, onValidationChange }: FontFieldProps ) => {
27
19
  const [ fontFamily, setFontFamily ] = useState( value );
28
- const [ errorMessage, setErrorMessage ] = useState( '' );
29
20
 
30
21
  const defaultRef = useRef< HTMLDivElement >( null );
31
22
  const anchorRef = usePopoverContentRef() ?? defaultRef.current;
@@ -46,7 +37,7 @@ export const FontField = ( { value, onChange }: FontFieldProps ) => {
46
37
  setFontFamily( newValue );
47
38
 
48
39
  const errorMsg = validateValue( newValue );
49
- setErrorMessage( errorMsg );
40
+ onValidationChange?.( errorMsg );
50
41
 
51
42
  onChange( errorMsg ? '' : newValue );
52
43
  };
@@ -56,41 +47,38 @@ export const FontField = ( { value, onChange }: FontFieldProps ) => {
56
47
  fontPopoverState.close();
57
48
  };
58
49
 
50
+ const id = useId();
51
+
59
52
  return (
60
- <Grid container gap={ 0.75 } alignItems="center">
61
- <Grid item xs={ 12 }>
62
- <FormLabel size="tiny">{ __( 'Value', 'elementor' ) }</FormLabel>
63
- </Grid>
64
- <Grid item xs={ 12 }>
65
- <UnstableTag
66
- variant="outlined"
67
- label={ fontFamily }
68
- endIcon={ <ChevronDownIcon fontSize="tiny" /> }
69
- { ...bindTrigger( fontPopoverState ) }
70
- fullWidth
53
+ <>
54
+ <UnstableTag
55
+ id={ id }
56
+ variant="outlined"
57
+ label={ fontFamily }
58
+ endIcon={ <ChevronDownIcon fontSize="tiny" /> }
59
+ { ...bindTrigger( fontPopoverState ) }
60
+ fullWidth
61
+ />
62
+ <Popover
63
+ disablePortal
64
+ disableScrollLock
65
+ anchorEl={ anchorRef }
66
+ anchorOrigin={ { vertical: 'top', horizontal: 'right' } }
67
+ transformOrigin={ { vertical: 'top', horizontal: -28 } }
68
+ { ...bindPopover( fontPopoverState ) }
69
+ >
70
+ <ItemSelector
71
+ itemsList={ mapFontSubs }
72
+ selectedItem={ fontFamily }
73
+ onItemChange={ handleFontFamilyChange }
74
+ onClose={ fontPopoverState.close }
75
+ sectionWidth={ sectionWidth }
76
+ title={ __( 'Font Family', 'elementor' ) }
77
+ itemStyle={ ( item ) => ( { fontFamily: item.value } ) }
78
+ onDebounce={ enqueueFont }
79
+ icon={ TextIcon as React.ElementType< { fontSize: string } > }
71
80
  />
72
- <Popover
73
- disablePortal
74
- disableScrollLock
75
- anchorEl={ anchorRef }
76
- anchorOrigin={ { vertical: 'top', horizontal: 'right' } }
77
- transformOrigin={ { vertical: 'top', horizontal: -28 } }
78
- { ...bindPopover( fontPopoverState ) }
79
- >
80
- <ItemSelector
81
- itemsList={ mapFontSubs }
82
- selectedItem={ fontFamily }
83
- onItemChange={ handleFontFamilyChange }
84
- onClose={ fontPopoverState.close }
85
- sectionWidth={ sectionWidth }
86
- title={ __( 'Font Family', 'elementor' ) }
87
- itemStyle={ ( item ) => ( { fontFamily: item.value } ) }
88
- onDebounce={ enqueueFont }
89
- icon={ TextIcon as React.ElementType< { fontSize: string } > }
90
- />
91
- </Popover>
92
- { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
93
- </Grid>
94
- </Grid>
81
+ </Popover>
82
+ </>
95
83
  );
96
84
  };
@@ -1,9 +1,10 @@
1
1
  import * as React from 'react';
2
2
  import { useId, useState } from 'react';
3
- import { FormHelperText, FormLabel, Grid, TextField } from '@elementor/ui';
3
+ import { TextField } from '@elementor/ui';
4
4
  import { __ } from '@wordpress/i18n';
5
5
 
6
6
  import { labelHint, validateLabel, VARIABLE_LABEL_MAX_LENGTH } from '../../utils/validations';
7
+ import { FormField } from '../ui/form-field';
7
8
 
8
9
  function isLabelEqual( a: string, b: string ) {
9
10
  return a.trim().toLowerCase() === b.trim().toLowerCase();
@@ -56,25 +57,16 @@ export const LabelField = ( { value, error, onChange }: LabelFieldProps ) => {
56
57
  const noticeMsg = errorMsg ? '' : noticeMessage;
57
58
 
58
59
  return (
59
- <Grid container gap={ 0.75 } alignItems="center">
60
- <Grid item xs={ 12 }>
61
- <FormLabel htmlFor={ id } size="tiny">
62
- { __( 'Name', 'elementor' ) }
63
- </FormLabel>
64
- </Grid>
65
- <Grid item xs={ 12 }>
66
- <TextField
67
- id={ id }
68
- size="tiny"
69
- fullWidth
70
- value={ label }
71
- error={ !! errorMsg }
72
- onChange={ ( e: React.ChangeEvent< HTMLInputElement > ) => handleChange( e.target.value ) }
73
- inputProps={ { maxLength: VARIABLE_LABEL_MAX_LENGTH } }
74
- />
75
- { errorMsg && <FormHelperText error>{ errorMsg }</FormHelperText> }
76
- { noticeMsg && <FormHelperText>{ noticeMsg }</FormHelperText> }
77
- </Grid>
78
- </Grid>
60
+ <FormField id={ id } label={ __( 'Name', 'elementor' ) } errorMsg={ errorMsg } noticeMsg={ noticeMsg }>
61
+ <TextField
62
+ id={ id }
63
+ size="tiny"
64
+ fullWidth
65
+ value={ label }
66
+ error={ !! errorMsg }
67
+ onChange={ ( e: React.ChangeEvent< HTMLInputElement > ) => handleChange( e.target.value ) }
68
+ inputProps={ { maxLength: VARIABLE_LABEL_MAX_LENGTH } }
69
+ />
70
+ </FormField>
79
71
  );
80
72
  };
@@ -0,0 +1,28 @@
1
+ import * as React from 'react';
2
+ import type { PropsWithChildren } from 'react';
3
+ import { FormHelperText, FormLabel, Grid } from '@elementor/ui';
4
+
5
+ type Props = PropsWithChildren< {
6
+ id?: string;
7
+ label: string;
8
+ errorMsg?: string;
9
+ noticeMsg?: string;
10
+ } >;
11
+
12
+ export const FormField = ( { id, label, errorMsg, noticeMsg, children }: Props ) => {
13
+ return (
14
+ <Grid container gap={ 0.75 } alignItems="center">
15
+ <Grid item xs={ 12 }>
16
+ <FormLabel htmlFor={ id } size="tiny">
17
+ { label }
18
+ </FormLabel>
19
+ </Grid>
20
+
21
+ <Grid item xs={ 12 }>
22
+ { children }
23
+ { errorMsg && <FormHelperText error>{ errorMsg }</FormHelperText> }
24
+ { noticeMsg && <FormHelperText>{ noticeMsg }</FormHelperText> }
25
+ </Grid>
26
+ </Grid>
27
+ );
28
+ };
@@ -13,6 +13,7 @@ import { createVariable } from '../hooks/use-prop-variables';
13
13
  import { trackVariableEvent } from '../utils/tracking';
14
14
  import { ERROR_MESSAGES, mapServerError } from '../utils/validations';
15
15
  import { LabelField, useLabelError } from './fields/label-field';
16
+ import { FormField } from './ui/form-field';
16
17
 
17
18
  const SIZE = 'tiny';
18
19
 
@@ -31,6 +32,7 @@ export const VariableCreation = ( { onGoBack, onClose }: Props ) => {
31
32
  const [ value, setValue ] = useState( initialValue );
32
33
  const [ label, setLabel ] = useState( '' );
33
34
  const [ errorMessage, setErrorMessage ] = useState( '' );
35
+ const [ valueFieldError, setValueFieldError ] = useState( '' );
34
36
 
35
37
  const { labelFieldError, setLabelFieldError } = useLabelError();
36
38
 
@@ -38,6 +40,7 @@ export const VariableCreation = ( { onGoBack, onClose }: Props ) => {
38
40
  setValue( '' );
39
41
  setLabel( '' );
40
42
  setErrorMessage( '' );
43
+ setValueFieldError( '' );
41
44
  };
42
45
 
43
46
  const closePopover = () => {
@@ -114,13 +117,17 @@ export const VariableCreation = ( { onGoBack, onClose }: Props ) => {
114
117
  setErrorMessage( '' );
115
118
  } }
116
119
  />
117
- <ValueField
118
- value={ value }
119
- onChange={ ( newValue ) => {
120
- setValue( newValue );
121
- setErrorMessage( '' );
122
- } }
123
- />
120
+ <FormField errorMsg={ valueFieldError } label={ __( 'Value', 'elementor' ) }>
121
+ <ValueField
122
+ value={ value }
123
+ onChange={ ( newValue ) => {
124
+ setValue( newValue );
125
+ setErrorMessage( '' );
126
+ setValueFieldError( '' );
127
+ } }
128
+ onValidationChange={ setValueFieldError }
129
+ />
130
+ </FormField>
124
131
 
125
132
  { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
126
133
  </PopoverContent>
@@ -16,6 +16,7 @@ import { ERROR_MESSAGES, mapServerError } from '../utils/validations';
16
16
  import { LabelField, useLabelError } from './fields/label-field';
17
17
  import { DeleteConfirmationDialog } from './ui/delete-confirmation-dialog';
18
18
  import { EDIT_CONFIRMATION_DIALOG_ID, EditConfirmationDialog } from './ui/edit-confirmation-dialog';
19
+ import { FormField } from './ui/form-field';
19
20
 
20
21
  const SIZE = 'tiny';
21
22
 
@@ -34,6 +35,7 @@ export const VariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) =
34
35
  const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
35
36
  const [ editConfirmation, setEditConfirmation ] = useState( false );
36
37
  const [ errorMessage, setErrorMessage ] = useState( '' );
38
+ const [ valueFieldError, setValueFieldError ] = useState( '' );
37
39
 
38
40
  const { labelFieldError, setLabelFieldError } = useLabelError();
39
41
  const variable = useVariable( editId );
@@ -182,13 +184,17 @@ export const VariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) =
182
184
  setErrorMessage( '' );
183
185
  } }
184
186
  />
185
- <ValueField
186
- value={ value }
187
- onChange={ ( newValue ) => {
188
- setValue( newValue );
189
- setErrorMessage( '' );
190
- } }
191
- />
187
+ <FormField errorMsg={ valueFieldError } label={ __( 'Value', 'elementor' ) }>
188
+ <ValueField
189
+ value={ value }
190
+ onChange={ ( newValue ) => {
191
+ setValue( newValue );
192
+ setErrorMessage( '' );
193
+ setValueFieldError( '' );
194
+ } }
195
+ onValidationChange={ setValueFieldError }
196
+ />
197
+ </FormField>
192
198
 
193
199
  { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
194
200
  </PopoverContent>
@@ -11,6 +11,7 @@ import { useVariableType } from '../context/variable-type-context';
11
11
  import { restoreVariable, useVariable } from '../hooks/use-prop-variables';
12
12
  import { ERROR_MESSAGES, mapServerError } from '../utils/validations';
13
13
  import { LabelField, useLabelError } from './fields/label-field';
14
+ import { FormField } from './ui/form-field';
14
15
 
15
16
  const SIZE = 'tiny';
16
17
 
@@ -32,6 +33,7 @@ export const VariableRestore = ( { variableId, onClose, onSubmit }: Props ) => {
32
33
  }
33
34
 
34
35
  const [ errorMessage, setErrorMessage ] = useState( '' );
36
+ const [ valueFieldError, setValueFieldError ] = useState( '' );
35
37
  const [ label, setLabel ] = useState( variable.label );
36
38
  const [ value, setValue ] = useState( variable.value );
37
39
 
@@ -95,13 +97,17 @@ export const VariableRestore = ( { variableId, onClose, onSubmit }: Props ) => {
95
97
  setErrorMessage( '' );
96
98
  } }
97
99
  />
98
- <ValueField
99
- value={ value }
100
- onChange={ ( newValue ) => {
101
- setValue( newValue );
102
- setErrorMessage( '' );
103
- } }
104
- />
100
+ <FormField errorMsg={ valueFieldError } label={ __( 'Value', 'elementor' ) }>
101
+ <ValueField
102
+ value={ value }
103
+ onChange={ ( newValue ) => {
104
+ setValue( newValue );
105
+ setErrorMessage( '' );
106
+ setValueFieldError( '' );
107
+ } }
108
+ onValidationChange={ setValueFieldError }
109
+ />
110
+ </FormField>
105
111
 
106
112
  { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
107
113
  </PopoverContent>
@@ -11,6 +11,7 @@ import { type NormalizedVariable } from '../types';
11
11
  type ValueFieldProps = {
12
12
  value: string;
13
13
  onChange: ( value: string ) => void;
14
+ onValidationChange?: ( value: string ) => void;
14
15
  };
15
16
 
16
17
  type FallbackPropTypeUtil = ReturnType< typeof createPropUtils >;
@@ -18,7 +19,7 @@ type FallbackPropTypeUtil = ReturnType< typeof createPropUtils >;
18
19
  type VariableTypeOptions = {
19
20
  icon: ForwardRefExoticComponent< Omit< SvgIconProps, 'ref' > & RefAttributes< SVGSVGElement > >;
20
21
  startIcon?: ( { value }: { value: string } ) => JSX.Element;
21
- valueField: ( { value, onChange }: ValueFieldProps ) => JSX.Element;
22
+ valueField: ( { value, onChange, onValidationChange }: ValueFieldProps ) => JSX.Element;
22
23
  variableType: string;
23
24
  fallbackPropTypeUtil: FallbackPropTypeUtil;
24
25
  propTypeUtil: PropTypeUtil< string, string >;