@elementor/editor-variables 3.35.0-393 → 3.35.0-395

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-variables",
3
- "version": "3.35.0-393",
3
+ "version": "3.35.0-395",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,20 +39,20 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.35.0-393",
43
- "@elementor/editor-canvas": "3.35.0-393",
44
- "@elementor/editor-controls": "3.35.0-393",
45
- "@elementor/editor-current-user": "3.35.0-393",
46
- "@elementor/editor-editing-panel": "3.35.0-393",
47
- "@elementor/editor-mcp": "3.35.0-393",
48
- "@elementor/editor-panels": "3.35.0-393",
49
- "@elementor/editor-props": "3.35.0-393",
50
- "@elementor/editor-ui": "3.35.0-393",
51
- "@elementor/editor-v1-adapters": "3.35.0-393",
52
- "@elementor/http-client": "3.35.0-393",
42
+ "@elementor/editor": "3.35.0-395",
43
+ "@elementor/editor-canvas": "3.35.0-395",
44
+ "@elementor/editor-controls": "3.35.0-395",
45
+ "@elementor/editor-current-user": "3.35.0-395",
46
+ "@elementor/editor-editing-panel": "3.35.0-395",
47
+ "@elementor/editor-mcp": "3.35.0-395",
48
+ "@elementor/editor-panels": "3.35.0-395",
49
+ "@elementor/editor-props": "3.35.0-395",
50
+ "@elementor/editor-ui": "3.35.0-395",
51
+ "@elementor/editor-v1-adapters": "3.35.0-395",
52
+ "@elementor/http-client": "3.35.0-395",
53
53
  "@elementor/icons": "^1.63.0",
54
- "@elementor/mixpanel": "3.35.0-393",
55
- "@elementor/schema": "3.35.0-393",
54
+ "@elementor/mixpanel": "3.35.0-395",
55
+ "@elementor/schema": "3.35.0-395",
56
56
  "@elementor/ui": "1.36.17",
57
57
  "@wordpress/i18n": "^5.13.0"
58
58
  },
@@ -1,15 +1,25 @@
1
1
  import * as React from 'react';
2
- import { createElement, useRef } from 'react';
2
+ import { createElement, useMemo, useRef } from 'react';
3
+ import { PromotionChip } from '@elementor/editor-ui';
3
4
  import { PlusIcon } from '@elementor/icons';
4
- import { bindMenu, bindTrigger, IconButton, Menu, MenuItem, type PopupState, Typography } from '@elementor/ui';
5
+ import { bindMenu, bindTrigger, Box, IconButton, Menu, MenuItem, type PopupState, Typography } from '@elementor/ui';
5
6
  import { __ } from '@wordpress/i18n';
6
7
 
8
+ import { useQuotaPermissions } from '../../hooks/use-quota-permissions';
7
9
  import { type TVariablesList } from '../../storage';
8
10
  import { trackVariablesManagerEvent } from '../../utils/tracking';
9
11
  import { getVariableTypes } from '../../variables-registry/variable-type-registry';
10
12
 
11
13
  export const SIZE = 'tiny';
12
14
 
