@elementor/editor-variables 3.35.0-470 → 3.35.0-472

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