@elementor/editor-variables 4.1.0-802 → 4.1.0-804
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 +24 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- package/src/mcp/variables-resource.ts +30 -14
package/dist/index.mjs
CHANGED
|
@@ -3821,33 +3821,42 @@ var trackOpenVariablePopover = (path, variableType) => {
|
|
|
3821
3821
|
import { z as z3 } from "@elementor/schema";
|
|
3822
3822
|
|
|
3823
3823
|
// src/mcp/variables-resource.ts
|
|
3824
|
+
import { __privateListenTo as listenTo3, commandEndEvent } from "@elementor/editor-v1-adapters";
|
|
3824
3825
|
var GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
3826
|
+
var buildGlobalVariablesPayload = async () => {
|
|
3827
|
+
const merged = {};
|
|
3828
|
+
Object.entries(service.variables()).forEach(([id2, variable]) => {
|
|
3829
|
+
if (!variable.deleted) {
|
|
3830
|
+
merged[id2] = { ...variable, version: "v4" };
|
|
3831
|
+
}
|
|
3832
|
+
});
|
|
3833
|
+
return merged;
|
|
3834
|
+
};
|
|
3825
3835
|
var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
|
|
3826
3836
|
[canvasMcpEntry, variablesMcpEntry].forEach((entry) => {
|
|
3827
3837
|
const { resource, sendResourceUpdated } = entry;
|
|
3838
|
+
const notifyGlobalVariablesUpdated = () => {
|
|
3839
|
+
sendResourceUpdated({
|
|
3840
|
+
uri: GLOBAL_VARIABLES_URI
|
|
3841
|
+
});
|
|
3842
|
+
};
|
|
3828
3843
|
resource(
|
|
3829
3844
|
"global-variables",
|
|
3830
3845
|
GLOBAL_VARIABLES_URI,
|
|
3831
3846
|
{
|
|
3832
|
-
description: "
|
|
3847
|
+
description: "Global variables available (v4)"
|
|
3833
3848
|
},
|
|
3834
3849
|
async () => {
|
|
3835
|
-
const variables =
|
|
3836
|
-
Object.entries(service.variables()).forEach(([id2, variable]) => {
|
|
3837
|
-
if (!variable.deleted) {
|
|
3838
|
-
variables[id2] = variable;
|
|
3839
|
-
}
|
|
3840
|
-
});
|
|
3850
|
+
const variables = await buildGlobalVariablesPayload();
|
|
3841
3851
|
return {
|
|
3842
|
-
contents: [
|
|
3852
|
+
contents: [
|
|
3853
|
+
{ uri: GLOBAL_VARIABLES_URI, mimeType: "application/json", text: JSON.stringify(variables) }
|
|
3854
|
+
]
|
|
3843
3855
|
};
|
|
3844
3856
|
}
|
|
3845
3857
|
);
|
|
3846
|
-
window.addEventListener("variables:updated",
|
|
3847
|
-
|
|
3848
|
-
uri: GLOBAL_VARIABLES_URI
|
|
3849
|
-
});
|
|
3850
|
-
});
|
|
3858
|
+
window.addEventListener("variables:updated", notifyGlobalVariablesUpdated);
|
|
3859
|
+
listenTo3(commandEndEvent("document/save/update"), notifyGlobalVariablesUpdated);
|
|
3851
3860
|
});
|
|
3852
3861
|
};
|
|
3853
3862
|
|
|
@@ -4144,7 +4153,7 @@ import * as React38 from "react";
|
|
|
4144
4153
|
import { useEffect as useEffect9, useState as useState20 } from "react";
|
|
4145
4154
|
import {
|
|
4146
4155
|
__privateUseListenTo as useListenTo,
|
|
4147
|
-
commandEndEvent,
|
|
4156
|
+
commandEndEvent as commandEndEvent2,
|
|
4148
4157
|
getCanvasIframeDocument
|
|
4149
4158
|
} from "@elementor/editor-v1-adapters";
|
|
4150
4159
|
import { Portal } from "@elementor/ui";
|
|
@@ -4161,7 +4170,7 @@ function StyleVariablesRenderer() {
|
|
|
4161
4170
|
return /* @__PURE__ */ React38.createElement(Portal, { container }, /* @__PURE__ */ React38.createElement("style", { "data-e-style-id": "e-variables", key: wrappedCss }, wrappedCss));
|
|
4162
4171
|
}
|
|
4163
4172
|
function usePortalContainer() {
|
|
4164
|
-
return useListenTo(
|
|
4173
|
+
return useListenTo(commandEndEvent2("editor/documents/attach-preview"), () => getCanvasIframeDocument()?.head);
|
|
4165
4174
|
}
|
|
4166
4175
|
function useStyleVariables() {
|
|
4167
4176
|
const [variables, setVariables] = useState20({});
|