@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.mjs CHANGED
@@ -3863,110 +3863,23 @@ var trackOpenVariablePopover = (path, variableType) => {
3863
3863
  };
3864
3864
 
3865
3865
  // src/mcp/manage-variable-tool.ts
3866
+ import { httpService as httpService3 } from "@elementor/http-client";
3866
3867
  import { z as z3 } from "@elementor/schema";
3867
- import { isProActive as isProActive2 } from "@elementor/utils";
3868
-
3869
- // src/sync/get-font-configs.ts
3870
- var getFontConfigs = () => {
3871
- return window.elementor?.config?.controls?.font?.options ?? {};
3872
- };
3868
+ import { isProActive } from "@elementor/utils";
3873
3869
 
3874
3870
  // src/mcp/variable-tool-prompt.ts
3875
- import { toolPrompts } from "@elementor/editor-mcp";
3876
- import { isProActive } from "@elementor/utils";
3877
3871
  var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
3878
- var generateVariablesPrompt = () => {
3879
- const prompt = toolPrompts("manage-global-variable");
3880
- const proIsActive = isProActive();
3881
- 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\`
3882
- - **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)
3883
- - ~~global-custom-size-variable~~ \u2014 requires Elementor Pro (not available on this site)`;
3884
- prompt.description(`
3885
- # Purpose
3886
- Create, update, or delete V4 global CSS variables. These are distinct from legacy v3 globals and map 1:1 to \`--css-var: VALUE\`.
3887
-
3888
- # Available Types
3889
- - **global-color-variable** \u2014 CSS color value. Example: \`#FF0000\`, \`rgba(255,0,0,1)\`, \`hsl(0,100%,50%)\`
3890
- - **global-font-variable** \u2014 Font family name ONLY \u2014 NOT a size or px value. Example: \`Roboto\`, \`Open Sans\`. NEVER pass px/rem here.
3891
- ${sizeVariableSection}
3892
-
3893
- # Naming Rules
3894
- - Labels must be **lowercase**, using only letters (a-z), numbers, digits (0-9), dashes (-), or underscores (_)
3895
- - No spaces, no special characters
3896
- - Example: "Headline Primary" \u2192 \`headline-primary\`
3897
- - Labels must be unique \u2014 always check [elementor://global-variables] first
3898
-
3899
- # Value Rules
3900
- - Provide a **plain CSS value** only \u2014 do NOT pass JSON, legacy-globals object structures, or variable references
3901
- - Values are inserted as-is: \`--css-var: <value>\`
3902
- - NEVER store a px/rem value inside a \`global-font-variable\` \u2014 use \`global-size-variable\` (Pro) instead
3903
-
3904
- # Operations
3905
- - **create** \u2014 requires \`type\`, \`label\`, \`value\`. Label must be unique.
3906
- - **update** \u2014 requires \`id\`, \`label\`, \`value\`. Get \`id\` from [elementor://global-variables]. When renaming: keep existing value. When changing value: keep exact existing label.
3907
- - **delete** \u2014 requires \`id\`. DESTRUCTIVE \u2014 always confirm with user before executing.
3908
- `);
3909
- prompt.parameter("action", '"create", "update", or "delete".');
3910
- prompt.parameter("type", "Variable type. Required for create. See Available Types above.");
3911
- prompt.parameter("label", "Variable name (lowercase, dash-separated). Required for create/update.");
3912
- prompt.parameter(
3913
- "value",
3914
- "Plain CSS value matching the variable type. Required for create/update. Do NOT pass JSON."
3915
- );
3916
- prompt.parameter("id", "Variable ID. Required for update/delete. Obtain from [elementor://global-variables].");
3917
- prompt.example(`
3918
- Create a brand color:
3919
- { "action": "create", "type": "global-color-variable", "label": "brand-primary", "value": "#1A73E8" }
3920
-
3921
- Create a heading font:
3922
- { "action": "create", "type": "global-font-variable", "label": "font-heading", "value": "Playfair Display" }
3923
-
3924
- Create a simple spacing size:
3925
- { "action": "create", "type": "global-size-variable", "label": "spacing-md", "value": "16px" }
3926
-
3927
- Create a fluid/responsive size using a CSS function (use global-custom-size-variable, NOT global-size-variable):
3928
- { "action": "create", "type": "global-custom-size-variable", "label": "spacing-fluid", "value": "clamp(1rem, 2vw, 2rem)" }
3929
-
3930
- Create a size that is a keyword:
3931
- { "action": "create", "type": "global-custom-size-variable", "label": "width-auto", "value": "auto" }
3932
-
3933
- Create a size using calc():
3934
- { "action": "create", "type": "global-custom-size-variable", "label": "sidebar-width", "value": "calc(100% - 32px)" }
3935
-
3936
- Update a variable's value (keep exact label):
3937
- { "action": "update", "id": "abc123", "label": "brand-primary", "value": "#0D47A1" }
3938
-
3939
- Rename a variable (keep existing value):
3940
- { "action": "update", "id": "abc123", "label": "brand-secondary", "value": "#1A73E8" }
3941
-
3942
- Delete a variable:
3943
- { "action": "delete", "id": "abc123" }
3944
- `);
3945
- prompt.instruction(
3946
- "Always read [elementor://global-variables] before creating to check existing variables and avoid duplicate labels."
3947
- );
3948
- return prompt.prompt();
3949
- };
3950
3872
 
