@elementor/editor-variables 3.32.0-81 → 3.32.0-83

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.32.0-81",
3
+ "version": "3.32.0-83",
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-81",
43
- "@elementor/editor-canvas": "3.32.0-81",
44
- "@elementor/editor-controls": "3.32.0-81",
45
- "@elementor/editor-current-user": "3.32.0-81",
46
- "@elementor/editor-editing-panel": "3.32.0-81",
47
- "@elementor/editor-panels": "3.32.0-81",
48
- "@elementor/editor-props": "3.32.0-81",
49
- "@elementor/editor-ui": "3.32.0-81",
50
- "@elementor/editor-v1-adapters": "3.32.0-81",
51
- "@elementor/http-client": "3.32.0-81",
42
+ "@elementor/editor": "3.32.0-83",
43
+ "@elementor/editor-canvas": "3.32.0-83",
44
+ "@elementor/editor-controls": "3.32.0-83",
45
+ "@elementor/editor-current-user": "3.32.0-83",
46
+ "@elementor/editor-editing-panel": "3.32.0-83",
47
+ "@elementor/editor-panels": "3.32.0-83",
48
+ "@elementor/editor-props": "3.32.0-83",
49
+ "@elementor/editor-ui": "3.32.0-83",
50
+ "@elementor/editor-v1-adapters": "3.32.0-83",
51
+ "@elementor/http-client": "3.32.0-83",
52
52
  "@elementor/icons": "1.46.0",
53
- "@elementor/schema": "3.32.0-81",
53
+ "@elementor/schema": "3.32.0-83",
54
54
  "@elementor/ui": "1.36.8",
55
55
  "@wordpress/i18n": "^5.13.0"
56
56
  },
@@ -7,15 +7,16 @@ export type VariableManagerMenuAction = {
7
7
  name: string;
8
8
  icon: React.ForwardRefExoticComponent< Omit< SvgIconProps, 'ref' > & React.RefAttributes< SVGSVGElement > >;
9
9
  color: string;
10
- onClick: () => void;
10
+ onClick: ( id: string ) => void;
11
11
  };
12
12
 
13
13
  type VariableEditMenuProps = {
14
14
  menuActions: VariableManagerMenuAction[];
15
15
  disabled?: boolean;
16
+ itemId: string;
16
17
  };
17
18
 
