@elementor/editor-variables 4.0.0-683 → 4.0.0

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": "4.0.0-683",
3
+ "version": "4.0.0",
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.0.0-683",
43
- "@elementor/editor-canvas": "4.0.0-683",
44
- "@elementor/editor-controls": "4.0.0-683",
45
- "@elementor/editor-current-user": "4.0.0-683",
46
- "@elementor/editor-mcp": "4.0.0-683",
47
- "@elementor/editor-panels": "4.0.0-683",
48
- "@elementor/editor-props": "4.0.0-683",
49
- "@elementor/editor-ui": "4.0.0-683",
50
- "@elementor/editor-v1-adapters": "4.0.0-683",
51
- "@elementor/menus": "4.0.0-683",
52
- "@elementor/http-client": "4.0.0-683",
53
- "@elementor/icons": "^1.68.0",
54
- "@elementor/events": "4.0.0-683",
55
- "@elementor/schema": "4.0.0-683",
42
+ "@elementor/editor": "4.0.0",
43
+ "@elementor/editor-canvas": "4.0.0",
44
+ "@elementor/editor-controls": "4.0.0",
45
+ "@elementor/editor-current-user": "4.0.0",
46
+ "@elementor/editor-mcp": "4.0.0",
47
+ "@elementor/editor-panels": "4.0.0",
48
+ "@elementor/editor-props": "4.0.0",
49
+ "@elementor/editor-ui": "4.0.0",
50
+ "@elementor/editor-v1-adapters": "4.0.0",
51
+ "@elementor/menus": "4.0.0",
52
+ "@elementor/http-client": "4.0.0",
53
+ "@elementor/icons": "^1.72.0",
54
+ "@elementor/events": "4.0.0",
55
+ "@elementor/schema": "4.0.0",
56
56
  "@elementor/ui": "1.37.2",
57
- "@elementor/utils": "4.0.0-683",
57
+ "@elementor/utils": "4.0.0",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -0,0 +1,33 @@
1
+ import { useEffect } from 'react';
2
+
3
+ import { service } from '../service';
4
+ import { styleVariablesRepository } from '../style-variables-repository';
5
+
6
+ export function GlobalStylesImportListener() {
7
+ useEffect( () => {
8
+ const handleGlobalStylesImported = ( event: CustomEvent ) => {
9
+ const importedVars = event.detail?.global_variables;
10
+
11
+ if ( ! importedVars ) {
12
+ return;
13
+ }
14
+
15
+ if ( importedVars.data && typeof importedVars.data === 'object' ) {
16
+ styleVariablesRepository.update( importedVars.data );
17
+ }
18
+
19
+ service.load();
20
+ };
21
+
22
+ window.addEventListener( 'elementor/global-styles/imported', handleGlobalStylesImported as EventListener );
23
+
24
+ return () => {
25
+ window.removeEventListener(
26
+ 'elementor/global-styles/imported',
27
+ handleGlobalStylesImported as EventListener
28
+ );
29
+ };
30
+ }, [] );
31
+
32
+ return null;
33
+ }
@@ -142,11 +142,12 @@ export const VariableCreation = ( { onGoBack, onClose }: Props ) => {
142
142
  } }
143
143
  onErrorChange={ ( errorMsg ) => {
144
144
  setLabelFieldError( {
145
- value: label,
145
+ value: '',
146
146
  message: errorMsg,
147
147
  } );
148
148
  } }
149
149
  onKeyDown={ handleKeyDown }
150
+ focusOnShow
150
151
  />
151
152
  </FormField>
152
153
  { ValueField && (
@@ -208,11 +208,12 @@ export const VariableEdit = ( { onClose, onGoBack, onSubmit, editId }: Props ) =
208
208
  } }
209
209
  onErrorChange={ ( errorMsg ) => {
210
210
  setLabelFieldError( {
211
- value: label,
211
+ value: '',
212
212
  message: errorMsg,
213
213
  } );
214
214
  } }
215
215
  onKeyDown={ handleKeyDown }
216
+ focusOnShow
216
217
  />
217
218
  </FormField>
