@elementor/editor-variables 0.13.0 → 0.14.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/index.js +837 -334
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +865 -317
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +10 -9
  7. package/src/components/color-variable-creation.tsx +28 -7
  8. package/src/components/color-variable-edit.tsx +117 -0
  9. package/src/components/color-variables-selection.tsx +98 -52
  10. package/src/components/font-variable-creation.tsx +18 -6
  11. package/src/components/font-variable-edit.tsx +146 -0
  12. package/src/components/font-variables-selection.tsx +97 -51
  13. package/src/components/ui/menu-item-content.tsx +51 -0
  14. package/src/components/ui/no-search-results.tsx +38 -0
  15. package/src/components/ui/no-variables.tsx +35 -0
  16. package/src/components/ui/styled-menu-list.tsx +31 -0
  17. package/src/components/variable-selection-popover.tsx +133 -0
  18. package/src/components/variables-repeater-item-slot.tsx +29 -0
  19. package/src/controls/color-variable-control.tsx +90 -0
  20. package/src/controls/font-variable-control.tsx +88 -0
  21. package/src/create-style-variables-repository.ts +3 -2
  22. package/src/hooks/use-prop-color-variable-action.tsx +7 -2
  23. package/src/hooks/use-prop-font-variable-action.tsx +7 -2
  24. package/src/hooks/use-prop-variables.ts +31 -4
  25. package/src/init-color-variables.ts +51 -3
  26. package/src/init-font-variables.ts +2 -2
  27. package/src/service.ts +23 -3
  28. package/src/storage.ts +5 -1
  29. package/src/types.ts +12 -8
  30. package/src/components/styled-menu-item.tsx +0 -10
  31. package/src/components/variables-selection-popover.tsx +0 -119
  32. package/src/controls/color-variables-selection-control.tsx +0 -34
  33. package/src/controls/font-variables-selection-control.tsx +0 -29
  34. /package/src/components/{color-indicator.tsx → ui/color-indicator.tsx} +0 -0
package/src/types.ts CHANGED
@@ -1,15 +1,19 @@
1
- export type VariableKey = string;
2
-
3
- export type VariableValue = string;
1
+ import type * as React from 'react';
2
+ import { type VirtualizedItem } from '@elementor/editor-ui';
4
3
 
5
4
  export type Variable = {
6
- value: VariableValue;
5
+ key?: string;
7
6
  label: string;
7
+ value: string;
8
8
  type: string;
9
+ deleted?: boolean;
10
+ deleted_at?: string;
9
11
  };
10
12
 
11
- export type Variables = {
12
- [ key: VariableKey ]: Variable;
13
- };
13
+ export type StyleVariables = Record< string, string >;
14
14
 