18
- export const VariableEditMenu = ( { menuActions, disabled }: VariableEditMenuProps ) => {
19
+ export const VariableEditMenu = ( { menuActions, disabled, itemId }: VariableEditMenuProps ) => {
19
20
  const menuState = usePopupState( {
20
21
  variant: 'popover',
21
22
  } );
@@ -51,7 +52,7 @@ export const VariableEditMenu = ( { menuActions, disabled }: VariableEditMenuPro
51
52
  <MenuItem
52
53
  key={ action.name }
53
54
  onClick={ () => {
54
- action.onClick?.();
55
+ action.onClick?.( itemId );
55
56
  menuState.close();
56
57
  } }
57
58
  sx={ {
@@ -8,13 +8,13 @@ export const VariableEditableCell = ( {
8
8
  initialValue,
9
9
  children,
10
10
  editableElement,
11
- onSave,
11
+ onChange,
12
12
  prefixElement,
13
13
  }: {
14
14
  initialValue: string;
15
15
  children: React.ReactNode;
16
16
  editableElement: ( { value, onChange, onValidationChange }: ValueFieldProps ) => JSX.Element;
17
- onSave: ( newValue: string ) => void;
17
+ onChange: ( newValue: string ) => void;
18
18
  prefixElement?: React.ReactNode;
19
19
  } ) => {
20
20
  const [ value, setValue ] = useState( initialValue );
@@ -25,7 +25,7 @@ export const VariableEditableCell = ( {
25
25
  };
26
26
 
27
27
  const handleSave = () => {
28
- onSave( value );
28
+ onChange( value );
29
29
  setIsEditing( false );
30
30
  };
31
31
 
@@ -47,21 +47,39 @@ export const VariableEditableCell = ( {
47
47
 
48
48
  const editableContent = editableElement( { value, onChange: handleChange } );
49
49
 
50
+ if ( isEditing ) {
51
+ return (
52
+ <ClickAwayListener onClickAway={ handleSave }>
53
+ <Stack
54
+ direction="row"
55
+ alignItems="center"
56
+ gap={ 1 }
57
+ onDoubleClick={ handleDoubleClick }
58
+ onKeyDown={ handleKeyDown }
59
+ tabIndex={ 0 }
60
+ role="button"
61
+ aria-label="Double click or press Space to edit"
62
+ >
63
+ { prefixElement }
64
+ { editableContent }
65
+ </Stack>
66
+ </ClickAwayListener>
67
+ );
68
+ }
69
+
50
70
  return (
51
- <ClickAwayListener onClickAway={ handleSave }>
52
- <Stack
53
- direction="row"
54
- alignItems="center"
55
- gap={ 1 }
56
- onDoubleClick={ handleDoubleClick }
57
- onKeyDown={ handleKeyDown }
58
- tabIndex={ 0 }
59
- role="button"
60
- aria-label="Double click or press Space to edit"
61
- >
62
- { prefixElement }
63
- { isEditing ? editableContent : children }
64
- </Stack>
65
- </ClickAwayListener>
71
+ <Stack
72
+ direction="row"
73
+ alignItems="center"
74
+ gap={ 1 }
75
+ onDoubleClick={ handleDoubleClick }
76
+ onKeyDown={ handleKeyDown }
77
+ tabIndex={ 0 }
78
+ role="button"
79
+ aria-label="Double click or press Space to edit"
80
+ >
81
+ { prefixElement }
82
+ { children }
83
+ </Stack>
66
84
  );
67
85
  };
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useEffect } from 'react';
2
+ import { useEffect, useState } from 'react';
3
3
  import {
4
4
  __createPanel as createPanel,
5
5
  Panel,
@@ -15,6 +15,7 @@ import { Alert, Box, Button, Divider, ErrorBoundary, IconButton, type IconButton
15
15
  import { __ } from '@wordpress/i18n';
16
16
 
17
17
  import { getVariables } from '../../hooks/use-prop-variables';
18
+ import { type TVariablesList } from '../../storage';
18
19
  import { VariablesManagerTable } from './variables-manager-table';
19
20
 
20
21
  const id = 'variables-manager';
@@ -33,8 +34,9 @@ export const { panel, usePanelActions } = createPanel( {
33
34
 
34
35
  export function VariablesManagerPanel() {
35
36
  const { close: closePanel } = usePanelActions();
36
- const isDirty = false;
37
- const variables = getVariables( false );
37
+ const [ isDirty, setIsDirty ] = useState( false );
38
+ const [ variables, setVariables ] = useState( getVariables( false ) );
39
+ const [ deletedVariables, setDeletedVariables ] = useState< string[] >( [] );
38
40
 
39
41
  usePreventUnload( isDirty );
40
42
 
@@ -43,10 +45,19 @@ export function VariablesManagerPanel() {
43
45
  name: __( 'Delete', 'elementor' ),
44
46
  icon: TrashIcon,
45
47
  color: 'error.main',
46
- onClick: () => {},
48
+ onClick: ( itemId: string ) => {
49
+ setDeletedVariables( [ ...deletedVariables, itemId ] );
50
+ setVariables( { ...variables, [ itemId ]: { ...variables[ itemId ], deleted: true } } );
51
+ setIsDirty( true );
52
+ },
47
53
  },
48
54
  ];
49
55
 
56
+ const handleOnChange = ( newVariables: TVariablesList ) => {
57
+ setVariables( newVariables );
58
+ setIsDirty( true );
59
+ };
60
+
50
61
  return (
51
62
  <ThemeProvider>
52
63
  <ErrorBoundary fallback={ <ErrorBoundaryFallback /> }>
@@ -77,7 +88,11 @@ export function VariablesManagerPanel() {
77
88
  height: '100%',
78
89
  } }
79
90
  >
80
- <VariablesManagerTable menuActions={ menuActions } variables={ variables } />
91
+ <VariablesManagerTable
92
+ menuActions={ menuActions }
93
+ variables={ variables }
94
+ onChange={ handleOnChange }
95
+ />
81
96
  </PanelBody>
82
97
 
83
98
  <PanelFooter>
@@ -27,22 +27,25 @@ import { VariableTableCell } from './variable-table-cell';
27
27
  type Props = {
28
28
  menuActions: VariableManagerMenuAction[];
29
29
  variables: TVariablesList;
30
+ onChange: ( variables: TVariablesList ) => void;
30
31
  };
31
32
 
32
- export const VariablesManagerTable = ( { menuActions, variables }: Props ) => {
33
+ export const VariablesManagerTable = ( { menuActions, variables, onChange: handleOnChange }: Props ) => {
33
34
  const [ ids, setIds ] = useState< string[] >( Object.keys( variables ) );
34
- const rows = ids.map( ( id ) => {
35
- const variable = variables[ id ];
36
- const variableType = getVariableType( variable.type );
35
+ const rows = ids
36
+ .filter( ( id ) => ! variables[ id ].deleted )
37
+ .map( ( id ) => {
38
+ const variable = variables[ id ];
39
+ const variableType = getVariableType( variable.type );
37
40
 
38
- return {
39
- id,
40
- name: variable.label,
41
- value: variable.value,
42
- type: variable.type,
43
- ...variableType,
44
- };
45
- } );
41
+ return {
42
+ id,
43
+ name: variable.label,
44
+ value: variable.value,
45
+ type: variable.type,
46
+ ...variableType,
47
+ };
48
+ } );
46
49
 
47
50
  const tableSX: SxProps = {
48
51
  minWidth: 250,
@@ -136,7 +139,14 @@ export const VariablesManagerTable = ( { menuActions, variables }: Props ) => {
136
139
  <VariableTableCell>
137
140
  <VariableEditableCell
138
141
  initialValue={ row.name }
139
- onSave={ () => {} }
142
+ onChange={ ( value ) => {
143
+ if ( value !== row.name ) {
144
+ handleOnChange( {
145
+ ...variables,
146
+ [ row.id ]: { ...variables[ row.id ], label: value },
147
+ } );
148
+ }
149
+ } }
140
150
  prefixElement={ createElement( row.icon, { fontSize: 'inherit' } ) }
141
151
  editableElement={ ( { value, onChange } ) => (
142
152
  <LabelField
@@ -159,7 +169,14 @@ export const VariablesManagerTable = ( { menuActions, variables }: Props ) => {
159
169
  <VariableTableCell>
160
170
  <VariableEditableCell
161
171
  initialValue={ row.value }
162
- onSave={ () => {} }
172
+ onChange={ ( value ) => {
173
+ if ( value !== row.value ) {
174
+ handleOnChange( {
175
+ ...variables,
176
+ [ row.id ]: { ...variables[ row.id ], value },
177
+ } );
178
+ }
179
+ } }
163
180
  editableElement={ row.valueField }
164
181
  >
165
182
  { row.startIcon && row.startIcon( { value: row.value } ) }
@@ -182,6 +199,7 @@ export const VariablesManagerTable = ( { menuActions, variables }: Props ) => {
182
199
  <VariableEditMenu
183
200
  menuActions={ menuActions }
184
201
  disabled={ isSorting }
202
+ itemId={ row.id }
185
203
  />
186
204
  </Stack>
187
205
  </VariableTableCell>