@elementor/editor-variables 3.32.0-64 → 3.32.0-65
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 +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +251 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/ui/mismatch-variable-alert.tsx +57 -0
- package/src/components/ui/tags/mismatch-tag.tsx +37 -0
- package/src/components/ui/variable/mismatch-variable.tsx +91 -0
- package/src/controls/variable-control.tsx +13 -3
- package/src/variables-registry/create-variable-type-registry.ts +15 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-variables",
|
|
3
|
-
"version": "3.32.0-
|
|
3
|
+
"version": "3.32.0-65",
|
|
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-
|
|
43
|
-
"@elementor/editor-canvas": "3.32.0-
|
|
44
|
-
"@elementor/editor-controls": "3.32.0-
|
|
45
|
-
"@elementor/editor-current-user": "3.32.0-
|
|
46
|
-
"@elementor/editor-editing-panel": "3.32.0-
|
|
47
|
-
"@elementor/editor-panels": "3.32.0-
|
|
48
|
-
"@elementor/editor-props": "3.32.0-
|
|
49
|
-
"@elementor/editor-ui": "3.32.0-
|
|
50
|
-
"@elementor/editor-v1-adapters": "3.32.0-
|
|
51
|
-
"@elementor/http-client": "3.32.0-
|
|
42
|
+
"@elementor/editor": "3.32.0-65",
|
|
43
|
+
"@elementor/editor-canvas": "3.32.0-65",
|
|
44
|
+
"@elementor/editor-controls": "3.32.0-65",
|
|
45
|
+
"@elementor/editor-current-user": "3.32.0-65",
|
|
46
|
+
"@elementor/editor-editing-panel": "3.32.0-65",
|
|
47
|
+
"@elementor/editor-panels": "3.32.0-65",
|
|
48
|
+
"@elementor/editor-props": "3.32.0-65",
|
|
49
|
+
"@elementor/editor-ui": "3.32.0-65",
|
|
50
|
+
"@elementor/editor-v1-adapters": "3.32.0-65",
|
|
51
|
+
"@elementor/http-client": "3.32.0-65",
|
|
52
52
|
"@elementor/icons": "1.46.0",
|
|
53
|
-
"@elementor/schema": "3.32.0-
|
|
53
|
+
"@elementor/schema": "3.32.0-65",
|
|
54
54
|
"@elementor/ui": "1.36.8",
|
|
55
55
|
"@wordpress/i18n": "^5.13.0"
|
|
56
56
|
},
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useSectionWidth } from '@elementor/editor-editing-panel';
|
|
3
|
+
import { Alert, AlertAction, AlertTitle, ClickAwayListener } from '@elementor/ui';
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
type AlertProps = {
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
onClear?: () => void;
|
|
9
|
+
triggerSelect?: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const i18n = {
|
|
13
|
+
title: __( 'Variable has changed', 'elementor' ),
|
|
14
|
+
message: __(
|
|
15
|
+
`This variable is no longer compatible with this property. You can clear it or select a different one.`,
|
|
16
|
+
'elementor'
|
|
17
|
+
),
|
|
18
|
+
buttons: {
|
|
19
|
+
clear: __( 'Clear', 'elementor' ),
|
|
20
|
+
select: __( 'Select variable', 'elementor' ),
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const MismatchVariableAlert = ( { onClose, onClear, triggerSelect }: AlertProps ) => {
|
|
25
|
+
const sectionWidth = useSectionWidth();
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<ClickAwayListener onClickAway={ onClose }>
|
|
29
|
+
<Alert
|
|
30
|
+
variant="standard"
|
|
31
|
+
severity="warning"
|
|
32
|
+
onClose={ onClose }
|
|
33
|
+
action={
|
|
34
|
+
<>
|
|
35
|
+
{ onClear && (
|
|
36
|
+
<AlertAction variant="contained" onClick={ onClear }>
|
|
37
|
+
{ i18n.buttons.clear }
|
|
38
|
+
</AlertAction>
|
|
39
|
+
) }
|
|
40
|
+
{ triggerSelect && (
|
|
41
|
+
<AlertAction variant="outlined" onClick={ triggerSelect }>
|
|
42
|
+
{ i18n.buttons.select }
|
|
43
|
+
</AlertAction>
|
|
44
|
+
) }
|
|
45
|
+
</>
|
|
46
|
+
}
|
|
47
|
+
sx={ {
|
|
48
|
+
width: sectionWidth,
|
|
49
|
+
minWidth: 300,
|
|
50
|
+
} }
|
|
51
|
+
>
|
|
52
|
+
<AlertTitle>{ i18n.title }</AlertTitle>
|
|
53
|
+
{ i18n.message }
|
|
54
|
+
</Alert>
|
|
55
|
+
</ClickAwayListener>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AlertTriangleFilledIcon } from '@elementor/icons';
|
|
3
|
+
import { Box, Chip, type ChipProps, type Theme, Tooltip, Typography } from '@elementor/ui';
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
export const MismatchTag = React.forwardRef< HTMLDivElement, ChipProps >( ( { label, onClick, ...props }, ref ) => {
|
|
7
|
+
return (
|
|
8
|
+
<Chip
|
|
9
|
+
ref={ ref }
|
|
10
|
+
size="tiny"
|
|
11
|
+
color="warning"
|
|
12
|
+
shape="rounded"
|
|
13
|
+
variant="standard"
|
|
14
|
+
onClick={ onClick }
|
|
15
|
+
icon={ <AlertTriangleFilledIcon /> }
|
|
16
|
+
label={
|
|
17
|
+
<Tooltip title={ label } placement="top">
|
|
18
|
+
<Box sx={ { display: 'flex', gap: 0.5, alignItems: 'center' } }>
|
|
19
|
+
<Typography variant="caption" noWrap>
|
|
20
|
+
{ label }
|
|
21
|
+
</Typography>
|
|
22
|
+
<Typography variant="caption" noWrap sx={ { textOverflow: 'initial', overflow: 'visible' } }>
|
|
23
|
+
({ __( 'changed', 'elementor' ) })
|
|
24
|
+
</Typography>
|
|
25
|
+
</Box>
|
|
26
|
+
</Tooltip>
|
|
27
|
+
}
|
|
28
|
+
sx={ {
|
|
29
|
+
height: ( theme: Theme ) => theme.spacing( 3.5 ),
|
|
30
|
+
borderRadius: ( theme: Theme ) => theme.spacing( 1 ),
|
|
31
|
+
justifyContent: 'flex-start',
|
|
32
|
+
width: '100%',
|
|
33
|
+
} }
|
|
34
|
+
{ ...props }
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
} );
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useId, useRef, useState } from 'react';
|
|
3
|
+
import { useBoundProp } from '@elementor/editor-controls';
|
|
4
|
+
import { Backdrop, bindPopover, Box, Infotip, Popover, usePopupState } from '@elementor/ui';
|
|
5
|
+
|
|
6
|
+
import { type Variable } from '../../../types';
|
|
7
|
+
import { VariableSelectionPopover } from '../../variable-selection-popover';
|
|
8
|
+
import { MismatchVariableAlert } from '../mismatch-variable-alert';
|
|
9
|
+
import { MismatchTag } from '../tags/mismatch-tag';
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
variable: Variable;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const MismatchVariable = ( { variable }: Props ) => {
|
|
16
|
+
const { setValue } = useBoundProp();
|
|
17
|
+
|
|
18
|
+
const anchorRef = useRef< HTMLDivElement >( null );
|
|
19
|
+
|
|
20
|
+
const popupId = useId();
|
|
21
|
+
const popupState = usePopupState( {
|
|
22
|
+
variant: 'popover',
|
|
23
|
+
popupId: `elementor-variables-list-${ popupId }`,
|
|
24
|
+
} );
|
|
25
|
+
|
|
26
|
+
const [ infotipVisible, setInfotipVisible ] = useState( false );
|
|
27
|
+
|
|
28
|
+
const toggleInfotip = () => setInfotipVisible( ( prev ) => ! prev );
|
|
29
|
+
const closeInfotip = () => setInfotipVisible( false );
|
|
30
|
+
|
|
31
|
+
const triggerSelect = () => {
|
|
32
|
+
closeInfotip();
|
|
33
|
+
|
|
34
|
+
popupState.setAnchorEl( anchorRef.current );
|
|
35
|
+
popupState.open();
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const clearValue = () => {
|
|
39
|
+
closeInfotip();
|
|
40
|
+
setValue( null );
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Box ref={ anchorRef }>
|
|
45
|
+
{ infotipVisible && <Backdrop open onClick={ closeInfotip } invisible /> }
|
|
46
|
+
<Infotip
|
|
47
|
+
color="warning"
|
|
48
|
+
placement="right-start"
|
|
49
|
+
open={ infotipVisible }
|
|
50
|
+
disableHoverListener
|
|
51
|
+
onClose={ closeInfotip }
|
|
52
|
+
content={
|
|
53
|
+
<MismatchVariableAlert
|
|
54
|
+
onClose={ closeInfotip }
|
|
55
|
+
onClear={ clearValue }
|
|
56
|
+
triggerSelect={ triggerSelect }
|
|
57
|
+
/>
|
|
58
|
+
}
|
|
59
|
+
slotProps={ {
|
|
60
|
+
popper: {
|
|
61
|
+
modifiers: [
|
|
62
|
+
{
|
|
63
|
+
name: 'offset',
|
|
64
|
+
options: { offset: [ 0, 24 ] },
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
} }
|
|
69
|
+
>
|
|
70
|
+
<MismatchTag label={ variable.label } onClick={ toggleInfotip } />
|
|
71
|
+
</Infotip>
|
|
72
|
+
|
|
73
|
+
<Popover
|
|
74
|
+
disableScrollLock
|
|
75
|
+
anchorEl={ anchorRef.current }
|
|
76
|
+
anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
|
|
77
|
+
transformOrigin={ { vertical: 'top', horizontal: 'right' } }
|
|
78
|
+
PaperProps={ {
|
|
79
|
+
sx: { my: 1 },
|
|
80
|
+
} }
|
|
81
|
+
{ ...bindPopover( popupState ) }
|
|
82
|
+
>
|
|
83
|
+
<VariableSelectionPopover
|
|
84
|
+
selectedVariable={ variable }
|
|
85
|
+
closePopover={ popupState.close }
|
|
86
|
+
propTypeKey={ variable.type }
|
|
87
|
+
/>
|
|
88
|
+
</Popover>
|
|
89
|
+
</Box>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
@@ -4,23 +4,33 @@ import { type TransformablePropValue } from '@elementor/editor-props';
|
|
|
4
4
|
|
|
5
5
|
import { AssignedVariable } from '../components/ui/variable/assigned-variable';
|
|
6
6
|
import { DeletedVariable } from '../components/ui/variable/deleted-variable';
|
|
7
|
+
import { MismatchVariable } from '../components/ui/variable/mismatch-variable';
|
|
7
8
|
import { MissingVariable } from '../components/ui/variable/missing-variable';
|
|
8
9
|
import { useVariable } from '../hooks/use-prop-variables';
|
|
10
|
+
import { getVariableType } from '../variables-registry/variable-type-registry';
|
|
9
11
|
|
|
10
12
|
export const VariableControl = () => {
|
|
11
|
-
const boundProp = useBoundProp()
|
|
13
|
+
const boundProp = useBoundProp();
|
|
12
14
|
|
|
13
|
-
const
|
|
15
|
+
const boundPropValue = boundProp.value as TransformablePropValue< string, string >;
|
|
16
|
+
|
|
17
|
+
const assignedVariable = useVariable( boundPropValue?.value );
|
|
14
18
|
|
|
15
19
|
if ( ! assignedVariable ) {
|
|
16
20
|
return <MissingVariable />;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
const { $$type: propTypeKey } =
|
|
23
|
+
const { $$type: propTypeKey } = boundPropValue;
|
|
20
24
|
|
|
21
25
|
if ( assignedVariable?.deleted ) {
|
|
22
26
|
return <DeletedVariable variable={ assignedVariable } propTypeKey={ propTypeKey } />;
|
|
23
27
|
}
|
|
24
28
|
|
|
29
|
+
const { isCompatible } = getVariableType( assignedVariable.type );
|
|
30
|
+
|
|
31
|
+
if ( isCompatible && ! isCompatible( boundProp?.propType, assignedVariable ) ) {
|
|
32
|
+
return <MismatchVariable variable={ assignedVariable } />;
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
return <AssignedVariable variable={ assignedVariable } propTypeKey={ propTypeKey } />;
|
|
26
36
|
};
|
|
@@ -12,7 +12,7 @@ import { type SvgIconProps } from '@elementor/ui';
|
|
|
12
12
|
|
|
13
13
|
import { inheritanceTransformer } from '../transformers/inheritance-transformer';
|
|
14
14
|
import { variableTransformer } from '../transformers/variable-transformer';
|
|
15
|
-
import { type NormalizedVariable } from '../types';
|
|
15
|
+
import { type NormalizedVariable, type Variable } from '../types';
|
|
16
16
|
|
|
17
17
|
export type ValueFieldProps = {
|
|
18
18
|
value: string;
|
|
@@ -32,6 +32,7 @@ type VariableTypeOptions = {
|
|
|
32
32
|
propTypeUtil: PropTypeUtil< string, string >;
|
|
33
33
|
selectionFilter?: ( variables: NormalizedVariable[], propType: PropType ) => NormalizedVariable[];
|
|
34
34
|
valueTransformer?: ( value: string ) => PropValue;
|
|
35
|
+
isCompatible?: ( propType: PropType, variable: Variable ) => boolean;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export type VariableTypesMap = Record< string, VariableTypeOptions >;
|
|
@@ -48,11 +49,23 @@ export function createVariableTypeRegistry() {
|
|
|
48
49
|
selectionFilter,
|
|
49
50
|
valueTransformer,
|
|
50
51
|
fallbackPropTypeUtil,
|
|
52
|
+
isCompatible,
|
|
51
53
|
}: VariableTypeOptions ) => {
|
|
52
54
|
if ( variableTypes[ propTypeUtil.key ] ) {
|
|
53
55
|
throw new Error( `Variable with key "${ propTypeUtil.key }" is already registered.` );
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
if ( ! isCompatible ) {
|
|
59
|
+
isCompatible = ( propType, variable: Variable ) => {
|
|
60
|
+
if ( 'union' === propType.kind ) {
|
|
61
|
+
if ( variable.type in propType.prop_types ) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
variableTypes[ propTypeUtil.key ] = {
|
|
57
70
|
icon,
|
|
58
71
|
startIcon,
|
|
@@ -62,6 +75,7 @@ export function createVariableTypeRegistry() {
|
|
|
62
75
|
selectionFilter,
|
|
63
76
|
valueTransformer,
|
|
64
77
|
fallbackPropTypeUtil,
|
|
78
|
+
isCompatible,
|
|
65
79
|
};
|
|
66
80
|
|
|
67
81
|
registerTransformer( propTypeUtil.key );
|