@elementor/editor-variables 4.1.0-767 → 4.1.0-769
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.js +62 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/variables-manager/hooks/use-variables-manager-state.ts +29 -0
- package/src/components/variables-manager/variables-manager-panel.tsx +20 -3
- package/src/utils/duplicate-label.ts +29 -0
- package/src/utils/tracking.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-variables",
|
|
3
|
-
"version": "4.1.0-
|
|
3
|
+
"version": "4.1.0-769",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,22 +39,22 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "4.1.0-
|
|
43
|
-
"@elementor/editor-canvas": "4.1.0-
|
|
44
|
-
"@elementor/editor-controls": "4.1.0-
|
|
45
|
-
"@elementor/editor-current-user": "4.1.0-
|
|
46
|
-
"@elementor/editor-mcp": "4.1.0-
|
|
47
|
-
"@elementor/editor-panels": "4.1.0-
|
|
48
|
-
"@elementor/editor-props": "4.1.0-
|
|
49
|
-
"@elementor/editor-ui": "4.1.0-
|
|
50
|
-
"@elementor/editor-v1-adapters": "4.1.0-
|
|
51
|
-
"@elementor/menus": "4.1.0-
|
|
52
|
-
"@elementor/http-client": "4.1.0-
|
|
42
|
+
"@elementor/editor": "4.1.0-769",
|
|
43
|
+
"@elementor/editor-canvas": "4.1.0-769",
|
|
44
|
+
"@elementor/editor-controls": "4.1.0-769",
|
|
45
|
+
"@elementor/editor-current-user": "4.1.0-769",
|
|
46
|
+
"@elementor/editor-mcp": "4.1.0-769",
|
|
47
|
+
"@elementor/editor-panels": "4.1.0-769",
|
|
48
|
+
"@elementor/editor-props": "4.1.0-769",
|
|
49
|
+
"@elementor/editor-ui": "4.1.0-769",
|
|
50
|
+
"@elementor/editor-v1-adapters": "4.1.0-769",
|
|
51
|
+
"@elementor/menus": "4.1.0-769",
|
|
52
|
+
"@elementor/http-client": "4.1.0-769",
|
|
53
53
|
"@elementor/icons": "^1.72.0",
|
|
54
|
-
"@elementor/events": "4.1.0-
|
|
55
|
-
"@elementor/schema": "4.1.0-
|
|
54
|
+
"@elementor/events": "4.1.0-769",
|
|
55
|
+
"@elementor/schema": "4.1.0-769",
|
|
56
56
|
"@elementor/ui": "1.37.5",
|
|
57
|
-
"@elementor/utils": "4.1.0-
|
|
57
|
+
"@elementor/utils": "4.1.0-769",
|
|
58
58
|
"@wordpress/i18n": "^5.13.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
@@ -4,6 +4,7 @@ import { generateTempId } from '../../../batch-operations';
|
|
|
4
4
|
import { getVariables } from '../../../hooks/use-prop-variables';
|
|
5
5
|
import { service } from '../../../service';
|
|
6
6
|
import { type TVariablesList } from '../../../storage';
|
|
7
|
+
import { generateDuplicateLabel } from '../../../utils/duplicate-label';
|
|
7
8
|
import { filterBySearch } from '../../../utils/filter-by-search';
|
|
8
9
|
import { applySelectionFilters, variablesToList } from '../../../utils/variables-to-list';
|
|
9
10
|
import { getVariableTypes } from '../../../variables-registry/variable-type-registry';
|
|
@@ -39,6 +40,33 @@ export const useVariablesManagerState = () => {
|
|
|
39
40
|
return newId;
|
|
40
41
|
}, [] );
|
|
41
42
|
|
|
43
|
+
const duplicateVariable = useCallback( ( sourceId: string ): string => {
|
|
44
|
+
const newId = generateTempId();
|
|
45
|
+
|
|
46
|
+
setVariables( ( prev ) => {
|
|
47
|
+
const source = prev[ sourceId ];
|
|
48
|
+
if ( ! source || source.deleted ) {
|
|
49
|
+
return prev;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const existingLabels = Object.values( prev )
|
|
53
|
+
.filter( ( v ) => ! v.deleted )
|
|
54
|
+
.map( ( v ) => v.label );
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...prev,
|
|
58
|
+
[ newId ]: {
|
|
59
|
+
label: generateDuplicateLabel( source.label, existingLabels ),
|
|
60
|
+
value: source.value,
|
|
61
|
+
type: source.type,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
} );
|
|
65
|
+
|
|
66
|
+
setIsDirty( true );
|
|
67
|
+
return newId;
|
|
68
|
+
}, [] );
|
|
69
|
+
|
|
42
70
|
const handleDeleteVariable = useCallback( ( itemId: string ) => {
|
|
43
71
|
setDeletedVariables( ( prev ) => [ ...prev, itemId ] );
|
|
44
72
|
setVariables( ( prev ) => ( { ...prev, [ itemId ]: { ...prev[ itemId ], deleted: true } } ) );
|
|
@@ -97,6 +125,7 @@ export const useVariablesManagerState = () => {
|
|
|
97
125
|
isSaveDisabled,
|
|
98
126
|
handleOnChange,
|
|
99
127
|
createVariable,
|
|
128
|
+
duplicateVariable,
|
|
100
129
|
handleDeleteVariable,
|
|
101
130
|
handleStartSync,
|
|
102
131
|
handleStopSync,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '@elementor/editor-panels';
|
|
12
12
|
import { ConfirmationDialog, SaveChangesDialog, SearchField, ThemeProvider, useDialog } from '@elementor/editor-ui';
|
|
13
13
|
import { changeEditMode } from '@elementor/editor-v1-adapters';
|
|
14
|
-
import { AlertTriangleFilledIcon, ColorFilterIcon, TrashIcon } from '@elementor/icons';
|
|
14
|
+
import { AlertTriangleFilledIcon, ColorFilterIcon, CopyIcon, TrashIcon } from '@elementor/icons';
|
|
15
15
|
import {
|
|
16
16
|
Alert,
|
|
17
17
|
AlertAction,
|
|
@@ -75,6 +75,7 @@ export function VariablesManagerPanel() {
|
|
|
75
75
|
isSaveDisabled,
|
|
76
76
|
handleOnChange,
|
|
77
77
|
createVariable,
|
|
78
|
+
duplicateVariable,
|
|
78
79
|
handleDeleteVariable,
|
|
79
80
|
handleStartSync: startSyncFromState,
|
|
80
81
|
handleStopSync: stopSyncFromState,
|
|
@@ -200,6 +201,22 @@ export function VariablesManagerPanel() {
|
|
|
200
201
|
},
|
|
201
202
|
} );
|
|
202
203
|
|
|
204
|
+
const duplicateAction = {
|
|
205
|
+
name: __( 'Duplicate', 'elementor' ),
|
|
206
|
+
icon: CopyIcon,
|
|
207
|
+
color: 'text.primary',
|
|
208
|
+
onClick: ( itemId: string ) => {
|
|
209
|
+
const newId = duplicateVariable( itemId );
|
|
210
|
+
startAutoEdit( newId );
|
|
211
|
+
|
|
212
|
+
const variableTypeOptions = getVariableType( variable.type );
|
|
213
|
+
trackVariablesManagerEvent( {
|
|
214
|
+
action: 'duplicate',
|
|
215
|
+
varType: variableTypeOptions?.variableType,
|
|
216
|
+
} );
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
|
|
203
220
|
const deleteAction = {
|
|
204
221
|
name: __( 'Delete', 'elementor' ),
|
|
205
222
|
icon: TrashIcon,
|
|
@@ -215,9 +232,9 @@ export function VariablesManagerPanel() {
|
|
|
215
232
|
},
|
|
216
233
|
};
|
|
217
234
|
|
|
218
|
-
return [ ...typeActions, deleteAction ];
|
|
235
|
+
return [ ...typeActions, duplicateAction, deleteAction ];
|
|
219
236
|
},
|
|
220
|
-
[ variables, handleStartSync, handleStopSync ]
|
|
237
|
+
[ variables, handleStartSync, handleStopSync, duplicateVariable, startAutoEdit ]
|
|
221
238
|
);
|
|
222
239
|
|
|
223
240
|
const hasVariables = Object.keys( variables ).length > 0;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { VARIABLE_LABEL_MAX_LENGTH } from './validations';
|
|
2
|
+
|
|
3
|
+
export const COPY_SUFFIX = '-Copy';
|
|
4
|
+
|
|
5
|
+
const trimToFit = ( base: string, suffix: string ): string => {
|
|
6
|
+
const combined = base + suffix;
|
|
7
|
+
if ( combined.length <= VARIABLE_LABEL_MAX_LENGTH ) {
|
|
8
|
+
return combined;
|
|
9
|
+
}
|
|
10
|
+
return base.slice( 0, VARIABLE_LABEL_MAX_LENGTH - suffix.length ) + suffix;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const generateDuplicateLabel = ( originalLabel: string, existingLabels: string[] ): string => {
|
|
14
|
+
const labelsSet = new Set( existingLabels );
|
|
15
|
+
|
|
16
|
+
const firstCandidate = trimToFit( originalLabel, COPY_SUFFIX );
|
|
17
|
+
if ( ! labelsSet.has( firstCandidate ) ) {
|
|
18
|
+
return firstCandidate;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for ( let i = 2; i <= labelsSet.size + 1; i++ ) {
|
|
22
|
+
const candidate = trimToFit( originalLabel, `${ COPY_SUFFIX }-${ i }` );
|
|
23
|
+
if ( ! labelsSet.has( candidate ) ) {
|
|
24
|
+
return candidate;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return firstCandidate;
|
|
29
|
+
};
|
package/src/utils/tracking.ts
CHANGED
|
@@ -24,7 +24,7 @@ export const trackVariableEvent = ( { varType, controlPath, action }: VariableEv
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
type VariablesManagerEventData = {
|
|
27
|
-
action: 'openManager' | 'add' | 'saveChanges' | 'delete';
|
|
27
|
+
action: 'openManager' | 'add' | 'saveChanges' | 'delete' | 'duplicate';
|
|
28
28
|
varType?: string;
|
|
29
29
|
controlPath?: string;
|
|
30
30
|
};
|