218
219
  { ValueField && (
@@ -127,11 +127,12 @@ export const VariableRestore = ( { variableId, onClose, onSubmit }: Props ) => {
127
127
  } }
128
128
  onErrorChange={ ( errorMsg ) => {
129
129
  setLabelFieldError( {
130
- value: label,
130
+ value: '',
131
131
  message: errorMsg,
132
132
  } );
133
133
  } }
134
134
  onKeyDown={ handleKeyDown }
135
+ focusOnShow
135
136
  />
136
137
  </FormField>
137
138
  { ValueField && (
@@ -25,7 +25,7 @@ import {
25
25
  } from '@elementor/ui';
26
26
  import { __ } from '@wordpress/i18n';
27
27
 
28
- import { trackVariablesManagerEvent } from '../../utils/tracking';
28
+ import { trackVariablesManagerEvent, trackVariableSyncToV3 } from '../../utils/tracking';
29
29
  import { type ErrorResponse, type MappedError, mapServerError } from '../../utils/validations';
30
30
  import { getMenuActionsForVariable, getVariableType } from '../../variables-registry/variable-type-registry';
31
31
  import { DeleteConfirmationDialog } from '../ui/delete-confirmation-dialog';
@@ -76,8 +76,8 @@ export function VariablesManagerPanel() {
76
76
  handleOnChange,
77
77
  createVariable,
78
78
  handleDeleteVariable,
79
- handleStartSync,
80
- handleStopSync,
79
+ handleStartSync: startSyncFromState,
80
+ handleStopSync: stopSyncFromState,
81
81
  handleSave,
82
82
  isSaving,
83
83
  handleSearch,
@@ -151,23 +151,37 @@ export function VariablesManagerPanel() {
151
151
  [ handleDeleteVariable ]
152
152
  );
153
153
 
154
- const handleStopSyncWithConfirmation = useCallback(
154
+ const commitStopSync = useCallback(
155
155
  ( itemId: string ) => {
156
- handleStopSync( itemId );
157
- setStopSyncConfirmation( null );
156
+ stopSyncFromState( itemId );
157
+ const variable = variables[ itemId ];
158
+ if ( variable ) {
159
+ trackVariableSyncToV3( { variableLabel: variable.label, action: 'unsync' } );
160
+ }
158
161
  },
159
- [ handleStopSync ]
162
+ [ stopSyncFromState, variables ]
160
163
  );
161
164
 
162
- const handleShowStopSyncDialog = useCallback(
165
+ const handleStartSync = useCallback(
166
+ ( itemId: string ) => {
167
+ startSyncFromState( itemId );
168
+ const variable = variables[ itemId ];
169
+ if ( variable ) {
170
+ trackVariableSyncToV3( { variableLabel: variable.label, action: 'sync' } );
171
+ }
172
+ },
173
+ [ startSyncFromState, variables ]
174
+ );
175
+
176
+ const handleStopSync = useCallback(
163
177
  ( itemId: string ) => {
164
178
  if ( ! isStopSyncSuppressed ) {
165
179
  setStopSyncConfirmation( itemId );
166
180
  } else {
167
- handleStopSync( itemId );
181
+ commitStopSync( itemId );
168
182
  }
169
183
  },
170
- [ isStopSyncSuppressed, handleStopSync ]
184
+ [ isStopSyncSuppressed, commitStopSync ]
171
185
  );
172
186
 
173
187
  const buildMenuActions = useCallback(
@@ -182,7 +196,7 @@ export function VariablesManagerPanel() {
182
196
  variableId,
183
197
  handlers: {
184
198
  onStartSync: handleStartSync,
185
- onStopSync: handleShowStopSyncDialog,
199
+ onStopSync: handleStopSync,
186
200
  },
187
201
  } );
188
202
 
@@ -203,7 +217,7 @@ export function VariablesManagerPanel() {
203
217
 
204
218
  return [ ...typeActions, deleteAction ];
205
219
  },
206
- [ variables, handleStartSync, handleShowStopSyncDialog ]
220
+ [ variables, handleStartSync, handleStopSync ]
207
221
  );
208
222
 
209
223
  const hasVariables = Object.keys( variables ).length > 0;
@@ -368,7 +382,10 @@ export function VariablesManagerPanel() {
368
382
  <StopSyncConfirmationDialog
369
383
  open
370
384
  onClose={ () => setStopSyncConfirmation( null ) }
371
- onConfirm={ () => handleStopSyncWithConfirmation( stopSyncConfirmation ) }
385
+ onConfirm={ () => {
386
+ commitStopSync( stopSyncConfirmation );
387
+ setStopSyncConfirmation( null );
388
+ } }
372
389
  />
373
390
  ) }
374
391
 
package/src/init.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { injectIntoLogic, injectIntoTop } from '@elementor/editor';
2
2
  import { registerControlReplacement } from '@elementor/editor-controls';
3
+ import { getMCPByDomain } from '@elementor/editor-mcp';
3
4
  import { __registerPanel as registerPanel } from '@elementor/editor-panels';
4
5
  import { isTransformable, type PropValue } from '@elementor/editor-props';
5
6
  import { controlActionsMenu } from '@elementor/menus';
6
7
 
8
+ import { GlobalStylesImportListener } from './components/global-styles-import-listener';
7
9
  import { OpenPanelFromEvent } from './components/open-panel-from-event';
8
10
  import { OpenPanelFromUrl } from './components/open-panel-from-url';
9
11
  import { panel } from './components/variables-manager/variables-manager-panel';
@@ -44,7 +46,7 @@ export function init() {
44
46
  } );
45
47
 
46
48
  variablesService.init().then( () => {
47
- initMcp();
49
+ initMcp( getMCPByDomain( 'variables' ), getMCPByDomain( 'canvas' ) );
48
50
  } );
49
51
 
50
52
  injectIntoTop( {
@@ -52,6 +54,11 @@ export function init() {
52
54
  component: StyleVariablesRenderer,
53
55
  } );
54
56
 
57
+ injectIntoLogic( {
58
+ id: 'variables-import-listener',
59
+ component: GlobalStylesImportListener,
60
+ } );
61
+
55
62
  injectIntoLogic( {
56
63
  id: 'variables-open-panel-from-url',
57
64
  component: OpenPanelFromUrl,
package/src/mcp/index.ts CHANGED
@@ -1,12 +1,18 @@
1
- import { isAngieAvailable } from '@elementor/editor-mcp';
1
+ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
2
 
3
3
  import { initManageVariableTool } from './manage-variable-tool';
4
4
  import { initVariablesResource } from './variables-resource';
5
5
 
6
- export function initMcp() {
7
- if ( ! isAngieAvailable() ) {
8
- return;
9
- }
10
- initManageVariableTool();
11
- initVariablesResource();
6
+ export function initMcp( reg: MCPRegistryEntry, canvasMcpEntry: MCPRegistryEntry ) {
7
+ const { setMCPDescription } = reg;
8
+ setMCPDescription(
9
+ `Everything related to V4 ( Atomic ) variables.
10
+ # Global variables
11
+ - Create/update/delete global variables
12
+ - Get list of global variables
13
+ - Get details of a global variable
14
+ `
15
+ );
16
+ initManageVariableTool( reg );
17
+ initVariablesResource( reg, canvasMcpEntry );
12
18
  }
@@ -1,11 +1,12 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
1
+ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
2
  import { z } from '@elementor/schema';
3
3
 
4
4
  import { service } from '../service';
5
5
  import { GLOBAL_VARIABLES_URI } from './variables-resource';
6
6
 
7
- export const initManageVariableTool = () => {
8
- getMCPByDomain( 'variables' ).addTool( {
7
+ export const initManageVariableTool = ( reg: MCPRegistryEntry ) => {
8
+ const { addTool } = reg;
9
+ addTool( {
9
10
  name: 'manage-global-variable',
10
11
  schema: {
11
12
  action: z.enum( [ 'create', 'update', 'delete' ] ).describe( 'Operation to perform' ),
@@ -1,17 +1,14 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
1
+ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
2
 
3
3
  import { service } from '../service';
4
4
  import { type TVariable } from '../storage';
5
5
 
6
6
  export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
7
7
 
8
- export const initVariablesResource = () => {
9
- const canvasMcpEntry = getMCPByDomain( 'canvas' );
10
- const variablesMcpEntry = getMCPByDomain( 'variables' );
11
-
8
+ export const initVariablesResource = ( variablesMcpEntry: MCPRegistryEntry, canvasMcpEntry: MCPRegistryEntry ) => {
12
9
  [ canvasMcpEntry, variablesMcpEntry ].forEach( ( entry ) => {
13
- const { mcpServer } = entry;
14
- mcpServer.resource(
10
+ const { resource, sendResourceUpdated } = entry;
11
+ resource(
15
12
  'global-variables',
16
13
  GLOBAL_VARIABLES_URI,
17
14
  {
@@ -33,7 +30,7 @@ export const initVariablesResource = () => {
33
30
  );
34
31
 
35
32
  window.addEventListener( 'variables:updated', () => {
36
- mcpServer.server.sendResourceUpdated( {
33
+ sendResourceUpdated( {
37
34
  uri: GLOBAL_VARIABLES_URI,
38
35
  } );
39
36
  } );
@@ -2,8 +2,7 @@ import * as React from 'react';
2
2
  import { trackUpgradePromotionClick } from '@elementor/editor-controls';
3
3
  import { colorPropTypeUtil, sizePropTypeUtil, stringPropTypeUtil } from '@elementor/editor-props';
4
4
  import { CtaButton } from '@elementor/editor-ui';
5
- import { isExperimentActive } from '@elementor/editor-v1-adapters';
6
- import { BrushIcon, ExpandDiagonalIcon, ResetIcon, TextIcon } from '@elementor/icons';
5
+ import { BrushIcon, ExpandDiagonalIcon, RefreshIcon, RefreshOffIcon, TextIcon } from '@elementor/icons';
7
6
  import { __ } from '@wordpress/i18n';
8
7
 
9
8
  import { ColorField } from './components/fields/color-field';
@@ -28,21 +27,17 @@ export function registerVariableTypes() {
28
27
  menuActionsFactory: ( { variable, variableId, handlers } ) => {
29
28
  const actions = [];
30
29
 
31
- if ( ! isExperimentActive( 'e_design_system_sync' ) ) {
32
- return [];
33
- }
34
-
35
30
  if ( variable.sync_to_v3 ) {
36
31
  actions.push( {
37
32
  name: __( 'Stop syncing to Global Colors', 'elementor' ),
38
- icon: ResetIcon,
33
+ icon: RefreshOffIcon,
39
34
  color: 'text.primary',
40
35
  onClick: () => handlers.onStopSync( variableId ),
41
36
  } );
42
37
  } else {
43
38
  actions.push( {
44
39
  name: __( 'Sync to Global Colors', 'elementor' ),
45
- icon: ResetIcon,
40
+ icon: RefreshIcon,
46
41
  color: 'text.primary',
47
42
  onClick: () => handlers.onStartSync( variableId ),
48
43
  } );
package/src/service.ts CHANGED
@@ -216,17 +216,17 @@ export const service = {
216
216
 
217
217
  if ( results ) {
218
218
  results.forEach( ( result: OperationResult ) => {
219
- if ( result.variable ) {
220
- const { id: variableId, ...variableData } = result.variable;
219
+ const variableId = result.id;
221
220
 
221
+ if ( result.variable ) {
222
222
  if ( result.type === 'create' ) {
223
- storage.add( variableId, variableData );
223
+ storage.add( variableId, result.variable );
224
224
  } else {
225
- storage.update( variableId, variableData );
225
+ storage.update( variableId, result.variable );
226
226
  }
227
227
 
228
228
  styleVariablesRepository.update( {
229
- [ variableId ]: variableData,
229
+ [ variableId ]: result.variable,
230
230
  } );
231
231
  }
232
232
  } );
@@ -52,3 +52,32 @@ export const trackVariablesManagerEvent = ( { action, varType, controlPath }: Va
52
52
 
53
53
  dispatchEvent?.( name, eventData );
54
54
  };
55
+
56
+ type VariableSyncToV3Data = {
57
+ variableLabel: string;
58
+ action: 'sync' | 'unsync';
59
+ };
60
+
61
+ export const trackVariableSyncToV3 = ( { variableLabel, action }: VariableSyncToV3Data ) => {
62
+ try {
63
+ const { dispatchEvent, config } = getMixpanel();
64
+ if ( ! config?.names?.variables?.variableSyncToV3 ) {
65
+ return;
66
+ }
67
+
68
+ const name = config.names.variables.variableSyncToV3;
69
+ const isSync = action === 'sync';
70
+
71
+ dispatchEvent?.( name, {
72
+ interaction_type: 'click',
73
+ target_type: variableLabel,
74
+ target_name: isSync ? 'sync_to_v3' : 'unsync_to_v3',
75
+ interaction_result: isSync ? 'var_is_synced_to_V3' : 'var_is_unsynced_from_V3',
76
+ target_location: 'widget_panel',
77
+ location_l1: 'var_manager',
78
+ interaction_description: isSync
79
+ ? `user_synced_${ variableLabel }_to_v3`
80
+ : `user_unsync_${ variableLabel }_from_v3`,
81
+ } );
82
+ } catch {}
83
+ };