@elementor/editor-variables 4.2.0-841 → 4.2.0-843

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
@@ -334,12 +334,13 @@ var buildOperationsArray = (originalVariables, currentVariables, deletedVariable
334
334
  // src/storage.ts
335
335
  var STORAGE_KEY = "elementor-global-variables";
336
336
  var STORAGE_WATERMARK_KEY = "elementor-global-variables-watermark";
337
+ var STORAGE_UPDATED_EVENT = "variables:updated";
337
338
  var OP_RW = "RW";
338
339
  var OP_RO = "RO";
339
340
  var Storage = class {
340
341
  state;
341
342
  notifyChange() {
342
- window.dispatchEvent(new Event("variables:updated"));
343
+ window.dispatchEvent(new Event(STORAGE_UPDATED_EVENT));
343
344
  }
344
345
  constructor() {
345
346
  this.state = {
@@ -1059,6 +1060,17 @@ var useVariablesManagerState = () => {
1059
1060
  const [isDirty, setIsDirty] = (0, import_react5.useState)(false);
1060
1061
  const [isSaving, setIsSaving] = (0, import_react5.useState)(false);
1061
1062
  const [searchValue, setSearchValue] = (0, import_react5.useState)("");
1063
+ (0, import_react5.useEffect)(() => {
1064
+ const handleStorageUpdated = () => {
1065
+ setVariables(getVariables(false));
1066
+ setDeletedVariables([]);
1067
+ setIsDirty(false);
1068
+ };
1069
+ window.addEventListener(STORAGE_UPDATED_EVENT, handleStorageUpdated);
1070
+ return () => {
1071
+ window.removeEventListener(STORAGE_UPDATED_EVENT, handleStorageUpdated);
1072
+ };
1073
+ }, []);
1062
1074
  const handleOnChange = (0, import_react5.useCallback)(
1063
1075
  (newVariables) => {
1064
1076
  setVariables({ ...variables, ...newVariables });
@@ -2412,14 +2424,7 @@ var import_react14 = require("react");
2412
2424
  var import_editor_canvas4 = require("@elementor/editor-canvas");
2413
2425
  function GlobalStylesImportListener() {
2414
2426
  (0, import_react14.useEffect)(() => {
2415
- const handleGlobalStylesImported = (event) => {
2416
- const importedVars = event.detail?.global_variables;
2417
- if (!importedVars) {
2418
- return;
2419
- }
2420
- if (importedVars.data && typeof importedVars.data === "object") {
2421
- styleVariablesRepository.update(importedVars.data);
2422
- }
2427
+ const handleGlobalStylesImported = () => {
2423
2428
  service.load();
2424
2429
  };
2425
2430
  window.addEventListener(import_editor_canvas4.GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
@@ -3956,7 +3961,7 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3956
3961
  };
3957
3962
  }
3958
3963
  );
3959
- window.addEventListener("variables:updated", notifyGlobalVariablesUpdated);
3964
+ window.addEventListener(STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated);
3960
3965
  (0, import_editor_v1_adapters6.__privateListenTo)((0, import_editor_v1_adapters6.commandEndEvent)("document/save/update"), notifyGlobalVariablesUpdated);
3961
3966
  });
3962
3967
  };
@@ -3971,7 +3976,9 @@ var initManageVariableTool = (reg) => {
3971
3976
  id: import_schema3.z.string().optional().describe("Variable id (required for update/delete). Get from list-global-variables."),
3972
3977
  type: import_schema3.z.string().optional().describe('Variable type: "global-color-variable" or "global-font-variable" (required for create)'),
3973
3978
  label: import_schema3.z.string().optional().describe("Variable label (required for create/update)"),
3974
- value: import_schema3.z.string().optional().describe("Variable value (required for create/update)")
3979
+ value: import_schema3.z.string().optional().describe(
3980
+ "The variable value (required for create/update). Provide a plain CSS value matching the variable type (font: family name; color: CSS color; size: value with unit). Never JSON."
3981
+ )
3975
3982
  },
3976
3983
  outputSchema: {
3977
3984
  status: import_schema3.z.enum(["ok"]).describe("Operation status"),
@@ -3987,14 +3994,11 @@ var initManageVariableTool = (reg) => {
3987
3994
  description: "Global variables"
3988
3995
  }
3989
3996
  ],
3990
- description: `Manages global variables (create/update/delete). Existing variables available in resources.
3991
- CREATE: requires type, label, value. Ensure label is unique.
3992
- UPDATE: requires id, label, value. When renaming: keep existing value. When updating value: keep exact label.
3993
- DELETE: requires id. DESTRUCTIVE - confirm with user first.
3994
-
3995
- # NAMING - IMPORTANT
3996
- the variables names should ALWAYS be lowercased and dashed spaced. example: "Headline Primary" should be "headline-primary"
3997
- `,
3997
+ description: `Create, update, or delete V4 global variables (distinct from legacy "globals").
3998
+ - Values: any valid CSS value, inserted as-is (1:1 with \`--css-var: VALUE\`). Do NOT pass JSON or legacy-globals object structures.
3999
+ - Names: lowercase, dash-separated (e.g. "Headline Primary" \u2192 "headline-primary").
4000
+ - Update: when renaming, keep the existing value; when updating value, keep the exact label.
4001
+ - Delete: destructive \u2014 confirm with user first.`,
3998
4002
  handler: async (params) => {
3999
4003
  const operations = getServiceActions(service);
4000
4004
  const op = operations[params.action];
@@ -4043,15 +4047,6 @@ function getServiceActions(svc) {
4043
4047
 
4044
4048
  // src/mcp/index.ts
4045
4049
  function initMcp(reg, canvasMcpEntry) {
4046
- const { setMCPDescription } = reg;
4047
- setMCPDescription(
4048
- `Everything related to V4 ( Atomic ) variables.
4049
- # Global variables
4050
- - Create/update/delete global variables
4051
- - Get list of global variables
4052
- - Get details of a global variable
4053
- `
4054
- );
4055
4050
  initManageVariableTool(reg);
4056
4051
  initVariablesResource(reg, canvasMcpEntry);
4057
4052
  }
@@ -4563,7 +4558,15 @@ function init() {
4563
4558
  useProps: usePropVariableAction
4564
4559
  });
4565
4560
  service.init().then(() => {
4566
- initMcp((0, import_editor_mcp.getMCPByDomain)("variables"), (0, import_editor_mcp.getMCPByDomain)("canvas"));
4561
+ const variablesMcpRegistry = (0, import_editor_mcp.getMCPByDomain)("variables", {
4562
+ instructions: `Everything related to V4 ( Atomic ) variables.
4563
+ # Global variables
4564
+ - Create/update/delete global variables
4565
+ - Get list of global variables
4566
+ - Get details of a global variable
4567
+ `
4568
+ });
4569
+ initMcp(variablesMcpRegistry, (0, import_editor_mcp.getMCPByDomain)("canvas"));
4567
4570
  });
4568
4571
  (0, import_editor.injectIntoTop)({
4569
4572
  id: "canvas-style-variables-render",