15
+ type MenuOptionConfig = {
16
+ key: string;
17
+ propTypeKey: string;
18
+ variableType: string;
19
+ defaultValue: string;
20
+ icon: React.ElementType;
21
+ };
22
+
13
23
  type VariableManagerCreateMenuProps = {
14
24
  variables: TVariablesList;
15
25
  onCreate: ( type: string, defaultName: string, defaultValue: string ) => void;
@@ -27,22 +37,19 @@ export const VariableManagerCreateMenu = ( {
27
37
 
28
38
  const variableTypes = getVariableTypes();
29
39
 
30
- const menuOptions = Object.entries( variableTypes )
31
- .filter( ( [ , variable ] ) => !! variable.defaultValue )
32
- .map( ( [ key, variable ] ) => {
33
- const displayName = variable.variableType.charAt( 0 ).toUpperCase() + variable.variableType.slice( 1 );
34
-
35
- return {
36
- key,
37
- name: displayName,
38
- icon: variable.icon,
39
- onClick: () => {
40
- const defaultName = getDefaultName( variables, key, variable.variableType );
41
- onCreate( key, defaultName, variable.defaultValue || '' );
42
- trackVariablesManagerEvent( { action: 'add', varType: variable.variableType } );
43
- },
44
- };
45
- } );
40
+ const menuOptionConfigs = useMemo(
41
+ () =>
42
+ Object.entries( variableTypes )
43
+ .filter( ( [ , variable ] ) => !! variable.defaultValue )
44
+ .map( ( [ key, variable ] ) => ( {
45
+ key,
46
+ propTypeKey: variable.propTypeUtil.key,
47
+ variableType: variable.variableType,
48
+ defaultValue: variable.defaultValue || '',
49
+ icon: variable.icon,
50
+ } ) ),
51
+ [ variableTypes ]
52
+ );
46
53
 
47
54
  return (
48
55
  <>
@@ -76,31 +83,66 @@ export const VariableManagerCreateMenu = ( {
76
83
  } }
77
84
  data-testid="variable-manager-create-menu"
78
85
  >
79
- { menuOptions.map( ( option ) => (
80
- <MenuItem
81
- key={ option.key }
82
- onClick={ () => {
83
- option.onClick?.();
84
- menuState.close();
85
- } }
86
- sx={ {
87
- gap: 1.5,
88
- } }
89
- >
90
- { createElement( option.icon, {
91
- fontSize: SIZE,
92
- color: 'action',
93
- } ) }
94
- <Typography variant="caption" color="text.primary">
95
- { option.name }
96
- </Typography>
97
- </MenuItem>
86
+ { menuOptionConfigs.map( ( config ) => (
87
+ <MenuOption
88
+ key={ config.key }
89
+ config={ config }
90
+ variables={ variables }
91
+ onCreate={ onCreate }
92
+ onClose={ menuState.close }
93
+ />
98
94
  ) ) }
99
95
  </Menu>
100
96
  </>
101
97
  );
102
98
  };
103
99
 
100
+ const MenuOption = ( {
101
+ config,
102
+ variables,
103
+ onCreate,
104
+ onClose,
105
+ }: {
106
+ config: MenuOptionConfig;
107
+ variables: TVariablesList;
108
+ onCreate: VariableManagerCreateMenuProps[ 'onCreate' ];
109
+ onClose: () => void;
110
+ } ) => {
111
+ const displayName = config.variableType.charAt( 0 ).toUpperCase() + config.variableType.slice( 1 );
112
+ const userQuotaPermissions = useQuotaPermissions( config.propTypeKey );
113
+ const isDisabled = ! userQuotaPermissions.canAdd();
114
+
115
+ const handleClick = () => {
116
+ if ( isDisabled ) {
117
+ return;
118
+ }
119
+
120
+ const defaultName = getDefaultName( variables, config.key, config.variableType );
121
+
122
+ onCreate( config.key, defaultName, config.defaultValue );
123
+ trackVariablesManagerEvent( { action: 'add', varType: config.variableType } );
124
+ onClose();
125
+ };
126
+
127
+ return (
128
+ <MenuItem onClick={ handleClick } sx={ { gap: 1.5, cursor: isDisabled ? 'default' : 'pointer' } }>
129
+ { createElement( config.icon, { fontSize: SIZE, color: isDisabled ? 'disabled' : 'action' } ) }
130
+ <Typography variant="caption" color={ isDisabled ? 'text.disabled' : 'text.primary' }>
131
+ { displayName }
132
+ </Typography>
133
+ { isDisabled && (
134
+ <Box
135
+ onClick={ () => {
136
+ event?.stopPropagation();
137
+ } }
138
+ >
139
+ <PromotionChip onClick={ () => {} } />
140
+ </Box>
141
+ ) }
142
+ </MenuItem>
143
+ );
144
+ };
145
+
104
146
  const getDefaultName = ( variables: TVariablesList, type: string, baseName: string ) => {
105
147
  const existingNames = Object.values( variables )
106
148
  .filter( ( variable ) => variable.type === type )
@@ -47,6 +47,7 @@ export function registerVariableTypes() {
47
47
  registerVariableType( {
48
48
  ...sizePromotions,
49
49
  key: sizeVariablePropTypeUtil.key,
50
+ defaultValue: '0px',
50
51
  } );
51
52
 
52
53
  registerVariableType( {