@elementor/editor-variables 4.5.0-1178 → 4.5.0-1180
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 +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +99 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
- 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.d.mts
CHANGED
|
@@ -56,6 +56,23 @@ type TVariable = {
|
|
|
56
56
|
};
|
|
57
57
|
type TVariablesList = Record<string, TVariable>;
|
|
58
58
|
|
|
59
|
+
type OperationType = 'create' | 'update' | 'delete' | 'restore';
|
|
60
|
+
|
|
61
|
+
type BatchOperation = {
|
|
62
|
+
type: OperationType;
|
|
63
|
+
id?: string;
|
|
64
|
+
variable?: {
|
|
65
|
+
id?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
label?: string;
|
|
68
|
+
value?: string;
|
|
69
|
+
order?: number;
|
|
70
|
+
sync_to_v3?: boolean;
|
|
71
|
+
};
|
|
72
|
+
label?: string;
|
|
73
|
+
value?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
59
76
|
type NormalizedVariable = {
|
|
60
77
|
key: string;
|
|
61
78
|
label: string;
|
|
@@ -114,11 +131,17 @@ declare const service: {
|
|
|
114
131
|
id: any;
|
|
115
132
|
variable: any;
|
|
116
133
|
}>;
|
|
134
|
+
applyLocalChange: (id: string, variable: TVariable, isNew: boolean) => void;
|
|
117
135
|
batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList, deletedVariables: string[]) => Promise<{
|
|
118
136
|
success: boolean;
|
|
119
137
|
watermark: any;
|
|
120
138
|
operations: number;
|
|
121
139
|
}>;
|
|
140
|
+
saveOperations: (operations: BatchOperation[]) => Promise<{
|
|
141
|
+
success: boolean;
|
|
142
|
+
watermark: any;
|
|
143
|
+
operations: number;
|
|
144
|
+
}>;
|
|
122
145
|
};
|
|
123
146
|
|
|
124
147
|
type VariableManagerMenuAction = {
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,23 @@ type TVariable = {
|
|
|
56
56
|
};
|
|
57
57
|
type TVariablesList = Record<string, TVariable>;
|
|
58
58
|
|
|
59
|
+
type OperationType = 'create' | 'update' | 'delete' | 'restore';
|
|
60
|
+
|
|
61
|
+
type BatchOperation = {
|
|
62
|
+
type: OperationType;
|
|
63
|
+
id?: string;
|
|
64
|
+
variable?: {
|
|
65
|
+
id?: string;
|
|
66
|
+
type?: string;
|
|
67
|
+
label?: string;
|
|
68
|
+
value?: string;
|
|
69
|
+
order?: number;
|
|
70
|
+
sync_to_v3?: boolean;
|
|
71
|
+
};
|
|
72
|
+
label?: string;
|
|
73
|
+
value?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
59
76
|
type NormalizedVariable = {
|
|
60
77
|
key: string;
|
|
61
78
|
label: string;
|
|
@@ -114,11 +131,17 @@ declare const service: {
|
|
|
114
131
|
id: any;
|
|
115
132
|
variable: any;
|
|
116
133
|
}>;
|
|
134
|
+
applyLocalChange: (id: string, variable: TVariable, isNew: boolean) => void;
|
|
117
135
|
batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList, deletedVariables: string[]) => Promise<{
|
|
118
136
|
success: boolean;
|
|
119
137
|
watermark: any;
|
|
120
138
|
operations: number;
|
|
121
139
|
}>;
|
|
140
|
+
saveOperations: (operations: BatchOperation[]) => Promise<{
|
|
141
|
+
success: boolean;
|
|
142
|
+
watermark: any;
|
|
143
|
+
operations: number;
|
|
144
|
+
}>;
|
|
122
145
|
};
|
|
123
146
|
|
|
124
147
|
type VariableManagerMenuAction = {
|
package/dist/index.js
CHANGED
|
@@ -612,8 +612,18 @@ var service = {
|
|
|
612
612
|
};
|
|
613
613
|
});
|
|
614
614
|
},
|
|
615
|
+
applyLocalChange: (id, variable, isNew) => {
|
|
616
|
+
if (isNew) {
|
|
617
|
+
storage.add(id, variable);
|
|
618
|
+
} else {
|
|
619
|
+
storage.update(id, variable);
|
|
620
|
+
}
|
|
621
|
+
styleVariablesRepository.update({ [id]: variable });
|
|
622
|
+
},
|
|
615
623
|
batchSave: (originalVariables, currentVariables, deletedVariables) => {
|
|
616
|
-
|
|
624
|
+
return service.saveOperations(buildOperationsArray(originalVariables, currentVariables, deletedVariables));
|
|
625
|
+
},
|
|
626
|
+
saveOperations: (operations) => {
|
|
617
627
|
const batchPayload = { operations, watermark: storage.state.watermark };
|
|
618
628
|
if (operations.length === 0) {
|
|
619
629
|
return Promise.resolve({
|
|
@@ -660,18 +670,6 @@ var handleWatermark = (operation, newWatermark) => {
|
|
|
660
670
|
}
|
|
661
671
|
storage.watermark(newWatermark);
|
|
662
672
|
};
|
|
663
|
-
var applyLocalMutation = (action, variableWithId, watermark) => {
|
|
664
|
-
const { id: variableId, ...variable } = variableWithId;
|
|
665
|
-
handleWatermark(OP_RW, watermark);
|
|
666
|
-
if (action === "create") {
|
|
667
|
-
storage.add(variableId, variable);
|
|
668
|
-
} else {
|
|
669
|
-
storage.update(variableId, variable);
|
|
670
|
-
}
|
|
671
|
-
styleVariablesRepository.update({
|
|
672
|
-
[variableId]: variable
|
|
673
|
-
});
|
|
674
|
-
};
|
|
675
673
|
|
|
676
674
|
// src/transformers/utils/resolve-css-variable.ts
|
|
677
675
|
var resolveCssVariable = (id, variable) => {
|
|
@@ -3898,11 +3896,72 @@ var import_http_client3 = require("@elementor/http-client");
|
|
|
3898
3896
|
var import_schema3 = require("@elementor/schema");
|
|
3899
3897
|
var import_utils3 = require("@elementor/utils");
|
|
3900
3898
|
|
|
3899
|
+
// src/mcp/pending-variable-changes.ts
|
|
3900
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
3901
|
+
var pendingChanges = [];
|
|
3902
|
+
var pendingSave = null;
|
|
3903
|
+
var getPendingAbilityOperations = () => pendingChanges.map((change) => ({ ...change }));
|
|
3904
|
+
var applyPlannedVariableChange = (change) => {
|
|
3905
|
+
const existing = service.variables()[change.id];
|
|
3906
|
+
if (change.action === "delete") {
|
|
3907
|
+
if (existing) {
|
|
3908
|
+
service.applyLocalChange(change.id, { ...existing, deleted: true }, false);
|
|
3909
|
+
}
|
|
3910
|
+
} else {
|
|
3911
|
+
service.applyLocalChange(
|
|
3912
|
+
change.id,
|
|
3913
|
+
{
|
|
3914
|
+
...existing,
|
|
3915
|
+
type: change.type ?? existing?.type ?? "",
|
|
3916
|
+
label: change.label ?? existing?.label ?? "",
|
|
3917
|
+
value: change.value ?? existing?.value ?? ""
|
|
3918
|
+
},
|
|
3919
|
+
change.action === "create"
|
|
3920
|
+
);
|
|
3921
|
+
}
|
|
3922
|
+
pendingChanges.push(change);
|
|
3923
|
+
(0, import_editor_v1_adapters2.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
|
|
3924
|
+
};
|
|
3925
|
+
var savePendingVariableChanges = () => {
|
|
3926
|
+
if (pendingSave) {
|
|
3927
|
+
return pendingSave;
|
|
3928
|
+
}
|
|
3929
|
+
if (!pendingChanges.length) {
|
|
3930
|
+
return Promise.resolve();
|
|
3931
|
+
}
|
|
3932
|
+
const changes = pendingChanges;
|
|
3933
|
+
pendingChanges = [];
|
|
3934
|
+
pendingSave = service.saveOperations(changes.map(toBatchOperation)).catch((error) => {
|
|
3935
|
+
pendingChanges = [...changes, ...pendingChanges];
|
|
3936
|
+
throw error;
|
|
3937
|
+
}).finally(() => {
|
|
3938
|
+
pendingSave = null;
|
|
3939
|
+
});
|
|
3940
|
+
return pendingSave;
|
|
3941
|
+
};
|
|
3942
|
+
var syncPendingVariableChangesWithDocumentSave = () => {
|
|
3943
|
+
(0, import_editor_v1_adapters2.registerDataHook)("dependency", "document/save/save", () => {
|
|
3944
|
+
savePendingVariableChanges()?.catch(() => {
|
|
3945
|
+
});
|
|
3946
|
+
return true;
|
|
3947
|
+
});
|
|
3948
|
+
};
|
|
3949
|
+
function toBatchOperation({ action, id, type, label, value }) {
|
|
3950
|
+
switch (action) {
|
|
3951
|
+
case "create":
|
|
3952
|
+
return { type: "create", variable: { id, type, label, value } };
|
|
3953
|
+
case "update":
|
|
3954
|
+
return { type: "update", id, variable: { label, value } };
|
|
3955
|
+
case "delete":
|
|
3956
|
+
return { type: "delete", id };
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3901
3960
|
// src/mcp/variable-tool-prompt.ts
|
|
3902
3961
|
var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
|
|
3903
3962
|
|
|
3904
3963
|
// src/mcp/variables-resource.ts
|
|
3905
|
-
var
|
|
3964
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
3906
3965
|
var import_http_client2 = require("@elementor/http-client");
|
|
3907
3966
|
var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
|
|
3908
3967
|
var GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
@@ -3934,13 +3993,14 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
|
|
|
3934
3993
|
}
|
|
3935
3994
|
);
|
|
3936
3995
|
window.addEventListener(STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated);
|
|
3937
|
-
(0,
|
|
3996
|
+
(0, import_editor_v1_adapters3.__privateListenTo)((0, import_editor_v1_adapters3.commandEndEvent)("document/save/update"), notifyGlobalVariablesUpdated);
|
|
3938
3997
|
});
|
|
3939
3998
|
};
|
|
3940
3999
|
|
|
3941
4000
|
// src/mcp/manage-variable-tool.ts
|
|
3942
4001
|
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
3943
4002
|
var TOOL_NAME = "manage-global-variable";
|
|
4003
|
+
var MAX_OPERATIONS_PER_REQUEST = 50;
|
|
3944
4004
|
var VARIABLE_TYPES = {
|
|
3945
4005
|
COLOR: "global-color-variable",
|
|
3946
4006
|
FONT: "global-font-variable",
|
|
@@ -3949,6 +4009,7 @@ var VARIABLE_TYPES = {
|
|
|
3949
4009
|
};
|
|
3950
4010
|
var initManageVariableTool = (reg) => {
|
|
3951
4011
|
const { addTool, resource } = reg;
|
|
4012
|
+
syncPendingVariableChangesWithDocumentSave();
|
|
3952
4013
|
const RUNTIME_ALLOWED_VARIABLE_TYPES = (0, import_utils3.isProActive)() ? [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT, VARIABLE_TYPES.SIZE, VARIABLE_TYPES.CUSTOM_SIZE] : [VARIABLE_TYPES.COLOR, VARIABLE_TYPES.FONT];
|
|
3953
4014
|
resource(
|
|
3954
4015
|
"manage-global-variable-guide",
|
|
@@ -3981,7 +4042,7 @@ var initManageVariableTool = (reg) => {
|
|
|
3981
4042
|
},
|
|
3982
4043
|
outputSchema: {
|
|
3983
4044
|
status: import_schema3.z.enum(["ok"]).describe("Operation status"),
|
|
3984
|
-
|
|
4045
|
+
id: import_schema3.z.string().describe("Id of the affected variable \u2014 use it for subsequent update/delete calls.")
|
|
3985
4046
|
},
|
|
3986
4047
|
requiredResources: [
|
|
3987
4048
|
{ uri: MANAGE_VARIABLES_GUIDE_URI, description: "Full guide for variable types, naming rules, and usage" },
|
|
@@ -3992,15 +4053,30 @@ var initManageVariableTool = (reg) => {
|
|
|
3992
4053
|
],
|
|
3993
4054
|
isDestructive: true,
|
|
3994
4055
|
handler: async (params) => {
|
|
4056
|
+
const pendingOperations = getPendingAbilityOperations();
|
|
4057
|
+
if (pendingOperations.length >= MAX_OPERATIONS_PER_REQUEST) {
|
|
4058
|
+
throw new Error("Too many unsaved variable changes. Save the page, then try again.");
|
|
4059
|
+
}
|
|
3995
4060
|
const { data } = await (0, import_http_client3.httpService)().post(MCP_PROXY_URL2, {
|
|
3996
4061
|
tool: TOOL_NAME,
|
|
3997
|
-
input: params
|
|
4062
|
+
input: { operations: [...pendingOperations, params], dry_run: true }
|
|
3998
4063
|
});
|
|
3999
|
-
const
|
|
4000
|
-
if (
|
|
4001
|
-
|
|
4064
|
+
const result = data.data.results?.[pendingOperations.length];
|
|
4065
|
+
if (result?.status !== "ok") {
|
|
4066
|
+
throw new Error(result?.message || "Unexpected response from server");
|
|
4067
|
+
}
|
|
4068
|
+
const id = result.id ?? params.id;
|
|
4069
|
+
if (!id) {
|
|
4070
|
+
throw new Error("Variable id is missing from the response");
|
|
4002
4071
|
}
|
|
4003
|
-
|
|
4072
|
+
applyPlannedVariableChange({
|
|
4073
|
+
action: params.action,
|
|
4074
|
+
id,
|
|
4075
|
+
type: result.type ?? params.type,
|
|
4076
|
+
label: result.label ?? params.label,
|
|
4077
|
+
value: params.value
|
|
4078
|
+
});
|
|
4079
|
+
return { status: "ok", id };
|
|
4004
4080
|
}
|
|
4005
4081
|
});
|
|
4006
4082
|
};
|
|
@@ -4229,7 +4305,7 @@ function registerVariableTypes() {
|
|
|
4229
4305
|
// src/renderers/style-variables-renderer.tsx
|
|
4230
4306
|
var React38 = __toESM(require("react"));
|
|
4231
4307
|
var import_react29 = require("react");
|
|
4232
|
-
var
|
|
4308
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
4233
4309
|
var import_ui35 = require("@elementor/ui");
|
|
4234
4310
|
var VARIABLES_WRAPPER = ":root";
|
|
4235
4311
|
function StyleVariablesRenderer() {
|
|
@@ -4244,7 +4320,7 @@ function StyleVariablesRenderer() {
|
|
|
4244
4320
|
return /* @__PURE__ */ React38.createElement(import_ui35.Portal, { container }, /* @__PURE__ */ React38.createElement("style", { "data-e-style-id": "e-variables", key: wrappedCss }, wrappedCss));
|
|
4245
4321
|
}
|
|
4246
4322
|
function usePortalContainer() {
|
|
4247
|
-
return (0,
|
|
4323
|
+
return (0, import_editor_v1_adapters4.__privateUseListenTo)((0, import_editor_v1_adapters4.commandEndEvent)("editor/documents/attach-preview"), () => (0, import_editor_v1_adapters4.getCanvasIframeDocument)()?.head);
|
|
4248
4324
|
}
|
|
4249
4325
|
function useStyleVariables() {
|
|
4250
4326
|
const [variables, setVariables] = (0, import_react29.useState)({});
|