@elementor/editor-variables 4.4.0 → 4.4.1
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 +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +143 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +137 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -15
- package/src/components/variable-creation.tsx +9 -1
- package/src/components/variable-edit.tsx +9 -1
- package/src/components/variable-form-header-location.tsx +13 -0
- package/src/components/variables-manager/variables-manager-panel.tsx +3 -1
- package/src/components/variables-manager-header-location.tsx +7 -0
- package/src/index.ts +2 -0
- package/src/mcp/manage-variable-tool.ts +43 -10
- package/src/mcp/pending-variable-changes.ts +93 -0
- package/src/service.ts +15 -22
package/dist/index.mjs
CHANGED
|
@@ -569,8 +569,18 @@ var service = {
|
|
|
569
569
|
};
|
|
570
570
|
});
|
|
571
571
|
},
|
|
572
|
+
applyLocalChange: (id, variable, isNew) => {
|
|
573
|
+
if (isNew) {
|
|
574
|
+
storage.add(id, variable);
|
|
575
|
+
} else {
|
|
576
|
+
storage.update(id, variable);
|
|
577
|
+
}
|
|
578
|
+
styleVariablesRepository.update({ [id]: variable });
|
|
579
|
+
},
|
|
572
580
|
batchSave: (originalVariables, currentVariables, deletedVariables) => {
|
|
573
|
-
|
|
581
|
+
return service.saveOperations(buildOperationsArray(originalVariables, currentVariables, deletedVariables));
|
|
582
|
+
},
|
|
583
|
+
saveOperations: (operations) => {
|
|
574
584
|
const batchPayload = { operations, watermark: storage.state.watermark };
|
|
575
585
|
if (operations.length === 0) {
|
|
576
586
|
return Promise.resolve({
|
|
@@ -617,18 +627,6 @@ var handleWatermark = (operation, newWatermark) => {
|
|
|
617
627
|
}
|
|
618
628
|
storage.watermark(newWatermark);
|
|
619
629
|
};
|
|
620
|
-
var applyLocalMutation = (action, variableWithId, watermark) => {
|
|
621
|
-
const { id: variableId, ...variable } = variableWithId;
|
|
622
|
-
handleWatermark(OP_RW, watermark);
|
|
623
|
-
if (action === "create") {
|
|
624
|
-
storage.add(variableId, variable);
|
|
625
|
-
} else {
|
|
626
|
-
storage.update(variableId, variable);
|
|
627
|
-
}
|
|
628
|
-
styleVariablesRepository.update({
|
|
629
|
-
[variableId]: variable
|
|
630
|
-
});
|
|
631
|
-
};
|
|
632
630
|
|
|
633
631
|
// src/transformers/utils/resolve-css-variable.ts
|
|
634
632
|
var resolveCssVariable = (id, variable) => {
|
|
@@ -835,6 +833,14 @@ var NoSearchResults = ({ searchValue, onClear, icon }) => {
|
|
|
835
833
|
);
|
|
836
834
|
};
|
|
837
835
|
|
|
836
|
+
// src/components/variables-manager-header-location.tsx
|
|
837
|
+
import { createLocation } from "@elementor/locations";
|
|
838
|
+
var {
|
|
839
|
+
Slot: VariablesManagerHeaderSlot,
|
|
840
|
+
inject: injectIntoVariablesManagerHeader,
|
|
841
|
+
useInjections: useVariablesManagerHeaderInjections
|
|
842
|
+
} = createLocation();
|
|
843
|
+
|
|
838
844
|
// src/components/variables-manager/hooks/use-auto-edit.ts
|
|
839
845
|
import { useCallback, useState } from "react";
|
|
840
846
|
var useAutoEdit = () => {
|
|
@@ -2172,7 +2178,7 @@ function VariablesManagerPanelContent({ onRequestClose, onExposeCloseAttempt })
|
|
|
2172
2178
|
}
|
|
2173
2179
|
}
|
|
2174
2180
|
),
|
|
2175
|
-
/* @__PURE__ */ React14.createElement(Box2, { sx: { display: "flex", flexShrink: 0, alignItems: "center" } }, /* @__PURE__ */ React14.createElement(
|
|
2181
|
+
/* @__PURE__ */ React14.createElement(Box2, { sx: { display: "flex", flexShrink: 0, alignItems: "center", gap: 0.5 } }, /* @__PURE__ */ React14.createElement(VariablesManagerHeaderSlot, null), /* @__PURE__ */ React14.createElement(
|
|
2176
2182
|
VariableManagerCreateMenu,
|
|
2177
2183
|
{
|
|
2178
2184
|
outlinedTrigger: true,
|
|
@@ -2540,10 +2546,18 @@ var FormField = ({ id, label, errorMsg, noticeMsg, children }) => {
|
|
|
2540
2546
|
return /* @__PURE__ */ React16.createElement(Grid, { container: true, gap: 0.75, alignItems: "center" }, /* @__PURE__ */ React16.createElement(Grid, { item: true, xs: 12 }, /* @__PURE__ */ React16.createElement(FormLabel, { htmlFor: id, size: "tiny" }, label)), /* @__PURE__ */ React16.createElement(Grid, { item: true, xs: 12 }, children, errorMsg && /* @__PURE__ */ React16.createElement(FormHelperText, { error: true }, errorMsg), noticeMsg && /* @__PURE__ */ React16.createElement(FormHelperText, null, noticeMsg)));
|
|
2541
2547
|
};
|
|
2542
2548
|
|
|
2549
|
+
// src/components/variable-form-header-location.tsx
|
|
2550
|
+
import { createLocation as createLocation2 } from "@elementor/locations";
|
|
2551
|
+
var {
|
|
2552
|
+
Slot: VariableFormHeaderSlot,
|
|
2553
|
+
inject: injectIntoVariableFormHeader,
|
|
2554
|
+
useInjections: useVariableFormHeaderInjections
|
|
2555
|
+
} = createLocation2();
|
|
2556
|
+
|
|
2543
2557
|
// src/components/variable-creation.tsx
|
|
2544
2558
|
var SIZE2 = "tiny";
|
|
2545
2559
|
var VariableCreation = ({ onGoBack, onClose }) => {
|
|
2546
|
-
const { icon: VariableIcon, valueField: ValueField, propTypeUtil } = useVariableType();
|
|
2560
|
+
const { icon: VariableIcon, valueField: ValueField, propTypeUtil, variableType } = useVariableType();
|
|
2547
2561
|
const { setVariableValue: setVariable, path } = useVariableBoundProp();
|
|
2548
2562
|
const { propType } = useBoundProp4();
|
|
2549
2563
|
const initialValue = useInitialValue();
|
|
@@ -2611,7 +2625,17 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2611
2625
|
{
|
|
2612
2626
|
icon: /* @__PURE__ */ React17.createElement(React17.Fragment, null, onGoBack && /* @__PURE__ */ React17.createElement(IconButton4, { size: SIZE2, "aria-label": __11("Go Back", "elementor"), onClick: onGoBack }, /* @__PURE__ */ React17.createElement(ArrowLeftIcon, { fontSize: SIZE2 })), /* @__PURE__ */ React17.createElement(VariableIcon, { fontSize: SIZE2 })),
|
|
2613
2627
|
title: __11("Create variable", "elementor"),
|
|
2614
|
-
onClose: closePopover
|
|
2628
|
+
onClose: closePopover,
|
|
2629
|
+
actions: [
|
|
2630
|
+
/* @__PURE__ */ React17.createElement(
|
|
2631
|
+
VariableFormHeaderSlot,
|
|
2632
|
+
{
|
|
2633
|
+
key: "variable-form-header",
|
|
2634
|
+
variableType,
|
|
2635
|
+
label: label || void 0
|
|
2636
|
+
}
|
|
2637
|
+
)
|
|
2638
|
+
]
|
|
2615
2639
|
}
|
|
2616
2640
|
), /* @__PURE__ */ React17.createElement(Divider2, null), /* @__PURE__ */ React17.createElement(PopoverContent, { p: 2 }, /* @__PURE__ */ React17.createElement(
|
|
2617
2641
|
FormField,
|
|
@@ -2806,7 +2830,17 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2806
2830
|
const closeEditDialog = () => () => {
|
|
2807
2831
|
setEditConfirmation(false);
|
|
2808
2832
|
};
|
|
2809
|
-
const actions = [
|
|
2833
|
+
const actions = [
|
|
2834
|
+
/* @__PURE__ */ React19.createElement(
|
|
2835
|
+
VariableFormHeaderSlot,
|
|
2836
|
+
{
|
|
2837
|
+
key: "variable-form-header",
|
|
2838
|
+
variableType,
|
|
2839
|
+
variableId: editId,
|
|
2840
|
+
label
|
|
2841
|
+
}
|
|
2842
|
+
)
|
|
2843
|
+
];
|
|
2810
2844
|
if (userPermissions.canDelete()) {
|
|
2811
2845
|
actions.push(
|
|
2812
2846
|
/* @__PURE__ */ React19.createElement(Tooltip, { key: "delete", placement: "top", title: DELETE_LABEL }, /* @__PURE__ */ React19.createElement(IconButton5, { size: SIZE3, onClick: handleDeleteConfirmation, "aria-label": DELETE_LABEL }, /* @__PURE__ */ React19.createElement(TrashIcon2, { fontSize: SIZE3 })))
|
|
@@ -3878,6 +3912,67 @@ import { httpService as httpService3 } from "@elementor/http-client";
|
|
|
3878
3912
|
import { z as z3 } from "@elementor/schema";
|
|
3879
3913
|
import { isProActive } from "@elementor/utils";
|
|
3880
3914
|
|
|
3915
|
+
// src/mcp/pending-variable-changes.ts
|
|
3916
|
+
import { __privateRunCommandSync as runCommandSync, registerDataHook } from "@elementor/editor-v1-adapters";
|
|
3917
|
+
var pendingChanges = [];
|
|
3918
|
+
var pendingSave = null;
|
|
3919
|
+
var getPendingAbilityOperations = () => pendingChanges.map((change) => ({ ...change }));
|
|
3920
|
+
var applyPlannedVariableChange = (change) => {
|
|
3921
|
+
const existing = service.variables()[change.id];
|
|
3922
|
+
if (change.action === "delete") {
|
|
3923
|
+
if (existing) {
|
|
3924
|
+
service.applyLocalChange(change.id, { ...existing, deleted: true }, false);
|
|
3925
|
+
}
|
|
3926
|
+
} else {
|
|
3927
|
+
service.applyLocalChange(
|
|
3928
|
+
change.id,
|
|
3929
|
+
{
|
|
3930
|
+
...existing,
|
|
3931
|
+
type: change.type ?? existing?.type ?? "",
|
|
3932
|
+
label: change.label ?? existing?.label ?? "",
|
|
3933
|
+
value: change.value ?? existing?.value ?? ""
|
|
3934
|
+
},
|
|
3935
|
+
change.action === "create"
|
|
3936
|
+
);
|
|
3937
|
+
}
|
|
3938
|
+
pendingChanges.push(change);
|
|
3939
|
+
runCommandSync("document/save/set-is-modified", { status: true }, { internal: true });
|
|
3940
|
+
};
|
|
3941
|
+
var savePendingVariableChanges = () => {
|
|
3942
|
+
if (pendingSave) {
|
|
3943
|
+
return pendingSave;
|
|
3944
|
+
}
|
|
3945
|
+
if (!pendingChanges.length) {
|
|
3946
|
+
return Promise.resolve();
|
|
3947
|
+
}
|
|
3948
|
+
const changes = pendingChanges;
|
|
3949
|
+
pendingChanges = [];
|
|
3950
|
+
pendingSave = service.saveOperations(changes.map(toBatchOperation)).catch((error) => {
|
|
3951
|
+
pendingChanges = [...changes, ...pendingChanges];
|
|
3952
|
+
throw error;
|
|
3953
|
+
}).finally(() => {
|
|
3954
|
+
pendingSave = null;
|
|
3955
|
+
});
|
|
3956
|
+
return pendingSave;
|
|
3957
|
+
};
|
|
3958
|
+
var syncPendingVariableChangesWithDocumentSave = () => {
|
|
3959
|
+
registerDataHook("dependency", "document/save/save", () => {
|
|
3960
|
+
savePendingVariableChanges()?.catch(() => {
|
|
3961
|
+
});
|
|
3962
|
+
return true;
|
|
3963
|
+
});
|
|
3964
|
+
};
|
|
3965
|
+
function toBatchOperation({ action, id, type, label, value }) {
|
|
3966
|
+
switch (action) {
|
|
3967
|
+
case "create":
|
|
3968
|
+
return { type: "create", variable: { id, type, label, value } };
|
|
3969
|
+
case "update":
|
|
3970
|
+
return { type: "update", id, variable: { label, value } };
|
|
3971
|
+
case "delete":
|
|
3972
|
+
return { type: "delete", id };
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
|
|
3881
3976
|
// src/mcp/variable-tool-prompt.ts
|
|
3882
3977
|
var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
|
|
3883
3978
|
|
|
@@ -3921,6 +4016,7 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
|
|
|
3921
4016
|
// src/mcp/manage-variable-tool.ts
|
|
3922
4017
|
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
3923
4018
|
var TOOL_NAME = "manage-global-variable";
|
|
4019
|
+
var MAX_OPERATIONS_PER_REQUEST = 50;
|
|
3924
4020
|
var VARIABLE_TYPES = {
|
|
3925
4021
|
COLOR: "global-color-variable",
|
|
3926
4022
|
FONT: "global-font-variable",
|
|
@@ -3929,6 +4025,7 @@ var VARIABLE_TYPES = {
|
|
|
3929
4025
|
};
|
|
3930
4026
|
var initManageVariableTool = (reg) => {
|
|
3931
4027
|
const { addTool, resource } = reg;
|
|
4028
|
+
syncPendingVariableChangesWithDocumentSave();
|
|
3932
4029
|
const RUNTIME_ALLOWED_VARIABLE_TYPES = isProActive() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
|
|
3933
4030
|
resource(
|
|
3934
4031
|
"manage-global-variable-guide",
|
|
@@ -3961,7 +4058,7 @@ var initManageVariableTool = (reg) => {
|
|
|
3961
4058
|
},
|
|
3962
4059
|
outputSchema: {
|
|
3963
4060
|
status: z3.enum(["ok"]).describe("Operation status"),
|
|
3964
|
-
|
|
4061
|
+
id: z3.string().describe("Id of the affected variable \u2014 use it for subsequent update/delete calls.")
|
|
3965
4062
|
},
|
|
3966
4063
|
requiredResources: [
|
|
3967
4064
|
{ uri: MANAGE_VARIABLES_GUIDE_URI, description: "Full guide for variable types, naming rules, and usage" },
|
|
@@ -3972,15 +4069,30 @@ var initManageVariableTool = (reg) => {
|
|
|
3972
4069
|
],
|
|
3973
4070
|
isDestructive: true,
|
|
3974
4071
|
handler: async (params) => {
|
|
4072
|
+
const pendingOperations = getPendingAbilityOperations();
|
|
4073
|
+
if (pendingOperations.length >= MAX_OPERATIONS_PER_REQUEST) {
|
|
4074
|
+
throw new Error("Too many unsaved variable changes. Save the page, then try again.");
|
|
4075
|
+
}
|
|
3975
4076
|
const { data } = await httpService3().post(MCP_PROXY_URL2, {
|
|
3976
4077
|
tool: TOOL_NAME,
|
|
3977
|
-
input: params
|
|
4078
|
+
input: { operations: [...pendingOperations, params], dry_run: true }
|
|
3978
4079
|
});
|
|
3979
|
-
const
|
|
3980
|
-
if (
|
|
3981
|
-
|
|
4080
|
+
const result = data.data.results?.[pendingOperations.length];
|
|
4081
|
+
if (result?.status !== "ok") {
|
|
4082
|
+
throw new Error(result?.message || "Unexpected response from server");
|
|
3982
4083
|
}
|
|
3983
|
-
|
|
4084
|
+
const id = result.id ?? params.id;
|
|
4085
|
+
if (!id) {
|
|
4086
|
+
throw new Error("Variable id is missing from the response");
|
|
4087
|
+
}
|
|
4088
|
+
applyPlannedVariableChange({
|
|
4089
|
+
action: params.action,
|
|
4090
|
+
id,
|
|
4091
|
+
type: result.type ?? params.type,
|
|
4092
|
+
label: result.label ?? params.label,
|
|
4093
|
+
value: params.value
|
|
4094
|
+
});
|
|
4095
|
+
return { status: "ok", id };
|
|
3984
4096
|
}
|
|
3985
4097
|
});
|
|
3986
4098
|
};
|
|
@@ -4583,6 +4695,8 @@ export {
|
|
|
4583
4695
|
getMenuActionsForVariable,
|
|
4584
4696
|
hasVariable,
|
|
4585
4697
|
init,
|
|
4698
|
+
injectIntoVariableFormHeader,
|
|
4699
|
+
injectIntoVariablesManagerHeader,
|
|
4586
4700
|
registerVariableType,
|
|
4587
4701
|
registerVariableTypes,
|
|
4588
4702
|
service,
|