@elementor/editor-variables 0.18.0 → 3.32.0-21

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +0 -28
  2. package/dist/index.d.mts +19 -1
  3. package/dist/index.d.ts +19 -1
  4. package/dist/index.js +1282 -1026
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1262 -990
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +16 -14
  9. package/src/api.ts +18 -2
  10. package/src/components/fields/color-field.tsx +3 -3
  11. package/src/components/fields/font-field.tsx +21 -10
  12. package/src/components/fields/label-field.tsx +31 -5
  13. package/src/components/ui/edit-confirmation-dialog.tsx +75 -0
  14. package/src/components/ui/missing-variable-alert.tsx +39 -0
  15. package/src/components/ui/no-variables.tsx +59 -26
  16. package/src/components/ui/tags/missing-tag.tsx +25 -0
  17. package/src/components/ui/variable/assigned-variable.tsx +11 -14
  18. package/src/components/ui/variable/deleted-variable.tsx +102 -50
  19. package/src/components/ui/variable/missing-variable.tsx +44 -0
  20. package/src/components/{color-variable-creation.tsx → variable-creation.tsx} +51 -22
  21. package/src/components/variable-edit.tsx +221 -0
  22. package/src/components/variable-restore.tsx +117 -0
  23. package/src/components/variable-selection-popover.tsx +91 -92
  24. package/src/components/variables-manager/variables-manager-panel.tsx +115 -0
  25. package/src/components/{font-variables-selection.tsx → variables-selection.tsx} +38 -17
  26. package/src/context/variable-selection-popover.context.tsx +19 -0
  27. package/src/context/variable-type-context.tsx +23 -0
  28. package/src/controls/variable-control.tsx +26 -0
  29. package/src/hooks/use-initial-value.ts +22 -0
  30. package/src/hooks/use-permissions.ts +15 -0
  31. package/src/hooks/use-prop-variable-action.tsx +53 -0
  32. package/src/hooks/use-prop-variables.ts +2 -2
  33. package/src/index.ts +1 -0
  34. package/src/init.ts +33 -4
  35. package/src/register-variable-types.tsx +29 -0
  36. package/src/repeater-injections.ts +5 -1
  37. package/src/service.ts +2 -19
  38. package/src/transformers/inheritance-transformer.tsx +30 -0
  39. package/src/transformers/utils/resolve-css-variable.ts +24 -0
  40. package/src/transformers/variable-transformer.ts +3 -16
  41. package/src/utils/tracking.ts +39 -0
  42. package/src/utils/validations.ts +40 -6
  43. package/src/variables-registry/create-variable-type-registry.ts +77 -0
  44. package/src/variables-registry/variable-type-registry.ts +3 -0
  45. package/src/components/color-variable-edit.tsx +0 -157
  46. package/src/components/color-variables-selection.tsx +0 -128
  47. package/src/components/font-variable-creation.tsx +0 -106
  48. package/src/components/font-variable-edit.tsx +0 -157
  49. package/src/components/variable-selection-popover.context.ts +0 -7
  50. package/src/controls/color-variable-control.tsx +0 -39
  51. package/src/controls/font-variable-control.tsx +0 -37
  52. package/src/hooks/use-prop-color-variable-action.tsx +0 -25
  53. package/src/hooks/use-prop-font-variable-action.tsx +0 -25
  54. package/src/init-color-variables.ts +0 -27
  55. package/src/init-font-variables.ts +0 -24
  56. package/src/utils.ts +0 -20
