@elementor/editor-variables 4.2.0-841 → 4.2.0-843

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.2.0-841",
3
+ "version": "4.2.0-843",
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.2.0-841",
43
- "@elementor/editor-canvas": "4.2.0-841",
44
- "@elementor/editor-controls": "4.2.0-841",
45
- "@elementor/editor-current-user": "4.2.0-841",
46
- "@elementor/editor-mcp": "4.2.0-841",
47
- "@elementor/editor-panels": "4.2.0-841",
48
- "@elementor/editor-props": "4.2.0-841",
49
- "@elementor/editor-ui": "4.2.0-841",
50
- "@elementor/editor-v1-adapters": "4.2.0-841",
51
- "@elementor/menus": "4.2.0-841",
52
- "@elementor/http-client": "4.2.0-841",
42
+ "@elementor/editor": "4.2.0-843",
43
+ "@elementor/editor-canvas": "4.2.0-843",
44
+ "@elementor/editor-controls": "4.2.0-843",
45
+ "@elementor/editor-current-user": "4.2.0-843",
46
+ "@elementor/editor-mcp": "4.2.0-843",
47
+ "@elementor/editor-panels": "4.2.0-843",
48
+ "@elementor/editor-props": "4.2.0-843",
49
+ "@elementor/editor-ui": "4.2.0-843",
50
+ "@elementor/editor-v1-adapters": "4.2.0-843",
51
+ "@elementor/menus": "4.2.0-843",
52
+ "@elementor/http-client": "4.2.0-843",
53
53
  "@elementor/icons": "~1.75.1",
54
- "@elementor/events": "4.2.0-841",
55
- "@elementor/schema": "4.2.0-841",
54
+ "@elementor/events": "4.2.0-843",
55
+ "@elementor/schema": "4.2.0-843",
56
56
  "@elementor/ui": "1.37.5",
57
- "@elementor/utils": "4.2.0-841",
57
+ "@elementor/utils": "4.2.0-843",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -2,28 +2,17 @@ import { useEffect } from 'react';
2
2
  import { GLOBAL_STYLES_IMPORTED_EVENT } from '@elementor/editor-canvas';
3
3
 
4
4
  import { service } from '../service';
5
- import { styleVariablesRepository } from '../style-variables-repository';
6
5
 
7
6
  export function GlobalStylesImportListener() {
8
7
  useEffect( () => {
9
- const handleGlobalStylesImported = ( event: CustomEvent ) => {
10
- const importedVars = event.detail?.global_variables;
11
-
12
- if ( ! importedVars ) {
13
- return;
14
- }
15
-
16
- if ( importedVars.data && typeof importedVars.data === 'object' ) {
17
- styleVariablesRepository.update( importedVars.data );
18
- }
19
-
8
+ const handleGlobalStylesImported = () => {
20
9
  service.load();
21
10
  };
22
11
 
23
- window.addEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported as EventListener );
12
+ window.addEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported );
24
13
 
25
14
  return () => {
26
- window.removeEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported as EventListener );
15
+ window.removeEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported );
27
16
  };
28
17
  }, [] );
29
18
 
@@ -1,9 +1,9 @@
1
- import { useCallback, useState } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
2
2
 
3
3
  import { generateTempId } from '../../../batch-operations';
4
4
  import { getVariables } from '../../../hooks/use-prop-variables';
5
5
  import { service } from '../../../service';
6
- import { type TVariablesList } from '../../../storage';
6
+ import { STORAGE_UPDATED_EVENT, type TVariablesList } from '../../../storage';
7
7
  import { generateDuplicateLabel } from '../../../utils/duplicate-label';
8
8
  import { filterBySearch } from '../../../utils/filter-by-search';
9
9
  import { applySelectionFilters, variablesToList } from '../../../utils/variables-to-list';
