@elementor/editor-variables 3.33.0-301 → 3.33.0-303

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.33.0-301",
3
+ "version": "3.33.0-303",
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.33.0-301",
43
- "@elementor/editor-canvas": "3.33.0-301",
44
- "@elementor/editor-controls": "3.33.0-301",
45
- "@elementor/editor-current-user": "3.33.0-301",
46
- "@elementor/editor-editing-panel": "3.33.0-301",
47
- "@elementor/editor-mcp": "3.33.0-301",
48
- "@elementor/editor-panels": "3.33.0-301",
49
- "@elementor/editor-props": "3.33.0-301",
50
- "@elementor/editor-ui": "3.33.0-301",
51
- "@elementor/editor-v1-adapters": "3.33.0-301",
52
- "@elementor/http-client": "3.33.0-301",
42
+ "@elementor/editor": "3.33.0-303",
43
+ "@elementor/editor-canvas": "3.33.0-303",
44
+ "@elementor/editor-controls": "3.33.0-303",
45
+ "@elementor/editor-current-user": "3.33.0-303",
46
+ "@elementor/editor-editing-panel": "3.33.0-303",
47
+ "@elementor/editor-mcp": "3.33.0-303",
48
+ "@elementor/editor-panels": "3.33.0-303",
49
+ "@elementor/editor-props": "3.33.0-303",
50
+ "@elementor/editor-ui": "3.33.0-303",
51
+ "@elementor/editor-v1-adapters": "3.33.0-303",
52
+ "@elementor/http-client": "3.33.0-303",
53
53
  "@elementor/icons": "^1.61.0",
54
- "@elementor/mixpanel": "3.33.0-301",
55
- "@elementor/schema": "3.33.0-301",
54
+ "@elementor/mixpanel": "3.33.0-303",
55
+ "@elementor/schema": "3.33.0-303",
56
56
  "@elementor/ui": "1.36.17",
57
57
  "@wordpress/i18n": "^5.13.0"
58
58
  },
package/src/mcp/index.ts CHANGED
@@ -4,6 +4,7 @@ import { initCreateVariableTool } from './create-variable-tool';
4
4
  import { initDeleteVariableTool } from './delete-variable-tool';
5
5
  import { initListVariablesTool } from './list-variables-tool';
6
6
  import { initUpdateVariableTool } from './update-variable-tool';
7
+ import { initVariablesResource } from './variables-resource';
7
8
 
8
9
  export function initMcp() {
9
10
  const { setMCPDescription } = getMCPByDomain( 'variables' );
@@ -12,4 +13,5 @@ export function initMcp() {
12
13
  initCreateVariableTool();
13
14
  initUpdateVariableTool();
14
15
  initDeleteVariableTool();
16
+ initVariablesResource();
15
17
  }
@@ -0,0 +1,28 @@
1
+ import { getMCPByDomain } from '@elementor/editor-mcp';
2
+
3
+ export const GLOBAL_VARIABLES_URI = 'elementor://variables';
4
+
5
+ export const initVariablesResource = () => {
6
+ const { mcpServer } = getMCPByDomain( 'variables' );
7
+
8
+ mcpServer.resource(
9
+ 'global-variables',
10
+ GLOBAL_VARIABLES_URI,
11
+ {
12
+ 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.',
14
+ },
15
+ async () => {
16
+ return {
17
+ contents: [ { uri: GLOBAL_VARIABLES_URI, text: localStorage[ 'elementor-global-variables' ] } ],
18
+ };
19
+ }
20
+ );
21
+
22
+ window.addEventListener( 'variables:updated', () => {
23
+ mcpServer.server.sendResourceUpdated( {
24
+ uri: GLOBAL_VARIABLES_URI,
25
+ contents: [ { uri: GLOBAL_VARIABLES_URI, text: localStorage[ 'elementor-global-variables' ] } ],
26
+ } );
27
+ } );
28
+ };
package/src/storage.ts CHANGED
@@ -21,6 +21,10 @@ export class Storage {
21
21
  variables: TVariablesList;
22
22
  };
23
23
 
24
+ notifyChange() {
25
+ window.dispatchEvent( new Event( 'variables:updated' ) );
26
+ }
27
+
24
28
  constructor() {
25
29
  this.state = {
26
30
  watermark: -1,
@@ -44,18 +48,21 @@ export class Storage {
44
48
 
45
49
  localStorage.setItem( STORAGE_WATERMARK_KEY, this.state.watermark.toString() );
46
50
  localStorage.setItem( STORAGE_KEY, JSON.stringify( this.state.variables ) );
51
+ this.notifyChange();
47
52
  }
48
53
 
49
54
  add( id: string, variable: TVariable ) {
50
55
  this.load();
51
56
  this.state.variables[ id ] = variable;
52
57
  localStorage.setItem( STORAGE_KEY, JSON.stringify( this.state.variables ) );
58
+ this.notifyChange();
53
59
  }
54
60
 
55
61
  update( id: string, variable: TVariable ) {
56
62
  this.load();
57
63
  this.state.variables[ id ] = variable;
58
64
  localStorage.setItem( STORAGE_KEY, JSON.stringify( this.state.variables ) );
65
+ this.notifyChange();
59
66
  }
60
67
 
61
68
  watermark( watermark: number ) {