@elementor/editor-controls 4.3.0-988 → 4.3.0-990

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-controls",
3
3
  "description": "This package contains the controls model and utils for the Elementor editor",
4
- "version": "4.3.0-988",
4
+ "version": "4.3.0-990",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,23 +40,23 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor-current-user": "4.3.0-988",
44
- "@elementor/editor-elements": "4.3.0-988",
45
- "@elementor/editor-props": "4.3.0-988",
46
- "@elementor/editor-responsive": "4.3.0-988",
47
- "@elementor/editor-ui": "4.3.0-988",
48
- "@elementor/editor-v1-adapters": "4.3.0-988",
49
- "@elementor/env": "4.3.0-988",
50
- "@elementor/events": "4.3.0-988",
51
- "@elementor/http-client": "4.3.0-988",
43
+ "@elementor/editor-current-user": "4.3.0-990",
44
+ "@elementor/editor-elements": "4.3.0-990",
45
+ "@elementor/editor-props": "4.3.0-990",
46
+ "@elementor/editor-responsive": "4.3.0-990",
47
+ "@elementor/editor-ui": "4.3.0-990",
48
+ "@elementor/editor-v1-adapters": "4.3.0-990",
49
+ "@elementor/env": "4.3.0-990",
50
+ "@elementor/events": "4.3.0-990",
51
+ "@elementor/http-client": "4.3.0-990",
52
52
  "@elementor/icons": "~1.75.1",
53
- "@elementor/locations": "4.3.0-988",
54
- "@elementor/query": "4.3.0-988",
55
- "@elementor/schema": "4.3.0-988",
56
- "@elementor/session": "4.3.0-988",
53
+ "@elementor/locations": "4.3.0-990",
54
+ "@elementor/query": "4.3.0-990",
55
+ "@elementor/schema": "4.3.0-990",
56
+ "@elementor/session": "4.3.0-990",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.3.0-988",
59
- "@elementor/wp-media": "4.3.0-988",
58
+ "@elementor/utils": "4.3.0-990",
59
+ "@elementor/wp-media": "4.3.0-990",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tiptap/extension-bold": "^3.11.1",
62
62
  "@tiptap/extension-document": "^3.11.1",
@@ -23,21 +23,37 @@ const SIZE = 'tiny';
23
23
  const toChipsOption = ( val: string, options: ChipsOption[] ): ChipsOption =>
24
24
  options.find( ( opt ) => opt.value === val ) ?? { label: val, value: val };
25
25
 
26
+ const optionValue = ( option: ChipsOption | string ): string => {
27
+ if ( 'string' === typeof option ) {
28
+ return option;
29
+ }
30
+
31
+ return 'string' === typeof option?.value ? option.value : '';
32
+ };
33
+
34
+ const optionLabel = ( option: ChipsOption | string ): string => {
35
+ if ( 'string' === typeof option ) {
36
+ return option;
37
+ }
38
+
39
+ if ( 'string' === typeof option?.label ) {
40
+ return option.label;
41
+ }
42
+
43
+ return optionValue( option );
44
+ };
45
+
26
46
  export const ChipsControl = createControl( ( { options, freeChips }: ChipsControlProps ) => {
27
47
  const { value, setValue, disabled } = useBoundProp( stringArrayPropTypeUtil );
28
48
 
29
49
  const selectedValues: string[] = ( value || [] )
30
50
  .map( ( item ) => stringPropTypeUtil.extract( item ) )
31
- .filter( ( val ): val is string => val !== null );
51
+ .filter( ( val ): val is string => 'string' === typeof val );
32
52
 
33
53
  const selectedOptions = selectedValues.map( ( val ) => toChipsOption( val, options ) );
34
54
 
35
55
  const handleChange = ( _: SyntheticEvent, newValue: ( ChipsOption | string )[] ) => {
36
- setValue(
37
- newValue.map( ( option ) =>
38
- stringPropTypeUtil.create( typeof option === 'string' ? option : option.value )
39
- )
40
- );
56
+ setValue( newValue.map( ( option ) => stringPropTypeUtil.create( optionValue( option ) ) ) );
41
57
  };
42
58
 
43
59
  return (
@@ -52,15 +68,11 @@ export const ChipsControl = createControl( ( { options, freeChips }: ChipsContro
52
68
  filterSelectedOptions
53
69
  onChange={ handleChange }
54
70
  options={ options }
55
- getOptionLabel={ ( option ) => ( typeof option === 'string' ? option : option.label ) }
56
- isOptionEqualToValue={ ( option, val ) => option.value === val.value }
71
+ getOptionLabel={ optionLabel }
72
+ isOptionEqualToValue={ ( option, val ) => optionValue( option ) === optionValue( val ) }
57
73
  renderInput={ ( params ) => <TextField { ...params } /> }
58
74
  renderTags={ ( tagValues, getTagProps ) => (
59
- <ChipsList
60
- getLabel={ ( option ) => ( typeof option === 'string' ? option : option.label ) }
61
- getTagProps={ getTagProps }
62
- values={ tagValues }
63
- />
75
+ <ChipsList getLabel={ optionLabel } getTagProps={ getTagProps } values={ tagValues } />
64
76
  ) }
65
77
  />
66
78
  </ControlActions>