@elementor/editor-variables 3.35.0-340 → 3.35.0-341

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": "3.35.0-340",
3
+ "version": "3.35.0-341",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,20 +39,20 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "3.35.0-340",
43
- "@elementor/editor-canvas": "3.35.0-340",
44
- "@elementor/editor-controls": "3.35.0-340",
45
- "@elementor/editor-current-user": "3.35.0-340",
46
- "@elementor/editor-editing-panel": "3.35.0-340",
47
- "@elementor/editor-mcp": "3.35.0-340",
48
- "@elementor/editor-panels": "3.35.0-340",
49
- "@elementor/editor-props": "3.35.0-340",
50
- "@elementor/editor-ui": "3.35.0-340",
51
- "@elementor/editor-v1-adapters": "3.35.0-340",
52
- "@elementor/http-client": "3.35.0-340",
42
+ "@elementor/editor": "3.35.0-341",
43
+ "@elementor/editor-canvas": "3.35.0-341",
44
+ "@elementor/editor-controls": "3.35.0-341",
45
+ "@elementor/editor-current-user": "3.35.0-341",
46
+ "@elementor/editor-editing-panel": "3.35.0-341",
47
+ "@elementor/editor-mcp": "3.35.0-341",
48
+ "@elementor/editor-panels": "3.35.0-341",
49
+ "@elementor/editor-props": "3.35.0-341",
50
+ "@elementor/editor-ui": "3.35.0-341",
51
+ "@elementor/editor-v1-adapters": "3.35.0-341",
52
+ "@elementor/http-client": "3.35.0-341",
53
53
  "@elementor/icons": "^1.62.0",
54
- "@elementor/mixpanel": "3.35.0-340",
55
- "@elementor/schema": "3.35.0-340",
54
+ "@elementor/mixpanel": "3.35.0-341",
55
+ "@elementor/schema": "3.35.0-341",
56
56
  "@elementor/ui": "1.36.17",
57
57
  "@wordpress/i18n": "^5.13.0"
58
58
  },
package/src/index.ts CHANGED
@@ -1,3 +1,11 @@
1
1
  export { init } from './init';
2
- export { registerVariableType } from './variables-registry/variable-type-registry';
3
2
  export { registerVariableTypes } from './register-variable-types';
3
+ export { service } from './service';
4
+ export { registerVariableType } from './variables-registry/variable-type-registry';
5
+ export { GLOBAL_VARIABLES_URI } from './mcp/variables-resource';
6
+
7
+ import { globalVariablesLLMResolvers } from './utils/llm-propvalue-label-resolver';
8
+
9
+ export const Utils = {
10
+ globalVariablesLLMResolvers,
11
+ } as const;
@@ -17,7 +17,7 @@ const OutputSchema = {
17
17
  };
18
18
 