@@ -1,157 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverBody } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, BrushIcon, TrashIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, FormHelperText, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { deleteVariable, updateVariable, useVariable } from '../hooks/use-prop-variables';
11
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
12
- import { ColorField } from './fields/color-field';
13
- import { LabelField } from './fields/label-field';
14
- import { DeleteConfirmationDialog } from './ui/delete-confirmation-dialog';
15
-
16
- const SIZE = 'tiny';
17
-
18
- type Props = {
19
- editId: string;
20
- onClose: () => void;
21
- onGoBack?: () => void;
22
- onSubmit?: () => void;
23
- };
24
-
25
- export const ColorVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) => {
26
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp( colorVariablePropTypeUtil );
27
- const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
28
- const [ errorMessage, setErrorMessage ] = useState( '' );
29
-
30
- const variable = useVariable( editId );
31
- if ( ! variable ) {
32
- throw new Error( `Global color variable not found` );
33
- }
34
-
35
- const [ color, setColor ] = useState( variable.value );
36
- const [ label, setLabel ] = useState( variable.label );
37
-
38
- const handleUpdate = () => {
39
- updateVariable( editId, {
40
- value: color,
41
- label,
42
- } )
43
- .then( () => {
44
- maybeTriggerBoundPropChange();
45
- onSubmit?.();
46
- } )
47
- .catch( ( error ) => {
48
- setErrorMessage( error.message );
49
- } );
50
- };
51
-
52
- const handleDelete = () => {
53
- deleteVariable( editId ).then( () => {
54
- maybeTriggerBoundPropChange();
55
- onSubmit?.();
56
- } );
57
- };
58
-
59
- const maybeTriggerBoundPropChange = () => {
60
- if ( editId === assignedValue ) {
61
- notifyBoundPropChange( editId );
62
- }
63
- };
64
-
65
- const handleDeleteConfirmation = () => {
66
- setDeleteConfirmation( true );
67
- };
68
-
69
- const closeDeleteDialog = () => () => {
70
- setDeleteConfirmation( false );
71
- };
72
-
73
- const actions = [];
74
-
75
- actions.push(
76
- <IconButton
77
- key="delete"
78
- size={ SIZE }
79
- aria-label={ __( 'Delete', 'elementor' ) }
80
- onClick={ handleDeleteConfirmation }
81
- >
82
- <TrashIcon fontSize={ SIZE } />
83
- </IconButton>
84
- );
85
-
86
- const hasEmptyValues = () => {
87
- return ! color.trim() || ! label.trim();
88
- };
89
-
90
- const noValueChanged = () => {
91
- return color === variable.value && label === variable.label;
92
- };
93
-
94
- const isSubmitDisabled = noValueChanged() || hasEmptyValues();
95
-
96
- return (
97
- <>
98
- <PopoverBody height="auto">
99
- <PopoverHeader
100
- title={ __( 'Edit variable', 'elementor' ) }
101
- onClose={ onClose }
102
- icon={
103
- <>
104
- { onGoBack && (
105
- <IconButton
106
- size={ SIZE }
107
- aria-label={ __( 'Go Back', 'elementor' ) }
108
- onClick={ onGoBack }
109
- >
110
- <ArrowLeftIcon fontSize={ SIZE } />
111
- </IconButton>
112
- ) }
113
- <BrushIcon fontSize={ SIZE } />
114
- </>
115
- }
116
- actions={ actions }
117
- />
118
-
119
- <Divider />
120
-
121
- <PopoverContent p={ 2 }>
122
- <LabelField
123
- value={ label }
124
- onChange={ ( value ) => {
125
- setLabel( value );
126
- setErrorMessage( '' );
127
- } }
128
- />
129
- <ColorField
130
- value={ color }
131
- onChange={ ( value ) => {
132
- setColor( value );
133
- setErrorMessage( '' );
134
- } }
135
- />
136
-
137
- { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
138
- </PopoverContent>
139
-
140
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
141
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleUpdate }>
142
- { __( 'Save', 'elementor' ) }
143
- </Button>
144
- </CardActions>
145
- </PopoverBody>
146
-
147
- { deleteConfirmation && (
148
- <DeleteConfirmationDialog
149
- open
150
- label={ label }
151
- onConfirm={ handleDelete }
152
- closeDialog={ closeDeleteDialog() }
153
- />
154
- ) }
155
- </>
156
- );
157
- };
@@ -1,128 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverBody } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader, PopoverMenuList, PopoverSearch, type VirtualizedItem } from '@elementor/editor-ui';
6
- import { BrushIcon, ColorFilterIcon, PlusIcon, SettingsIcon } from '@elementor/icons';
7
- import { Divider, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { useFilteredVariables } from '../hooks/use-prop-variables';
11
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
12
- import { type ExtendedVirtualizedItem } from '../types';
13
- import { ColorIndicator } from './ui/color-indicator';
14
- import { MenuItemContent } from './ui/menu-item-content';
15
- import { NoSearchResults } from './ui/no-search-results';
16
- import { NoVariables } from './ui/no-variables';
17
- import { VariablesStyledMenuList } from './ui/styled-menu-list';
18
-
19
- const SIZE = 'tiny';
20
-
21
- type Props = {
22
- closePopover: () => void;
23
- onAdd?: () => void;
24
- onEdit?: ( key: string ) => void;
25
- onSettings?: () => void;
26
- };
27
-
28
- export const ColorVariablesSelection = ( { closePopover, onAdd, onEdit, onSettings }: Props ) => {
29
- const { value: variable, setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );
30
- const [ searchValue, setSearchValue ] = useState( '' );
31
-
32
- const {
33
- list: variables,
34
- hasMatches: hasSearchResults,
35
- isSourceNotEmpty: hasVariables,
36
- } = useFilteredVariables( searchValue, colorVariablePropTypeUtil.key );
37
-
38
- const handleSetColorVariable = ( key: string ) => {
39
- setVariable( key );
40
- closePopover();
41
- };
42
-
43
- const actions = [];
44
-
45
- if ( onAdd ) {
46
- actions.push(
47
- <IconButton key="add" size={ SIZE } onClick={ onAdd }>
48
- <PlusIcon fontSize={ SIZE } />
49
- </IconButton>
50
- );
51
- }
52
-
53
- if ( onSettings ) {
54
- actions.push(
55
- <IconButton key="settings" size={ SIZE } onClick={ onSettings }>
56
- <SettingsIcon fontSize={ SIZE } />
57
- </IconButton>
58
- );
59
- }
60
-
61
- const items: ExtendedVirtualizedItem[] = variables.map( ( { value, label, key } ) => ( {
62
- type: 'item' as const,
63
- value: key,
64
- label,
65
- icon: <ColorIndicator size="inherit" component="span" value={ value } />,
66
- secondaryText: value,
67
- onEdit: () => onEdit?.( key ),
68
- } ) );
69
-
70
- const handleSearch = ( search: string ) => {
71
- setSearchValue( search );
72
- };
73
-
74
- const handleClearSearch = () => {
75
- setSearchValue( '' );
76
- };
77
-
78
- return (
79
- <PopoverBody>
80
- <PopoverHeader
81
- title={ __( 'Variables', 'elementor' ) }
82
- icon={ <ColorFilterIcon fontSize={ SIZE } /> }
83
- onClose={ closePopover }
84
- actions={ actions }
85
- />
86
-
87
- { hasVariables && (
88
- <PopoverSearch
89
- value={ searchValue }
90
- onSearch={ handleSearch }
91
- placeholder={ __( 'Search', 'elementor' ) }
92
- />
93
- ) }
94
-
95
- <Divider />
96
-
97
- { hasVariables && hasSearchResults && (
98
- <PopoverMenuList
99
- items={ items }
100
- onSelect={ handleSetColorVariable }
101
- onClose={ () => {} }
102
- selectedValue={ variable }
103
- data-testid="color-variables-list"
104
- menuListTemplate={ VariablesStyledMenuList }
105
- menuItemContentTemplate={ ( item: VirtualizedItem< 'item', string > ) => (
106
- <MenuItemContent item={ item } />
107
- ) }
108
- />
109
- ) }
110
-
111
- { ! hasSearchResults && hasVariables && (
112
- <NoSearchResults
113
- searchValue={ searchValue }
114
- onClear={ handleClearSearch }
115
- icon={ <BrushIcon fontSize="large" /> }
116
- />
117
- ) }
118
-
119
- { ! hasVariables && (
120
- <NoVariables
121
- title={ __( 'Create your first color variable', 'elementor' ) }
122
- icon={ <BrushIcon fontSize="large" /> }
123
- onAdd={ onAdd }
124
- />
125
- ) }
126
- </PopoverBody>
127
- );
128
- };
@@ -1,106 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverBody } from '@elementor/editor-editing-panel';
5
- import { PopoverHeader } from '@elementor/editor-ui';
6
- import { ArrowLeftIcon, TextIcon } from '@elementor/icons';
7
- import { Button, CardActions, Divider, FormHelperText, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
10
- import { createVariable } 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
-
15
- const SIZE = 'tiny';
16
-
17
- type Props = {
18
- onGoBack?: () => void;
19
- onClose: () => void;
20
- };
21
-
22
- export const FontVariableCreation = ( { onClose, onGoBack }: Props ) => {
23
- const { setValue: setVariable } = useBoundProp( fontVariablePropTypeUtil );
24
-
25
- const [ fontFamily, setFontFamily ] = useState( '' );
26
- const [ label, setLabel ] = useState( '' );
27
- const [ errorMessage, setErrorMessage ] = useState( '' );
28
-
29
- const resetFields = () => {
30
- setFontFamily( '' );
31
- setLabel( '' );
32
- setErrorMessage( '' );
33
- };
34
-
35
- const closePopover = () => {
36
- resetFields();
37
- onClose();
38
- };
39
-
40
- const handleCreate = () => {
41
- createVariable( {
42
- value: fontFamily,
43
- label,
44
- type: fontVariablePropTypeUtil.key,
45
- } )
46
- .then( ( key ) => {
47
- setVariable( key );
48
- closePopover();
49
- } )
50
- .catch( ( error ) => {
51
- setErrorMessage( error.message );
52
- } );
53
- };
54
-
55
- const hasEmptyValue = () => {
56
- return '' === fontFamily.trim() || '' === label.trim();
57
- };
58
-
59
- const isSubmitDisabled = hasEmptyValue();
60
-
61
- return (
62
- <PopoverBody height="auto">
63
- <PopoverHeader
64
- icon={
65
- <>
66
- { onGoBack && (
67
- <IconButton size={ SIZE } aria-label={ __( 'Go Back', 'elementor' ) } onClick={ onGoBack }>
68
- <ArrowLeftIcon fontSize={ SIZE } />
69
- </IconButton>
70
- ) }
71
- <TextIcon fontSize={ SIZE } />
72
- </>
73
- }
74
- title={ __( 'Create variable', 'elementor' ) }
75
- onClose={ closePopover }
76
- />
77
-
78
- <Divider />
79
-
80
- <PopoverContent p={ 2 }>
81
- <LabelField
82
- value={ label }
83
- onChange={ ( value ) => {
84
- setLabel( value );
85
- setErrorMessage( '' );
86
- } }
87
- />
88
- <FontField
89
- value={ fontFamily }
90
- onChange={ ( value ) => {
91
- setFontFamily( value );
92
- setErrorMessage( '' );
93
- } }
94
- />
95
-
96
- { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
97
- </PopoverContent>
98
-
99
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
100
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleCreate }>
101
- { __( 'Create', 'elementor' ) }
102
- </Button>
103
- </CardActions>
104
- </PopoverBody>
105
- );
106
- };
@@ -1,157 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { PopoverContent, useBoundProp } from '@elementor/editor-controls';
4
- import { PopoverBody } 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, FormHelperText, IconButton } from '@elementor/ui';
8
- import { __ } from '@wordpress/i18n';
9
-
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';
15
-
16
- const SIZE = 'tiny';
17
-
18
- type Props = {
19
- editId: string;
20
- onClose: () => void;
21
- onGoBack?: () => void;
22
- onSubmit?: () => void;
23
- };
24
-
25
- export const FontVariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) => {
26
- const { setValue: notifyBoundPropChange, value: assignedValue } = useBoundProp( fontVariablePropTypeUtil );
27
- const [ deleteConfirmation, setDeleteConfirmation ] = useState( false );
28
- const [ errorMessage, setErrorMessage ] = useState( '' );
29
-
30
- const variable = useVariable( editId );
31
- if ( ! variable ) {
32
- throw new Error( `Global font variable "${ editId }" not found` );
33
- }
34
-
35
- const [ fontFamily, setFontFamily ] = useState( variable.value );
36
- const [ label, setLabel ] = useState( variable.label );
37
-
38
- const handleUpdate = () => {
39
- updateVariable( editId, {
40
- value: fontFamily,
41
- label,
42
- } )
43
- .then( () => {
44
- maybeTriggerBoundPropChange();
45
- onSubmit?.();
46
- } )
47
- .catch( ( error ) => {
48
- setErrorMessage( error.message );
49
- } );
50
- };
51
-
52
- const handleDelete = () => {
53
- deleteVariable( editId ).then( () => {
54
- maybeTriggerBoundPropChange();
55
- onSubmit?.();
56
- } );
57
- };
58
-
59
- const maybeTriggerBoundPropChange = () => {
60
- if ( editId === assignedValue ) {
61
- notifyBoundPropChange( editId );
62
- }
63
- };
64
-
65
- const handleDeleteConfirmation = () => {
66
- setDeleteConfirmation( true );
67
- };
68
-
69
- const closeDeleteDialog = () => () => {
70
- setDeleteConfirmation( false );
71
- };
72
-
73
- const hasEmptyValue = () => {
74
- return ! fontFamily.trim() || ! label.trim();
75
- };
76
-
77
- const noValueChanged = () => {
78
- return fontFamily === variable.value && label === variable.label;
79
- };
80
-
81
- const isSubmitDisabled = noValueChanged() || hasEmptyValue();
82
-
83
- const actions = [];
84
-
85
- actions.push(
86
- <IconButton
87
- key="delete"
88
- size={ SIZE }
89
- aria-label={ __( 'Delete', 'elementor' ) }
90
- onClick={ handleDeleteConfirmation }
91
- >
92
- <TrashIcon fontSize={ SIZE } />
93
- </IconButton>
94
- );
95
-
96
- return (
97
- <>
98
- <PopoverBody height="auto">
99
- <PopoverHeader
100
- icon={
101
- <>
102
- { onGoBack && (
103
- <IconButton
104
- size={ SIZE }
105
- aria-label={ __( 'Go Back', 'elementor' ) }
106
- onClick={ onGoBack }
107
- >
108
- <ArrowLeftIcon fontSize={ SIZE } />
109
- </IconButton>
110
- ) }
111
- <TextIcon fontSize={ SIZE } />
112
- </>
113
- }
114
- title={ __( 'Edit variable', 'elementor' ) }
115
- onClose={ onClose }
116
- actions={ actions }
117
- />
118
-
119
- <Divider />
120
-
121
- <PopoverContent p={ 2 }>
122
- <LabelField
123
- value={ label }
124
- onChange={ ( value ) => {
125
- setLabel( value );
126
- setErrorMessage( '' );
127
- } }
128
- />
129
- <FontField
130
- value={ fontFamily }
131
- onChange={ ( value ) => {
132
- setFontFamily( value );
133
- setErrorMessage( '' );
134
- } }
135
- />
136
-
137
- { errorMessage && <FormHelperText error>{ errorMessage }</FormHelperText> }
138
- </PopoverContent>
139
-
140
- <CardActions sx={ { pt: 0.5, pb: 1 } }>
141
- <Button size="small" variant="contained" disabled={ isSubmitDisabled } onClick={ handleUpdate }>
142
- { __( 'Save', 'elementor' ) }
143
- </Button>
144
- </CardActions>
145
- </PopoverBody>
146
-
147
- { deleteConfirmation && (
148
- <DeleteConfirmationDialog
149
- open
150
- label={ label }
151
- onConfirm={ handleDelete }
152
- closeDialog={ closeDeleteDialog() }
153
- />
154
- ) }
155
- </>
156
- );
157
- };
@@ -1,7 +0,0 @@
1
- import { createContext, useContext } from 'react';
2
-
3
- export const PopoverContentRefContext = createContext< React.RefObject< HTMLDivElement > | null >( null );
4
-
5
- export const usePopoverContentRef = () => {
6
- return useContext( PopoverContentRefContext );
7
- };
@@ -1,39 +0,0 @@
1
- import * as React from 'react';
2
- import { useBoundProp } from '@elementor/editor-controls';
3
- import { colorPropTypeUtil } from '@elementor/editor-props';
4
-
5
- import { ColorIndicator } from '../components/ui/color-indicator';
6
- import { AssignedVariable } from '../components/ui/variable/assigned-variable';
7
- import { DeletedVariable } from '../components/ui/variable/deleted-variable';
8
- import { useVariable } from '../hooks/use-prop-variables';
9
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
10
-
11
- export const ColorVariableControl = () => {
12
- const { value: variableValue } = useBoundProp( colorVariablePropTypeUtil );
13
- const assignedVariable = useVariable( variableValue );
14
-
15
- if ( ! assignedVariable ) {
16
- throw new Error( `Global color variable ${ variableValue } not found` );
17
- }
18
-
19
- const isVariableDeleted = assignedVariable?.deleted;
20
-
21
- if ( isVariableDeleted ) {
22
- return (
23
- <DeletedVariable
24
- variable={ assignedVariable }
25
- variablePropTypeUtil={ colorVariablePropTypeUtil }
26
- fallbackPropTypeUtil={ colorPropTypeUtil }
27
- />
28
- );
29
- }
30
-
31
- return (
32
- <AssignedVariable
33
- variable={ assignedVariable }
34
- variablePropTypeUtil={ colorVariablePropTypeUtil }
35
- fallbackPropTypeUtil={ colorPropTypeUtil }
36
- additionalStartIcon={ <ColorIndicator size="inherit" value={ assignedVariable.value } component="span" /> }
37
- />
38
- );
39
- };
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- import { useBoundProp } from '@elementor/editor-controls';
3
- import { stringPropTypeUtil } from '@elementor/editor-props';
4
-
5
- import { AssignedVariable } from '../components/ui/variable/assigned-variable';
6
- import { DeletedVariable } from '../components/ui/variable/deleted-variable';
7
- import { useVariable } from '../hooks/use-prop-variables';
8
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
9
-
10
- export const FontVariableControl = () => {
11
- const { value: variableValue } = useBoundProp( fontVariablePropTypeUtil );
12
- const assignedVariable = useVariable( variableValue );
13
-
14
- if ( ! assignedVariable ) {
15
- throw new Error( `Global font variable ${ variableValue } not found` );
16
- }
17
-
18
- const isVariableDeleted = assignedVariable?.deleted;
19
-
20
- if ( isVariableDeleted ) {
21
- return (
22
- <DeletedVariable
23
- variable={ assignedVariable }
24
- variablePropTypeUtil={ fontVariablePropTypeUtil }
25
- fallbackPropTypeUtil={ stringPropTypeUtil }
26
- />
27
- );
28
- }
29
-
30
- return (
31
- <AssignedVariable
32
- variable={ assignedVariable }
33
- variablePropTypeUtil={ fontVariablePropTypeUtil }
34
- fallbackPropTypeUtil={ stringPropTypeUtil }
35
- />
36
- );
37
- };
@@ -1,25 +0,0 @@
1
- import * as React from 'react';
2
- import { type PopoverActionProps, useBoundProp } from '@elementor/editor-editing-panel';
3
- import { ColorFilterIcon } from '@elementor/icons';
4
- import { __ } from '@wordpress/i18n';
5
-
6
- import { VariableSelectionPopover } from '../components/variable-selection-popover';
7
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
8
- import { supportsColorVariables } from '../utils';
9
-
10
- export const usePropColorVariableAction = (): PopoverActionProps => {
11
- const { propType } = useBoundProp();
12
-
13
- const visible = !! propType && supportsColorVariables( propType );
14
-
15
- return {
16
- visible,
17
- icon: ColorFilterIcon,
18
- title: __( 'Variables', 'elementor' ),
19
- content: ( { close: closePopover } ) => {
20
- return (
21
- <VariableSelectionPopover closePopover={ closePopover } propTypeKey={ colorVariablePropTypeUtil.key } />
22
- );
23
- },
24
- };
25
- };
@@ -1,25 +0,0 @@
1
- import * as React from 'react';
2
- import { type PopoverActionProps, useBoundProp } from '@elementor/editor-editing-panel';
3
- import { ColorFilterIcon } from '@elementor/icons';
4
- import { __ } from '@wordpress/i18n';
5
-
6
- import { VariableSelectionPopover } from '../components/variable-selection-popover';
7
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
8
- import { supportsFontVariables } from '../utils';
9
-
10
- export const usePropFontVariableAction = (): PopoverActionProps => {
11
- const { propType } = useBoundProp();
12
-
13
- const visible = !! propType && supportsFontVariables( propType );
14
-
15
- return {
16
- visible,
17
- icon: ColorFilterIcon,
18
- title: __( 'Variables', 'elementor' ),
19
- content: ( { close: closePopover } ) => {
20
- return (
21
- <VariableSelectionPopover closePopover={ closePopover } propTypeKey={ fontVariablePropTypeUtil.key } />
22
- );
23
- },
24
- };
25
- };