@elementor/editor-controls 4.3.0-1009 → 4.3.0-1010

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-1009",
4
+ "version": "4.3.0-1010",
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-1009",
44
- "@elementor/editor-elements": "4.3.0-1009",
45
- "@elementor/editor-props": "4.3.0-1009",
46
- "@elementor/editor-responsive": "4.3.0-1009",
47
- "@elementor/editor-ui": "4.3.0-1009",
48
- "@elementor/editor-v1-adapters": "4.3.0-1009",
49
- "@elementor/env": "4.3.0-1009",
50
- "@elementor/events": "4.3.0-1009",
51
- "@elementor/http-client": "4.3.0-1009",
43
+ "@elementor/editor-current-user": "4.3.0-1010",
44
+ "@elementor/editor-elements": "4.3.0-1010",
45
+ "@elementor/editor-props": "4.3.0-1010",
46
+ "@elementor/editor-responsive": "4.3.0-1010",
47
+ "@elementor/editor-ui": "4.3.0-1010",
48
+ "@elementor/editor-v1-adapters": "4.3.0-1010",
49
+ "@elementor/env": "4.3.0-1010",
50
+ "@elementor/events": "4.3.0-1010",
51
+ "@elementor/http-client": "4.3.0-1010",
52
52
  "@elementor/icons": "~1.75.1",
53
- "@elementor/locations": "4.3.0-1009",
54
- "@elementor/query": "4.3.0-1009",
55
- "@elementor/schema": "4.3.0-1009",
56
- "@elementor/session": "4.3.0-1009",
53
+ "@elementor/locations": "4.3.0-1010",
54
+ "@elementor/query": "4.3.0-1010",
55
+ "@elementor/schema": "4.3.0-1010",
56
+ "@elementor/session": "4.3.0-1010",
57
57
  "@elementor/ui": "1.37.5",
58
- "@elementor/utils": "4.3.0-1009",
59
- "@elementor/wp-media": "4.3.0-1009",
58
+ "@elementor/utils": "4.3.0-1010",
59
+ "@elementor/wp-media": "4.3.0-1010",
60
60
  "@monaco-editor/react": "^4.7.0",
61
61
  "@tiptap/extension-bold": "^3.11.1",
62
62
  "@tiptap/extension-document": "^3.11.1",
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { stringPropTypeUtil, type StringPropValue } from '@elementor/editor-props';
3
3
  import { MenuListItem } from '@elementor/editor-ui';
4
- import { Select, type SelectChangeEvent, type SelectProps, Typography } from '@elementor/ui';
4
+ import { MenuSubheader, Select, type SelectChangeEvent, type SelectProps, Typography } from '@elementor/ui';
5
5
 
6
6
  import { useBoundProp } from '../bound-prop-context';
7
7
  import ControlActions from '../control-actions/control-actions';
@@ -13,8 +13,14 @@ export type SelectOption = {
13
13
  disabled?: boolean;
14
14
  };
15
15
 
16
- type SelectControlProps = {
16
+ export type SelectOptionGroup = {
17
+ label: string;
17
18
  options: SelectOption[];
19
+ };
20
+
21
+ type SelectControlProps = {
22
+ options?: SelectOption[];
23
+ groups?: SelectOptionGroup[];
18
24
  onChange?: ( newValue: string | null, previousValue: string | null | undefined ) => void;
19
25
  MenuProps?: SelectProps[ 'MenuProps' ];
20
26
  ariaLabel?: string;
@@ -29,7 +35,7 @@ const DEFAULT_MENU_PROPS = {
29
35
  };
30
36
 
31
37
  export const SelectControl = createControl(
32
- ( { options, onChange, MenuProps = DEFAULT_MENU_PROPS, ariaLabel }: SelectControlProps ) => {
38
+ ( { options = [], groups = [], onChange, MenuProps = DEFAULT_MENU_PROPS, ariaLabel }: SelectControlProps ) => {
33
39
  const { value, setValue, disabled, placeholder } = useBoundProp( stringPropTypeUtil );
34
40
  const handleChange = ( event: SelectChangeEvent< StringPropValue[ 'value' ] > ) => {
35
41
  const newValue = event.target.value || null;
@@ -37,7 +43,8 @@ export const SelectControl = createControl(
37
43
  onChange?.( newValue, value );
38
44
  setValue( newValue );
39
45
  };
40
- const isDisabled = disabled || options.length === 0;
46
+ const flatOptions = flattenGroupedOptions( options, groups );
47
+ const isDisabled = disabled || flatOptions.length === 0;
41
48
 
42
49
  return (
43
50
  <ControlActions>
@@ -48,24 +55,54 @@ export const SelectControl = createControl(
48
55
  MenuProps={ MenuProps }
49
56
  aria-label={ ariaLabel || placeholder }
50
57
  renderValue={ ( selectedValue: string | null ) =>
51
- getSelectRenderValue( options, placeholder, selectedValue )
58
+ getSelectRenderValue( flatOptions, placeholder, selectedValue )
52
59
  }
53
60
  value={ value ?? '' }
54
61
  onChange={ handleChange }
55
62
  disabled={ isDisabled }
56
63
  fullWidth
57
64
  >
58
- { options.map( ( { label, ...props } ) => (
59
- <MenuListItem key={ props.value } { ...props } value={ props.value ?? '' }>
60
- { label }
61
- </MenuListItem>
62
- ) ) }
65
+ { groups.length
66
+ ? groups.flatMap( ( group ) => renderGroup( group ) )
67
+ : options.map( ( option ) => renderOption( option ) ) }
63
68
  </Select>
64
69
  </ControlActions>
65
70
  );
66
71
  }
67
72
  );
68
73
 
74
+ const GROUPED_OPTION_INDENT = 3.5;
75
+
76
+ function renderGroup( group: SelectOptionGroup ): React.ReactNode[] {
77
+ return [
78
+ <MenuSubheader key={ `group-${ group.label }` } sx={ { fontWeight: 400, color: 'text.tertiary' } }>
79
+ { group.label }
80
+ </MenuSubheader>,
81
+ ...group.options.map( ( option ) => renderOption( option, true ) ),
82
+ ];
83
+ }
84
+
85
+ function renderOption( { label, ...props }: SelectOption, isGrouped = false ): React.ReactNode {
86
+ return (
87
+ <MenuListItem
88
+ key={ props.value }
89
+ { ...props }
90
+ value={ props.value ?? '' }
91
+ sx={ isGrouped ? { pl: GROUPED_OPTION_INDENT } : undefined }
92
+ >
93
+ { label }
94
+ </MenuListItem>
95
+ );
96
+ }
97
+
98
+ function flattenGroupedOptions( options: SelectOption[], groups: SelectOptionGroup[] ): SelectOption[] {
99
+ if ( ! groups.length ) {
100
+ return options;
101
+ }
102
+
103
+ return groups.flatMap( ( group ) => group.options );
104
+ }
105
+
69
106
  export function getSelectRenderValue(
70
107
  options: SelectOption[],
71
108
  placeholder: string | null | undefined,