19
19
  export const initCreateVariableTool = () => {
20
- getMCPByDomain( 'variables' ).addTool( {
20
+ getMCPByDomain( 'canvas' ).addTool( {
21
21
  name: 'create-global-variable',
22
22
  schema: InputSchema,
23
23
  outputSchema: OutputSchema,
@@ -4,7 +4,7 @@ import { z } from '@elementor/schema';
4
4
  import { service } from '../service';
5
5
 
6
6
  export const initDeleteVariableTool = () => {
7
- getMCPByDomain( 'variables' ).addTool( {
7
+ getMCPByDomain( 'canvas' ).addTool( {
8
8
  name: 'delete-global-variable',
9
9
  schema: {
10
10
  id: z.string().describe( 'The unique identifier of the variable to be deleted.' ),
package/src/mcp/index.ts CHANGED
@@ -1,15 +1,9 @@
1
- import { getMCPByDomain } from '@elementor/editor-mcp';
2
-
3
1
  import { initCreateVariableTool } from './create-variable-tool';
4
2
  import { initDeleteVariableTool } from './delete-variable-tool';
5
- import { initListVariablesTool } from './list-variables-tool';
6
3
  import { initUpdateVariableTool } from './update-variable-tool';
7
4
  import { initVariablesResource } from './variables-resource';
8
5
 
9
6
  export function initMcp() {
10
- const { setMCPDescription } = getMCPByDomain( 'variables' );
11
- setMCPDescription( `Elementor Editor Variables MCP` );
12
- initListVariablesTool();
13
7
  initCreateVariableTool();
14
8
  initUpdateVariableTool();
15
9
  initDeleteVariableTool();
@@ -19,9 +19,9 @@ const VariableListSchema = {
19
19
  };
20
20
 
21
21
  export const initListVariablesTool = () => {
22
- getMCPByDomain( 'variables' ).addTool( {
22
+ getMCPByDomain( 'canvas' ).addTool( {
23
23
  name: 'list-global-variables',
24
- description: `List editor global variables
24
+ description: `List the global variables
25
25
 
26
26
  ## When to use this tool:
27
27
  - When a user requests to see all available global variables in the Elementor editor.
@@ -4,7 +4,7 @@ import { z } from '@elementor/schema';
4
4
  import { service } from '../service';
5
5
 
6
6
  export const initUpdateVariableTool = () => {
7
- getMCPByDomain( 'variables' ).addTool( {
7
+ getMCPByDomain( 'canvas' ).addTool( {
8
8
  schema: {
9
9
  id: z.string().describe( 'The unique identifier of the variable to be updated or renamed.' ),
10
10
  label: z
@@ -1,20 +1,30 @@
1
1
  import { getMCPByDomain } from '@elementor/editor-mcp';
2
2
 
3
- export const GLOBAL_VARIABLES_URI = 'elementor://variables';
3
+ import { service } from '../service';
4
+ import { type TVariable } from '../storage';
5
+
6
+ export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
4
7
 
5
8
  export const initVariablesResource = () => {
6
- const { mcpServer } = getMCPByDomain( 'variables' );
9
+ const { mcpServer } = getMCPByDomain( 'canvas' );
7
10
 
8
11
  mcpServer.resource(
9
12
  'global-variables',
10
13
  GLOBAL_VARIABLES_URI,
11
14
  {
12
15
  description:
13
- 'Global variables list. Variables are being used in this way: If it is directly in the schema, you need to put the ID which is the key inside the object.',
16
+ 'List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)',
14
17
  },
15
18
  async () => {
19
+ const variables: Record< string, TVariable > = {};
20
+ Object.entries( service.variables() ).forEach( ( [ id, variable ] ) => {
21
+ if ( ! variable.deleted ) {
22
+ variables[ id ] = variable;
23
+ }
24
+ } );
25
+
16
26
  return {
17
- contents: [ { uri: GLOBAL_VARIABLES_URI, text: localStorage[ 'elementor-global-variables' ] } ],
27
+ contents: [ { uri: GLOBAL_VARIABLES_URI, text: JSON.stringify( variables ) } ],
18
28
  };
19
29
  }
20
30
  );
package/src/service.ts CHANGED
@@ -2,7 +2,7 @@ import { __ } from '@wordpress/i18n';
2
2
 
3
3
  import { apiClient } from './api';
4
4
  import { buildOperationsArray, type OperationResult } from './batch-operations';
5
- import { OP_RW, Storage, type TVariablesList } from './storage';
5
+ import { OP_RW, Storage, type TVariable, type TVariablesList } from './storage';
6
6
  import { styleVariablesRepository } from './style-variables-repository';
7
7
  import { type Variable } from './types';
8
8
 
@@ -13,6 +13,18 @@ export const service = {
13
13
  return storage.load();
14
14
  },
15
15
 
16
+ findIdByLabel( needle: string ): string {
17
+ const variableId = Object.entries( this.variables() ).find( ( [ , variable ] ) => variable.label === needle );
18
+ if ( ! variableId ) {
19
+ throw new Error( `Variable with label ${ needle } not found` );
20
+ }
21
+ return variableId[ 0 ];
22
+ },
23
+
24
+ findVariableByLabel( needle: string ): TVariable | null {
25
+ return Object.values( this.variables() ).find( ( variable ) => variable.label === needle ) || null;
26
+ },
27
+
16
28
  getWatermark: (): number => {
17
29
  return storage.state.watermark;
18
30
  },
@@ -16,9 +16,11 @@ export const resolveCssVariable = ( id: string, variable: TVariable ) => {
16
16
  return null;
17
17
  }
18
18
 
19
+ const validCssVariableName = `--${ name }`;
20
+
19
21
  if ( ! fallbackValue.trim() ) {
20
- return `var(--${ name })`;
22
+ return `var(${ validCssVariableName })`;
21
23
  }
22
24
 
23
- return `var(--${ name }, ${ fallbackValue })`;
25
+ return `var(${ validCssVariableName }, ${ fallbackValue })`;
24
26
  };
@@ -1,14 +1,17 @@
1
1
  import { createTransformer } from '@elementor/editor-canvas';
2
2
 
3
3
  import { service } from '../service';
4
+ import { type TVariable } from '../storage';
4
5
  import { resolveCssVariable } from './utils/resolve-css-variable';
5
6
 
6
- export const variableTransformer = createTransformer( ( id: string ) => {
7
+ export const variableTransformer = createTransformer( ( idOrLabel: string ) => {
7
8
  const variables = service.variables();
8
9
 
9
- if ( ! variables[ id ] ) {
10
+ const targetVariable: TVariable | null = variables[ idOrLabel ] || service.findVariableByLabel( idOrLabel );
11
+ if ( ! targetVariable ) {
10
12
  return null;
11
13
  }
14
+ const id = service.findIdByLabel( targetVariable.label );
12
15
 
13
- return resolveCssVariable( id, variables[ id ] );
16
+ return resolveCssVariable( id, targetVariable );
14
17
  } );
@@ -0,0 +1,25 @@
1
+ import { service } from '../service';
2
+
3
+ export const globalVariablesLLMResolvers = {
4
+ 'global-color-variable': ( value: unknown ) => {
5
+ const idOrLabel = String( value );
6
+ return {
7
+ $$type: 'global-color-variable',
8
+ value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
9
+ };
10
+ },
11
+ 'global-font-variable': ( value: unknown ) => {
12
+ const idOrLabel = String( value );
13
+ return {
14
+ $$type: 'global-font-variable',
15
+ value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
16
+ };
17
+ },
18
+ 'global-size-variable': ( value: unknown ) => {
19
+ const idOrLabel = String( value );
20
+ return {
21
+ $$type: 'global-size-variable',
22
+ value: service.variables()[ idOrLabel ] ? idOrLabel : service.findIdByLabel( idOrLabel ),
23
+ };
24
+ },
25
+ };