15
- export type StyleVariables = Record< VariableKey, VariableValue >;
15
+ export type ExtendedVirtualizedItem = VirtualizedItem< 'item', string > & {
16
+ icon: React.ReactNode;
17
+ secondaryText: string;
18
+ onEdit?: () => void;
19
+ };
@@ -1,10 +0,0 @@
1
- import { MenuItem, styled } from '@elementor/ui';
2
-
3
- export const StyledMenuItem = styled( MenuItem )( () => ( {
4
- pl: 2,
5
- pr: 1,
6
- py: 0.5,
7
- '&:hover .MuiSvgIcon-root': {
8
- opacity: 1,
9
- },
10
- } ) );
@@ -1,119 +0,0 @@
1
- import * as React from 'react';
2
- import { useId, useRef } from 'react';
3
- import { PopoverHeader } from '@elementor/editor-ui';
4
- import { ColorFilterIcon, DetachIcon, PlusIcon } from '@elementor/icons';
5
- import {
6
- bindPopover,
7
- bindTrigger,
8
- Box,
9
- IconButton,
10
- Popover,
11
- Stack,
12
- Typography,
13
- UnstableTag as Tag,
14
- usePopupState,
15
- } from '@elementor/ui';
16
- import { __ } from '@wordpress/i18n';
17
-
18
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
19
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
20
- import { type Variable } from '../types';
21
- import { ColorVariableCreation } from './color-variable-creation';
22
- import { FontVariableCreation } from './font-variable-creation';
23
-
24
- type Props = {
25
- selectedVariable: Variable;
26
- unlinkVariable: () => void;
27
- children: ( { closePopover }: { closePopover: () => void } ) => React.ReactNode;
28
- startTagAdornment?: React.ReactNode;
29
- };
30
-
31
- const SIZE = 'tiny';
32
-
33
- export const VariablesSelectionPopover = ( {
34
- selectedVariable,
35
- unlinkVariable,
36
- startTagAdornment,
37
- children,
38
- }: Props ) => {
39
- const id = useId();
40
- const popupState = usePopupState( { variant: 'popover', popupId: `elementor-variables-action-${ id }` } );
41
- const creationPopupState = usePopupState( { variant: 'popover', popupId: `elementor-variables-creation-${ id }` } );
42
-
43
- const closePopover = () => popupState.close();
44
-
45
- const handleCreateButtonClick = ( event: React.MouseEvent ) => {
46
- closePopover();
47
- bindTrigger( creationPopupState ).onClick( event );
48
- };
49
-
50
- const anchorRef = useRef< HTMLDivElement >( null );
51
- const { label } = selectedVariable;
52
-
53
- const colorCreationEnabled = colorVariablePropTypeUtil.key === selectedVariable.type;
54
- const fontCreationEnabled = fontVariablePropTypeUtil.key === selectedVariable.type;
55
-
56
- return (
57
- <Box ref={ anchorRef }>
58
- <Tag
59
- fullWidth
60
- showActionsOnHover
61
- { ...bindTrigger( popupState ) }
62
- startIcon={
63
- <Stack spacing={ 1 } direction="row" alignItems="center">
64
- { startTagAdornment }
65
- <ColorFilterIcon fontSize={ 'inherit' } sx={ { mr: 1 } } />
66
- </Stack>
67
- }
68
- label={
69
- <Box sx={ { display: 'inline-grid' } }>
70
- <Typography sx={ { textOverflow: 'ellipsis', overflowX: 'hidden' } } variant="subtitle2">
71
- { label }
72
- </Typography>
73
- </Box>
74
- }
75
- actions={
76
- <IconButton size={ SIZE } onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>
77
- <DetachIcon fontSize={ SIZE } />
78
- </IconButton>
79
- }
80
- />
81
- <Popover
82
- { ...bindPopover( popupState ) }
83
- disableScrollLock
84
- anchorEl={ anchorRef.current }
85
- anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
86
- transformOrigin={ { vertical: 'top', horizontal: 'right' } }
87
- >
88
- <PopoverHeader
89
- title={ __( 'Variables', 'elementor' ) }
90
- onClose={ closePopover }
91
- icon={ <ColorFilterIcon fontSize={ SIZE } /> }
92
- actions={ [
93
- <IconButton
94
- key="createVariable"
95
- { ...bindTrigger( creationPopupState ) }
96
- size={ SIZE }
97
- onClick={ handleCreateButtonClick }
98
- >
99
- <PlusIcon fontSize={ SIZE } />
100
- </IconButton>,
101
- ] }
102
- />
103
- { children?.( { closePopover } ) }
104
- </Popover>
105
-
106
- <Box ref={ anchorRef }>
107
- <Popover
108
- { ...bindPopover( creationPopupState ) }
109
- anchorEl={ anchorRef.current }
110
- anchorOrigin={ { vertical: 'bottom', horizontal: 'right' } }
111
- transformOrigin={ { vertical: 'top', horizontal: 'right' } }
112
- >
113
- { colorCreationEnabled && <ColorVariableCreation onClose={ creationPopupState.close } /> }
114
- { fontCreationEnabled && <FontVariableCreation onClose={ creationPopupState.close } /> }
115
- </Popover>
116
- </Box>
117
- </Box>
118
- );
119
- };
@@ -1,34 +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/color-indicator';
6
- import { ColorVariablesSelection } from '../components/color-variables-selection';
7
- import { VariablesSelectionPopover } from '../components/variables-selection-popover';
8
- import { useVariable } from '../hooks/use-prop-variables';
9
- import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
10
-
11
- export const ColorVariablesSelectionControl = () => {
12
- const { setValue } = useBoundProp();
13
- const { value: variableValue } = useBoundProp( colorVariablePropTypeUtil );
14
-
15
- const selectedVariable = useVariable( variableValue );
16
-
17
- if ( ! selectedVariable ) {
18
- throw new Error( `Global color variable ${ variableValue } not found` );
19
- }
20
-
21
- const unlinkVariable = () => {
22
- setValue( colorPropTypeUtil.create( selectedVariable.value ) );
23
- };
24
-
25
- return (
26
- <VariablesSelectionPopover
27
- selectedVariable={ selectedVariable }
28
- unlinkVariable={ unlinkVariable }
29
- startTagAdornment={ <ColorIndicator size="inherit" component="span" value={ selectedVariable.value } /> }
30
- >
31
- { ( { closePopover } ) => <ColorVariablesSelection onSelect={ closePopover } /> }
32
- </VariablesSelectionPopover>
33
- );
34
- };
@@ -1,29 +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 { FontVariablesSelection } from '../components/font-variables-selection';
6
- import { VariablesSelectionPopover } from '../components/variables-selection-popover';
7
- import { useVariable } from '../hooks/use-prop-variables';
8
- import { fontVariablePropTypeUtil } from '../prop-types/font-variable-prop-type';
9
-
10
- export const FontVariablesSelectionControl = () => {
11
- const { setValue: setFontFamily } = useBoundProp();
12
- const { value: variableValue } = useBoundProp( fontVariablePropTypeUtil );
13
-
14
- const selectedVariable = useVariable( variableValue );
15
-
16
- if ( ! selectedVariable ) {
17
- throw new Error( `Global font variable ${ variableValue } not found` );
18
- }
19
-
20
- const unlinkVariable = () => {
21
- setFontFamily( stringPropTypeUtil.create( selectedVariable.value ) );
22
- };
23
-
24
- return (
25
- <VariablesSelectionPopover selectedVariable={ selectedVariable } unlinkVariable={ unlinkVariable }>
26
- { ( { closePopover } ) => <FontVariablesSelection onSelect={ closePopover } /> }
27
- </VariablesSelectionPopover>
28
- );
29
- };