@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 CHANGED
@@ -6,6 +6,18 @@ import * as _mui_material from '@mui/material';
6
6
 
7
7
  declare function init(): void;
8
8
 
9
+ declare function registerVariableTypes(): void;
10
+
11
+ type TVariable = {
12
+ type: string;
13
+ label: string;
14
+ value: string;
15
+ order?: number;
16
+ deleted?: boolean;
17
+ deleted_at?: string;
18
+ };
19
+ type TVariablesList = Record<string, TVariable>;
20
+
9
21
  type Variable = {
10
22
  key?: string;
11
23
  label: string;
@@ -21,6 +33,36 @@ type NormalizedVariable = {
21
33
  order?: number;
22
34
  };
23
35
 
36
+ declare const service: {
37
+ variables: () => TVariablesList;
38
+ findIdByLabel(needle: string): string;
39
+ findVariableByLabel(needle: string): TVariable | null;
40
+ getWatermark: () => number;
41
+ init: () => Promise<any>;
42
+ load: () => Promise<any>;
43
+ create: ({ type, label, value }: Variable) => Promise<{
44
+ id: any;
45
+ variable: any;
46
+ }>;
47
+ update: (id: string, { label, value }: Omit<Variable, "type">) => Promise<{
48
+ id: any;
49
+ variable: any;
50
+ }>;
51
+ delete: (id: string) => Promise<{
52
+ id: any;
53
+ variable: any;
54
+ }>;
55
+ restore: (id: string, label?: string, value?: string) => Promise<{
56
+ id: any;
57
+ variable: any;
58
+ }>;
59
+ batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList) => Promise<{
60
+ success: boolean;
61
+ watermark: any;
62
+ operations: number;
63
+ }>;
64
+ };
65
+
24
66
  type ValueFieldProps = {
25
67
  value: string;
26
68
  onChange: (value: string) => void;
@@ -51,6 +93,23 @@ declare const registerVariableType: ({ key, icon, startIcon, valueField, propTyp
51
93
  isCompatible?: (propType: _elementor_editor_props.PropType, variable: Variable) => boolean;
52
94
  }) => void;
53
95
 
54
- declare function registerVariableTypes(): void;
96
+ declare const GLOBAL_VARIABLES_URI = "elementor://global-variables";
97
+
98
+ declare const Utils: {
99
+ readonly globalVariablesLLMResolvers: {
100
+ 'global-color-variable': (value: unknown) => {
101
+ $$type: string;
102
+ value: string;
103
+ };
104
+ 'global-font-variable': (value: unknown) => {
105
+ $$type: string;
106
+ value: string;
107
+ };
108
+ 'global-size-variable': (value: unknown) => {
109
+ $$type: string;
110
+ value: string;
111
+ };
112
+ };
113
+ };
55
114
 
56
- export { init, registerVariableType, registerVariableTypes };
115
+ export { GLOBAL_VARIABLES_URI, Utils, init, registerVariableType, registerVariableTypes, service };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,18 @@ import * as _mui_material from '@mui/material';
6
6
 
7
7
  declare function init(): void;
8
8
 
9
+ declare function registerVariableTypes(): void;
10
+
11
+ type TVariable = {
12
+ type: string;
13
+ label: string;
14
+ value: string;
15
+ order?: number;
16
+ deleted?: boolean;
17
+ deleted_at?: string;
18
+ };
19
+ type TVariablesList = Record<string, TVariable>;
20
+
9
21
  type Variable = {
10
22
  key?: string;
11
23
  label: string;
@@ -21,6 +33,36 @@ type NormalizedVariable = {
21
33
  order?: number;
22
34
  };
23
35
 
36
+ declare const service: {
37
+ variables: () => TVariablesList;
38
+ findIdByLabel(needle: string): string;
39
+ findVariableByLabel(needle: string): TVariable | null;
40
+ getWatermark: () => number;
41
+ init: () => Promise<any>;
42
+ load: () => Promise<any>;
43
+ create: ({ type, label, value }: Variable) => Promise<{
44
+ id: any;
45
+ variable: any;
46
+ }>;
47
+ update: (id: string, { label, value }: Omit<Variable, "type">) => Promise<{
48
+ id: any;
49
+ variable: any;
50
+ }>;
51
+ delete: (id: string) => Promise<{
52
+ id: any;
53
+ variable: any;
54
+ }>;
55
+ restore: (id: string, label?: string, value?: string) => Promise<{
56
+ id: any;
57
+ variable: any;
58
+ }>;
59
+ batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList) => Promise<{
60
+ success: boolean;
61
+ watermark: any;
62
+ operations: number;
63
+ }>;
64
+ };
65
+
24
66
  type ValueFieldProps = {
25
67
  value: string;
26
68
  onChange: (value: string) => void;
@@ -51,6 +93,23 @@ declare const registerVariableType: ({ key, icon, startIcon, valueField, propTyp
51
93
  isCompatible?: (propType: _elementor_editor_props.PropType, variable: Variable) => boolean;
52
94
  }) => void;
53
95
 
54
- declare function registerVariableTypes(): void;
96
+ declare const GLOBAL_VARIABLES_URI = "elementor://global-variables";
97
+
98
+ declare const Utils: {
99
+ readonly globalVariablesLLMResolvers: {
100
+ 'global-color-variable': (value: unknown) => {
101
+ $$type: string;
102
+ value: string;
103
+ };
104
+ 'global-font-variable': (value: unknown) => {
105
+ $$type: string;
106
+ value: string;
107
+ };
108
+ 'global-size-variable': (value: unknown) => {
109
+ $$type: string;
110
+ value: string;
111
+ };
112
+ };
113
+ };
55
114
 
56
- export { init, registerVariableType, registerVariableTypes };
115
+ export { GLOBAL_VARIABLES_URI, Utils, init, registerVariableType, registerVariableTypes, service };
package/dist/index.js CHANGED
@@ -30,9 +30,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ GLOBAL_VARIABLES_URI: () => GLOBAL_VARIABLES_URI,
34
+ Utils: () => Utils,
33
35
  init: () => init,
34
36
  registerVariableType: () => registerVariableType,
35
- registerVariableTypes: () => registerVariableTypes
37
+ registerVariableTypes: () => registerVariableTypes,
38
+ service: () => service
36
39
  });
