@elementor/editor-variables 3.35.0-340 → 3.35.0-342
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.d.mts +61 -2
- package/dist/index.d.ts +61 -2
- package/dist/index.js +76 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/index.ts +9 -1
- package/src/mcp/create-variable-tool.ts +1 -1
- package/src/mcp/delete-variable-tool.ts +1 -1
- package/src/mcp/index.ts +0 -6
- package/src/mcp/list-variables-tool.ts +2 -2
- package/src/mcp/update-variable-tool.ts +1 -1
- package/src/mcp/variables-resource.ts +14 -4
- package/src/service.ts +13 -1
- package/src/transformers/utils/resolve-css-variable.ts +4 -2
- package/src/transformers/variable-transformer.ts +6 -3
- package/src/utils/llm-propvalue-label-resolver.ts +25 -0
package/dist/index.mjs
CHANGED
|
@@ -434,6 +434,16 @@ var service = {
|
|
|
434
434
|
variables: () => {
|
|
435
435
|
return storage.load();
|
|
436
436
|
},
|
|
437
|
+
findIdByLabel(needle) {
|
|
438
|
+
const variableId = Object.entries(this.variables()).find(([, variable]) => variable.label === needle);
|
|
439
|
+
if (!variableId) {
|
|
440
|
+
throw new Error(`Variable with label ${needle} not found`);
|
|
441
|
+
}
|
|
442
|
+
return variableId[0];
|
|
443
|
+
},
|
|
444
|
+
findVariableByLabel(needle) {
|
|
445
|
+
return Object.values(this.variables()).find((variable) => variable.label === needle) || null;
|
|
446
|
+
},
|
|
437
447
|
getWatermark: () => {
|
|
438
448
|
return storage.state.watermark;
|
|
439
449
|
},
|
|
@@ -602,10 +612,11 @@ var resolveCssVariable = (id2, variable) => {
|
|
|
602
612
|
if (!name.trim()) {
|
|
603
613
|
return null;
|
|
604
614
|
}
|
|
615
|
+
const validCssVariableName = `--${name}`;
|
|
605
616
|
if (!fallbackValue.trim()) {
|
|
606
|
-
return `var(
|
|
617
|
+
return `var(${validCssVariableName})`;
|
|
607
618
|
}
|
|
608
|
-
return `var(
|
|
619
|
+
return `var(${validCssVariableName}, ${fallbackValue})`;
|
|
609
620
|
};
|
|
610
621
|
|
|
611
622
|
// src/transformers/inheritance-transformer.tsx
|
|
@@ -622,12 +633,14 @@ var inheritanceTransformer = createTransformer((id2) => {
|
|
|
622
633
|
|
|
623
634
|
// src/transformers/variable-transformer.ts
|
|
624
635
|
import { createTransformer as createTransformer2 } from "@elementor/editor-canvas";
|
|
625
|
-
var variableTransformer = createTransformer2((
|
|
636
|
+
var variableTransformer = createTransformer2((idOrLabel) => {
|
|
626
637
|
const variables = service.variables();
|
|
627
|
-
|
|
638
|
+
const targetVariable = variables[idOrLabel] || service.findVariableByLabel(idOrLabel);
|
|
639
|
+
if (!targetVariable) {
|
|
628
640
|
return null;
|
|
629
641
|
}
|
|
630
|
-
|
|
642
|
+
const id2 = service.findIdByLabel(targetVariable.label);
|
|
643
|
+
return resolveCssVariable(id2, targetVariable);
|
|
631
644
|
});
|
|
632
645
|
|
|
633
646
|
// src/variables-registry/create-variable-type-registry.ts
|
|
@@ -3291,9 +3304,6 @@ var trackOpenVariablePopover = (path, variableType) => {
|
|
|
3291
3304
|
});
|
|
3292
3305
|
};
|
|
3293
3306
|
|
|
3294
|
-
// src/mcp/index.ts
|
|
3295
|
-
import { getMCPByDomain as getMCPByDomain6 } from "@elementor/editor-mcp";
|
|
3296
|
-
|
|
3297
3307
|
// src/mcp/create-variable-tool.ts
|
|
3298
3308
|
import { getMCPByDomain } from "@elementor/editor-mcp";
|
|
3299
3309
|
import { z as z3 } from "@elementor/schema";
|
|
@@ -3307,7 +3317,7 @@ var OutputSchema = {
|
|
|
3307
3317
|
message: z3.string().optional().describe("Optional message providing additional information about the operation")
|
|
3308
3318
|
};
|
|
3309
3319
|
var initCreateVariableTool = () => {
|
|
3310
|
-
getMCPByDomain("
|
|
3320
|
+
getMCPByDomain("canvas").addTool({
|
|
3311
3321
|
name: "create-global-variable",
|
|
3312
3322
|
schema: InputSchema,
|
|
3313
3323
|
outputSchema: OutputSchema,
|
|
@@ -3363,7 +3373,7 @@ In that case, inform the user the type is unsupported and they should try anothe
|
|
|
3363
3373
|
import { getMCPByDomain as getMCPByDomain2 } from "@elementor/editor-mcp";
|
|
3364
3374
|
import { z as z4 } from "@elementor/schema";
|
|
3365
3375
|
var initDeleteVariableTool = () => {
|
|
3366
|
-
getMCPByDomain2("
|
|
3376
|
+
getMCPByDomain2("canvas").addTool({
|
|
3367
3377
|
name: "delete-global-variable",
|
|
3368
3378
|
schema: {
|
|
3369
3379
|
id: z4.string().describe("The unique identifier of the variable to be deleted.")
|
|
@@ -3407,76 +3417,23 @@ When a variable is deleted, all references to it in all pages accross the websit
|
|
|
3407
3417
|
});
|
|
3408
3418
|
};
|
|
3409
3419
|
|
|
3410
|
-
// src/mcp/
|
|
3420
|
+
// src/mcp/update-variable-tool.ts
|
|
3411
3421
|
import { getMCPByDomain as getMCPByDomain3 } from "@elementor/editor-mcp";
|
|
3412
3422
|
import { z as z5 } from "@elementor/schema";
|
|
3413
|
-
var VariableSchema = {
|
|
3414
|
-
type: z5.string().describe("The type of the variable."),
|
|
3415
|
-
label: z5.string().describe("The label of the variable, displayed to the user"),
|
|
3416
|
-
value: z5.string().describe("The value of the variable."),
|
|
3417
|
-
id: z5.string().describe(
|
|
3418
|
-
"The unique identifier of the variable. Used for internal reference, not to be exposed to end users"
|
|
3419
|
-
)
|
|
3420
|
-
};
|
|
3421
|
-
var VariableListSchema = {
|
|
3422
|
-
variables: z5.array(z5.object(VariableSchema)).describe("List of variables")
|
|
3423
|
-
};
|
|
3424
|
-
var initListVariablesTool = () => {
|
|
3425
|
-
getMCPByDomain3("variables").addTool({
|
|
3426
|
-
name: "list-global-variables",
|
|
3427
|
-
description: `List editor global variables
|
|
3428
|
-
|
|
3429
|
-
## When to use this tool:
|
|
3430
|
-
- When a user requests to see all available global variables in the Elementor editor.
|
|
3431
|
-
- When you need to be exact on a variable label, to avoid any mistakes.
|
|
3432
|
-
- When you want to see the most up-to-date list of global variables.
|
|
3433
|
-
- Before using any other variables related tools that makes changes, such as deletion, creation, or updates. This ensures you have the latest information and there is no naming collision or mismatching.
|
|
3434
|
-
|
|
3435
|
-
## Example tool response (JSON format):
|
|
3436
|
-
\`\`\`json
|
|
3437
|
-
{ variables: [
|
|
3438
|
-
{ type: 'global-color-variable', label: 'Cool', value: 'rgb(1,2,3)', id: 'some-unique-id' },
|
|
3439
|
-
{ type: 'global-font-variable', label: 'Headline', value: 'serif', id: 'some-other-unique-id' },
|
|
3440
|
-
] }
|
|
3441
|
-
\`\`\`
|
|
3442
|
-
|
|
3443
|
-
Once you get the response, please display the variables in a user-friendly way, unless explicitly requested otherwise.
|
|
3444
|
-
Unless explicitly requested otherwise, response in HTML Format, prefer to use tables or unordered lists.
|
|
3445
|
-
|
|
3446
|
-
Note: **The label is most improtant to be seen as-is without any changes.**
|
|
3447
|
-
|
|
3448
|
-
<important>
|
|
3449
|
-
**Do not omit the label**. This is important for the user to identify the variable.
|
|
3450
|
-
**Do not change the label**, it must be displayed exactly as it is, in it's original characters as received from this tool.
|
|
3451
|
-
</important>
|
|
3452
|
-
`,
|
|
3453
|
-
outputSchema: VariableListSchema,
|
|
3454
|
-
handler: async () => {
|
|
3455
|
-
const variables = service.variables();
|
|
3456
|
-
return {
|
|
3457
|
-
variables: Object.entries(variables).map(([id2, varData]) => ({ id: id2, ...varData }))
|
|
3458
|
-
};
|
|
3459
|
-
}
|
|
3460
|
-
});
|
|
3461
|
-
};
|
|
3462
|
-
|
|
3463
|
-
// src/mcp/update-variable-tool.ts
|
|
3464
|
-
import { getMCPByDomain as getMCPByDomain4 } from "@elementor/editor-mcp";
|
|
3465
|
-
import { z as z6 } from "@elementor/schema";
|
|
3466
3423
|
var initUpdateVariableTool = () => {
|
|
3467
|
-
|
|
3424
|
+
getMCPByDomain3("canvas").addTool({
|
|
3468
3425
|
schema: {
|
|
3469
|
-
id:
|
|
3470
|
-
label:
|
|
3426
|
+
id: z5.string().describe("The unique identifier of the variable to be updated or renamed."),
|
|
3427
|
+
label: z5.string().describe(
|
|
3471
3428
|
"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."
|
|
3472
3429
|
),
|
|
3473
|
-
value:
|
|
3430
|
+
value: z5.string().describe(
|
|
3474
3431
|
"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."
|
|
3475
3432
|
)
|
|
3476
3433
|
},
|
|
3477
3434
|
outputSchema: {
|
|
3478
|
-
status:
|
|
3479
|
-
message:
|
|
3435
|
+
status: z5.enum(["ok", "error"]).describe("The status of the operation"),
|
|
3436
|
+
message: z5.string().optional().describe("Optional message providing additional information about the operation")
|
|
3480
3437
|
},
|
|
3481
3438
|
name: "update-global-variable",
|
|
3482
3439
|
description: `Update an existing global variable
|
|
@@ -3534,19 +3491,25 @@ Failed update, which must be displayed to the end user. If the error message is
|
|
|
3534
3491
|
};
|
|
3535
3492
|
|
|
3536
3493
|
// src/mcp/variables-resource.ts
|
|
3537
|
-
import { getMCPByDomain as
|
|
3538
|
-
var GLOBAL_VARIABLES_URI = "elementor://variables";
|
|
3494
|
+
import { getMCPByDomain as getMCPByDomain4 } from "@elementor/editor-mcp";
|
|
3495
|
+
var GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
3539
3496
|
var initVariablesResource = () => {
|
|
3540
|
-
const { mcpServer } =
|
|
3497
|
+
const { mcpServer } = getMCPByDomain4("canvas");
|
|
3541
3498
|
mcpServer.resource(
|
|
3542
3499
|
"global-variables",
|
|
3543
3500
|
GLOBAL_VARIABLES_URI,
|
|
3544
3501
|
{
|
|
3545
|
-
description: "Global variables
|
|
3502
|
+
description: "List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)"
|
|
3546
3503
|
},
|
|
3547
3504
|
async () => {
|
|
3505
|
+
const variables = {};
|
|
3506
|
+
Object.entries(service.variables()).forEach(([id2, variable]) => {
|
|
3507
|
+
if (!variable.deleted) {
|
|
3508
|
+
variables[id2] = variable;
|
|
3509
|
+
}
|
|
3510
|
+
});
|
|
3548
3511
|
return {
|
|
3549
|
-
contents: [{ uri: GLOBAL_VARIABLES_URI, text:
|
|
3512
|
+
contents: [{ uri: GLOBAL_VARIABLES_URI, text: JSON.stringify(variables) }]
|
|
3550
3513
|
};
|
|
3551
3514
|
}
|
|
3552
3515
|
);
|
|
@@ -3560,9 +3523,6 @@ var initVariablesResource = () => {
|
|
|
3560
3523
|
|
|
3561
3524
|
// src/mcp/index.ts
|
|
3562
3525
|
function initMcp() {
|
|
3563
|
-
const { setMCPDescription } = getMCPByDomain6("variables");
|
|
3564
|
-
setMCPDescription(`Elementor Editor Variables MCP`);
|
|
3565
|
-
initListVariablesTool();
|
|
3566
3526
|
initCreateVariableTool();
|
|
3567
3527
|
initUpdateVariableTool();
|
|
3568
3528
|
initDeleteVariableTool();
|
|
@@ -3838,9 +3798,42 @@ function hasVariable(value) {
|
|
|
3838
3798
|
}
|
|
3839
3799
|
return false;
|
|
3840
3800
|
}
|
|
3801
|
+
|
|
3802
|
+
// src/utils/llm-propvalue-label-resolver.ts
|
|
3803
|
+
var globalVariablesLLMResolvers = {
|
|
3804
|
+
"global-color-variable": (value) => {
|
|
3805
|
+
const idOrLabel = String(value);
|
|
3806
|
+
return {
|
|
3807
|
+
$$type: "global-color-variable",
|
|
3808
|
+
value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
|
|
3809
|
+
};
|
|
3810
|
+
},
|
|
3811
|
+
"global-font-variable": (value) => {
|
|
3812
|
+
const idOrLabel = String(value);
|
|
3813
|
+
return {
|
|
3814
|
+
$$type: "global-font-variable",
|
|
3815
|
+
value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
|
|
3816
|
+
};
|
|
3817
|
+
},
|
|
3818
|
+
"global-size-variable": (value) => {
|
|
3819
|
+
const idOrLabel = String(value);
|
|
3820
|
+
return {
|
|
3821
|
+
$$type: "global-size-variable",
|
|
3822
|
+
value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
|
|
3823
|
+
};
|
|
3824
|
+
}
|
|
3825
|
+
};
|
|
3826
|
+
|
|
3827
|
+
// src/index.ts
|
|
3828
|
+
var Utils = {
|
|
3829
|
+
globalVariablesLLMResolvers
|
|
3830
|
+
};
|
|
3841
3831
|
export {
|
|
3832
|
+
GLOBAL_VARIABLES_URI,
|
|
3833
|
+
Utils,
|
|
3842
3834
|
init,
|
|
3843
3835
|
registerVariableType,
|
|
3844
|
-
registerVariableTypes
|
|
3836
|
+
registerVariableTypes,
|
|
3837
|
+
service
|
|
3845
3838
|
};
|
|
3846
3839
|
//# sourceMappingURL=index.mjs.map
|