@@ -17,6 +17,20 @@ export const useVariablesManagerState = () => {
17
17
  const [ isSaving, setIsSaving ] = useState( false );
18
18
  const [ searchValue, setSearchValue ] = useState( '' );
19
19
 
20
+ useEffect( () => {
21
+ const handleStorageUpdated = () => {
22
+ setVariables( getVariables( false ) );
23
+ setDeletedVariables( [] );
24
+ setIsDirty( false );
25
+ };
26
+
27
+ window.addEventListener( STORAGE_UPDATED_EVENT, handleStorageUpdated );
28
+
29
+ return () => {
30
+ window.removeEventListener( STORAGE_UPDATED_EVENT, handleStorageUpdated );
31
+ };
32
+ }, [] );
33
+
20
34
  const handleOnChange = useCallback(
21
35
  ( newVariables: TVariablesList ) => {
22
36
  setVariables( { ...variables, ...newVariables } );
package/src/init.ts CHANGED
@@ -47,7 +47,15 @@ export function init() {
47
47
  } );
48
48
 
49
49
  variablesService.init().then( () => {
50
- initMcp( getMCPByDomain( 'variables' ), getMCPByDomain( 'canvas' ) );
50
+ const variablesMcpRegistry = getMCPByDomain( 'variables', {
51
+ instructions: `Everything related to V4 ( Atomic ) variables.
52
+ # Global variables
53
+ - Create/update/delete global variables
54
+ - Get list of global variables
55
+ - Get details of a global variable
56
+ `,
57
+ } );
58
+ initMcp( variablesMcpRegistry, getMCPByDomain( 'canvas' ) );
51
59
  } );
52
60
 
53
61
  injectIntoTop( {
package/src/mcp/index.ts CHANGED
@@ -4,15 +4,6 @@ import { initManageVariableTool } from './manage-variable-tool';
4
4
  import { initVariablesResource } from './variables-resource';
5
5
 
6
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
7
  initManageVariableTool( reg );
17
8
  initVariablesResource( reg, canvasMcpEntry );
18
9
  }
@@ -20,7 +20,12 @@ export const initManageVariableTool = ( reg: MCPRegistryEntry ) => {
20
20
  .optional()
21
21
  .describe( 'Variable type: "global-color-variable" or "global-font-variable" (required for create)' ),
22
22
  label: z.string().optional().describe( 'Variable label (required for create/update)' ),
23
- value: z.string().optional().describe( 'Variable value (required for create/update)' ),
23
+ value: z
24
+ .string()
25
+ .optional()
26
+ .describe(
27
+ 'The variable value (required for create/update). Provide a plain CSS value matching the variable type (font: family name; color: CSS color; size: value with unit). Never JSON.'
28
+ ),
24
29
  },
25
30
  outputSchema: {
26
31
  status: z.enum( [ 'ok' ] ).describe( 'Operation status' ),
@@ -36,14 +41,11 @@ export const initManageVariableTool = ( reg: MCPRegistryEntry ) => {
36
41
  description: 'Global variables',
37
42
  },
38
43
  ],
39
- description: `Manages global variables (create/update/delete). Existing variables available in resources.
40
- CREATE: requires type, label, value. Ensure label is unique.
41
- UPDATE: requires id, label, value. When renaming: keep existing value. When updating value: keep exact label.
42
- DELETE: requires id. DESTRUCTIVE - confirm with user first.
43
-
44
- # NAMING - IMPORTANT
45
- the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
46
- `,
44
+ description: `Create, update, or delete V4 global variables (distinct from legacy "globals").
45
+ - Values: any valid CSS value, inserted as-is (1:1 with \`--css-var: VALUE\`). Do NOT pass JSON or legacy-globals object structures.
46
+ - Names: lowercase, dash-separated (e.g. "Headline Primary" "headline-primary").
47
+ - Update: when renaming, keep the existing value; when updating value, keep the exact label.
48
+ - Delete: destructive — confirm with user first.`,
47
49
  handler: async ( params ) => {
48
50
  const operations = getServiceActions( service );
49
51
  const op = operations[ params.action ];
@@ -2,7 +2,7 @@ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
2
  import { __privateListenTo as listenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
3
3
 
4
4
  import { service } from '../service';
5
- import { type TVariable } from '../storage';
5
+ import { STORAGE_UPDATED_EVENT, type TVariable } from '../storage';
6
6
 
7
7
  export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
8
8
 
@@ -47,7 +47,7 @@ export const initVariablesResource = ( variablesMcpEntry: MCPRegistryEntry, canv
47
47
  }
48
48
  );
49
49
 
50
- window.addEventListener( 'variables:updated', notifyGlobalVariablesUpdated );
50
+ window.addEventListener( STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated );
51
51
 
52
52
  listenTo( commandEndEvent( 'document/save/update' ), notifyGlobalVariablesUpdated );
53
53
  } );
package/src/storage.ts CHANGED
@@ -13,6 +13,8 @@ export type TVariablesList = Record< string, TVariable >;
13
13
  const STORAGE_KEY = 'elementor-global-variables';
14
14
  const STORAGE_WATERMARK_KEY = 'elementor-global-variables-watermark';
15
15
 
16
+ export const STORAGE_UPDATED_EVENT = 'variables:updated';
17
+
16
18
  export const OP_RW = 'RW';
17
19
  const OP_RO = 'RO';
18
20
 
@@ -23,7 +25,7 @@ export class Storage {
23
25
  };
24
26
 
25
27
  notifyChange() {
26
- window.dispatchEvent( new Event( 'variables:updated' ) );
28
+ window.dispatchEvent( new Event( STORAGE_UPDATED_EVENT ) );
27
29
  }
28
30
 
29
31
  constructor() {