@elementor/editor-variables 3.32.0-60 → 3.32.0-62
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/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +371 -286
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +316 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/components/variables-manager/variable-editable-cell.tsx +70 -0
- package/src/components/variables-manager/variables-manager-panel.tsx +3 -1
- package/src/components/variables-manager/variables-manager-table.tsx +39 -18
- package/src/variables-registry/create-variable-type-registry.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-variables",
|
|
3
|
-
"version": "3.32.0-
|
|
3
|
+
"version": "3.32.0-62",
|
|
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-
|
|
43
|
-
"@elementor/editor-canvas": "3.32.0-
|
|
44
|
-
"@elementor/editor-controls": "3.32.0-
|
|
45
|
-
"@elementor/editor-current-user": "3.32.0-
|
|
46
|
-
"@elementor/editor-editing-panel": "3.32.0-
|
|
47
|
-
"@elementor/editor-panels": "3.32.0-
|
|
48
|
-
"@elementor/editor-props": "3.32.0-
|
|
49
|
-
"@elementor/editor-ui": "3.32.0-
|
|
50
|
-
"@elementor/editor-v1-adapters": "3.32.0-
|
|
51
|
-
"@elementor/http-client": "3.32.0-
|
|
42
|
+
"@elementor/editor": "3.32.0-62",
|
|
43
|
+
"@elementor/editor-canvas": "3.32.0-62",
|
|
44
|
+
"@elementor/editor-controls": "3.32.0-62",
|
|
45
|
+
"@elementor/editor-current-user": "3.32.0-62",
|
|
46
|
+
"@elementor/editor-editing-panel": "3.32.0-62",
|
|
47
|
+
"@elementor/editor-panels": "3.32.0-62",
|
|
48
|
+
"@elementor/editor-props": "3.32.0-62",
|
|
49
|
+
"@elementor/editor-ui": "3.32.0-62",
|
|
50
|
+
"@elementor/editor-v1-adapters": "3.32.0-62",
|
|
51
|
+
"@elementor/http-client": "3.32.0-62",
|
|
52
52
|
"@elementor/icons": "1.46.0",
|
|
53
|
-
"@elementor/schema": "3.32.0-
|
|
53
|
+
"@elementor/schema": "3.32.0-62",
|
|
54
54
|
"@elementor/ui": "1.36.8",
|
|
55
55
|
"@wordpress/i18n": "^5.13.0"
|
|
56
56
|
},
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { ClickAwayListener, Stack } from '@elementor/ui';
|
|
4
|
+
|
|
5
|
+
import { type ValueFieldProps } from '../../variables-registry/create-variable-type-registry';
|
|
6
|
+
|
|
7
|
+
export const VariableEditableCell = ( {
|
|
8
|
+
initialValue,
|
|
9
|
+
children,
|
|
10
|
+
editableElement,
|
|
11
|
+
onSave,
|
|
12
|
+
prefixElement,
|
|
13
|
+
disableCloseOnBlur,
|
|
14
|
+
}: {
|
|
15
|
+
initialValue: string;
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
editableElement: ( { value, onChange, onValidationChange }: ValueFieldProps ) => JSX.Element;
|
|
18
|
+
onSave: ( newValue: string ) => void;
|
|
19
|
+
prefixElement?: React.ReactNode;
|
|
20
|
+
disableCloseOnBlur?: boolean;
|
|
21
|
+
} ) => {
|
|
22
|
+
const [ value, setValue ] = useState( initialValue );
|
|
23
|
+
const [ isEditing, setIsEditing ] = useState( false );
|
|
24
|
+
|
|
25
|
+
const handleDoubleClick = () => {
|
|
26
|
+
setIsEditing( true );
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handleSave = () => {
|
|
30
|
+
onSave( value );
|
|
31
|
+
setIsEditing( false );
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const handleKeyDown = ( event: React.KeyboardEvent< HTMLDivElement > ) => {
|
|
35
|
+
if ( event.key === 'Enter' ) {
|
|
36
|
+
handleSave();
|
|
37
|
+
} else if ( event.key === 'Escape' ) {
|
|
38
|
+
setIsEditing( false );
|
|
39
|
+
}
|
|
40
|
+
if ( event.key === ' ' && ! isEditing ) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
setIsEditing( true );
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handleChange = ( newValue: string ) => {
|
|
47
|
+
setValue( newValue );
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const editableContent = editableElement( { value, onChange: handleChange } );
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<ClickAwayListener onClickAway={ handleSave }>
|
|
54
|
+
<Stack
|
|
55
|
+
direction="row"
|
|
56
|
+
alignItems="center"
|
|
57
|
+
gap={ 1 }
|
|
58
|
+
onDoubleClick={ handleDoubleClick }
|
|
59
|
+
onBlur={ disableCloseOnBlur ? undefined : handleSave }
|
|
60
|
+
onKeyDown={ handleKeyDown }
|
|
61
|
+
tabIndex={ 0 }
|
|
62
|
+
role="button"
|
|
63
|
+
aria-label="Double click or press Space to edit"
|
|
64
|
+
>
|
|
65
|
+
{ prefixElement }
|
|
66
|
+
{ isEditing ? editableContent : children }
|
|
67
|
+
</Stack>
|
|
68
|
+
</ClickAwayListener>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
@@ -14,6 +14,7 @@ import { ColorFilterIcon, TrashIcon, XIcon } from '@elementor/icons';
|
|
|
14
14
|
import { Alert, Box, Button, Divider, ErrorBoundary, IconButton, type IconButtonProps, Stack } from '@elementor/ui';
|
|
15
15
|
import { __ } from '@wordpress/i18n';
|
|
16
16
|
|
|
17
|
+
import { getVariables } from '../../hooks/use-prop-variables';
|
|
17
18
|
import { VariablesManagerTable } from './variables-manager-table';
|
|
18
19
|
|
|
19
20
|
const id = 'variables-manager';
|
|
@@ -33,6 +34,7 @@ export const { panel, usePanelActions } = createPanel( {
|
|
|
33
34
|
export function VariablesManagerPanel() {
|
|
34
35
|
const { close: closePanel } = usePanelActions();
|
|
35
36
|
const isDirty = false;
|
|
37
|
+
const variables = getVariables( false );
|
|
36
38
|
|
|
37
39
|
usePreventUnload( isDirty );
|
|
38
40
|
|
|
@@ -73,7 +75,7 @@ export function VariablesManagerPanel() {
|
|
|
73
75
|
} }
|
|
74
76
|
>
|
|
75
77
|
<Divider />
|
|
76
|
-
<VariablesManagerTable menuActions={ menuActions } />
|
|
78
|
+
<VariablesManagerTable menuActions={ menuActions } variables={ variables } />
|
|
77
79
|
</PanelBody>
|
|
78
80
|
|
|
79
81
|
<PanelFooter>
|
|
@@ -11,33 +11,38 @@ import {
|
|
|
11
11
|
TableContainer,
|
|
12
12
|
TableHead,
|
|
13
13
|
TableRow,
|
|
14
|
+
TextField,
|
|
14
15
|
UnstableSortableItem,
|
|
15
16
|
type UnstableSortableItemRenderProps,
|
|
16
17
|
UnstableSortableProvider,
|
|
17
18
|
} from '@elementor/ui';
|
|
18
19
|
import { __ } from '@wordpress/i18n';
|
|
19
20
|
|
|
20
|
-
import {
|
|
21
|
+
import { type TVariablesList } from '../../storage';
|
|
21
22
|
import { getVariableType } from '../../variables-registry/variable-type-registry';
|
|
22
23
|
import { VariableEditMenu, type VariableManagerMenuAction } from './variable-edit-menu';
|
|
24
|
+
import { VariableEditableCell } from './variable-editable-cell';
|
|
23
25
|
import { VariableTableCell } from './variable-table-cell';
|
|
24
26
|
|
|
25
27
|
type Props = {
|
|
26
28
|
menuActions: VariableManagerMenuAction[];
|
|
29
|
+
variables: TVariablesList;
|
|
27
30
|
};
|
|
28
31
|
|
|
29
|
-
export const VariablesManagerTable = ( { menuActions }: Props ) => {
|
|
30
|
-
const variables = getVariables( false );
|
|
31
|
-
|
|
32
|
+
export const VariablesManagerTable = ( { menuActions, variables }: Props ) => {
|
|
32
33
|
const [ ids, setIds ] = useState< string[] >( Object.keys( variables ) );
|
|
33
|
-
const rows = ids.map( ( id ) =>
|
|
34
|
-
id
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const rows = ids.map( ( id ) => {
|
|
35
|
+
const variable = variables[ id ];
|
|
36
|
+
const variableType = getVariableType( variable.type );
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
id,
|
|
40
|
+
name: variable.label,
|
|
41
|
+
value: variable.value,
|
|
42
|
+
type: variable.type,
|
|
43
|
+
...variableType,
|
|
44
|
+
};
|
|
45
|
+
} );
|
|
41
46
|
|
|
42
47
|
const tableSX: SxProps = {
|
|
43
48
|
minWidth: 250,
|
|
@@ -129,21 +134,37 @@ export const VariablesManagerTable = ( { menuActions }: Props ) => {
|
|
|
129
134
|
</IconButton>
|
|
130
135
|
</VariableTableCell>
|
|
131
136
|
<VariableTableCell>
|
|
132
|
-
<
|
|
133
|
-
{
|
|
137
|
+
<VariableEditableCell
|
|
138
|
+
initialValue={ row.name }
|
|
139
|
+
onSave={ () => {} }
|
|
140
|
+
prefixElement={ createElement( row.icon, { fontSize: 'inherit' } ) }
|
|
141
|
+
editableElement={ ( { value, onChange } ) => (
|
|
142
|
+
<TextField
|
|
143
|
+
size="tiny"
|
|
144
|
+
value={ value }
|
|
145
|
+
onChange={ (
|
|
146
|
+
event: React.ChangeEvent< HTMLInputElement >
|
|
147
|
+
) => onChange( event.target.value ) }
|
|
148
|
+
/>
|
|
149
|
+
) }
|
|
150
|
+
>
|
|
134
151
|
<EllipsisWithTooltip title={ row.name }>
|
|
135
152
|
{ row.name }
|
|
136
153
|
</EllipsisWithTooltip>
|
|
137
|
-
</
|
|
154
|
+
</VariableEditableCell>
|
|
138
155
|
</VariableTableCell>
|
|
139
156
|
<VariableTableCell>
|
|
140
|
-
<
|
|
157
|
+
<VariableEditableCell
|
|
158
|
+
initialValue={ row.value }
|
|
159
|
+
onSave={ () => {} }
|
|
160
|
+
editableElement={ row.valueField }
|
|
161
|
+
disableCloseOnBlur
|
|
162
|
+
>
|
|
141
163
|
{ row.startIcon && row.startIcon( { value: row.value } ) }
|
|
142
|
-
|
|
143
164
|
<EllipsisWithTooltip title={ row.value }>
|
|
144
165
|
{ row.value }
|
|
145
166
|
</EllipsisWithTooltip>
|
|
146
|
-
</
|
|
167
|
+
</VariableEditableCell>
|
|
147
168
|
</VariableTableCell>
|
|
148
169
|
<VariableTableCell
|
|
149
170
|
align="right"
|
|
@@ -14,7 +14,7 @@ import { inheritanceTransformer } from '../transformers/inheritance-transformer'
|
|
|
14
14
|
import { variableTransformer } from '../transformers/variable-transformer';
|
|
15
15
|
import { type NormalizedVariable } from '../types';
|
|
16
16
|
|
|
17
|
-
type ValueFieldProps = {
|
|
17
|
+
export type ValueFieldProps = {
|
|
18
18
|
value: string;
|
|
19
19
|
onChange: ( value: string ) => void;
|
|
20
20
|
onValidationChange?: ( value: string ) => void;
|