@elementor/editor-variables 4.2.0-876 → 4.2.0-878

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
@@ -2412,7 +2412,7 @@ var StopSyncConfirmationDialog = ({ open, onClose, onConfirm }) => {
2412
2412
  // src/init.ts
2413
2413
  var import_editor = require("@elementor/editor");
2414
2414
  var import_editor_controls18 = require("@elementor/editor-controls");
2415
- var import_editor_mcp = require("@elementor/editor-mcp");
2415
+ var import_editor_mcp2 = require("@elementor/editor-mcp");
2416
2416
  var import_editor_panels2 = require("@elementor/editor-panels");
2417
2417
  var import_editor_props10 = require("@elementor/editor-props");
2418
2418
  var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
@@ -3924,6 +3924,84 @@ var trackOpenVariablePopover = (path, variableType) => {
3924
3924
 
3925
3925
  // src/mcp/manage-variable-tool.ts
3926
3926
  var import_schema3 = require("@elementor/schema");
3927
+ var import_utils4 = require("@elementor/utils");
3928
+
3929
+ // src/mcp/variable-tool-prompt.ts
3930
+ var import_editor_mcp = require("@elementor/editor-mcp");
3931
+ var import_utils3 = require("@elementor/utils");
3932
+ var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
3933
+ var generateVariablesPrompt = () => {
3934
+ const prompt = (0, import_editor_mcp.toolPrompts)("manage-global-variable");
3935
+ const proIsActive = (0, import_utils3.isProActive)();
3936
+ 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\`
3937
+ - **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)
3938
+ - ~~global-custom-size-variable~~ \u2014 requires Elementor Pro (not available on this site)`;
3939
+ prompt.description(`
3940
+ # Purpose
3941
+ Create, update, or delete V4 global CSS variables. These are distinct from legacy v3 globals and map 1:1 to \`--css-var: VALUE\`.
3942
+
3943
+ # Available Types
3944
+ - **global-color-variable** \u2014 CSS color value. Example: \`#FF0000\`, \`rgba(255,0,0,1)\`, \`hsl(0,100%,50%)\`
3945
+ - **global-font-variable** \u2014 Font family name ONLY \u2014 NOT a size or px value. Example: \`Roboto\`, \`Open Sans\`. NEVER pass px/rem here.
3946
+ ${sizeVariableSection}
3947
+
3948
+ # Naming Rules
3949
+ - Labels must be **lowercase**, using only letters (a-z), numbers, digits (0-9), dashes (-), or underscores (_)
3950
+ - No spaces, no special characters
3951
+ - Example: "Headline Primary" \u2192 \`headline-primary\`
3952
+ - Labels must be unique \u2014 always check [elementor://global-variables] first
3953
+
3954
+ # Value Rules
3955
+ - Provide a **plain CSS value** only \u2014 do NOT pass JSON, legacy-globals object structures, or variable references
3956
+ - Values are inserted as-is: \`--css-var: <value>\`
3957
+ - NEVER store a px/rem value inside a \`global-font-variable\` \u2014 use \`global-size-variable\` (Pro) instead
3958
+
3959
+ # Operations
3960
+ - **create** \u2014 requires \`type\`, \`label\`, \`value\`. Label must be unique.
3961
+ - **update** \u2014 requires \`id\`, \`label\`, \`value\`. Get \`id\` from [elementor://global-variables]. When renaming: keep existing value. When changing value: keep exact existing label.
3962
+ - **delete** \u2014 requires \`id\`. DESTRUCTIVE \u2014 always confirm with user before executing.
3963
+ `);
3964
+ prompt.parameter("action", '"create", "update", or "delete".');
3965
+ prompt.parameter("type", "Variable type. Required for create. See Available Types above.");
3966
+ prompt.parameter("label", "Variable name (lowercase, dash-separated). Required for create/update.");
3967
+ prompt.parameter(
3968
+ "value",
3969
+ "Plain CSS value matching the variable type. Required for create/update. Do NOT pass JSON."
3970
+ );
3971
+ prompt.parameter("id", "Variable ID. Required for update/delete. Obtain from [elementor://global-variables].");
3972
+ prompt.example(`
3973
+ Create a brand color:
3974
+ { "action": "create", "type": "global-color-variable", "label": "brand-primary", "value": "#1A73E8" }
3975
+
3976
+ Create a heading font:
3977
+ { "action": "create", "type": "global-font-variable", "label": "font-heading", "value": "Playfair Display" }
3978
+
3979
+ Create a simple spacing size:
3980
+ { "action": "create", "type": "global-size-variable", "label": "spacing-md", "value": "16px" }
3981
+
3982
+ Create a fluid/responsive size using a CSS function (use global-custom-size-variable, NOT global-size-variable):
3983
+ { "action": "create", "type": "global-custom-size-variable", "label": "spacing-fluid", "value": "clamp(1rem, 2vw, 2rem)" }
3984
+
3985
+ Create a size that is a keyword:
3986
+ { "action": "create", "type": "global-custom-size-variable", "label": "width-auto", "value": "auto" }
3987
+
3988
+ Create a size using calc():
3989
+ { "action": "create", "type": "global-custom-size-variable", "label": "sidebar-width", "value": "calc(100% - 32px)" }
3990
+
3991
+ Update a variable's value (keep exact label):
3992
+ { "action": "update", "id": "abc123", "label": "brand-primary", "value": "#0D47A1" }
3993
+
3994
+ Rename a variable (keep existing value):
3995
+ { "action": "update", "id": "abc123", "label": "brand-secondary", "value": "#1A73E8" }
3996
+
3997
+ Delete a variable:
3998
+ { "action": "delete", "id": "abc123" }
3999
+ `);
4000
+ prompt.instruction(
4001
+ "Always read [elementor://global-variables] before creating to check existing variables and avoid duplicate labels."
4002
+ );
4003
+ return prompt.prompt();
4004
+ };
3927
4005
 
3928
4006
  // src/mcp/variables-resource.ts
3929
4007
  var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
@@ -3966,17 +4044,52 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3966
4044
  };
3967
4045
 
3968
4046
  // src/mcp/manage-variable-tool.ts
4047
+ var VARIABLE_TYPES = {
4048
+ COLOR: "global-color-variable",
4049
+ FONT: "global-font-variable",
4050
+ SIZE: "global-size-variable",
4051
+ CUSTOM_SIZE: "global-custom-size-variable"
4052
+ };
4053
+ var LENGTH_UNIT_PATTERN = /^(auto|\d+(\.\d+)?(px|rem|em|vh|vw|%|ch|s|ms))$/i;
4054
+ var COLOR_PATTERN = /^(#[0-9a-f]{3,8}|rgba?\(|hsl)/i;
4055
+ function validateValueForType(type, value) {
4056
+ if (type === VARIABLE_TYPES.FONT && LENGTH_UNIT_PATTERN.test(value.trim())) {
4057
+ 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.`;
4058
+ }
4059
+ if (type === VARIABLE_TYPES.COLOR && !COLOR_PATTERN.test(value.trim())) {
4060
+ return `Color variable value should be a CSS color (e.g. "#FF0000"), got "${value}".`;
4061
+ }
4062
+ if (type === VARIABLE_TYPES.SIZE && !LENGTH_UNIT_PATTERN.test(value.trim())) {
4063
+ return `Size variable value should include a CSS unit (e.g. "16px") or be "auto", got "${value}".`;
4064
+ }
4065
+ return null;
4066
+ }
3969
4067
  var initManageVariableTool = (reg) => {
3970
- const { addTool } = reg;
4068
+ const { addTool, resource } = reg;
4069
+ resource(
4070
+ "manage-global-variable-guide",
4071
+ MANAGE_VARIABLES_GUIDE_URI,
4072
+ {
4073
+ title: "Manage Global Variable Guide",
4074
+ description: "Detailed guide for using the manage-global-variable tool",
4075
+ mimeType: "text/plain"
4076
+ },
4077
+ async (uri) => ({
4078
+ contents: [{ uri: uri.href, mimeType: "text/plain", text: generateVariablesPrompt() }]
4079
+ })
4080
+ );
3971
4081
  addTool({
3972
4082
  name: "manage-global-variable",
4083
+ description: "Manage V4 global variables (color, font, size). Read the guide resource before use.",
3973
4084
  schema: {
3974
4085
  action: import_schema3.z.enum(["create", "update", "delete"]).describe("Operation to perform"),
3975
- id: import_schema3.z.string().optional().describe("Variable id (required for update/delete). Get from list-global-variables."),
3976
- type: import_schema3.z.string().optional().describe('Variable type: "global-color-variable" or "global-font-variable" (required for create)'),
3977
- label: import_schema3.z.string().optional().describe("Variable label (required for create/update)"),
4086
+ id: import_schema3.z.string().optional().describe("Variable id \u2014 required for update/delete. Get from the global-variables resource."),
4087
+ type: import_schema3.z.string().optional().describe(
4088
+ 'Variable type \u2014 required for create. One of: "global-color-variable", "global-font-variable", "global-size-variable", "global-custom-size-variable" (size types require Elementor Pro). NEVER store px/rem values in a font variable.'
4089
+ ),
4090
+ label: import_schema3.z.string().optional().describe("Variable label (lowercase, dash-separated) \u2014 required for create/update."),
3978
4091
  value: import_schema3.z.string().optional().describe(
3979
- "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."
4092
+ 'Plain CSS value \u2014 required for create/update. Color: hex/rgba/hsl. Font: family name only, never px/rem. Size: value with unit e.g. "16px", or "auto" (Pro). Do NOT pass JSON.'
3980
4093
  )
3981
4094
  },
3982
4095
  outputSchema: {
@@ -3984,29 +4097,22 @@ var initManageVariableTool = (reg) => {
3984
4097
  message: import_schema3.z.string().optional().describe("Error details if status is error")
3985
4098
  },
3986
4099
  requiredResources: [
4100
+ { uri: MANAGE_VARIABLES_GUIDE_URI, description: "Full guide for variable types, naming rules, and usage" },
3987
4101
  {
3988
4102
  uri: GLOBAL_VARIABLES_URI,
3989
- description: "Global variables"
4103
+ description: "Current global variables \u2014 check before creating to avoid duplicates"
3990
4104
  }
3991
4105
  ],
3992
- description: `Create, update, or delete V4 global variables (distinct from legacy "globals").
3993
- - Values: any valid CSS value, inserted as-is (1:1 with \`--css-var: VALUE\`). Do NOT pass JSON or legacy-globals object structures.
3994
- - Names: lowercase, dash-separated (e.g. "Headline Primary" \u2192 "headline-primary").
3995
- - Update: when renaming, keep the existing value; when updating value, keep the exact label.
3996
- - Delete: destructive \u2014 confirm with user first.`,
4106
+ isDestructive: true,
3997
4107
  handler: async (params) => {
3998
4108
  const operations = getServiceActions(service);
3999
4109
  const op = operations[params.action];
4000
4110
  if (op) {
4001
4111
  await op(params);
4002
- return {
4003
- status: "ok"
4004
- };
4112
+ return { status: "ok" };
4005
4113
  }
4006
4114
  throw new Error(`Unknown action ${params.action}`);
4007
- },
4008
- isDestructive: true
4009
- // Because delete is destructive
4115
+ }
4010
4116
  });
4011
4117
  };
4012
4118
  function getServiceActions(svc) {
@@ -4015,10 +4121,17 @@ function getServiceActions(svc) {
4015
4121
  if (!type || !label || !value) {
4016
4122
  throw new Error("Create requires type, label, and value");
4017
4123
  }
4124
+ if ((type === VARIABLE_TYPES.SIZE || type === VARIABLE_TYPES.CUSTOM_SIZE) && !(0, import_utils4.isProActive)()) {
4125
+ throw new Error("Creating size variables requires Elementor Pro.");
4126
+ }
4018
4127
  const labelError = validateLabel(label);
4019
4128
  if (labelError) {
4020
4129
  throw new Error(labelError);
4021
4130
  }
4131
+ const valueError = validateValueForType(type, value);
4132
+ if (valueError) {
4133
+ throw new Error(valueError);
4134
+ }
4022
4135
  return svc.create({ type, label, value });
4023
4136
  },
4024
4137
  update({ id: id2, label, value }) {
@@ -4029,6 +4142,13 @@ function getServiceActions(svc) {
4029
4142
  if (labelError) {
4030
4143
  throw new Error(labelError);
4031
4144
  }
4145
+ const existingVariable = svc.variables()[id2];
4146
+ if (existingVariable) {
4147
+ const valueError = validateValueForType(existingVariable.type, value);
4148
+ if (valueError) {
4149
+ throw new Error(valueError);
4150
+ }
4151
+ }
4032
4152
  return svc.update(id2, { label, value });
4033
4153
  },
4034
4154
  delete({ id: id2 }) {
@@ -4553,7 +4673,7 @@ function init() {
4553
4673
  useProps: usePropVariableAction
4554
4674
  });
4555
4675
  service.init().then(() => {
4556
- const variablesMcpRegistry = (0, import_editor_mcp.getMCPByDomain)("variables", {
4676
+ const variablesMcpRegistry = (0, import_editor_mcp2.getMCPByDomain)("variables", {
4557
4677
  instructions: `Everything related to V4 ( Atomic ) variables.
4558
4678
  # Global variables
4559
4679
  - Create/update/delete global variables
@@ -4561,7 +4681,7 @@ function init() {
4561
4681
  - Get details of a global variable
4562
4682
  `
4563
4683
  });
4564
- initMcp(variablesMcpRegistry, (0, import_editor_mcp.getMCPByDomain)("canvas"));
4684
+ initMcp(variablesMcpRegistry, (0, import_editor_mcp2.getMCPByDomain)("canvas"));
4565
4685
  });
4566
4686
  (0, import_editor.injectIntoTop)({
4567
4687
  id: "canvas-style-variables-render",