37
40
  module.exports = __toCommonJS(index_exports);
38
41
 
@@ -455,6 +458,16 @@ var service = {
455
458
  variables: () => {
456
459
  return storage.load();
457
460
  },
461
+ findIdByLabel(needle) {
462
+ const variableId = Object.entries(this.variables()).find(([, variable]) => variable.label === needle);
463
+ if (!variableId) {
464
+ throw new Error(`Variable with label ${needle} not found`);
465
+ }
466
+ return variableId[0];
467
+ },
468
+ findVariableByLabel(needle) {
469
+ return Object.values(this.variables()).find((variable) => variable.label === needle) || null;
470
+ },
458
471
  getWatermark: () => {
459
472
  return storage.state.watermark;
460
473
  },
@@ -623,10 +636,11 @@ var resolveCssVariable = (id2, variable) => {
623
636
  if (!name.trim()) {
624
637
  return null;
625
638
  }
639
+ const validCssVariableName = `--${name}`;
626
640
  if (!fallbackValue.trim()) {
627
- return `var(--${name})`;
641
+ return `var(${validCssVariableName})`;
628
642
  }
629
- return `var(--${name}, ${fallbackValue})`;
643
+ return `var(${validCssVariableName}, ${fallbackValue})`;
630
644
  };
631
645
 
632
646
  // src/transformers/inheritance-transformer.tsx
@@ -643,12 +657,14 @@ var inheritanceTransformer = (0, import_editor_canvas.createTransformer)((id2) =
643
657
 
644
658
  // src/transformers/variable-transformer.ts
645
659
  var import_editor_canvas2 = require("@elementor/editor-canvas");
646
- var variableTransformer = (0, import_editor_canvas2.createTransformer)((id2) => {
660
+ var variableTransformer = (0, import_editor_canvas2.createTransformer)((idOrLabel) => {
647
661
  const variables = service.variables();
648
- if (!variables[id2]) {
662
+ const targetVariable = variables[idOrLabel] || service.findVariableByLabel(idOrLabel);
663
+ if (!targetVariable) {
649
664
  return null;
650
665
  }
651
- return resolveCssVariable(id2, variables[id2]);
666
+ const id2 = service.findIdByLabel(targetVariable.label);
667
+ return resolveCssVariable(id2, targetVariable);
652
668
  });
653
669
 
654
670
  // src/variables-registry/create-variable-type-registry.ts
@@ -3284,9 +3300,6 @@ var trackOpenVariablePopover = (path, variableType) => {
3284
3300
  });
3285
3301
  };
3286
3302
 
3287
- // src/mcp/index.ts
3288
- var import_editor_mcp6 = require("@elementor/editor-mcp");
3289
-
3290
3303
  // src/mcp/create-variable-tool.ts
3291
3304
  var import_editor_mcp = require("@elementor/editor-mcp");
3292
3305
  var import_schema3 = require("@elementor/schema");
@@ -3300,7 +3313,7 @@ var OutputSchema = {
3300
3313
  message: import_schema3.z.string().optional().describe("Optional message providing additional information about the operation")
3301
3314
  };
3302
3315
  var initCreateVariableTool = () => {
3303
- (0, import_editor_mcp.getMCPByDomain)("variables").addTool({
3316
+ (0, import_editor_mcp.getMCPByDomain)("canvas").addTool({
3304
3317
  name: "create-global-variable",
3305
3318
  schema: InputSchema,
3306
3319
  outputSchema: OutputSchema,
@@ -3356,7 +3369,7 @@ In that case, inform the user the type is unsupported and they should try anothe
3356
3369
  var import_editor_mcp2 = require("@elementor/editor-mcp");
3357
3370
  var import_schema4 = require("@elementor/schema");
3358
3371
  var initDeleteVariableTool = () => {
3359
- (0, import_editor_mcp2.getMCPByDomain)("variables").addTool({
3372
+ (0, import_editor_mcp2.getMCPByDomain)("canvas").addTool({
3360
3373
  name: "delete-global-variable",
3361
3374
  schema: {
3362
3375
  id: import_schema4.z.string().describe("The unique identifier of the variable to be deleted.")
@@ -3400,76 +3413,23 @@ When a variable is deleted, all references to it in all pages accross the websit
3400
3413
  });
3401
3414
  };
3402
3415
 
3403
- // src/mcp/list-variables-tool.ts
3416
+ // src/mcp/update-variable-tool.ts
3404
3417
  var import_editor_mcp3 = require("@elementor/editor-mcp");
3405
3418
  var import_schema5 = require("@elementor/schema");
3406
- var VariableSchema = {
3407
- type: import_schema5.z.string().describe("The type of the variable."),
3408
- label: import_schema5.z.string().describe("The label of the variable, displayed to the user"),
3409
- value: import_schema5.z.string().describe("The value of the variable."),
3410
- id: import_schema5.z.string().describe(
3411
- "The unique identifier of the variable. Used for internal reference, not to be exposed to end users"
3412
- )
3413
- };
3414
- var VariableListSchema = {
3415
- variables: import_schema5.z.array(import_schema5.z.object(VariableSchema)).describe("List of variables")
3416
- };
3417
- var initListVariablesTool = () => {
3418
- (0, import_editor_mcp3.getMCPByDomain)("variables").addTool({
3419
- name: "list-global-variables",
3420
- description: `List editor global variables
3421
-
3422
- ## When to use this tool:
3423
- - When a user requests to see all available global variables in the Elementor editor.
3424
- - When you need to be exact on a variable label, to avoid any mistakes.
3425
- - When you want to see the most up-to-date list of global variables.
3426
- - 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.
3427
-
3428
- ## Example tool response (JSON format):
3429
- \`\`\`json
3430
- { variables: [
3431
- { type: 'global-color-variable', label: 'Cool', value: 'rgb(1,2,3)', id: 'some-unique-id' },
3432
- { type: 'global-font-variable', label: 'Headline', value: 'serif', id: 'some-other-unique-id' },
3433
- ] }
3434
- \`\`\`
3435
-
3436
- Once you get the response, please display the variables in a user-friendly way, unless explicitly requested otherwise.
3437
- Unless explicitly requested otherwise, response in HTML Format, prefer to use tables or unordered lists.
3438
-
3439
- Note: **The label is most improtant to be seen as-is without any changes.**
3440
-
3441
- <important>
3442
- **Do not omit the label**. This is important for the user to identify the variable.
3443
- **Do not change the label**, it must be displayed exactly as it is, in it's original characters as received from this tool.
3444
- </important>
3445
- `,
3446
- outputSchema: VariableListSchema,
3447
- handler: async () => {
3448
- const variables = service.variables();
3449
- return {
3450
- variables: Object.entries(variables).map(([id2, varData]) => ({ id: id2, ...varData }))
3451
- };
3452
- }
3453
- });
3454
- };
3455
-
3456
- // src/mcp/update-variable-tool.ts
3457
- var import_editor_mcp4 = require("@elementor/editor-mcp");
3458
- var import_schema6 = require("@elementor/schema");
3459
3419
  var initUpdateVariableTool = () => {
3460
- (0, import_editor_mcp4.getMCPByDomain)("variables").addTool({
3420
+ (0, import_editor_mcp3.getMCPByDomain)("canvas").addTool({
3461
3421
  schema: {
3462
- id: import_schema6.z.string().describe("The unique identifier of the variable to be updated or renamed."),
3463
- label: import_schema6.z.string().describe(
3422
+ id: import_schema5.z.string().describe("The unique identifier of the variable to be updated or renamed."),
3423
+ label: import_schema5.z.string().describe(
3464
3424
  "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."
3465
3425
  ),
3466
- value: import_schema6.z.string().describe(
3426
+ value: import_schema5.z.string().describe(
3467
3427
  "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."
3468
3428
  )
3469
3429
  },
3470
3430
  outputSchema: {
3471
- status: import_schema6.z.enum(["ok", "error"]).describe("The status of the operation"),
3472
- message: import_schema6.z.string().optional().describe("Optional message providing additional information about the operation")
3431
+ status: import_schema5.z.enum(["ok", "error"]).describe("The status of the operation"),
3432
+ message: import_schema5.z.string().optional().describe("Optional message providing additional information about the operation")
3473
3433
  },
3474
3434
  name: "update-global-variable",
3475
3435
  description: `Update an existing global variable
@@ -3527,19 +3487,25 @@ Failed update, which must be displayed to the end user. If the error message is
3527
3487
  };
3528
3488
 
3529
3489
  // src/mcp/variables-resource.ts
3530
- var import_editor_mcp5 = require("@elementor/editor-mcp");
3531
- var GLOBAL_VARIABLES_URI = "elementor://variables";
3490
+ var import_editor_mcp4 = require("@elementor/editor-mcp");
3491
+ var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3532
3492
  var initVariablesResource = () => {
3533
- const { mcpServer } = (0, import_editor_mcp5.getMCPByDomain)("variables");
3493
+ const { mcpServer } = (0, import_editor_mcp4.getMCPByDomain)("canvas");
3534
3494
  mcpServer.resource(
3535
3495
  "global-variables",
3536
3496
  GLOBAL_VARIABLES_URI,
3537
3497
  {
3538
- description: "Global variables list. Variables are being used in this way: If it is directly in the schema, you need to put the ID which is the key inside the object."
3498
+ description: "List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)"
3539
3499
  },
3540
3500
  async () => {
3501
+ const variables = {};
3502
+ Object.entries(service.variables()).forEach(([id2, variable]) => {
3503
+ if (!variable.deleted) {
3504
+ variables[id2] = variable;
3505
+ }
3506
+ });
3541
3507
  return {
3542
- contents: [{ uri: GLOBAL_VARIABLES_URI, text: localStorage["elementor-global-variables"] }]
3508
+ contents: [{ uri: GLOBAL_VARIABLES_URI, text: JSON.stringify(variables) }]
3543
3509
  };
3544
3510
  }
3545
3511
  );
@@ -3553,9 +3519,6 @@ var initVariablesResource = () => {
3553
3519
 
3554
3520
  // src/mcp/index.ts
3555
3521
  function initMcp() {
3556
- const { setMCPDescription } = (0, import_editor_mcp6.getMCPByDomain)("variables");
3557
- setMCPDescription(`Elementor Editor Variables MCP`);
3558
- initListVariablesTool();
3559
3522
  initCreateVariableTool();
3560
3523
  initUpdateVariableTool();
3561
3524
  initDeleteVariableTool();
@@ -3831,10 +3794,43 @@ function hasVariable(value) {
3831
3794
  }
3832
3795
  return false;
3833
3796
  }
3797
+
3798
+ // src/utils/llm-propvalue-label-resolver.ts
3799
+ var globalVariablesLLMResolvers = {
3800
+ "global-color-variable": (value) => {
3801
+ const idOrLabel = String(value);
3802
+ return {
3803
+ $$type: "global-color-variable",
3804
+ value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3805
+ };
3806
+ },
3807
+ "global-font-variable": (value) => {
3808
+ const idOrLabel = String(value);
3809
+ return {
3810
+ $$type: "global-font-variable",
3811
+ value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3812
+ };
3813
+ },
3814
+ "global-size-variable": (value) => {
3815
+ const idOrLabel = String(value);
3816
+ return {
3817
+ $$type: "global-size-variable",
3818
+ value: service.variables()[idOrLabel] ? idOrLabel : service.findIdByLabel(idOrLabel)
3819
+ };
3820
+ }
3821
+ };
3822
+
3823
+ // src/index.ts
3824
+ var Utils = {
3825
+ globalVariablesLLMResolvers
3826
+ };
3834
3827
  // Annotate the CommonJS export names for ESM import in node:
3835
3828
  0 && (module.exports = {
3829
+ GLOBAL_VARIABLES_URI,
3830
+ Utils,
3836
3831
  init,
3837
3832
  registerVariableType,
3838
- registerVariableTypes
3833
+ registerVariableTypes,
3834
+ service
3839
3835
  });
3840
3836
  //# sourceMappingURL=index.js.map