@elementor/editor-variables 4.3.0-976 → 4.3.0-978

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.js CHANGED
@@ -2371,7 +2371,7 @@ var StopSyncConfirmationDialog = ({ open, onClose, onConfirm }) => {
2371
2371
  // src/init.ts
2372
2372
  var import_editor = require("@elementor/editor");
2373
2373
  var import_editor_controls18 = require("@elementor/editor-controls");
2374
- var import_editor_mcp3 = require("@elementor/editor-mcp");
2374
+ var import_editor_mcp2 = require("@elementor/editor-mcp");
2375
2375
  var import_editor_props11 = require("@elementor/editor-props");
2376
2376
  var import_menus = require("@elementor/menus");
2377
2377
 
@@ -3883,110 +3883,23 @@ var trackOpenVariablePopover = (path, variableType) => {
3883
3883
  };
3884
3884
 
3885
3885
  // src/mcp/manage-variable-tool.ts
3886
+ var import_http_client3 = require("@elementor/http-client");
3886
3887
  var import_schema3 = require("@elementor/schema");
3887
- var import_utils4 = require("@elementor/utils");
3888
-
3889
- // src/sync/get-font-configs.ts
3890
- var getFontConfigs = () => {
3891
- return window.elementor?.config?.controls?.font?.options ?? {};
3892
- };
3888
+ var import_utils3 = require("@elementor/utils");
3893
3889
 
3894
3890
  // src/mcp/variable-tool-prompt.ts
3895
- var import_editor_mcp2 = require("@elementor/editor-mcp");
3896
- var import_utils3 = require("@elementor/utils");
3897
3891
  var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
3898
- var generateVariablesPrompt = () => {
3899
- const prompt = (0, import_editor_mcp2.toolPrompts)("manage-global-variable");
3900
- const proIsActive = (0, import_utils3.isProActive)();
3901
- const sizeVariableSection = proIsActive ? `- **global-size-variable** \u2014 A simple CSS length with a unit (Elementor Pro). Use this for fixed spacing, font sizes, or layout values. Example: \`16px\`, \`1.5rem\`, \`2em\`, \`10vh\`
3902
- - **global-custom-size-variable** \u2014 Any CSS size expression that goes beyond a simple number + unit (Elementor Pro). Use this when the value is a CSS function, a keyword, or a combination of units that \`global-size-variable\` cannot represent. Example: \`auto\`, \`clamp(1rem, 2vw, 2rem)\`, \`calc(100% - 32px)\`, \`min(50vw, 600px)\`, \`300ms\`, \`2ch\`. When in doubt: if the value contains a function call or a keyword, use \`global-custom-size-variable\`.` : `- ~~global-size-variable~~ \u2014 requires Elementor Pro (not available on this site)
3903
- - ~~global-custom-size-variable~~ \u2014 requires Elementor Pro (not available on this site)`;
3904
- prompt.description(`
3905
- # Purpose
3906
- Create, update, or delete V4 global CSS variables. These are distinct from legacy v3 globals and map 1:1 to \`--css-var: VALUE\`.
3907
-
3908
- # Available Types
3909
- - **global-color-variable** \u2014 CSS color value. Example: \`#FF0000\`, \`rgba(255,0,0,1)\`, \`hsl(0,100%,50%)\`
3910
- - **global-font-variable** \u2014 Font family name ONLY \u2014 NOT a size or px value. Example: \`Roboto\`, \`Open Sans\`. NEVER pass px/rem here.
3911
- ${sizeVariableSection}
3912
-
3913
- # Naming Rules
3914
- - Labels must be **lowercase**, using only letters (a-z), numbers, digits (0-9), dashes (-), or underscores (_)
3915
- - No spaces, no special characters
3916
- - Example: "Headline Primary" \u2192 \`headline-primary\`
3917
- - Labels must be unique \u2014 always check [elementor://global-variables] first
3918
-
3919
- # Value Rules
3920
- - Provide a **plain CSS value** only \u2014 do NOT pass JSON, legacy-globals object structures, or variable references
3921
- - Values are inserted as-is: \`--css-var: <value>\`
3922
- - NEVER store a px/rem value inside a \`global-font-variable\` \u2014 use \`global-size-variable\` (Pro) instead
3923
-
3924
- # Operations
3925
- - **create** \u2014 requires \`type\`, \`label\`, \`value\`. Label must be unique.
3926
- - **update** \u2014 requires \`id\`, \`label\`, \`value\`. Get \`id\` from [elementor://global-variables]. When renaming: keep existing value. When changing value: keep exact existing label.
3927
- - **delete** \u2014 requires \`id\`. DESTRUCTIVE \u2014 always confirm with user before executing.
3928
- `);
3929
- prompt.parameter("action", '"create", "update", or "delete".');
3930
- prompt.parameter("type", "Variable type. Required for create. See Available Types above.");
3931
- prompt.parameter("label", "Variable name (lowercase, dash-separated). Required for create/update.");
3932
- prompt.parameter(
3933
- "value",
3934
- "Plain CSS value matching the variable type. Required for create/update. Do NOT pass JSON."
3935
- );
3936
- prompt.parameter("id", "Variable ID. Required for update/delete. Obtain from [elementor://global-variables].");
3937
- prompt.example(`
3938
- Create a brand color:
3939
- { "action": "create", "type": "global-color-variable", "label": "brand-primary", "value": "#1A73E8" }
3940
-
3941
- Create a heading font:
3942
- { "action": "create", "type": "global-font-variable", "label": "font-heading", "value": "Playfair Display" }
3943
-
3944
- Create a simple spacing size:
3945
- { "action": "create", "type": "global-size-variable", "label": "spacing-md", "value": "16px" }
3946
-
3947
- Create a fluid/responsive size using a CSS function (use global-custom-size-variable, NOT global-size-variable):
3948
- { "action": "create", "type": "global-custom-size-variable", "label": "spacing-fluid", "value": "clamp(1rem, 2vw, 2rem)" }
3949
-
3950
- Create a size that is a keyword:
3951
- { "action": "create", "type": "global-custom-size-variable", "label": "width-auto", "value": "auto" }
3952
-
3953
- Create a size using calc():
3954
- { "action": "create", "type": "global-custom-size-variable", "label": "sidebar-width", "value": "calc(100% - 32px)" }
3955
-
3956
- Update a variable's value (keep exact label):
3957
- { "action": "update", "id": "abc123", "label": "brand-primary", "value": "#0D47A1" }
3958
-
3959
- Rename a variable (keep existing value):
3960
- { "action": "update", "id": "abc123", "label": "brand-secondary", "value": "#1A73E8" }
3961
-
3962
- Delete a variable:
3963
- { "action": "delete", "id": "abc123" }
3964
- `);
3965
- prompt.instruction(
3966
- "Always read [elementor://global-variables] before creating to check existing variables and avoid duplicate labels."
3967
- );
3968
- return prompt.prompt();
3969
- };
3970
3892
 
3971
3893
  // src/mcp/variables-resource.ts
3972
3894
  var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
3895
+ var import_http_client2 = require("@elementor/http-client");
3896
+ var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
3973
3897
  var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3974
- var buildGlobalVariablesPayload = async () => {
3975
- const merged = {};
3976
- Object.entries(service.variables()).forEach(([id, variable]) => {
3977
- if (!variable.deleted) {
3978
- merged[id] = { ...variable, version: "v4" };
3979
- }
3980
- });
3981
- return merged;
3982
- };
3983
3898
  var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3984
3899
  [canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
3985
3900
  const { resource, sendResourceUpdated } = entry;
3986
3901
  const notifyGlobalVariablesUpdated = () => {
3987
- sendResourceUpdated({
3988
- uri: GLOBAL_VARIABLES_URI
3989
- });
3902
+ sendResourceUpdated({ uri: GLOBAL_VARIABLES_URI });
3990
3903
  };
3991
3904
  resource(
3992
3905
  "global-variables",
@@ -3994,11 +3907,17 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3994
3907
  {
3995
3908
  description: "Global variables available (v4)"
3996
3909
  },
3997
- async () => {
3998
- const variables = await buildGlobalVariablesPayload();
3910
+ async (uri) => {
3911
+ const { data } = await (0, import_http_client2.httpService)().get(MCP_PROXY_URL, {
3912
+ params: { uri: uri.href }
3913
+ });
3999
3914
  return {
4000
3915
  contents: [
4001
- { uri: GLOBAL_VARIABLES_URI, mimeType: "application/json", text: JSON.stringify(variables) }
3916
+ {
3917
+ uri: uri.href,
3918
+ mimeType: "application/json",
3919
+ text: JSON.stringify(data.data ?? {})
3920
+ }
4002
3921
  ]
4003
3922
  };
4004
3923
  }
@@ -4009,37 +3928,17 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
4009
3928
  };
4010
3929
 
4011
3930
  // src/mcp/manage-variable-tool.ts
3931
+ var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
3932
+ var TOOL_NAME = "manage-global-variable";
4012
3933
  var VARIABLE_TYPES = {
4013
3934
  COLOR: "global-color-variable",
4014
3935
  FONT: "global-font-variable",
4015
3936
  SIZE: "global-size-variable",
4016
3937
  CUSTOM_SIZE: "global-custom-size-variable"
4017
3938
  };
4018
- var LENGTH_UNIT_PATTERN = /^(auto|\d+(\.\d+)?(px|rem|em|vh|vw|%|ch|s|ms))$/i;
4019
- var COLOR_PATTERN = /^(#[0-9a-f]{3,8}|rgba?\(|hsl)/i;
4020
- function validateValueForType(type, value) {
4021
- if (type === VARIABLE_TYPES.FONT && LENGTH_UNIT_PATTERN.test(value.trim())) {
4022
- return `Font variable value must be a font family name (e.g. "Roboto"), not a size value like "${value}". Use "global-size-variable" or "global-custom-size-variable" for spacing/size values.`;
4023
- }
4024
- if (type === VARIABLE_TYPES.COLOR && !COLOR_PATTERN.test(value.trim())) {
4025
- return `Color variable value should be a CSS color (e.g. "#FF0000"), got "${value}".`;
4026
- }
4027
- if (type === VARIABLE_TYPES.SIZE && !LENGTH_UNIT_PATTERN.test(value.trim())) {
4028
- return `Size variable value should include a CSS unit (e.g. "16px") or be "auto", got "${value}".`;
4029
- }
4030
- if (type === VARIABLE_TYPES.FONT && !isFontAvailable(value)) {
4031
- return `Font "${value}" is not supported in WordPress. Please choose one of the available font families.`;
4032
- }
4033
- return null;
4034
- }
4035
- function isFontAvailable(font) {
4036
- const fonts = getFontConfigs();
4037
- const key = font.trim();
4038
- return !!fonts?.[key];
4039
- }
4040
3939
  var initManageVariableTool = (reg) => {
4041
3940
  const { addTool, resource } = reg;
4042
- const RUNTIME_ALLOWED_VARIABLE_TYPES = (0, import_utils4.isProActive)() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
3941
+ const RUNTIME_ALLOWED_VARIABLE_TYPES = (0, import_utils3.isProActive)() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
4043
3942
  resource(
4044
3943
  "manage-global-variable-guide",
4045
3944
  MANAGE_VARIABLES_GUIDE_URI,
@@ -4048,12 +3947,17 @@ var initManageVariableTool = (reg) => {
4048
3947
  description: "Detailed guide for using the manage-global-variable tool",
4049
3948
  mimeType: "text/plain"
4050
3949
  },
4051
- async (uri) => ({
4052
- contents: [{ uri: uri.href, mimeType: "text/plain", text: generateVariablesPrompt() }]
4053
- })
3950
+ async (uri) => {
3951
+ const { data } = await (0, import_http_client3.httpService)().get(MCP_PROXY_URL2, {
3952
+ params: { uri: uri.href }
3953
+ });
3954
+ return {
3955
+ contents: [{ uri: uri.href, mimeType: "text/plain", text: data.data }]
3956
+ };
3957
+ }
4054
3958
  );
4055
3959
  addTool({
4056
- name: "manage-global-variable",
3960
+ name: TOOL_NAME,
4057
3961
  description: "Manage V4 global variables (color, font, size, custom-size). Read the guide resource before use. font = font-famliy, size = measured unit, custom-size = calculated values",
4058
3962
  schema: {
4059
3963
  action: import_schema3.z.enum(["create", "update", "delete"]),
@@ -4077,60 +3981,14 @@ var initManageVariableTool = (reg) => {
4077
3981
  ],
4078
3982
  isDestructive: true,
4079
3983
  handler: async (params) => {
4080
- const operations = getServiceActions(service);
4081
- const op = operations[params.action];
4082
- if (op) {
4083
- await op(params);
4084
- return { status: "ok" };
4085
- }
4086
- throw new Error(`Unknown action ${params.action}`);
3984
+ await (0, import_http_client3.httpService)().post(MCP_PROXY_URL2, {
3985
+ tool: TOOL_NAME,
3986
+ input: params
3987
+ });
3988
+ return { status: "ok" };
4087
3989
  }
4088
3990
  });
4089
3991
  };
4090
- function getServiceActions(svc) {
4091
- return {
4092
- create({ type, label, value }) {
4093
- if (!type || !label || !value) {
4094
- throw new Error("Create requires type, label, and value");
4095
- }
4096
- if ((type === VARIABLE_TYPES.SIZE || type === VARIABLE_TYPES.CUSTOM_SIZE) && !(0, import_utils4.isProActive)()) {
4097
- throw new Error("Creating size variables requires Elementor Pro.");
4098
- }
4099
- const labelError = validateLabel(label);
4100
- if (labelError) {
4101
- throw new Error(labelError);
4102
- }
4103
- const valueError = validateValueForType(type, value);
4104
- if (valueError) {
4105
- throw new Error(valueError);
4106
- }
4107
- return svc.create({ type, label, value }, { eventData: { executedBy: "mcp_tool" } });
4108
- },
4109
- update({ id, label, value }) {
4110
- if (!id || !label || !value) {
4111
- throw new Error("Update requires id, label, and value");
4112
- }
4113
- const labelError = validateLabel(label);
4114
- if (labelError) {
4115
- throw new Error(labelError);
4116
- }
4117
- const existingVariable = svc.variables()[id];
4118
- if (existingVariable) {
4119
- const valueError = validateValueForType(existingVariable.type, value);
4120
- if (valueError) {
4121
- throw new Error(valueError);
4122
- }
4123
- }
4124
- return svc.update(id, { label, value }, { eventData: { executedBy: "mcp_tool" } });
4125
- },
4126
- delete({ id }) {
4127
- if (!id) {
4128
- throw new Error("delete requires id");
4129
- }
4130
- return svc.delete(id);
4131
- }
4132
- };
4133
- }
4134
3992
 
4135
3993
  // src/mcp/index.ts
4136
3994
  function initMcp(reg, canvasMcpEntry) {
@@ -4651,7 +4509,7 @@ function init() {
4651
4509
  useProps: usePropVariableAction
4652
4510
  });
4653
4511
  service.init();
4654
- const variablesMcpRegistry = (0, import_editor_mcp3.getMCPByDomain)("variables", {
4512
+ const variablesMcpRegistry = (0, import_editor_mcp2.getMCPByDomain)("variables", {
4655
4513
  instructions: `Everything related to V4 ( Atomic ) variables.
4656
4514
  # Global variables
4657
4515
  - Create/update/delete global variables
@@ -4659,7 +4517,7 @@ function init() {
4659
4517
  - Get details of a global variable
4660
4518
  `
4661
4519
  });
4662
- initMcp(variablesMcpRegistry, (0, import_editor_mcp3.getMCPByDomain)("canvas"));
4520
+ initMcp(variablesMcpRegistry, (0, import_editor_mcp2.getMCPByDomain)("canvas"));
4663
4521
  (0, import_editor.injectIntoTop)({
4664
4522
  id: "canvas-style-variables-render",
4665
4523
  component: StyleVariablesRenderer