@elementor/editor-variables 3.35.0-469 → 3.35.0-471

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
@@ -3425,240 +3425,119 @@ var trackOpenVariablePopover = (path, variableType) => {
3425
3425
  });
3426
3426
  };
3427
3427
 
3428
- // src/mcp/create-variable-tool.ts
3429
- var import_editor_mcp = require("@elementor/editor-mcp");
3428
+ // src/mcp/manage-variable-tool.ts
3429
+ var import_editor_mcp2 = require("@elementor/editor-mcp");
3430
3430
  var import_schema3 = require("@elementor/schema");
3431
- var InputSchema = {
3432
- type: import_schema3.z.string().describe('The type of the variable. Example values: "global-color-variable" or "global-font-variable".'),
3433
- label: import_schema3.z.string().describe("The label of the variable, displayed to the user"),
3434
- value: import_schema3.z.string().describe("The value of the variable, should correspond to the type")
3435
- };
3436
- var OutputSchema = {
3437
- status: import_schema3.z.enum(["ok", "error"]).describe("The status of the operation"),
3438
- message: import_schema3.z.string().optional().describe("Optional message providing additional information about the operation")
3439
- };
3440
- var initCreateVariableTool = () => {
3441
- (0, import_editor_mcp.getMCPByDomain)("canvas").addTool({
3442
- name: "create-global-variable",
3443
- schema: InputSchema,
3444
- outputSchema: OutputSchema,
3445
- modelPreferences: {
3446
- intelligencePriority: 0.7,
3447
- speedPriority: 0.7
3448
- },
3449
- description: `Create a new global variable
3450
- ## When to use this tool:
3451
- - When a user requests to create a new global variable in the Elementor editor.
3452
- - When you need to add a new variable to be used in the editor.
3453
-
3454
- ## Prequisites:
3455
- - Ensure you have the most up-to-date list of existing global variables to avoid label duplication. You can use the "list-global-variables" tool to fetch the current variables.
3456
- - Make sure when creating a new variable, the label is unique and not already in use.
3457
- - If the user does not provide a label, ask them to provide one before proceeding.
3458
- - If the user does not provide a type, ask them to provide one before proceeding.
3459
- - If the user does not provide a value, ask them to provide one before proceeding.
3460
-
3461
- ## Required parameters:
3462
- - type: The type of the variable. Possible values are 'global-color-variable' or 'global-font-variable'.
3463
- - label: The label of the variable, displayed to the user. Must be unique and not already in use.
3464
- - value: The value of the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif').
3465
-
3466
- ## Example tool call (JSON format):
3467
- \`\`\`json
3468
- { "type": "global-color-variable", "label": "My Cool Color", "value": "rgb(1,2,3)" }
3469
- \`\`\`
3470
-
3471
- ## Example tool response (JSON format):
3472
- \`\`\`json
3473
- { "status": "ok" }
3474
- \`\`\`
3475
-
3476
- ## Example to a failed tool response, which must be displayed to the end user. If the error message is not plain, attempt to find the most useful part of the message and display it.
3477
- { "status": "error", "message": "Unsupported type 'global-kuku-variable'" }
3478
-
3479
- In that case, inform the user the type is unsupported and they should try another type, perhaps consult to online documentation.
3480
- `,
3481
- handler: async (params) => {
3482
- const { type, label, value } = params;
3483
- try {
3484
- await service.create({ type, label, value });
3485
- } catch (error) {
3486
- const message = error.message || "Unknown server error";
3487
- return {
3488
- status: "error",
3489
- message: `There was an error creating the variable: ${message}`
3490
- };
3491
- }
3492
- return { status: "ok" };
3493
- }
3494
- });
3495
- };
3496
3431
 
