@elementor/editor-variables 4.1.0-manual → 4.2.0-839
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 +22 -13
- package/dist/index.d.ts +22 -13
- package/dist/index.js +567 -415
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +565 -411
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -16
- package/src/components/global-styles-import-listener.tsx +3 -5
- package/src/components/variable-selection-popover.tsx +10 -4
- package/src/components/variables-manager/variables-manager-create-menu.tsx +8 -1
- package/src/components/variables-manager/variables-manager-panel.tsx +285 -150
- package/src/components/variables-repeater-item-slot.tsx +20 -0
- package/src/index.ts +4 -0
- package/src/init.ts +12 -9
- package/src/mcp/manage-variable-tool.ts +9 -0
- package/src/mcp/variables-resource.ts +30 -14
- package/src/repeater-injections.ts +22 -0
- package/src/types.ts +2 -11
package/src/init.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { registerControlReplacement } from '@elementor/editor-controls';
|
|
|
3
3
|
import { getMCPByDomain } from '@elementor/editor-mcp';
|
|
4
4
|
import { __registerPanel as registerPanel } from '@elementor/editor-panels';
|
|
5
5
|
import { isTransformable, type PropValue } from '@elementor/editor-props';
|
|
6
|
+
import { isExperimentActive } from '@elementor/editor-v1-adapters';
|
|
6
7
|
import { controlActionsMenu } from '@elementor/menus';
|
|
7
8
|
|
|
8
9
|
import { GlobalStylesImportListener } from './components/global-styles-import-listener';
|
|
@@ -59,17 +60,19 @@ export function init() {
|
|
|
59
60
|
component: GlobalStylesImportListener,
|
|
60
61
|
} );
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
if ( ! isExperimentActive( 'e_editor_design_system_panel' ) ) {
|
|
64
|
+
injectIntoLogic( {
|
|
65
|
+
id: 'variables-open-panel-from-url',
|
|
66
|
+
component: OpenPanelFromUrl,
|
|
67
|
+
} );
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
injectIntoLogic( {
|
|
70
|
+
id: 'variables-open-panel-from-event',
|
|
71
|
+
component: OpenPanelFromEvent,
|
|
72
|
+
} );
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
registerPanel( panel );
|
|
75
|
+
}
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
function hasVariableAssigned( value: PropValue ) {
|
|
@@ -2,6 +2,7 @@ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
|
2
2
|
import { z } from '@elementor/schema';
|
|
3
3
|
|
|
4
4
|
import { service } from '../service';
|
|
5
|
+
import { validateLabel } from '../utils/validations';
|
|
5
6
|
import { GLOBAL_VARIABLES_URI } from './variables-resource';
|
|
6
7
|
|
|
7
8
|
export const initManageVariableTool = ( reg: MCPRegistryEntry ) => {
|
|
@@ -68,12 +69,20 @@ function getServiceActions( svc: typeof service ) {
|
|
|
68
69
|
if ( ! type || ! label || ! value ) {
|
|
69
70
|
throw new Error( 'Create requires type, label, and value' );
|
|
70
71
|
}
|
|
72
|
+
const labelError = validateLabel( label );
|
|
73
|
+
if ( labelError ) {
|
|
74
|
+
throw new Error( labelError );
|
|
75
|
+
}
|
|
71
76
|
return svc.create( { type, label, value } );
|
|
72
77
|
},
|
|
73
78
|
update( { id, label, value }: Opts< { id: string; label: string; value: string } > ) {
|
|
74
79
|
if ( ! id || ! label || ! value ) {
|
|
75
80
|
throw new Error( 'Update requires id, label, and value' );
|
|
76
81
|
}
|
|
82
|
+
const labelError = validateLabel( label );
|
|
83
|
+
if ( labelError ) {
|
|
84
|
+
throw new Error( labelError );
|
|
85
|
+
}
|
|
77
86
|
return svc.update( id, { label, value } );
|
|
78
87
|
},
|
|
79
88
|
delete( { id }: Opts< { id: string } > ) {
|
|
@@ -1,38 +1,54 @@
|
|
|
1
1
|
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
2
|
+
import { __privateListenTo as listenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
|
|
2
3
|
|
|
3
4
|
import { service } from '../service';
|
|
4
5
|
import { type TVariable } from '../storage';
|
|
5
6
|
|
|
6
7
|
export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
|
|
7
8
|
|
|
9
|
+
type GlobalVariablesResourceEntry =
|
|
10
|
+
| ( TVariable & { version: 'v4' } )
|
|
11
|
+
| ( Record< string, unknown > & { version: 'v3' } );
|
|
12
|
+
|
|
13
|
+
const buildGlobalVariablesPayload = async (): Promise< Record< string, GlobalVariablesResourceEntry > > => {
|
|
14
|
+
const merged: Record< string, GlobalVariablesResourceEntry > = {};
|
|
15
|
+
Object.entries( service.variables() ).forEach( ( [ id, variable ] ) => {
|
|
16
|
+
if ( ! variable.deleted ) {
|
|
17
|
+
merged[ id ] = { ...variable, version: 'v4' };
|
|
18
|
+
}
|
|
19
|
+
} );
|
|
20
|
+
return merged;
|
|
21
|
+
};
|
|
22
|
+
|
|
8
23
|
export const initVariablesResource = ( variablesMcpEntry: MCPRegistryEntry, canvasMcpEntry: MCPRegistryEntry ) => {
|
|
9
24
|
[ canvasMcpEntry, variablesMcpEntry ].forEach( ( entry ) => {
|
|
10
25
|
const { resource, sendResourceUpdated } = entry;
|
|
26
|
+
|
|
27
|
+
const notifyGlobalVariablesUpdated = () => {
|
|
28
|
+
sendResourceUpdated( {
|
|
29
|
+
uri: GLOBAL_VARIABLES_URI,
|
|
30
|
+
} );
|
|
31
|
+
};
|
|
32
|
+
|
|
11
33
|
resource(
|
|
12
34
|
'global-variables',
|
|
13
35
|
GLOBAL_VARIABLES_URI,
|
|
14
36
|
{
|
|
15
|
-
description:
|
|
16
|
-
'List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)',
|
|
37
|
+
description: 'Global variables available (v4)',
|
|
17
38
|
},
|
|
18
39
|
async () => {
|
|
19
|
-
const variables
|
|
20
|
-
Object.entries( service.variables() ).forEach( ( [ id, variable ] ) => {
|
|
21
|
-
if ( ! variable.deleted ) {
|
|
22
|
-
variables[ id ] = variable;
|
|
23
|
-
}
|
|
24
|
-
} );
|
|
40
|
+
const variables = await buildGlobalVariablesPayload();
|
|
25
41
|
|
|
26
42
|
return {
|
|
27
|
-
contents: [
|
|
43
|
+
contents: [
|
|
44
|
+
{ uri: GLOBAL_VARIABLES_URI, mimeType: 'application/json', text: JSON.stringify( variables ) },
|
|
45
|
+
],
|
|
28
46
|
};
|
|
29
47
|
}
|
|
30
48
|
);
|
|
31
49
|
|
|
32
|
-
window.addEventListener( 'variables:updated',
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} );
|
|
36
|
-
} );
|
|
50
|
+
window.addEventListener( 'variables:updated', notifyGlobalVariablesUpdated );
|
|
51
|
+
|
|
52
|
+
listenTo( commandEndEvent( 'document/save/update' ), notifyGlobalVariablesUpdated );
|
|
37
53
|
} );
|
|
38
54
|
};
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
backgroundColorOverlayPropTypeUtil,
|
|
4
4
|
cssFilterFunctionPropUtil,
|
|
5
5
|
dropShadowFilterPropTypeUtil,
|
|
6
|
+
moveTransformPropTypeUtil,
|
|
6
7
|
type PropValue,
|
|
7
8
|
selectionSizePropTypeUtil,
|
|
8
9
|
shadowPropTypeUtil,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
FilterDropShadowIconIndicator,
|
|
17
18
|
FilterDropShadowRepeaterLabel,
|
|
18
19
|
FilterSingleSizeRepeaterLabel,
|
|
20
|
+
TransformRepeaterLabel,
|
|
19
21
|
TransitionsSizeVariableLabel,
|
|
20
22
|
} from './components/variables-repeater-item-slot';
|
|
21
23
|
import { colorVariablePropTypeUtil, customSizeVariablePropTypeUtil, sizeVariablePropTypeUtil } from './prop-types';
|
|
@@ -28,6 +30,7 @@ export function registerRepeaterInjections() {
|
|
|
28
30
|
backgroundOverlayRepeaterInjections();
|
|
29
31
|
boxShadowRepeaterInjections();
|
|
30
32
|
transitionsRepeaterInjections();
|
|
33
|
+
transformRepeaterInjections();
|
|
31
34
|
filterRepeaterInjections();
|
|
32
35
|
}
|
|
33
36
|
|
|
@@ -75,6 +78,25 @@ function boxShadowRepeaterInjections() {
|
|
|
75
78
|
} );
|
|
76
79
|
}
|
|
77
80
|
|
|
81
|
+
function transformRepeaterInjections() {
|
|
82
|
+
injectIntoRepeaterItemLabel( {
|
|
83
|
+
id: 'transform-size-variables-label',
|
|
84
|
+
component: TransformRepeaterLabel,
|
|
85
|
+
condition: ( { value }: Args ) => {
|
|
86
|
+
if ( moveTransformPropTypeUtil.isValid( value ) ) {
|
|
87
|
+
const { x: xAxis, y: yAxis, z: zAxis } = moveTransformPropTypeUtil.extract( value ) || {};
|
|
88
|
+
return (
|
|
89
|
+
hasAssignedSizeVariable( xAxis ) ||
|
|
90
|
+
hasAssignedSizeVariable( yAxis ) ||
|
|
91
|
+
hasAssignedSizeVariable( zAxis )
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return false;
|
|
96
|
+
},
|
|
97
|
+
} );
|
|
98
|
+
}
|
|
99
|
+
|
|
78
100
|
function transitionsRepeaterInjections() {
|
|
79
101
|
injectIntoRepeaterItemLabel( {
|
|
80
102
|
id: 'transition-size-variables-label',
|
package/src/types.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
+
import { type StyleVariables, type Variable } from '@elementor/editor-styles';
|
|
2
3
|
import { type VirtualizedItem } from '@elementor/editor-ui';
|
|
3
4
|
|
|
4
|
-
export type Variable
|
|
5
|
-
key?: string;
|
|
6
|
-
label: string;
|
|
7
|
-
value: string;
|
|
8
|
-
type: string;
|
|
9
|
-
deleted?: boolean;
|
|
10
|
-
deleted_at?: string;
|
|
11
|
-
sync_to_v3?: boolean;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type StyleVariables = Record< string, Variable >;
|
|
5
|
+
export type { StyleVariables, Variable };
|
|
15
6
|
|
|
16
7
|
export type ExtendedVirtualizedItem = VirtualizedItem< 'item', string > & {
|
|
17
8
|
icon: React.ReactNode;
|