@elementor/editor-variables 4.1.0-802 → 4.1.0-803

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
@@ -3818,33 +3818,42 @@ var trackOpenVariablePopover = (path, variableType) => {
3818
3818
  var import_schema3 = require("@elementor/schema");
3819
3819
 
3820
3820
  // src/mcp/variables-resource.ts
3821
+ var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
3821
3822
  var GLOBAL_VARIABLES_URI = "elementor://global-variables";
3823
+ var buildGlobalVariablesPayload = async () => {
3824
+ const merged = {};
3825
+ Object.entries(service.variables()).forEach(([id2, variable]) => {
3826
+ if (!variable.deleted) {
3827
+ merged[id2] = { ...variable, version: "v4" };
3828
+ }
3829
+ });
3830
+ return merged;
3831
+ };
3822
3832
  var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
3823
3833
  [canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
3824
3834
  const { resource, sendResourceUpdated } = entry;
3835
+ const notifyGlobalVariablesUpdated = () => {
3836
+ sendResourceUpdated({
3837
+ uri: GLOBAL_VARIABLES_URI
3838
+ });
3839
+ };
3825
3840
  resource(
3826
3841
  "global-variables",
3827
3842
  GLOBAL_VARIABLES_URI,
3828
3843
  {
3829
- description: "List of Global variables. Defined as a key-value store (ID as key, global-variable object as value)"
3844
+ description: "Global variables available (v4)"
3830
3845
  },
3831
3846
  async () => {
3832
- const variables = {};
3833
- Object.entries(service.variables()).forEach(([id2, variable]) => {
3834
- if (!variable.deleted) {
3835
- variables[id2] = variable;
3836
- }
3837
- });
3847
+ const variables = await buildGlobalVariablesPayload();
3838
3848
  return {
3839
- contents: [{ uri: GLOBAL_VARIABLES_URI, text: JSON.stringify(variables) }]
3849
+ contents: [
3850
+ { uri: GLOBAL_VARIABLES_URI, mimeType: "application/json", text: JSON.stringify(variables) }
3851
+ ]
3840
3852
  };
3841
3853
  }
3842
3854
  );
3843
- window.addEventListener("variables:updated", () => {
3844
- sendResourceUpdated({
3845
- uri: GLOBAL_VARIABLES_URI
3846
- });
3847
- });
3855
+ window.addEventListener("variables:updated", notifyGlobalVariablesUpdated);
3856
+ (0, import_editor_v1_adapters6.__privateListenTo)((0, import_editor_v1_adapters6.commandEndEvent)("document/save/update"), notifyGlobalVariablesUpdated);
3848
3857
  });
3849
3858
  };
3850
3859
 
@@ -4139,7 +4148,7 @@ function registerVariableTypes() {
4139
4148
  // src/renderers/style-variables-renderer.tsx
4140
4149
  var React38 = __toESM(require("react"));
4141
4150
  var import_react30 = require("react");
4142
- var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
4151
+ var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
4143
4152
  var import_ui35 = require("@elementor/ui");
4144
4153
  var VARIABLES_WRAPPER = ":root";
4145
4154
  function StyleVariablesRenderer() {
@@ -4154,7 +4163,7 @@ function StyleVariablesRenderer() {
4154
4163
  return /* @__PURE__ */ React38.createElement(import_ui35.Portal, { container }, /* @__PURE__ */ React38.createElement("style", { "data-e-style-id": "e-variables", key: wrappedCss }, wrappedCss));
4155
4164
  }
4156
4165
  function usePortalContainer() {
4157
- return (0, import_editor_v1_adapters6.__privateUseListenTo)((0, import_editor_v1_adapters6.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_v1_adapters6.getCanvasIframeDocument)()?.head);
4166
+ return (0, import_editor_v1_adapters7.__privateUseListenTo)((0, import_editor_v1_adapters7.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_v1_adapters7.getCanvasIframeDocument)()?.head);
4158
4167
  }
4159
4168
  function useStyleVariables() {
4160
4169
  const [variables, setVariables] = (0, import_react30.useState)({});