@elementor/editor-controls 4.3.0-1008 → 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/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +77 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/controls/email-form-action-control/email-chips-field.tsx +37 -10
- package/src/controls/email-form-action-control/fields.tsx +38 -15
- package/src/controls/email-form-action-control/utils.ts +6 -0
- package/src/controls/mention-text-area-control.tsx +2 -2
- package/src/controls/select-control.tsx +47 -10
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-
|
|
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-
|
|
44
|
-
"@elementor/editor-elements": "4.3.0-
|
|
45
|
-
"@elementor/editor-props": "4.3.0-
|
|
46
|
-
"@elementor/editor-responsive": "4.3.0-
|
|
47
|
-
"@elementor/editor-ui": "4.3.0-
|
|
48
|
-
"@elementor/editor-v1-adapters": "4.3.0-
|
|
49
|
-
"@elementor/env": "4.3.0-
|
|
50
|
-
"@elementor/events": "4.3.0-
|
|
51
|
-
"@elementor/http-client": "4.3.0-
|
|
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-
|
|
54
|
-
"@elementor/query": "4.3.0-
|
|
55
|
-
"@elementor/schema": "4.3.0-
|
|
56
|
-
"@elementor/session": "4.3.0-
|
|
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-
|
|
59
|
-
"@elementor/wp-media": "4.3.0-
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { type KeyboardEvent, type SyntheticEvent, useState } from 'react';
|
|
2
|
+
import { type KeyboardEvent, type SyntheticEvent, useMemo, useState } from 'react';
|
|
3
3
|
import { stringArrayPropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
|
|
4
4
|
import { Autocomplete, Grid, TextField } from '@elementor/ui';
|
|
5
5
|
|
|
@@ -8,13 +8,28 @@ import { ChipsList } from '../../components/chips-list';
|
|
|
8
8
|
import { ControlFormLabel } from '../../components/control-form-label';
|
|
9
9
|
import ControlActions from '../../control-actions/control-actions';
|
|
10
10
|
import { createControl } from '../../create-control';
|
|
11
|
-
import {
|
|
11
|
+
import { type Suggestion } from '../../hooks/use-form-field-suggestions';
|
|
12
|
+
import { createMentionPattern } from '../mention-text-area-control';
|
|
13
|
+
import { CHIP_TRIGGER_KEYS, isFormFieldShortcode, isValidEmail } from './utils';
|
|
14
|
+
|
|
15
|
+
const isValidRecipient = ( address: string ) => isValidEmail( address ) || isFormFieldShortcode( address );
|
|
16
|
+
|
|
17
|
+
function resolveMention( raw: string, suggestions: Suggestion[] ): string {
|
|
18
|
+
if ( ! raw.startsWith( '@' ) ) {
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const match = suggestions.find( ( suggestion ) => createMentionPattern( suggestion.value, 'start' ).test( raw ) );
|
|
23
|
+
|
|
24
|
+
return match ? `[${ match.value }]` : raw;
|
|
25
|
+
}
|
|
12
26
|
|
|
13
27
|
type EmailChipsControlProps = {
|
|
14
28
|
placeholder?: string;
|
|
29
|
+
suggestions?: Suggestion[];
|
|
15
30
|
};
|
|
16
31
|
|
|
17
|
-
export const EmailChipsControl = createControl( ( { placeholder }: EmailChipsControlProps ) => {
|
|
32
|
+
export const EmailChipsControl = createControl( ( { placeholder, suggestions = [] }: EmailChipsControlProps ) => {
|
|
18
33
|
const { value, setValue, disabled } = useBoundProp( stringArrayPropTypeUtil );
|
|
19
34
|
const [ inputValue, setInputValue ] = useState( '' );
|
|
20
35
|
|
|
@@ -24,10 +39,15 @@ export const EmailChipsControl = createControl( ( { placeholder }: EmailChipsCon
|
|
|
24
39
|
.map( ( item ) => stringPropTypeUtil.extract( item ) )
|
|
25
40
|
.filter( ( val ): val is string => val !== null );
|
|
26
41
|
|
|
42
|
+
const suggestionOptions = useMemo(
|
|
43
|
+
() => suggestions.map( ( suggestion ) => `[${ suggestion.value }]` ),
|
|
44
|
+
[ suggestions ]
|
|
45
|
+
);
|
|
46
|
+
|
|
27
47
|
const tryAddChip = ( raw: string ) => {
|
|
28
|
-
const address = raw.trim();
|
|
48
|
+
const address = resolveMention( raw.trim(), suggestions );
|
|
29
49
|
|
|
30
|
-
if ( ! address || selectedValues.includes( address ) || !
|
|
50
|
+
if ( ! address || selectedValues.includes( address ) || ! isValidRecipient( address ) ) {
|
|
31
51
|
return;
|
|
32
52
|
}
|
|
33
53
|
|
|
@@ -39,9 +59,9 @@ export const EmailChipsControl = createControl( ( { placeholder }: EmailChipsCon
|
|
|
39
59
|
const updated = [];
|
|
40
60
|
|
|
41
61
|
for ( const entry of newValue ) {
|
|
42
|
-
const address = entry.trim();
|
|
62
|
+
const address = resolveMention( entry.trim(), suggestions );
|
|
43
63
|
|
|
44
|
-
if ( ! address || !
|
|
64
|
+
if ( ! address || ! isValidRecipient( address ) ) {
|
|
45
65
|
continue;
|
|
46
66
|
}
|
|
47
67
|
|
|
@@ -82,7 +102,13 @@ export const EmailChipsControl = createControl( ( { placeholder }: EmailChipsCon
|
|
|
82
102
|
} }
|
|
83
103
|
value={ selectedValues }
|
|
84
104
|
onChange={ handleChange }
|
|
85
|
-
options={
|
|
105
|
+
options={ suggestionOptions }
|
|
106
|
+
filterOptions={ ( options, state ) => {
|
|
107
|
+
const query = state.inputValue.trim().replace( /^@/, '' ).toLowerCase();
|
|
108
|
+
|
|
109
|
+
return query ? options.filter( ( option ) => option.toLowerCase().includes( query ) ) : options;
|
|
110
|
+
} }
|
|
111
|
+
filterSelectedOptions
|
|
86
112
|
onBlur={ handleBlur }
|
|
87
113
|
getOptionLabel={ ( option ) => option }
|
|
88
114
|
isOptionEqualToValue={ ( option, val ) => option === val }
|
|
@@ -100,15 +126,16 @@ export const EmailChipsControl = createControl( ( { placeholder }: EmailChipsCon
|
|
|
100
126
|
type EmailChipsFieldProps = {
|
|
101
127
|
fieldLabel: string;
|
|
102
128
|
placeholder?: string;
|
|
129
|
+
suggestions?: Suggestion[];
|
|
103
130
|
};
|
|
104
131
|
|
|
105
|
-
export const EmailChipsField = ( { fieldLabel, placeholder }: EmailChipsFieldProps ) => (
|
|
132
|
+
export const EmailChipsField = ( { fieldLabel, placeholder, suggestions }: EmailChipsFieldProps ) => (
|
|
106
133
|
<Grid container direction="column" gap={ 0.5 }>
|
|
107
134
|
<Grid item>
|
|
108
135
|
<ControlFormLabel>{ fieldLabel }</ControlFormLabel>
|
|
109
136
|
</Grid>
|
|
110
137
|
<Grid item>
|
|
111
|
-
<EmailChipsControl placeholder={ placeholder } />
|
|
138
|
+
<EmailChipsControl placeholder={ placeholder } suggestions={ suggestions } />
|
|
112
139
|
</Grid>
|
|
113
140
|
</Grid>
|
|
114
141
|
);
|
|
@@ -13,11 +13,26 @@ import { EmailChipsField } from './email-chips-field';
|
|
|
13
13
|
import { EmailField } from './email-field';
|
|
14
14
|
import { shouldShowMentionsInfo } from './utils';
|
|
15
15
|
|
|
16
|
-
export const SendToField = ( { placeholder }: { placeholder?: string } ) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
export const SendToField = ( { placeholder }: { placeholder?: string } ) => {
|
|
17
|
+
const suggestions = useFormFieldSuggestions( { inputType: 'email' } );
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<PropKeyProvider bind="to">
|
|
21
|
+
<Stack gap={ 0.5 }>
|
|
22
|
+
<EmailChipsField
|
|
23
|
+
fieldLabel={ __( 'Send to', 'elementor' ) }
|
|
24
|
+
placeholder={ placeholder }
|
|
25
|
+
suggestions={ suggestions }
|
|
26
|
+
/>
|
|
27
|
+
{ shouldShowMentionsInfo() && (
|
|
28
|
+
<InfoAlert>
|
|
29
|
+
{ __( 'Type @ or an email field name to insert its submitted value.', 'elementor' ) }
|
|
30
|
+
</InfoAlert>
|
|
31
|
+
) }
|
|
32
|
+
</Stack>
|
|
33
|
+
</PropKeyProvider>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
21
36
|
|
|
22
37
|
export const SubjectField = () => (
|
|
23
38
|
<EmailField
|
|
@@ -92,17 +107,25 @@ export const ReplyToField = () => {
|
|
|
92
107
|
);
|
|
93
108
|
};
|
|
94
109
|
|
|
95
|
-
export const CcField = () =>
|
|
96
|
-
|
|
97
|
-
<EmailChipsField fieldLabel={ __( 'Cc', 'elementor' ) } />
|
|
98
|
-
</PropKeyProvider>
|
|
99
|
-
);
|
|
110
|
+
export const CcField = () => {
|
|
111
|
+
const suggestions = useFormFieldSuggestions( { inputType: 'email' } );
|
|
100
112
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
);
|
|
113
|
+
return (
|
|
114
|
+
<PropKeyProvider bind="cc">
|
|
115
|
+
<EmailChipsField fieldLabel={ __( 'Cc', 'elementor' ) } suggestions={ suggestions } />
|
|
116
|
+
</PropKeyProvider>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export const BccField = () => {
|
|
121
|
+
const suggestions = useFormFieldSuggestions( { inputType: 'email' } );
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
<PropKeyProvider bind="bcc">
|
|
125
|
+
<EmailChipsField fieldLabel={ __( 'Bcc', 'elementor' ) } suggestions={ suggestions } />
|
|
126
|
+
</PropKeyProvider>
|
|
127
|
+
);
|
|
128
|
+
};
|
|
106
129
|
|
|
107
130
|
export const MetaDataField = () => (
|
|
108
131
|
<PropKeyProvider bind="meta-data">
|
|
@@ -9,6 +9,12 @@ export function isValidEmail( email: string ): boolean {
|
|
|
9
9
|
return z.string().email().safeParse( email ).success;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
const FORM_FIELD_SHORTCODE_PATTERN = /^\[[^[\]]+]$/;
|
|
13
|
+
|
|
14
|
+
export function isFormFieldShortcode( value: string ): boolean {
|
|
15
|
+
return FORM_FIELD_SHORTCODE_PATTERN.test( value );
|
|
16
|
+
}
|
|
17
|
+
|
|
12
18
|
export const shouldShowMentionsInfo = (): boolean => {
|
|
13
19
|
if ( ! hasProInstalled() ) {
|
|
14
20
|
return true;
|
|
@@ -81,9 +81,9 @@ const MentionWrapper = styled( 'div' )( ( { theme } ) => ( {
|
|
|
81
81
|
},
|
|
82
82
|
} ) );
|
|
83
83
|
|
|
84
|
-
type TriggerPosition = 'start' | 'auto';
|
|
84
|
+
export type TriggerPosition = 'start' | 'auto';
|
|
85
85
|
|
|
86
|
-
function createMentionPattern( value: string, triggerPosition: TriggerPosition ): RegExp {
|
|
86
|
+
export function createMentionPattern( value: string, triggerPosition: TriggerPosition ): RegExp {
|
|
87
87
|
const escaped = value.replace( /[.*+?^${}()|[\]\\]/g, '\\$&' );
|
|
88
88
|
const prefix = 'start' === triggerPosition ? '^' : '';
|
|
89
89
|
|
|
@@ -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
|
|
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
|
|
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(
|
|
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
|
-
{
|
|
59
|
-
|
|
60
|
-
|
|
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,
|