3497
- // src/mcp/delete-variable-tool.ts
3498
- var import_editor_mcp2 = require("@elementor/editor-mcp");
3499
- var import_schema4 = require("@elementor/schema");
3500
- var initDeleteVariableTool = () => {
3501
- (0, import_editor_mcp2.getMCPByDomain)("canvas").addTool({
3502
- name: "delete-global-variable",
3503
- schema: {
3504
- id: import_schema4.z.string().describe("The unique identifier of the variable to be deleted.")
3505
- },
3506
- outputSchema: {
3507
- status: import_schema4.z.enum(["ok", "error"]).describe("The status of the operation")
3508
- },
3509
- modelPreferences: {
3510
- intelligencePriority: 0.7,
3511
- speedPriority: 0.8
3512
- },
3513
- description: `Delete an existing global variable
3514
-
3515
- ## When to use this tool:
3516
- - When a user requests to delete an existing global variable in the Elementor editor.
3517
- - When you need to remove a variable that is no longer needed or relevant, with the user's confirmation.
3518
-
3519
- ## Prerequisites:
3520
- - Ensure you have the most up-to-date list of existing global variables. You can use the "list-global-variables" tool to fetch the current variables.
3521
- - Reference the variable by the "id" property, given from the "list-global-variables" tool.
3522
- - Make sure you have the unique identifier of the variable to be deleted before using this tool.
3523
- - Confirm with the user that they want to proceed with the deletion, as this action is irreversible.
3524
-
3525
- <notice>
3526
- A use might reference a variable by it's label, but you must always use the unique identifier (id) to delete it.
3527
- If you only have the label, use the "list-global-variables" tool to find the corresponding id.
3528
- </notice>
3529
-
3530
- <important>
3531
- This operation is destructive and cannot be undone. Ensure that the user is fully aware of the consequences before proceeding.
3532
- When a variable is deleted, all references to it in all pages accross the website will lose their effect.
3533
- </important>`,
3534
- handler: async (params) => {
3535
- const { id: id2 } = params;
3536
- try {
3537
- await service.delete(id2);
3538
- return { status: "ok" };
3539
- } catch (err) {
3432
+ // src/mcp/variables-resource.ts
3433
+ var import_editor_mcp = require("@elementor/editor-mcp");
3434
+ var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3435
+ var initVariablesResource = () => {
3436
+ const canvasMcpEntry = (0, import_editor_mcp.getMCPByDomain)("canvas");
3437
+ const variablesMcpEntry = (0, import_editor_mcp.getMCPByDomain)("variables");
3438
+ [canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
3439
+ const { mcpServer } = entry;
3440
+ mcpServer.resource(
3441
+ "global-variables",
3442
+ GLOBAL_VARIABLES_URI,
3443
+ {
3444
+ description: "List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)"
3445
+ },
3446
+ async () => {
3447
+ const variables = {};
3448
+ Object.entries(service.variables()).forEach(([id2, variable]) => {
3449
+ if (!variable.deleted) {
3450
+ variables[id2] = variable;
3451
+ }
3452
+ });
3540
3453
  return {
3541
- status: "error"
3454
+ contents: [{ uri: GLOBAL_VARIABLES_URI, text: JSON.stringify(variables) }]
3542
3455
  };
3543
3456
  }
3544
- },
3545
- isDestrcutive: true
3457
+ );
3458
+ window.addEventListener("variables:updated", () => {
3459
+ mcpServer.server.sendResourceUpdated({
3460
+ uri: GLOBAL_VARIABLES_URI,
3461
+ contents: [{ uri: GLOBAL_VARIABLES_URI, text: localStorage["elementor-global-variables"] }]
3462
+ });
3463
+ });
3546
3464
  });
3547
3465
  };
3548
3466
 
3549
- // src/mcp/update-variable-tool.ts
3550
- var import_editor_mcp3 = require("@elementor/editor-mcp");
3551
- var import_schema5 = require("@elementor/schema");
3552
- var initUpdateVariableTool = () => {
3553
- (0, import_editor_mcp3.getMCPByDomain)("canvas").addTool({
3467
+ // src/mcp/manage-variable-tool.ts
3468
+ var initManageVariableTool = () => {
3469
+ (0, import_editor_mcp2.getMCPByDomain)("variables").addTool({
3470
+ name: "manage-global-variable",
3554
3471
  schema: {
3555
- id: import_schema5.z.string().describe("The unique identifier of the variable to be updated or renamed."),
3556
- label: import_schema5.z.string().describe(
3557
- "The label of the variable to be stored after the change. If the user only wishes to update the value, this must be strictly equal to the current label."
3558
- ),
3559
- value: import_schema5.z.string().describe(
3560
- "The new value for the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif'). If the user wishes to rename only, make sure you provide the existing value."
3561
- )
3472
+ action: import_schema3.z.enum(["create", "update", "delete"]).describe("Operation to perform"),
3473
+ id: import_schema3.z.string().optional().describe("Variable id (required for update/delete). Get from list-global-variables."),
3474
+ type: import_schema3.z.string().optional().describe('Variable type: "global-color-variable" or "global-font-variable" (required for create)'),
3475
+ label: import_schema3.z.string().optional().describe("Variable label (required for create/update)"),
3476
+ value: import_schema3.z.string().optional().describe("Variable value (required for create/update)")
3562
3477
  },
3563
3478
  outputSchema: {
3564
- status: import_schema5.z.enum(["ok", "error"]).describe("The status of the operation"),
3565
- message: import_schema5.z.string().optional().describe("Optional message providing additional information about the operation")
3479
+ status: import_schema3.z.enum(["ok"]).describe("Operation status"),
3480
+ message: import_schema3.z.string().optional().describe("Error details if status is error")
3566
3481
  },
3567
- name: "update-global-variable",
3568
3482
  modelPreferences: {
3569
3483
  intelligencePriority: 0.75,
3570
- speedPriority: 0.7
3484
+ speedPriority: 0.75
3571
3485
  },
3572
- description: `Update an existing global variable
3573
-
3574
- ## When to use this tool:
3575
- - When a user requests to update an existing global variable in the Elementor editor.
3576
- - When you need to modify the value of an existing variable.
3577
- - When you want to rename an existing variable (change its label).
3578
- - When you want to both rename and modify the value of an existing variable.
3579
-
3580
- ## Prerequisites:
3581
- - Ensure you have the most up-to-date list of existing global variables to avoid label duplication. You can use the "list-global-variables" tool to fetch the current variables.
3582
- - Make sure when updating a variable, the new label is unique and not already in use by another variable.
3583
- - Make sure you understand whether you are updating a value, renaming, or both.
3584
- - Reference the variable by the "id" property, given from the "list-global-variables" tool.
3585
- - If the user wishes to rename, make sure you have the existing value.
3586
- - If the user wishes to update the value, make sure you have to **correct label**.
3587
- - You must have the unique identifier, the current label, the current value, and the new value or label or both, before using this tool.
3588
-
3589
- ## Required parameters:
3590
- - id: The unique identifier of the variable to be updated or renamed.
3591
- - label: The label of the variable to be stored after the change. If the user only wishes to update the value, this must be strictly equal to the current label.
3592
- - value: The new value for the variable. For color variables, this should be a valid CSS color (e.g., 'rgb(255,0,0)', '#ff0000', 'red'). For font variables, this should be a valid font family (e.g., 'Arial', 'serif'). If the user wishes to rename only, make sure you provide the existing value.
3593
-
3594
- ## Example tool call (JSON format):
3595
- \`\`\`json
3596
- { "id": "some-unique-id", "label": "Cool", "value": "rgb(0,140,250)" }
3597
- \`\`\`
3598
-
3599
- ## Example responses (JSON format):
3600
- Successful update:
3601
- \`\`\`json
3602
- { "status": "ok" }
3603
- \`\`\`
3604
-
3605
- Failed update, which must be displayed to the end user. If the error message is not plain, attempt to find the most useful part of the message and display it.
3606
- \`\`\`json
3607
- { "status": "error", "message": "Label 'Cool' is already in use by another variable." }
3608
- \`\`\`
3486
+ requiredResources: [
3487
+ {
3488
+ uri: GLOBAL_VARIABLES_URI,
3489
+ description: "Global variables"
3490
+ }
3491
+ ],
3492
+ description: `Manages global variables (create/update/delete). Existing variables available in resources.
3493
+ CREATE: requires type, label, value. Ensure label is unique.
3494
+ UPDATE: requires id, label, value. When renaming: keep existing value. When updating value: keep exact label.
3495
+ DELETE: requires id. DESTRUCTIVE - confirm with user first.
3496
+
3497
+ # NAMING - IMPORTANT
3498
+ the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
3609
3499
  `,
3610
3500
  handler: async (params) => {
3611
- const { id: id2, label, value } = params;
3612
- try {
3613
- await service.update(id2, { label, value });
3614
- return { status: "ok" };
3615
- } catch (error) {
3616
- const message = error.message || "Unknown server error";
3501
+ const operations = getServiceActions(service);
3502
+ const op = operations[params.action];
3503
+ if (op) {
3504
+ await op(params);
3617
3505
  return {
3618
- status: "error",
3619
- message: `There was an error creating the variable: ${message}`
3506
+ status: "ok"
3620
3507
  };
3621
3508
  }
3622
- }
3509
+ throw new Error(`Unknown action ${params.action}`);
3510
+ },
3511
+ isDestructive: true
3512
+ // Because delete is destructive
3623
3513
  });
3624
3514
  };
3625
-
3626
- // src/mcp/variables-resource.ts
3627
- var import_editor_mcp4 = require("@elementor/editor-mcp");
3628
- var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3629
- var initVariablesResource = () => {
3630
- const { mcpServer } = (0, import_editor_mcp4.getMCPByDomain)("canvas");
3631
- mcpServer.resource(
3632
- "global-variables",
3633
- GLOBAL_VARIABLES_URI,
3634
- {
3635
- description: "List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)"
3515
+ function getServiceActions(svc) {
3516
+ return {
3517
+ create({ type, label, value }) {
3518
+ if (!type || !label || !value) {
3519
+ throw new Error("Create requires type, label, and value");
3520
+ }
3521
+ return svc.create({ type, label, value });
3636
3522
  },
3637
- async () => {
3638
- const variables = {};
3639
- Object.entries(service.variables()).forEach(([id2, variable]) => {
3640
- if (!variable.deleted) {
3641
- variables[id2] = variable;
3642
- }
3643
- });
3644
- return {
3645
- contents: [{ uri: GLOBAL_VARIABLES_URI, text: JSON.stringify(variables) }]
3646
- };
3523
+ update({ id: id2, label, value }) {
3524
+ if (!id2 || !label || !value) {
3525
+ throw new Error("Update requires id, label, and value");
3526
+ }
3527
+ return svc.update(id2, { label, value });
3528
+ },
3529
+ delete({ id: id2 }) {
3530
+ if (!id2) {
3531
+ throw new Error("delete requires id");
3532
+ }
3533
+ return svc.delete(id2);
3647
3534
  }
3648
- );
3649
- window.addEventListener("variables:updated", () => {
3650
- mcpServer.server.sendResourceUpdated({
3651
- uri: GLOBAL_VARIABLES_URI,
3652
- contents: [{ uri: GLOBAL_VARIABLES_URI, text: localStorage["elementor-global-variables"] }]
3653
- });
3654
- });
3655
- };
3535
+ };
3536
+ }
3656
3537
 
3657
3538
  // src/mcp/index.ts
3658
3539
  function initMcp() {
3659
- initCreateVariableTool();
3660
- initUpdateVariableTool();
3661
- initDeleteVariableTool();
3540
+ initManageVariableTool();
3662
3541
  initVariablesResource();
3663
3542
  }
3664
3543
 
@@ -3784,8 +3663,8 @@ var FontField = ({ value, onChange, onValidationChange }) => {
3784
3663
 
3785
3664
  // src/prop-types/size-variable-prop-type.ts
3786
3665
  var import_editor_props4 = require("@elementor/editor-props");
3787
- var import_schema6 = require("@elementor/schema");
3788
- var sizeVariablePropTypeUtil = (0, import_editor_props4.createPropUtils)("global-size-variable", import_schema6.z.string());
3666
+ var import_schema4 = require("@elementor/schema");
3667
+ var sizeVariablePropTypeUtil = (0, import_editor_props4.createPropUtils)("global-size-variable", import_schema4.z.string());
3789
3668
 
3790
3669
  // src/transformers/empty-transformer.tsx
3791
3670
  var import_editor_canvas4 = require("@elementor/editor-canvas");
@@ -3963,28 +3842,17 @@ function hasVariableAssigned(value) {
3963
3842
  }
3964
3843
 
3965
3844
  // src/utils/llm-propvalue-label-resolver.ts
3845
+ var defaultResolver = (key) => (value) => {
3846
+ const idOrLabel = String(value);
3847
+ return {
3848
+ $$type: key,
3849
+ value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3850
+ };
3851
+ };
3966
3852
  var globalVariablesLLMResolvers = {
3967
- "global-color-variable": (value) => {
3968
- const idOrLabel = String(value);
3969
- return {
3970
- $$type: "global-color-variable",
3971
- value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3972
- };
3973
- },
3974
- "global-font-variable": (value) => {
3975
- const idOrLabel = String(value);
3976
- return {
3977
- $$type: "global-font-variable",
3978
- value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3979
- };
3980
- },
3981
- "global-size-variable": (value) => {
3982
- const idOrLabel = String(value);
3983
- return {
3984
- $$type: "global-size-variable",
3985
- value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3986
- };
3987
- }
3853
+ "global-color-variable": defaultResolver("global-color-variable"),
3854
+ "global-font-variable": defaultResolver("global-font-variable"),
3855
+ "global-size-variable": defaultResolver("global-size-variable")
3988
3856
  };
3989
3857
 
3990
3858
  // src/index.ts