@elementor/editor-variables 0.15.0 → 0.16.0
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/CHANGELOG.md +38 -0
- package/dist/index.js +647 -495
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +637 -512
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
- package/src/components/color-variable-creation.tsx +11 -52
- package/src/components/color-variable-edit.tsx +88 -83
- package/src/components/fields/color-field.tsx +54 -0
- package/src/components/fields/font-field.tsx +85 -0
- package/src/components/fields/label-field.tsx +54 -0
- package/src/components/font-variable-creation.tsx +13 -72
- package/src/components/font-variable-edit.tsx +86 -111
- package/src/components/ui/delete-confirmation-dialog.tsx +55 -0
- package/src/components/ui/menu-item-content.tsx +2 -5
- package/src/components/ui/{variable-tag.tsx → tags/assigned-tag.tsx} +1 -1
- package/src/components/ui/tags/deleted-tag.tsx +26 -0
- package/src/components/ui/variable/assigned-variable.tsx +70 -0
- package/src/components/ui/variable/deleted-variable.tsx +20 -0
- package/src/controls/color-variable-control.tsx +15 -48
- package/src/controls/font-variable-control.tsx +14 -43
- package/src/init-color-variables.ts +3 -48
- package/src/repeater-injections.ts +35 -0
- package/src/utils/validations.ts +42 -0
|
@@ -1,26 +1,17 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { PopoverHeader
|
|
6
|
-
import { ArrowLeftIcon,
|
|
7
|
-
import {
|
|
8
|
-
bindPopover,
|
|
9
|
-
bindTrigger,
|
|
10
|
-
Button,
|
|
11
|
-
CardActions,
|
|
12
|
-
Divider,
|
|
13
|
-
FormLabel,
|
|
14
|
-
Grid,
|
|
15
|
-
IconButton,
|
|
16
|
-
Popover,
|
|
17
|
-
TextField,
|
|
18
|
-
UnstableTag,
|
|
19
|
-
usePopupState,
|
|
20
|
-
} from '@elementor/ui';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
|
|
4
|
+
import { PopoverScrollableContent } from '@elementor/editor-editing-panel';
|
|
5
|
+
import { PopoverHeader } from '@elementor/editor-ui';
|
|
6
|
+
import { ArrowLeftIcon, TextIcon, TrashIcon } from '@elementor/icons';
|
|
7
|
+
import { Button, CardActions, Divider, IconButton } from '@elementor/ui';
|
|
21
8
|
import { __ } from '@wordpress/i18n';
|
|
22
9
|
|
|
23
10
|
import { deleteVariable, updateVariable, useVariable } from '../hooks/use-prop-variables';
|
|
11
|
+
import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
|
|
12
|
+
import { FontField } from './fields/font-field';
|
|
13
|
+
import { LabelField } from './fields/label-field';
|
|
14
|
+
import { DeleteConfirmationDialog } from './ui/delete-confirmation-dialog';
|
|
24
15
|
|
|
25
16
|
const SIZE = 'tiny';
|
|
26
17
|
|
|
@@ -32,8 +23,10 @@ type Props = {
|
|
|
32
23
|
};
|
|
33
24
|
|
|
34
25
|
export const FontVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) => {
|
|
35
|
-
const
|
|
26
|
+
const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp( fontVariablePropTypeUtil );
|
|
27
|
+
const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
|
|
36
28
|
|
|
29
|
+
const variable = useVariable( editId );
|
|
37
30
|
if ( ! variable ) {
|
|
38
31
|
throw new Error( `Global font variable "${ editId }" not found` );
|
|
39
32
|
}
|
|
@@ -41,123 +34,105 @@ export const FontVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props
|
|
|
41
34
|
const [ fontFamily, setFontFamily ] = useState( variable.value );
|
|
42
35
|
const [ label, setLabel ] = useState( variable.label );
|
|
43
36
|
|
|
44
|
-
const variableNameId = useId();
|
|
45
|
-
const variableValueId = useId();
|
|
46
|
-
|
|
47
|
-
const anchorRef = useRef< HTMLDivElement >( null );
|
|
48
|
-
const fontPopoverState = usePopupState( { variant: 'popover' } );
|
|
49
|
-
|
|
50
|
-
const fontFamilies = useFontFamilies();
|
|
51
|
-
|
|
52
37
|
const handleUpdate = () => {
|
|
53
38
|
updateVariable( editId, {
|
|
54
39
|
value: fontFamily,
|
|
55
40
|
label,
|
|
56
41
|
} ).then( () => {
|
|
42
|
+
maybeTriggerBoundPropChange();
|
|
57
43
|
onSubmit?.();
|
|
58
44
|
} );
|
|
59
45
|
};
|
|
60
46
|
|
|
61
47
|
const handleDelete = () => {
|
|
62
48
|
deleteVariable( editId ).then( () => {
|
|
49
|
+
maybeTriggerBoundPropChange();
|
|
63
50
|
onSubmit?.();
|
|
64
51
|
} );
|
|
65
52
|
};
|
|
66
53
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
const maybeTriggerBoundPropChange = () => {
|
|
55
|
+
if ( editId === assignedValue ) {
|
|
56
|
+
notifyBoundPropChange( editId );
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const handleDeleteConfirmation = () => {
|
|
61
|
+
setDeleteConfirmation( true );
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const closeDeleteDialog = () => () => {
|
|
65
|
+
setDeleteConfirmation( false );
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const hasEmptyValue = () => {
|
|
69
|
+
return ! fontFamily.trim() || ! label.trim();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const noValueChanged = () => {
|
|
73
|
+
return fontFamily === variable.value && label === variable.label;
|
|
74
|
+
};
|
|
70
75
|
|
|
71
|
-
const
|
|
76
|
+
const isSubmitDisabled = noValueChanged() || hasEmptyValue();
|
|
72
77
|
|
|
73
78
|
const actions = [];
|
|
74
79
|
|
|
75
80
|
actions.push(
|
|
76
|
-
<IconButton
|
|
81
|
+
<IconButton
|
|
82
|
+
key="delete"
|
|
83
|
+
size={ SIZE }
|
|
84
|
+
aria-label={ __( 'Delete', 'elementor' ) }
|
|
85
|
+
onClick={ handleDeleteConfirmation }
|
|
86
|
+
>
|
|
77
87
|
<TrashIcon fontSize={ SIZE } />
|
|
78
88
|
</IconButton>
|
|
79
89
|
);
|
|
80
90
|
|
|
81
91
|
return (
|
|
82
|
-
|
|
83
|
-
<
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{ onGoBack && (
|
|
87
|
-
<IconButton size={ SIZE } aria-label={ __( 'Go Back', 'elementor' ) } onClick={ onGoBack }>
|
|
88
|
-
<ArrowLeftIcon fontSize={ SIZE } />
|
|
89
|
-
</IconButton>
|
|
90
|
-
) }
|
|
91
|
-
<TextIcon fontSize={ SIZE } />
|
|
92
|
-
</>
|
|
93
|
-
}
|
|
94
|
-
title={ __( 'Edit variable', 'elementor' ) }
|
|
95
|
-
onClose={ onClose }
|
|
96
|
-
actions={ actions }
|
|
97
|
-
/>
|
|
98
|
-
|
|
99
|
-
<Divider />
|
|
100
|
-
|
|
101
|
-
<PopoverContent p={ 2 }>
|
|
102
|
-
<Grid container gap={ 0.75 } alignItems="center">
|
|
103
|
-
<Grid item xs={ 12 }>
|
|
104
|
-
<FormLabel htmlFor={ variableNameId } size="tiny">
|
|
105
|
-
{ __( 'Name', 'elementor' ) }
|
|
106
|
-
</FormLabel>
|
|
107
|
-
</Grid>
|
|
108
|
-
<Grid item xs={ 12 }>
|
|
109
|
-
<TextField
|
|
110
|
-
id={ variableNameId }
|
|
111
|
-
size="tiny"
|
|
112
|
-
fullWidth
|
|
113
|
-
value={ label }
|
|
114
|
-
onChange={ ( e: React.ChangeEvent< HTMLInputElement > ) => setLabel( e.target.value ) }
|
|
115
|
-
/>
|
|
116
|
-
</Grid>
|
|
117
|
-
</Grid>
|
|
118
|
-
|
|
119
|
-
<Grid container gap={ 0.75 } alignItems="center">
|
|
120
|
-
<Grid item xs={ 12 }>
|
|
121
|
-
<FormLabel htmlFor={ variableValueId } size="tiny">
|
|
122
|
-
{ __( 'Value', 'elementor' ) }
|
|
123
|
-
</FormLabel>
|
|
124
|
-
</Grid>
|
|
125
|
-
<Grid item xs={ 12 }>
|
|
92
|
+
<>
|
|
93
|
+
<PopoverScrollableContent height="auto">
|
|
94
|
+
<PopoverHeader
|
|
95
|
+
icon={
|
|
126
96
|
<>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
disableScrollLock
|
|
138
|
-
anchorEl={ anchorRef.current }
|
|
139
|
-
anchorOrigin={ { vertical: 'top', horizontal: 'right' } }
|
|
140
|
-
transformOrigin={ { vertical: 'top', horizontal: -20 } }
|
|
141
|
-
{ ...bindPopover( fontPopoverState ) }
|
|
142
|
-
>
|
|
143
|
-
<FontFamilySelector
|
|
144
|
-
fontFamilies={ fontFamilies }
|
|
145
|
-
fontFamily={ fontFamily }
|
|
146
|
-
onFontFamilyChange={ setFontFamily }
|
|
147
|
-
onClose={ fontPopoverState.close }
|
|
148
|
-
sectionWidth={ sectionWidth }
|
|
149
|
-
/>
|
|
150
|
-
</Popover>
|
|
97
|
+
{ onGoBack && (
|
|
98
|
+
<IconButton
|
|
99
|
+
size={ SIZE }
|
|
100
|
+
aria-label={ __( 'Go Back', 'elementor' ) }
|
|
101
|
+
onClick={ onGoBack }
|
|
102
|
+
>
|
|
103
|
+
<ArrowLeftIcon fontSize={ SIZE } />
|
|
104
|
+
</IconButton>
|
|
105
|
+
) }
|
|
106
|
+
<TextIcon fontSize={ SIZE } />
|
|
151
107
|
</>
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
108
|
+
}
|
|
109
|
+
title={ __( 'Edit variable', 'elementor' ) }
|
|
110
|
+
onClose={ onClose }
|
|
111
|
+
actions={ actions }
|
|
112
|
+
/>
|
|
113
|
+
|
|
114
|
+
<Divider />
|
|
115
|
+
|
|
116
|
+
<PopoverContent p={ 2 }>
|
|
117
|
+
<LabelField value={ label } onChange={ setLabel } />
|
|
118
|
+
<FontField value={ fontFamily } onChange={ setFontFamily } />
|
|
119
|
+
</PopoverContent>
|
|
120
|
+
|
|
121
|
+
<CardActions sx={ { pt: 0.5, pb: 1 } }>
|
|
122
|
+
<Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleUpdate }>
|
|
123
|
+
{ __( 'Save', 'elementor' ) }
|
|
124
|
+
</Button>
|
|
125
|
+
</CardActions>
|
|
126
|
+
</PopoverScrollableContent>
|
|
127
|
+
|
|
128
|
+
{ deleteConfirmation && (
|
|
129
|
+
<DeleteConfirmationDialog
|
|
130
|
+
open
|
|
131
|
+
label={ label }
|
|
132
|
+
onConfirm={ handleDelete }
|
|
133
|
+
closeDialog={ closeDeleteDialog() }
|
|
134
|
+
/>
|
|
135
|
+
) }
|
|
136
|
+
</>
|
|
162
137
|
);
|
|
163
138
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AlertOctagonFilledIcon } from '@elementor/icons';
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogActions,
|
|
7
|
+
DialogContent,
|
|
8
|
+
DialogContentText,
|
|
9
|
+
DialogTitle,
|
|
10
|
+
Typography,
|
|
11
|
+
} from '@elementor/ui';
|
|
12
|
+
import { __ } from '@wordpress/i18n';
|
|
13
|
+
|
|
14
|
+
const TITLE_ID = 'delete-variable-dialog';
|
|
15
|
+
|
|
16
|
+
export const DeleteConfirmationDialog = ( {
|
|
17
|
+
open,
|
|
18
|
+
label,
|
|
19
|
+
closeDialog,
|
|
20
|
+
onConfirm,
|
|
21
|
+
}: {
|
|
22
|
+
open: boolean;
|
|
23
|
+
label: string;
|
|
24
|
+
closeDialog: () => void;
|
|
25
|
+
onConfirm: () => void;
|
|
26
|
+
} ) => {
|
|
27
|
+
return (
|
|
28
|
+
<Dialog open={ open } onClose={ closeDialog } aria-labelledby={ TITLE_ID } maxWidth="xs">
|
|
29
|
+
<DialogTitle id={ TITLE_ID } display="flex" alignItems="center" gap={ 1 } sx={ { lineHeight: 1 } }>
|
|
30
|
+
<AlertOctagonFilledIcon color="error" />
|
|
31
|
+
{ __( 'Delete Variable', 'elementor' ) }
|
|
32
|
+
</DialogTitle>
|
|
33
|
+
<DialogContent>
|
|
34
|
+
<DialogContentText variant="body2" color="textPrimary">
|
|
35
|
+
{ __( 'You are about to delete', 'elementor' ) }
|
|
36
|
+
<Typography variant="subtitle2" component="span">
|
|
37
|
+
{ label }
|
|
38
|
+
</Typography>
|
|
39
|
+
{ __(
|
|
40
|
+
'Variable. Note that its value is still being used anywhere on your site where it was connected to the variable.',
|
|
41
|
+
'elementor'
|
|
42
|
+
) }
|
|
43
|
+
</DialogContentText>
|
|
44
|
+
</DialogContent>
|
|
45
|
+
<DialogActions>
|
|
46
|
+
<Button color="secondary" onClick={ closeDialog }>
|
|
47
|
+
{ __( 'Cancel', 'elementor' ) }
|
|
48
|
+
</Button>
|
|
49
|
+
<Button variant="contained" color="error" onClick={ onConfirm }>
|
|
50
|
+
{ __( 'Delete', 'elementor' ) }
|
|
51
|
+
</Button>
|
|
52
|
+
</DialogActions>
|
|
53
|
+
</Dialog>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { EllipsisWithTooltip, type VirtualizedItem } from '@elementor/editor-ui';
|
|
3
|
-
import { isExperimentActive } from '@elementor/editor-v1-adapters';
|
|
4
3
|
import { EditIcon } from '@elementor/icons';
|
|
5
4
|
import { Box, IconButton, ListItemIcon, Typography } from '@elementor/ui';
|
|
6
5
|
import { __ } from '@wordpress/i18n';
|
|
7
6
|
|
|
8
7
|
const SIZE = 'tiny';
|
|
9
8
|
|
|
10
|
-
const isVersion330Active = isExperimentActive( 'e_v_3_30' );
|
|
11
|
-
|
|
12
9
|
export const MenuItemContent = < T, V extends string >( { item }: { item: VirtualizedItem< T, V > } ) => {
|
|
13
10
|
const onEdit = item.onEdit as ( ( value: V ) => void ) | undefined;
|
|
14
11
|
|
|
@@ -27,8 +24,8 @@ export const MenuItemContent = < T, V extends string >( { item }: { item: Virtua
|
|
|
27
24
|
<EllipsisWithTooltip
|
|
28
25
|
title={ item.label || item.value }
|
|
29
26
|
as={ Typography }
|
|
30
|
-
variant=
|
|
31
|
-
color=
|
|
27
|
+
variant="caption"
|
|
28
|
+
color="text.primary"
|
|
32
29
|
sx={ { marginTop: '1px', lineHeight: '2' } }
|
|
33
30
|
maxWidth="50%"
|
|
34
31
|
/>
|
|
@@ -9,7 +9,7 @@ interface VariableTagProps extends UnstableTagProps {
|
|
|
9
9
|
onUnlink?: () => void;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const AssignedTag = ( { startIcon, label, onUnlink, ...props }: VariableTagProps ) => {
|
|
13
13
|
const actions = [];
|
|
14
14
|
|
|
15
15
|
if ( onUnlink ) {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ColorFilterIcon } from '@elementor/icons';
|
|
3
|
+
import { Box, Typography, UnstableTag as Tag, type UnstableTagProps } from '@elementor/ui';
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
export const DeletedTag = ( { label }: UnstableTagProps ) => {
|
|
7
|
+
return (
|
|
8
|
+
<Tag
|
|
9
|
+
showActionsOnHover
|
|
10
|
+
fullWidth
|
|
11
|
+
label={
|
|
12
|
+
<Box sx={ { display: 'inline-grid', minWidth: 0 } }>
|
|
13
|
+
<Typography sx={ { lineHeight: 1.34 } } variant="caption" noWrap>
|
|
14
|
+
{ label }
|
|
15
|
+
</Typography>
|
|
16
|
+
</Box>
|
|
17
|
+
}
|
|
18
|
+
startIcon={ <ColorFilterIcon fontSize="tiny" /> }
|
|
19
|
+
endAdornment={
|
|
20
|
+
<Typography sx={ { lineHeight: 1.34 } } variant="caption" noWrap>
|
|
21
|
+
({ __( 'deleted', 'elementor' ) })
|
|
22
|
+
</Typography>
|
|
23
|
+
}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useId, useRef } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useBoundProp } from '@elementor/editor-controls';
|
|
4
|
+
import { type PropTypeUtil } from '@elementor/editor-props';
|
|
5
|
+
import { ColorFilterIcon } from '@elementor/icons';
|
|
6
|
+
import { bindPopover, bindTrigger, Box, Popover, usePopupState } from '@elementor/ui';
|
|
7
|
+
|
|
8
|
+
import { type Variable } from '../../../types';
|
|
9
|
+
import { VariableSelectionPopover } from '../../variable-selection-popover';
|
|
10
|
+
import { AssignedTag, SIZE } from '../tags/assigned-tag';
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
variablePropTypeUtil: PropTypeUtil< string, string >;
|
|
14
|
+
fallbackPropTypeUtil: PropTypeUtil< string, string | null > | PropTypeUtil< string, string >;
|
|
15
|
+
additionalStartIcon?: React.ReactNode;
|
|
16
|
+
variable: Variable;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const AssignedVariable = ( {
|
|
20
|
+
variable,
|
|
21
|
+
variablePropTypeUtil,
|
|
22
|
+
fallbackPropTypeUtil,
|
|
23
|
+
additionalStartIcon,
|
|
24
|
+
}: Props ) => {
|
|
25
|
+
const { setValue } = useBoundProp();
|
|
26
|
+
const anchorRef = useRef< HTMLDivElement >( null );
|
|
27
|
+
|
|
28
|
+
const popupId = useId();
|
|
29
|
+
const popupState = usePopupState( {
|
|
30
|
+
variant: 'popover',
|
|
31
|
+
popupId: `elementor-variables-list-${ popupId }`,
|
|
32
|
+
} );
|
|
33
|
+
|
|
34
|
+
const unlinkVariable = () => {
|
|
35
|
+
setValue( fallbackPropTypeUtil.create( variable.value ) );
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Box ref={ anchorRef }>
|
|
40
|
+
<AssignedTag
|
|
41
|
+
label={ variable.label }
|
|
42
|
+
startIcon={
|
|
43
|
+
<>
|
|
44
|
+
<ColorFilterIcon fontSize={ SIZE } />
|
|
45
|
+
|
|
46
|
+
{ additionalStartIcon }
|
|
47
|
+
</>
|
|
48
|
+
}
|
|
49
|
+
onUnlink={ unlinkVariable }
|
|
50
|
+
{ ...bindTrigger( popupState ) }
|
|
51
|
+
/>
|
|
52
|
+
<Popover
|
|
53
|
+
disableScrollLock
|
|
54
|
+
anchorEl={ anchorRef.current }
|
|
55
|
+
anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
|
|
56
|
+
transformOrigin={ { vertical: 'top', horizontal: 'right' } }
|
|
57
|
+
PaperProps={ {
|
|
58
|
+
sx: { my: 1 },
|
|
59
|
+
} }
|
|
60
|
+
{ ...bindPopover( popupState ) }
|
|
61
|
+
>
|
|
62
|
+
<VariableSelectionPopover
|
|
63
|
+
selectedVariable={ variable }
|
|
64
|
+
closePopover={ popupState.close }
|
|
65
|
+
propTypeKey={ variablePropTypeUtil.key }
|
|
66
|
+
/>
|
|
67
|
+
</Popover>
|
|
68
|
+
</Box>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { Box } from '@elementor/ui';
|
|
4
|
+
|
|
5
|
+
import { type Variable } from '../../../types';
|
|
6
|
+
import { DeletedTag } from '../tags/deleted-tag';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
variable: Variable;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const DeletedVariable = ( { variable }: Props ) => {
|
|
13
|
+
const anchorRef = useRef< HTMLDivElement >( null );
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Box ref={ anchorRef }>
|
|
17
|
+
<DeletedTag label={ variable.label } />
|
|
18
|
+
</Box>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -1,66 +1,33 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useId, useRef } from 'react';
|
|
3
2
|
import { useBoundProp } from '@elementor/editor-controls';
|
|
4
3
|
import { colorPropTypeUtil } from '@elementor/editor-props';
|
|
5
|
-
import { ColorFilterIcon } from '@elementor/icons';
|
|
6
|
-
import { bindPopover, bindTrigger, Box, Popover, usePopupState } from '@elementor/ui';
|
|
7
4
|
|
|
8
5
|
import { ColorIndicator } from '../components/ui/color-indicator';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
6
|
+
import { AssignedVariable } from '../components/ui/variable/assigned-variable';
|
|
7
|
+
import { DeletedVariable } from '../components/ui/variable/deleted-variable';
|
|
11
8
|
import { useVariable } from '../hooks/use-prop-variables';
|
|
12
9
|
import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
|
|
13
10
|
|
|
14
11
|
export const ColorVariableControl = () => {
|
|
15
|
-
const { setValue: setColor } = useBoundProp();
|
|
16
12
|
const { value: variableValue } = useBoundProp( colorVariablePropTypeUtil );
|
|
13
|
+
const assignedVariable = useVariable( variableValue );
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const popupId = useId();
|
|
21
|
-
const popupState = usePopupState( {
|
|
22
|
-
variant: 'popover',
|
|
23
|
-
popupId: `elementor-variables-list-${ popupId }`,
|
|
24
|
-
} );
|
|
25
|
-
|
|
26
|
-
const selectedVariable = useVariable( variableValue );
|
|
27
|
-
if ( ! selectedVariable ) {
|
|
15
|
+
if ( ! assignedVariable ) {
|
|
28
16
|
throw new Error( `Global color variable ${ variableValue } not found` );
|
|
29
17
|
}
|
|
30
18
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
const isVariableDeleted = assignedVariable?.deleted;
|
|
20
|
+
|
|
21
|
+
if ( isVariableDeleted ) {
|
|
22
|
+
return <DeletedVariable variable={ assignedVariable } />;
|
|
23
|
+
}
|
|
34
24
|
|
|
35
25
|
return (
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<ColorIndicator size="inherit" value={ selectedVariable.value } component="span" />
|
|
43
|
-
</>
|
|
44
|
-
}
|
|
45
|
-
onUnlink={ unlinkVariable }
|
|
46
|
-
{ ...bindTrigger( popupState ) }
|
|
47
|
-
/>
|
|
48
|
-
<Popover
|
|
49
|
-
disableScrollLock
|
|
50
|
-
anchorEl={ anchorRef.current }
|
|
51
|
-
anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
|
|
52
|
-
transformOrigin={ { vertical: 'top', horizontal: 'right' } }
|
|
53
|
-
PaperProps={ {
|
|
54
|
-
sx: { my: 1 },
|
|
55
|
-
} }
|
|
56
|
-
{ ...bindPopover( popupState ) }
|
|
57
|
-
>
|
|
58
|
-
<VariableSelectionPopover
|
|
59
|
-
selectedVariable={ selectedVariable }
|
|
60
|
-
closePopover={ popupState.close }
|
|
61
|
-
propTypeKey={ colorVariablePropTypeUtil.key }
|
|
62
|
-
/>
|
|
63
|
-
</Popover>
|
|
64
|
-
</Box>
|
|
26
|
+
<AssignedVariable
|
|
27
|
+
variable={ assignedVariable }
|
|
28
|
+
variablePropTypeUtil={ colorVariablePropTypeUtil }
|
|
29
|
+
fallbackPropTypeUtil={ colorPropTypeUtil }
|
|
30
|
+
additionalStartIcon={ <ColorIndicator size="inherit" value={ assignedVariable.value } component="span" /> }
|
|
31
|
+
/>
|
|
65
32
|
);
|
|
66
33
|
};
|
|
@@ -1,60 +1,31 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useId, useRef } from 'react';
|
|
3
2
|
import { useBoundProp } from '@elementor/editor-controls';
|
|
4
3
|
import { stringPropTypeUtil } from '@elementor/editor-props';
|
|
5
|
-
import { ColorFilterIcon } from '@elementor/icons';
|
|
6
|
-
import { bindPopover, bindTrigger, Box, Popover, usePopupState } from '@elementor/ui';
|
|
7
4
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
5
|
+
import { AssignedVariable } from '../components/ui/variable/assigned-variable';
|
|
6
|
+
import { DeletedVariable } from '../components/ui/variable/deleted-variable';
|
|
10
7
|
import { useVariable } from '../hooks/use-prop-variables';
|
|
11
8
|
import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
|
|
12
9
|
|
|
13
10
|
export const FontVariableControl = () => {
|
|
14
|
-
const { setValue: setFontFamily } = useBoundProp();
|
|
15
11
|
const { value: variableValue } = useBoundProp( fontVariablePropTypeUtil );
|
|
12
|
+
const assignedVariable = useVariable( variableValue );
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const popupId = useId();
|
|
20
|
-
const popupState = usePopupState( {
|
|
21
|
-
variant: 'popover',
|
|
22
|
-
popupId: `elementor-variables-list-${ popupId }`,
|
|
23
|
-
} );
|
|
24
|
-
|
|
25
|
-
const selectedVariable = useVariable( variableValue );
|
|
26
|
-
if ( ! selectedVariable ) {
|
|
14
|
+
if ( ! assignedVariable ) {
|
|
27
15
|
throw new Error( `Global font variable ${ variableValue } not found` );
|
|
28
16
|
}
|
|
29
17
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const isVariableDeleted = assignedVariable?.deleted;
|
|
19
|
+
|
|
20
|
+
if ( isVariableDeleted ) {
|
|
21
|
+
return <DeletedVariable variable={ assignedVariable } />;
|
|
22
|
+
}
|
|
33
23
|
|
|
34
24
|
return (
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{ ...bindTrigger( popupState ) }
|
|
41
|
-
/>
|
|
42
|
-
<Popover
|
|
43
|
-
disableScrollLock
|
|
44
|
-
anchorEl={ anchorRef.current }
|
|
45
|
-
anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
|
|
46
|
-
transformOrigin={ { vertical: 'top', horizontal: 'right' } }
|
|
47
|
-
PaperProps={ {
|
|
48
|
-
sx: { my: 1 },
|
|
49
|
-
} }
|
|
50
|
-
{ ...bindPopover( popupState ) }
|
|
51
|
-
>
|
|
52
|
-
<VariableSelectionPopover
|
|
53
|
-
selectedVariable={ selectedVariable }
|
|
54
|
-
closePopover={ popupState.close }
|
|
55
|
-
propTypeKey={ fontVariablePropTypeUtil.key }
|
|
56
|
-
/>
|
|
57
|
-
</Popover>
|
|
58
|
-
</Box>
|
|
25
|
+
<AssignedVariable
|
|
26
|
+
variable={ assignedVariable }
|
|
27
|
+
variablePropTypeUtil={ fontVariablePropTypeUtil }
|
|
28
|
+
fallbackPropTypeUtil={ stringPropTypeUtil }
|
|
29
|
+
/>
|
|
59
30
|
);
|
|
60
31
|
};
|