@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.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { KeyboardEvent } from 'react';
|
|
3
|
+
import * as _elementor_locations from '@elementor/locations';
|
|
3
4
|
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
4
5
|
import { PropType } from '@elementor/editor-props';
|
|
5
6
|
import { z } from '@elementor/schema';
|
|
@@ -17,6 +18,15 @@ declare function VariablesManagerPanelEmbedded({ onRequestClose, onExposeCloseAt
|
|
|
17
18
|
|
|
18
19
|
declare function init(): void;
|
|
19
20
|
|
|
21
|
+
type VariableFormHeaderProps = {
|
|
22
|
+
variableType: string;
|
|
23
|
+
variableId?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
};
|
|
26
|
+
declare const injectIntoVariableFormHeader: (args: _elementor_locations.InjectArgs<VariableFormHeaderProps>) => void;
|
|
27
|
+
|
|
28
|
+
declare const injectIntoVariablesManagerHeader: (args: _elementor_locations.InjectArgs<object>) => void;
|
|
29
|
+
|
|
20
30
|
declare const GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
21
31
|
|
|
22
32
|
declare const sizeVariablePropTypeUtil: {
|
|
@@ -56,6 +66,23 @@ type TVariable = {
|
|
|
56
66
|
};
|
|
57
67
|
type TVariablesList = Record<string, TVariable>;
|
|
58
68
|
|
|
69
|
+
type OperationType = 'create' | 'update' | 'delete' | 'restore';
|
|
70
|
+
|
|
71
|
+
type BatchOperation = {
|
|
72
|
+
type: OperationType;
|
|
73
|
+
id?: string;
|
|
74
|
+
variable?: {
|
|
75
|
+
id?: string;
|
|
76
|
+
type?: string;
|
|
77
|
+
label?: string;
|
|
78
|
+
value?: string;
|
|
79
|
+
order?: number;
|
|
80
|
+
sync_to_v3?: boolean;
|
|
81
|
+
};
|
|
82
|
+
label?: string;
|
|
83
|
+
value?: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
59
86
|
type NormalizedVariable = {
|
|
60
87
|
key: string;
|
|
61
88
|
label: string;
|
|
@@ -114,11 +141,17 @@ declare const service: {
|
|
|
114
141
|
id: any;
|
|
115
142
|
variable: any;
|
|
116
143
|
}>;
|
|
144
|
+
applyLocalChange: (id: string, variable: TVariable, isNew: boolean) => void;
|
|
117
145
|
batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList, deletedVariables: string[]) => Promise<{
|
|
118
146
|
success: boolean;
|
|
119
147
|
watermark: any;
|
|
120
148
|
operations: number;
|
|
121
149
|
}>;
|
|
150
|
+
saveOperations: (operations: BatchOperation[]) => Promise<{
|
|
151
|
+
success: boolean;
|
|
152
|
+
watermark: any;
|
|
153
|
+
operations: number;
|
|
154
|
+
}>;
|
|
122
155
|
};
|
|
123
156
|
|
|
124
157
|
type VariableManagerMenuAction = {
|
|
@@ -191,4 +224,4 @@ declare const Utils: {
|
|
|
191
224
|
};
|
|
192
225
|
};
|
|
193
226
|
|
|
194
|
-
export { GLOBAL_VARIABLES_URI, type MenuActionContext, type MenuActionsFactory, Utils, type VariableManagerMenuAction, VariablesManagerPanelEmbedded, type VariablesManagerPanelEmbeddedProps, getMenuActionsForVariable, hasVariable, init, registerVariableType, registerVariableTypes, service, sizeVariablePropTypeUtil, trackVariablesManagerEvent };
|
|
227
|
+
export { GLOBAL_VARIABLES_URI, type MenuActionContext, type MenuActionsFactory, Utils, type VariableFormHeaderProps, type VariableManagerMenuAction, VariablesManagerPanelEmbedded, type VariablesManagerPanelEmbeddedProps, getMenuActionsForVariable, hasVariable, init, injectIntoVariableFormHeader, injectIntoVariablesManagerHeader, registerVariableType, registerVariableTypes, service, sizeVariablePropTypeUtil, trackVariablesManagerEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { KeyboardEvent } from 'react';
|
|
3
|
+
import * as _elementor_locations from '@elementor/locations';
|
|
3
4
|
import * as _elementor_editor_props from '@elementor/editor-props';
|
|
4
5
|
import { PropType } from '@elementor/editor-props';
|
|
5
6
|
import { z } from '@elementor/schema';
|
|
@@ -17,6 +18,15 @@ declare function VariablesManagerPanelEmbedded({ onRequestClose, onExposeCloseAt
|
|
|
17
18
|
|
|
18
19
|
declare function init(): void;
|
|
19
20
|
|
|
21
|
+
type VariableFormHeaderProps = {
|
|
22
|
+
variableType: string;
|
|
23
|
+
variableId?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
};
|
|
26
|
+
declare const injectIntoVariableFormHeader: (args: _elementor_locations.InjectArgs<VariableFormHeaderProps>) => void;
|
|
27
|
+
|
|
28
|
+
declare const injectIntoVariablesManagerHeader: (args: _elementor_locations.InjectArgs<object>) => void;
|
|
29
|
+
|
|
20
30
|
declare const GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
21
31
|
|
|
22
32
|
declare const sizeVariablePropTypeUtil: {
|
|
@@ -56,6 +66,23 @@ type TVariable = {
|
|
|
56
66
|
};
|
|
57
67
|
type TVariablesList = Record<string, TVariable>;
|
|
58
68
|
|
|
69
|
+
type OperationType = 'create' | 'update' | 'delete' | 'restore';
|
|
70
|
+
|
|
71
|
+
type BatchOperation = {
|
|
72
|
+
type: OperationType;
|
|
73
|
+
id?: string;
|
|
74
|
+
variable?: {
|
|
75
|
+
id?: string;
|
|
76
|
+
type?: string;
|
|
77
|
+
label?: string;
|
|
78
|
+
value?: string;
|
|
79
|
+
order?: number;
|
|
80
|
+
sync_to_v3?: boolean;
|
|
81
|
+
};
|
|
82
|
+
label?: string;
|
|
83
|
+
value?: string;
|
|
84
|
+
};
|
|
85
|
+
|
|
59
86
|
type NormalizedVariable = {
|
|
60
87
|
key: string;
|
|
61
88
|
label: string;
|
|
@@ -114,11 +141,17 @@ declare const service: {
|
|
|
114
141
|
id: any;
|
|
115
142
|
variable: any;
|
|
116
143
|
}>;
|
|
144
|
+
applyLocalChange: (id: string, variable: TVariable, isNew: boolean) => void;
|
|
117
145
|
batchSave: (originalVariables: TVariablesList, currentVariables: TVariablesList, deletedVariables: string[]) => Promise<{
|
|
118
146
|
success: boolean;
|
|
119
147
|
watermark: any;
|
|
120
148
|
operations: number;
|
|
121
149
|
}>;
|
|
150
|
+
saveOperations: (operations: BatchOperation[]) => Promise<{
|
|
151
|
+
success: boolean;
|
|
152
|
+
watermark: any;
|
|
153
|
+
operations: number;
|
|
154
|
+
}>;
|
|
122
155
|
};
|
|
123
156
|
|
|
124
157
|
type VariableManagerMenuAction = {
|
|
@@ -191,4 +224,4 @@ declare const Utils: {
|
|
|
191
224
|
};
|
|
192
225
|
};
|
|
193
226
|
|
|
194
|
-
export { GLOBAL_VARIABLES_URI, type MenuActionContext, type MenuActionsFactory, Utils, type VariableManagerMenuAction, VariablesManagerPanelEmbedded, type VariablesManagerPanelEmbeddedProps, getMenuActionsForVariable, hasVariable, init, registerVariableType, registerVariableTypes, service, sizeVariablePropTypeUtil, trackVariablesManagerEvent };
|
|
227
|
+
export { GLOBAL_VARIABLES_URI, type MenuActionContext, type MenuActionsFactory, Utils, type VariableFormHeaderProps, type VariableManagerMenuAction, VariablesManagerPanelEmbedded, type VariablesManagerPanelEmbeddedProps, getMenuActionsForVariable, hasVariable, init, injectIntoVariableFormHeader, injectIntoVariablesManagerHeader, registerVariableType, registerVariableTypes, service, sizeVariablePropTypeUtil, trackVariablesManagerEvent };
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,8 @@ __export(index_exports, {
|
|
|
36
36
|
getMenuActionsForVariable: () => getMenuActionsForVariable,
|
|
37
37
|
hasVariable: () => hasVariable,
|
|
38
38
|
init: () => init,
|
|
39
|
+
injectIntoVariableFormHeader: () => injectIntoVariableFormHeader,
|
|
40
|
+
injectIntoVariablesManagerHeader: () => injectIntoVariablesManagerHeader,
|
|
39
41
|
registerVariableType: () => registerVariableType,
|
|
40
42
|
registerVariableTypes: () => registerVariableTypes,
|
|
41
43
|
service: () => service,
|
|
@@ -612,8 +614,18 @@ var service = {
|
|
|
612
614
|
};
|
|
613
615
|
});
|
|
614
616
|
},
|
|
617
|
+
applyLocalChange: (id, variable, isNew) => {
|
|
618
|
+
if (isNew) {
|
|
619
|
+
storage.add(id, variable);
|
|
620
|
+
} else {
|
|
621
|
+
storage.update(id, variable);
|
|
622
|
+
}
|
|
623
|
+
styleVariablesRepository.update({ [id]: variable });
|
|
624
|
+
},
|
|
615
625
|
batchSave: (originalVariables, currentVariables, deletedVariables) => {
|
|
616
|
-
|
|
626
|
+
return service.saveOperations(buildOperationsArray(originalVariables, currentVariables, deletedVariables));
|
|
627
|
+
},
|
|
628
|
+
saveOperations: (operations) => {
|
|
617
629
|
const batchPayload = { operations, watermark: storage.state.watermark };
|
|
618
630
|
if (operations.length === 0) {
|
|
619
631
|
return Promise.resolve({
|
|
@@ -660,18 +672,6 @@ var handleWatermark = (operation, newWatermark) => {
|
|
|
660
672
|
}
|
|
661
673
|
storage.watermark(newWatermark);
|
|
662
674
|
};
|
|
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
675
|
|
|
676
676
|
// src/transformers/utils/resolve-css-variable.ts
|
|
677
677
|
var resolveCssVariable = (id, variable) => {
|
|
@@ -878,6 +878,14 @@ var NoSearchResults = ({ searchValue, onClear, icon }) => {
|
|
|
878
878
|
);
|
|
879
879
|
};
|
|
880
880
|
|
|
881
|
+
// src/components/variables-manager-header-location.tsx
|
|
882
|
+
var import_locations = require("@elementor/locations");
|
|
883
|
+
var {
|
|
884
|
+
Slot: VariablesManagerHeaderSlot,
|
|
885
|
+
inject: injectIntoVariablesManagerHeader,
|
|
886
|
+
useInjections: useVariablesManagerHeaderInjections
|
|
887
|
+
} = (0, import_locations.createLocation)();
|
|
888
|
+
|
|
881
889
|
// src/components/variables-manager/hooks/use-auto-edit.ts
|
|
882
890
|
var import_react = require("react");
|
|
883
891
|
var useAutoEdit = () => {
|
|
@@ -2207,7 +2215,7 @@ function VariablesManagerPanelContent({ onRequestClose, onExposeCloseAttempt })
|
|
|
2207
2215
|
}
|
|
2208
2216
|
}
|
|
2209
2217
|
),
|
|
2210
|
-
/* @__PURE__ */ React14.createElement(import_ui14.Box, { sx: { display: "flex", flexShrink: 0, alignItems: "center" } }, /* @__PURE__ */ React14.createElement(
|
|
2218
|
+
/* @__PURE__ */ React14.createElement(import_ui14.Box, { sx: { display: "flex", flexShrink: 0, alignItems: "center", gap: 0.5 } }, /* @__PURE__ */ React14.createElement(VariablesManagerHeaderSlot, null), /* @__PURE__ */ React14.createElement(
|
|
2211
2219
|
VariableManagerCreateMenu,
|
|
2212
2220
|
{
|
|
2213
2221
|
outlinedTrigger: true,
|
|
@@ -2575,10 +2583,18 @@ var FormField = ({ id, label, errorMsg, noticeMsg, children }) => {
|
|
|
2575
2583
|
return /* @__PURE__ */ React16.createElement(import_ui16.Grid, { container: true, gap: 0.75, alignItems: "center" }, /* @__PURE__ */ React16.createElement(import_ui16.Grid, { item: true, xs: 12 }, /* @__PURE__ */ React16.createElement(import_ui16.FormLabel, { htmlFor: id, size: "tiny" }, label)), /* @__PURE__ */ React16.createElement(import_ui16.Grid, { item: true, xs: 12 }, children, errorMsg && /* @__PURE__ */ React16.createElement(import_ui16.FormHelperText, { error: true }, errorMsg), noticeMsg && /* @__PURE__ */ React16.createElement(import_ui16.FormHelperText, null, noticeMsg)));
|
|
2576
2584
|
};
|
|
2577
2585
|
|
|
2586
|
+
// src/components/variable-form-header-location.tsx
|
|
2587
|
+
var import_locations2 = require("@elementor/locations");
|
|
2588
|
+
var {
|
|
2589
|
+
Slot: VariableFormHeaderSlot,
|
|
2590
|
+
inject: injectIntoVariableFormHeader,
|
|
2591
|
+
useInjections: useVariableFormHeaderInjections
|
|
2592
|
+
} = (0, import_locations2.createLocation)();
|
|
2593
|
+
|
|
2578
2594
|
// src/components/variable-creation.tsx
|
|
2579
2595
|
var SIZE2 = "tiny";
|
|
2580
2596
|
var VariableCreation = ({ onGoBack, onClose }) => {
|
|
2581
|
-
const { icon: VariableIcon, valueField: ValueField, propTypeUtil } = useVariableType();
|
|
2597
|
+
const { icon: VariableIcon, valueField: ValueField, propTypeUtil, variableType } = useVariableType();
|
|
2582
2598
|
const { setVariableValue: setVariable, path } = useVariableBoundProp();
|
|
2583
2599
|
const { propType } = (0, import_editor_controls5.useBoundProp)();
|
|
2584
2600
|
const initialValue = useInitialValue();
|
|
@@ -2646,7 +2662,17 @@ var VariableCreation = ({ onGoBack, onClose }) => {
|
|
|
2646
2662
|
{
|
|
2647
2663
|
icon: /* @__PURE__ */ React17.createElement(React17.Fragment, null, onGoBack && /* @__PURE__ */ React17.createElement(import_ui17.IconButton, { size: SIZE2, "aria-label": (0, import_i18n11.__)("Go Back", "elementor"), onClick: onGoBack }, /* @__PURE__ */ React17.createElement(import_icons6.ArrowLeftIcon, { fontSize: SIZE2 })), /* @__PURE__ */ React17.createElement(VariableIcon, { fontSize: SIZE2 })),
|
|
2648
2664
|
title: (0, import_i18n11.__)("Create variable", "elementor"),
|
|
2649
|
-
onClose: closePopover
|
|
2665
|
+
onClose: closePopover,
|
|
2666
|
+
actions: [
|
|
2667
|
+
/* @__PURE__ */ React17.createElement(
|
|
2668
|
+
VariableFormHeaderSlot,
|
|
2669
|
+
{
|
|
2670
|
+
key: "variable-form-header",
|
|
2671
|
+
variableType,
|
|
2672
|
+
label: label || void 0
|
|
2673
|
+
}
|
|
2674
|
+
)
|
|
2675
|
+
]
|
|
2650
2676
|
}
|
|
2651
2677
|
), /* @__PURE__ */ React17.createElement(import_ui17.Divider, null), /* @__PURE__ */ React17.createElement(import_editor_controls5.PopoverContent, { p: 2 }, /* @__PURE__ */ React17.createElement(
|
|
2652
2678
|
FormField,
|
|
@@ -2831,7 +2857,17 @@ var VariableEdit = ({ onClose, onGoBack, onSubmit, editId }) => {
|
|
|
2831
2857
|
const closeEditDialog = () => () => {
|
|
2832
2858
|
setEditConfirmation(false);
|
|
2833
2859
|
};
|
|
2834
|
-
const actions = [
|
|
2860
|
+
const actions = [
|
|
2861
|
+
/* @__PURE__ */ React19.createElement(
|
|
2862
|
+
VariableFormHeaderSlot,
|
|
2863
|
+
{
|
|
2864
|
+
key: "variable-form-header",
|
|
2865
|
+
variableType,
|
|
2866
|
+
variableId: editId,
|
|
2867
|
+
label
|
|
2868
|
+
}
|
|
2869
|
+
)
|
|
2870
|
+
];
|
|
2835
2871
|
if (userPermissions.canDelete()) {
|
|
2836
2872
|
actions.push(
|
|
2837
2873
|
/* @__PURE__ */ React19.createElement(import_ui19.Tooltip, { key: "delete", placement: "top", title: DELETE_LABEL }, /* @__PURE__ */ React19.createElement(import_ui19.IconButton, { size: SIZE3, onClick: handleDeleteConfirmation, "aria-label": DELETE_LABEL }, /* @__PURE__ */ React19.createElement(import_icons8.TrashIcon, { fontSize: SIZE3 })))
|
|
@@ -3898,11 +3934,72 @@ var import_http_client3 = require("@elementor/http-client");
|
|
|
3898
3934
|
var import_schema3 = require("@elementor/schema");
|
|
3899
3935
|
var import_utils3 = require("@elementor/utils");
|
|
3900
3936
|
|
|
3937
|
+
// src/mcp/pending-variable-changes.ts
|
|
3938
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
3939
|
+
var pendingChanges = [];
|
|
3940
|
+
var pendingSave = null;
|
|
3941
|
+
var getPendingAbilityOperations = () => pendingChanges.map((change) => ({ ...change }));
|
|
3942
|
+
var applyPlannedVariableChange = (change) => {
|
|
3943
|
+
const existing = service.variables()[change.id];
|
|
3944
|
+
if (change.action === "delete") {
|
|
3945
|
+
if (existing) {
|
|
3946
|
+
service.applyLocalChange(change.id, { ...existing, deleted: true }, false);
|
|
3947
|
+
}
|
|
3948
|
+
} else {
|
|
3949
|
+
service.applyLocalChange(
|
|
3950
|
+
change.id,
|
|
3951
|
+
{
|
|
3952
|
+
...existing,
|
|
3953
|
+
type: change.type ?? existing?.type ?? "",
|
|
3954
|
+
label: change.label ?? existing?.label ?? "",
|
|
3955
|
+
value: change.value ?? existing?.value ?? ""
|
|
3956
|
+
},
|
|
3957
|
+
change.action === "create"
|
|
3958
|
+
);
|
|
3959
|
+
}
|
|
3960
|
+
pendingChanges.push(change);
|
|
3961
|
+
(0, import_editor_v1_adapters2.__privateRunCommandSync)("document/save/set-is-modified", { status: true }, { internal: true });
|
|
3962
|
+
};
|
|
3963
|
+
var savePendingVariableChanges = () => {
|
|
3964
|
+
if (pendingSave) {
|
|
3965
|
+
return pendingSave;
|
|
3966
|
+
}
|
|
3967
|
+
if (!pendingChanges.length) {
|
|
3968
|
+
return Promise.resolve();
|
|
3969
|
+
}
|
|
3970
|
+
const changes = pendingChanges;
|
|
3971
|
+
pendingChanges = [];
|
|
3972
|
+
pendingSave = service.saveOperations(changes.map(toBatchOperation)).catch((error) => {
|
|
3973
|
+
pendingChanges = [...changes, ...pendingChanges];
|
|
3974
|
+
throw error;
|
|
3975
|
+
}).finally(() => {
|
|
3976
|
+
pendingSave = null;
|
|
3977
|
+
});
|
|
3978
|
+
return pendingSave;
|
|
3979
|
+
};
|
|
3980
|
+
var syncPendingVariableChangesWithDocumentSave = () => {
|
|
3981
|
+
(0, import_editor_v1_adapters2.registerDataHook)("dependency", "document/save/save", () => {
|
|
3982
|
+
savePendingVariableChanges()?.catch(() => {
|
|
3983
|
+
});
|
|
3984
|
+
return true;
|
|
3985
|
+
});
|
|
3986
|
+
};
|
|
3987
|
+
function toBatchOperation({ action, id, type, label, value }) {
|
|
3988
|
+
switch (action) {
|
|
3989
|
+
case "create":
|
|
3990
|
+
return { type: "create", variable: { id, type, label, value } };
|
|
3991
|
+
case "update":
|
|
3992
|
+
return { type: "update", id, variable: { label, value } };
|
|
3993
|
+
case "delete":
|
|
3994
|
+
return { type: "delete", id };
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
|
|
3901
3998
|
// src/mcp/variable-tool-prompt.ts
|
|
3902
3999
|
var MANAGE_VARIABLES_GUIDE_URI = "elementor://variables/tools/manage-global-variable-guide";
|
|
3903
4000
|
|
|
3904
4001
|
// src/mcp/variables-resource.ts
|
|
3905
|
-
var
|
|
4002
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
3906
4003
|
var import_http_client2 = require("@elementor/http-client");
|
|
3907
4004
|
var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
|
|
3908
4005
|
var GLOBAL_VARIABLES_URI = "elementor://global-variables";
|
|
@@ -3934,13 +4031,14 @@ var initVariablesResource = (variablesMcpEntry, canvasMcpEntry) => {
|
|
|
3934
4031
|
}
|
|
3935
4032
|
);
|
|
3936
4033
|
window.addEventListener(STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated);
|
|
3937
|
-
(0,
|
|
4034
|
+
(0, import_editor_v1_adapters3.__privateListenTo)((0, import_editor_v1_adapters3.commandEndEvent)("document/save/update"), notifyGlobalVariablesUpdated);
|
|
3938
4035
|
});
|
|
3939
4036
|
};
|
|
3940
4037
|
|
|
3941
4038
|
// src/mcp/manage-variable-tool.ts
|
|
3942
4039
|
var MCP_PROXY_URL2 = "elementor/v1/mcp-proxy";
|
|
3943
4040
|
var TOOL_NAME = "manage-global-variable";
|
|
4041
|
+
var MAX_OPERATIONS_PER_REQUEST = 50;
|
|
3944
4042
|
var VARIABLE_TYPES = {
|
|
3945
4043
|
COLOR: "global-color-variable",
|
|
3946
4044
|
FONT: "global-font-variable",
|
|
@@ -3949,6 +4047,7 @@ var VARIABLE_TYPES = {
|
|
|
3949
4047
|
};
|
|
3950
4048
|
var initManageVariableTool = (reg) => {
|
|
3951
4049
|
const { addTool, resource } = reg;
|
|
4050
|
+
syncPendingVariableChangesWithDocumentSave();
|
|
3952
4051
|
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
4052
|
resource(
|
|
3954
4053
|
"manage-global-variable-guide",
|
|
@@ -3981,7 +4080,7 @@ var initManageVariableTool = (reg) => {
|
|
|
3981
4080
|
},
|
|
3982
4081
|
outputSchema: {
|
|
3983
4082
|
status: import_schema3.z.enum(["ok"]).describe("Operation status"),
|
|
3984
|
-
|
|
4083
|
+
id: import_schema3.z.string().describe("Id of the affected variable \u2014 use it for subsequent update/delete calls.")
|
|
3985
4084
|
},
|
|
3986
4085
|
requiredResources: [
|
|
3987
4086
|
{ uri: MANAGE_VARIABLES_GUIDE_URI, description: "Full guide for variable types, naming rules, and usage" },
|
|
@@ -3992,15 +4091,30 @@ var initManageVariableTool = (reg) => {
|
|
|
3992
4091
|
],
|
|
3993
4092
|
isDestructive: true,
|
|
3994
4093
|
handler: async (params) => {
|
|
4094
|
+
const pendingOperations = getPendingAbilityOperations();
|
|
4095
|
+
if (pendingOperations.length >= MAX_OPERATIONS_PER_REQUEST) {
|
|
4096
|
+
throw new Error("Too many unsaved variable changes. Save the page, then try again.");
|
|
4097
|
+
}
|
|
3995
4098
|
const { data } = await (0, import_http_client3.httpService)().post(MCP_PROXY_URL2, {
|
|
3996
4099
|
tool: TOOL_NAME,
|
|
3997
|
-
input: params
|
|
4100
|
+
input: { operations: [...pendingOperations, params], dry_run: true }
|
|
3998
4101
|
});
|
|
3999
|
-
const
|
|
4000
|
-
if (
|
|
4001
|
-
|
|
4102
|
+
const result = data.data.results?.[pendingOperations.length];
|
|
4103
|
+
if (result?.status !== "ok") {
|
|
4104
|
+
throw new Error(result?.message || "Unexpected response from server");
|
|
4105
|
+
}
|
|
4106
|
+
const id = result.id ?? params.id;
|
|
4107
|
+
if (!id) {
|
|
4108
|
+
throw new Error("Variable id is missing from the response");
|
|
4002
4109
|
}
|
|
4003
|
-
|
|
4110
|
+
applyPlannedVariableChange({
|
|
4111
|
+
action: params.action,
|
|
4112
|
+
id,
|
|
4113
|
+
type: result.type ?? params.type,
|
|
4114
|
+
label: result.label ?? params.label,
|
|
4115
|
+
value: params.value
|
|
4116
|
+
});
|
|
4117
|
+
return { status: "ok", id };
|
|
4004
4118
|
}
|
|
4005
4119
|
});
|
|
4006
4120
|
};
|
|
@@ -4229,7 +4343,7 @@ function registerVariableTypes() {
|
|
|
4229
4343
|
// src/renderers/style-variables-renderer.tsx
|
|
4230
4344
|
var React38 = __toESM(require("react"));
|
|
4231
4345
|
var import_react29 = require("react");
|
|
4232
|
-
var
|
|
4346
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
4233
4347
|
var import_ui35 = require("@elementor/ui");
|
|
4234
4348
|
var VARIABLES_WRAPPER = ":root";
|
|
4235
4349
|
function StyleVariablesRenderer() {
|
|
@@ -4244,7 +4358,7 @@ function StyleVariablesRenderer() {
|
|
|
4244
4358
|
return /* @__PURE__ */ React38.createElement(import_ui35.Portal, { container }, /* @__PURE__ */ React38.createElement("style", { "data-e-style-id": "e-variables", key: wrappedCss }, wrappedCss));
|
|
4245
4359
|
}
|
|
4246
4360
|
function usePortalContainer() {
|
|
4247
|
-
return (0,
|
|
4361
|
+
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
4362
|
}
|
|
4249
4363
|
function useStyleVariables() {
|
|
4250
4364
|
const [variables, setVariables] = (0, import_react29.useState)({});
|
|
@@ -4587,6 +4701,8 @@ var Utils = {
|
|
|
4587
4701
|
getMenuActionsForVariable,
|
|
4588
4702
|
hasVariable,
|
|
4589
4703
|
init,
|
|
4704
|
+
injectIntoVariableFormHeader,
|
|
4705
|
+
injectIntoVariablesManagerHeader,
|
|
4590
4706
|
registerVariableType,
|
|
4591
4707
|
registerVariableTypes,
|
|
4592
4708
|
service,
|