3951
3873
  // src/mcp/variables-resource.ts
3952
3874
  import { __privateListenTo as listenTo, commandEndEvent } from "@elementor/editor-v1-adapters";
3875
+ import { httpService as httpService2 } from "@elementor/http-client";
3876
+ var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
3953
3877
  var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3954
- var buildGlobalVariablesPayload = async () => {
3955
- const merged = {};
3956
- Object.entries(service.variables()).forEach(([id, variable]) => {
3957
- if (!variable.deleted) {
3958
- merged[id] = { ...variable, version: "v4" };
3959
- }
3960
- });
3961
- return merged;
3962
- };
3963
3878
  var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3964
3879
  [canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
3965
3880
  const { resource, sendResourceUpdated } = entry;
3966
3881
  const notifyGlobalVariablesUpdated = () => {
3967
- sendResourceUpdated({
3968
- uri: GLOBAL_VARIABLES_URI
3969
- });
3882
+ sendResourceUpdated({ uri: GLOBAL_VARIABLES_URI });
3970
3883
  };
3971
3884
  resource(
3972
3885
  "global-variables",
@@ -3974,11 +3887,17 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3974
3887
  {
3975
3888
  description: "Global variables available (v4)"
3976
3889
  },
3977
- async () => {
3978
- const variables = await buildGlobalVariablesPayload();
3890
+ async (uri) => {
3891
+ const { data } = await httpService2().get(MCP_PROXY_URL, {
3892
+ params: { uri: uri.href }
3893
+ });
3979
3894
  return {
3980
3895
  contents: [
3981
- { uri: GLOBAL_VARIABLES_URI, mimeType: "application/json", text: JSON.stringify(variables) }
3896
+ {
3897
+ uri: uri.href,
3898
+ mimeType: "application/json",
3899
+ text: JSON.stringify(data.data ?? {})
3900
+ }
3982
3901
  ]
3983
3902
  };
3984
3903
  }
@@ -3989,37 +3908,17 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3989
3908
  };
3990
3909
 
3991
3910
  // src/mcp/manage-variable-tool.ts
3911
+ var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
3912
+ var TOOL_NAME = "manage-global-variable";
3992
3913
  var VARIABLE_TYPES = {
3993
3914
  COLOR: "global-color-variable",
3994
3915
  FONT: "global-font-variable",
3995
3916
  SIZE: "global-size-variable",
3996
3917
  CUSTOM_SIZE: "global-custom-size-variable"
3997
3918
  };
3998
- var LENGTH_UNIT_PATTERN = /^(auto|\d+(\.\d+)?(px|rem|em|vh|vw|%|ch|s|ms))$/i;
3999
- var COLOR_PATTERN = /^(#[0-9a-f]{3,8}|rgba?\(|hsl)/i;
4000
- function validateValueForType(type, value) {
4001
- if (type === VARIABLE_TYPES.FONT && LENGTH_UNIT_PATTERN.test(value.trim())) {
4002
- 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.`;
4003
- }
4004
- if (type === VARIABLE_TYPES.COLOR && !COLOR_PATTERN.test(value.trim())) {
4005
- return `Color variable value should be a CSS color (e.g. "#FF0000"), got "${value}".`;
4006
- }
4007
- if (type === VARIABLE_TYPES.SIZE && !LENGTH_UNIT_PATTERN.test(value.trim())) {
4008
- return `Size variable value should include a CSS unit (e.g. "16px") or be "auto", got "${value}".`;
4009
- }
4010
- if (type === VARIABLE_TYPES.FONT && !isFontAvailable(value)) {
4011
- return `Font "${value}" is not supported in WordPress. Please choose one of the available font families.`;
4012
- }
4013
- return null;
4014
- }
4015
- function isFontAvailable(font) {
4016
- const fonts = getFontConfigs();
4017
- const key = font.trim();
4018
- return !!fonts?.[key];
4019
- }
4020
3919
  var initManageVariableTool = (reg) => {
4021
3920
  const { addTool, resource } = reg;
4022
- const RUNTIME_ALLOWED_VARIABLE_TYPES = isProActive2() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
3921
+ const RUNTIME_ALLOWED_VARIABLE_TYPES = isProActive() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
4023
3922
  resource(
4024
3923
  "manage-global-variable-guide",
4025
3924
  MANAGE_VARIABLES_GUIDE_URI,
@@ -4028,12 +3927,17 @@ var initManageVariableTool = (reg) => {
4028
3927
  description: "Detailed guide for using the manage-global-variable tool",
4029
3928
  mimeType: "text/plain"
4030
3929
  },
4031
- async (uri) => ({
4032
- contents: [{ uri: uri.href, mimeType: "text/plain", text: generateVariablesPrompt() }]
4033
- })
3930
+ async (uri) => {
3931
+ const { data } = await httpService3().get(MCP_PROXY_URL2, {
3932
+ params: { uri: uri.href }
3933
+ });
3934
+ return {
3935
+ contents: [{ uri: uri.href, mimeType: "text/plain", text: data.data }]
3936
+ };
3937
+ }
4034
3938
  );
4035
3939
  addTool({
4036
- name: "manage-global-variable",
3940
+ name: TOOL_NAME,
4037
3941
  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",
4038
3942
  schema: {
4039
3943
  action: z3.enum(["create", "update", "delete"]),
@@ -4057,60 +3961,14 @@ var initManageVariableTool = (reg) => {
4057
3961
  ],
4058
3962
  isDestructive: true,
4059
3963
  handler: async (params) => {
4060
- const operations = getServiceActions(service);
4061
- const op = operations[params.action];
4062
- if (op) {
4063
- await op(params);
4064
- return { status: "ok" };
4065
- }
4066
- throw new Error(`Unknown action ${params.action}`);
3964
+ await httpService3().post(MCP_PROXY_URL2, {
3965
+ tool: TOOL_NAME,
3966
+ input: params
3967
+ });
3968
+ return { status: "ok" };
4067
3969
  }
4068
3970
  });
4069
3971
  };
4070
- function getServiceActions(svc) {
4071
- return {
4072
- create({ type, label, value }) {
4073
- if (!type || !label || !value) {
4074
- throw new Error("Create requires type, label, and value");
4075
- }
4076
- if ((type === VARIABLE_TYPES.SIZE || type === VARIABLE_TYPES.CUSTOM_SIZE) && !isProActive2()) {
4077
- throw new Error("Creating size variables requires Elementor Pro.");
4078
- }
4079
- const labelError = validateLabel(label);
4080
- if (labelError) {
4081
- throw new Error(labelError);
4082
- }
4083
- const valueError = validateValueForType(type, value);
4084
- if (valueError) {
4085
- throw new Error(valueError);
4086
- }
4087
- return svc.create({ type, label, value }, { eventData: { executedBy: "mcp_tool" } });
4088
- },
4089
- update({ id, label, value }) {
4090
- if (!id || !label || !value) {
4091
- throw new Error("Update requires id, label, and value");
4092
- }
4093
- const labelError = validateLabel(label);
4094
- if (labelError) {
4095
- throw new Error(labelError);
4096
- }
4097
- const existingVariable = svc.variables()[id];
4098
- if (existingVariable) {
4099
- const valueError = validateValueForType(existingVariable.type, value);
4100
- if (valueError) {
4101
- throw new Error(valueError);
4102
- }
4103
- }
4104
- return svc.update(id, { label, value }, { eventData: { executedBy: "mcp_tool" } });
4105
- },
4106
- delete({ id }) {
4107
- if (!id) {
4108
- throw new Error("delete requires id");
4109
- }
4110
- return svc.delete(id);
4111
- }
4112
- };
4113
- }
4114
3972
 
4115
3973
  // src/mcp/index.ts
4116
3974
  function initMcp(reg, canvasMcpEntry) {