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