@elementor/editor-global-classes 4.3.0-1001 → 4.3.0-1002
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 +99 -300
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +91 -292
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
- package/src/mcp-integration/index.ts +2 -2
- package/src/mcp-integration/manage-classes-tool.ts +85 -0
- package/src/mcp-integration/mcp-manage-global-classes.ts +0 -314
package/dist/index.js
CHANGED
|
@@ -1974,7 +1974,7 @@ var GlobalClassesList = ({
|
|
|
1974
1974
|
search: { debouncedValue: searchValue }
|
|
1975
1975
|
} = useSearchAndFilters();
|
|
1976
1976
|
const cssClasses = useOrderedClasses();
|
|
1977
|
-
const
|
|
1977
|
+
const dispatch8 = (0, import_store20.__useDispatch)();
|
|
1978
1978
|
const filters = useFilters();
|
|
1979
1979
|
const [draggedItemId, setDraggedItemId] = (0, import_react8.useState)(null);
|
|
1980
1980
|
const [loading, setLoading] = (0, import_react8.useState)({});
|
|
@@ -2007,22 +2007,22 @@ var GlobalClassesList = ({
|
|
|
2007
2007
|
}
|
|
2008
2008
|
});
|
|
2009
2009
|
(0, import_react8.useEffect)(() => {
|
|
2010
|
-
const
|
|
2010
|
+
const handler = (event) => {
|
|
2011
2011
|
if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
|
|
2012
2012
|
event.stopImmediatePropagation();
|
|
2013
2013
|
event.preventDefault();
|
|
2014
2014
|
if (event.shiftKey) {
|
|
2015
|
-
|
|
2015
|
+
dispatch8(slice.actions.redo());
|
|
2016
2016
|
return;
|
|
2017
2017
|
}
|
|
2018
|
-
|
|
2018
|
+
dispatch8(slice.actions.undo());
|
|
2019
2019
|
}
|
|
2020
2020
|
};
|
|
2021
|
-
window.addEventListener("keydown",
|
|
2021
|
+
window.addEventListener("keydown", handler, {
|
|
2022
2022
|
capture: true
|
|
2023
2023
|
});
|
|
2024
|
-
return () => window.removeEventListener("keydown",
|
|
2025
|
-
}, [
|
|
2024
|
+
return () => window.removeEventListener("keydown", handler);
|
|
2025
|
+
}, [dispatch8]);
|
|
2026
2026
|
if (!cssClasses?.length) {
|
|
2027
2027
|
return /* @__PURE__ */ React17.createElement(EmptyState, null);
|
|
2028
2028
|
}
|
|
@@ -2082,7 +2082,7 @@ var GlobalClassesList = ({
|
|
|
2082
2082
|
source: "class-manager"
|
|
2083
2083
|
});
|
|
2084
2084
|
void await loadExistingClasses([cssClass.id]);
|
|
2085
|
-
|
|
2085
|
+
dispatch8(
|
|
2086
2086
|
slice.actions.update({
|
|
2087
2087
|
style: {
|
|
2088
2088
|
id: cssClass.id,
|
|
@@ -2108,7 +2108,7 @@ var GlobalClassesList = ({
|
|
|
2108
2108
|
} else if (newValue && onStartSyncRequest) {
|
|
2109
2109
|
onStartSyncRequest(id);
|
|
2110
2110
|
} else {
|
|
2111
|
-
|
|
2111
|
+
dispatch8(
|
|
2112
2112
|
slice.actions.update({
|
|
2113
2113
|
style: {
|
|
2114
2114
|
id,
|
|
@@ -2135,10 +2135,10 @@ var StyledHeader = (0, import_ui14.styled)(import_ui14.Typography)(({ theme, var
|
|
|
2135
2135
|
}
|
|
2136
2136
|
}));
|
|
2137
2137
|
var useReorder = (draggedItemId, setDraggedItemId, draggedItemLabel) => {
|
|
2138
|
-
const
|
|
2138
|
+
const dispatch8 = (0, import_store20.__useDispatch)();
|
|
2139
2139
|
const order = useClassesOrder();
|
|
2140
2140
|
const reorder = (newIds) => {
|
|
2141
|
-
|
|
2141
|
+
dispatch8(slice.actions.setOrder(newIds));
|
|
2142
2142
|
if (draggedItemId) {
|
|
2143
2143
|
trackGlobalClasses({
|
|
2144
2144
|
event: "classManagerReorder",
|
|
@@ -2650,9 +2650,9 @@ var initClassesResource = (classesMcpEntry, canvasMcpEntry) => {
|
|
|
2650
2650
|
var import_editor = require("@elementor/editor");
|
|
2651
2651
|
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
2652
2652
|
var import_editor_embedded_documents_manager = require("@elementor/editor-embedded-documents-manager");
|
|
2653
|
-
var
|
|
2653
|
+
var import_editor_mcp2 = require("@elementor/editor-mcp");
|
|
2654
2654
|
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
2655
|
-
var
|
|
2655
|
+
var import_store34 = require("@elementor/store");
|
|
2656
2656
|
|
|
2657
2657
|
// src/components/class-manager/class-manager-button.tsx
|
|
2658
2658
|
var React20 = __toESM(require("react"));
|
|
@@ -2755,7 +2755,7 @@ var import_react11 = require("react");
|
|
|
2755
2755
|
var import_editor_canvas = require("@elementor/editor-canvas");
|
|
2756
2756
|
var import_store28 = require("@elementor/store");
|
|
2757
2757
|
function GlobalStylesImportListener() {
|
|
2758
|
-
const
|
|
2758
|
+
const dispatch8 = (0, import_store28.__useDispatch)();
|
|
2759
2759
|
(0, import_react11.useEffect)(() => {
|
|
2760
2760
|
const handleGlobalStylesImported = async (event) => {
|
|
2761
2761
|
const customEvent = event;
|
|
@@ -2764,7 +2764,7 @@ function GlobalStylesImportListener() {
|
|
|
2764
2764
|
loadCurrentDocumentClasses();
|
|
2765
2765
|
return;
|
|
2766
2766
|
}
|
|
2767
|
-
|
|
2767
|
+
dispatch8(
|
|
2768
2768
|
slice.actions.updateAfterTemplateImport({
|
|
2769
2769
|
addedItems: globalClasses.added_items,
|
|
2770
2770
|
addedIdsOrder: globalClasses.added_items_order,
|
|
@@ -2776,7 +2776,7 @@ function GlobalStylesImportListener() {
|
|
|
2776
2776
|
return () => {
|
|
2777
2777
|
window.removeEventListener(import_editor_canvas.GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
|
|
2778
2778
|
};
|
|
2779
|
-
}, [
|
|
2779
|
+
}, [dispatch8]);
|
|
2780
2780
|
return null;
|
|
2781
2781
|
}
|
|
2782
2782
|
|
|
@@ -2793,9 +2793,67 @@ function PopulateStore() {
|
|
|
2793
2793
|
return null;
|
|
2794
2794
|
}
|
|
2795
2795
|
|
|
2796
|
+
// src/mcp-integration/manage-classes-tool.ts
|
|
2797
|
+
var import_http_client2 = require("@elementor/http-client");
|
|
2798
|
+
var import_schema = require("@elementor/schema");
|
|
2799
|
+
var import_store30 = require("@elementor/store");
|
|
2800
|
+
var MCP_PROXY_URL = "elementor/v1/mcp-proxy";
|
|
2801
|
+
var TOOL_NAME = "manage-classes";
|
|
2802
|
+
var initManageClassesTool = (reg) => {
|
|
2803
|
+
const { addTool } = reg;
|
|
2804
|
+
addTool({
|
|
2805
|
+
name: TOOL_NAME,
|
|
2806
|
+
description: "Manage V4 global CSS classes on the active kit. Create, update, or delete a single class using raw CSS declarations.",
|
|
2807
|
+
schema: {
|
|
2808
|
+
action: import_schema.z.enum(["create", "update", "delete"]),
|
|
2809
|
+
id: import_schema.z.string().optional().describe("Class id \u2014 required for update/delete. Get from the global-classes resource."),
|
|
2810
|
+
label: import_schema.z.string().optional().describe("Class label (lowercase, dash-separated) \u2014 required for create/update."),
|
|
2811
|
+
css: import_schema.z.record(import_schema.z.string()).optional().describe("Raw CSS declarations (property \u2192 value) \u2014 required for create/update.")
|
|
2812
|
+
},
|
|
2813
|
+
outputSchema: {
|
|
2814
|
+
status: import_schema.z.enum(["ok"]).describe("Operation status")
|
|
2815
|
+
},
|
|
2816
|
+
requiredResources: [
|
|
2817
|
+
{
|
|
2818
|
+
uri: GLOBAL_CLASSES_URI,
|
|
2819
|
+
description: "Current global classes \u2014 check before creating to avoid duplicates"
|
|
2820
|
+
}
|
|
2821
|
+
],
|
|
2822
|
+
isDestructive: true,
|
|
2823
|
+
handler: async (params) => {
|
|
2824
|
+
const { data } = await (0, import_http_client2.httpService)().post(MCP_PROXY_URL, {
|
|
2825
|
+
tool: TOOL_NAME,
|
|
2826
|
+
input: params
|
|
2827
|
+
});
|
|
2828
|
+
const payload = data.data;
|
|
2829
|
+
const { create, update, delete: del } = globalClassesStylesProvider.actions;
|
|
2830
|
+
switch (params.action) {
|
|
2831
|
+
case "create":
|
|
2832
|
+
if (payload.class && create) {
|
|
2833
|
+
create(payload.class.label, payload.class.variants, payload.class.id);
|
|
2834
|
+
}
|
|
2835
|
+
break;
|
|
2836
|
+
case "update":
|
|
2837
|
+
if (payload.class && update) {
|
|
2838
|
+
update(payload.class);
|
|
2839
|
+
}
|
|
2840
|
+
break;
|
|
2841
|
+
case "delete":
|
|
2842
|
+
if (params.id && del) {
|
|
2843
|
+
del(params.id);
|
|
2844
|
+
}
|
|
2845
|
+
break;
|
|
2846
|
+
}
|
|
2847
|
+
(0, import_store30.__dispatch)(slice.actions.reset({ context: "frontend" }));
|
|
2848
|
+
window.dispatchEvent(new CustomEvent("classes:updated", { detail: { context: "frontend" } }));
|
|
2849
|
+
return { status: "ok" };
|
|
2850
|
+
}
|
|
2851
|
+
});
|
|
2852
|
+
};
|
|
2853
|
+
|
|
2796
2854
|
// src/mcp-integration/mcp-apply-unapply-global-classes.ts
|
|
2797
2855
|
var import_editor_editing_panel = require("@elementor/editor-editing-panel");
|
|
2798
|
-
var
|
|
2856
|
+
var import_schema2 = require("@elementor/schema");
|
|
2799
2857
|
|
|
2800
2858
|
// src/mcp-integration/apply-global-class-guide-prompt.ts
|
|
2801
2859
|
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
@@ -2849,12 +2907,12 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2849
2907
|
);
|
|
2850
2908
|
addTool({
|
|
2851
2909
|
schema: {
|
|
2852
|
-
classId:
|
|
2853
|
-
elementId:
|
|
2910
|
+
classId: import_schema2.z.string().describe("The ID of the class to apply"),
|
|
2911
|
+
elementId: import_schema2.z.string().describe("The ID of the element to which the class will be applied")
|
|
2854
2912
|
},
|
|
2855
2913
|
outputSchema: {
|
|
2856
|
-
result:
|
|
2857
|
-
llm_instructions:
|
|
2914
|
+
result: import_schema2.z.string().describe("Result message indicating the success of the apply operation"),
|
|
2915
|
+
llm_instructions: import_schema2.z.string().describe("Instructions what to do next, Important to follow these instructions!")
|
|
2858
2916
|
},
|
|
2859
2917
|
name: "apply-global-class",
|
|
2860
2918
|
description: `Apply a global class to an element for shared design-system styling. Read the full guide at [${APPLY_GLOBAL_CLASS_GUIDE_URI}].`,
|
|
@@ -2880,11 +2938,11 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2880
2938
|
addTool({
|
|
2881
2939
|
name: "unapply-global-class",
|
|
2882
2940
|
schema: {
|
|
2883
|
-
classId:
|
|
2884
|
-
elementId:
|
|
2941
|
+
classId: import_schema2.z.string().describe("The ID of the class to unapply"),
|
|
2942
|
+
elementId: import_schema2.z.string().describe("The ID of the element from which the class will be unapplied")
|
|
2885
2943
|
},
|
|
2886
2944
|
outputSchema: {
|
|
2887
|
-
result:
|
|
2945
|
+
result: import_schema2.z.string().describe("Result message indicating the success of the unapply operation")
|
|
2888
2946
|
},
|
|
2889
2947
|
description: `Unapply a global class from an element by class ID. Resolve class names to IDs via [${GLOBAL_CLASSES_URI}].`,
|
|
2890
2948
|
requiredResources: [{ description: "Global classes list", uri: GLOBAL_CLASSES_URI }],
|
|
@@ -2902,21 +2960,21 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2902
2960
|
}
|
|
2903
2961
|
|
|
2904
2962
|
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2905
|
-
var
|
|
2963
|
+
var import_schema3 = require("@elementor/schema");
|
|
2906
2964
|
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2907
2965
|
const { addTool } = reg;
|
|
2908
2966
|
const globalClassesUsageSchema = {
|
|
2909
|
-
usages:
|
|
2910
|
-
|
|
2911
|
-
classId:
|
|
2967
|
+
usages: import_schema3.z.array(
|
|
2968
|
+
import_schema3.z.object({
|
|
2969
|
+
classId: import_schema3.z.string().describe(
|
|
2912
2970
|
'The ID of the class, not visible to the user. To retrieve the name of the class, use the "list-global-classes" tool'
|
|
2913
2971
|
),
|
|
2914
|
-
usages:
|
|
2915
|
-
|
|
2916
|
-
pageId:
|
|
2917
|
-
title:
|
|
2918
|
-
total:
|
|
2919
|
-
elements:
|
|
2972
|
+
usages: import_schema3.z.array(
|
|
2973
|
+
import_schema3.z.object({
|
|
2974
|
+
pageId: import_schema3.z.string().describe("The ID of the page where the class is used"),
|
|
2975
|
+
title: import_schema3.z.string().describe("The title of the page where the class is used"),
|
|
2976
|
+
total: import_schema3.z.number().describe("The number of times the class is used on this page"),
|
|
2977
|
+
elements: import_schema3.z.array(import_schema3.z.string()).describe("List of element IDs using this class on the page")
|
|
2920
2978
|
})
|
|
2921
2979
|
)
|
|
2922
2980
|
})
|
|
@@ -2964,270 +3022,11 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2964
3022
|
});
|
|
2965
3023
|
}
|
|
2966
3024
|
|
|
2967
|
-
// src/mcp-integration/mcp-manage-global-classes.ts
|
|
2968
|
-
var import_editor_canvas2 = require("@elementor/editor-canvas");
|
|
2969
|
-
var import_editor_mcp2 = require("@elementor/editor-mcp");
|
|
2970
|
-
var import_schema3 = require("@elementor/schema");
|
|
2971
|
-
var schema = {
|
|
2972
|
-
action: import_schema3.z.enum(["create", "modify", "delete"]).describe("Operation to perform"),
|
|
2973
|
-
classId: import_schema3.z.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
|
|
2974
|
-
globalClassName: import_schema3.z.string().optional().describe("Global class name (required for create)"),
|
|
2975
|
-
style: import_schema3.z.object({
|
|
2976
|
-
default: import_schema3.z.string().describe("Plaintext CSS for the default state. MUST be non-empty \u2014 blank strings are rejected."),
|
|
2977
|
-
hover: import_schema3.z.string().describe("Plaintext CSS for the :hover state. optional").optional(),
|
|
2978
|
-
focus: import_schema3.z.string().describe("Plaintext CSS for the :focus state. optional").optional(),
|
|
2979
|
-
active: import_schema3.z.string().describe("Plaintext CSS for the :active state. optional").optional()
|
|
2980
|
-
}).describe(
|
|
2981
|
-
"Plaintext CSS per pseudo-state. All states are converted in one bulk request; unconvertible declarations are stored as custom CSS."
|
|
2982
|
-
),
|
|
2983
|
-
breakpoint: import_schema3.z.nullable(import_schema3.z.string().describe("Responsive breakpoint name for styles. Defaults to desktop (null).")).default(null).describe("Responsive breakpoint name for styles. Defaults to desktop (null).")
|
|
2984
|
-
};
|
|
2985
|
-
var outputSchema = {
|
|
2986
|
-
status: import_schema3.z.enum(["ok", "error"]).describe("Operation status"),
|
|
2987
|
-
classId: import_schema3.z.string().optional().describe("Class ID (returned on create success)"),
|
|
2988
|
-
message: import_schema3.z.string().optional().describe("Error details if status is error")
|
|
2989
|
-
};
|
|
2990
|
-
var handler = async (input) => {
|
|
2991
|
-
const { action, classId: rawClassId, globalClassName, style: rawStyle, breakpoint } = input;
|
|
2992
|
-
let classId = rawClassId;
|
|
2993
|
-
if (action === "create" && !globalClassName) {
|
|
2994
|
-
return {
|
|
2995
|
-
status: "error",
|
|
2996
|
-
message: "Create requires globalClassName"
|
|
2997
|
-
};
|
|
2998
|
-
}
|
|
2999
|
-
if (action === "modify" && !classId) {
|
|
3000
|
-
return {
|
|
3001
|
-
status: "error",
|
|
3002
|
-
message: "Modify requires classId"
|
|
3003
|
-
};
|
|
3004
|
-
}
|
|
3005
|
-
if (action === "delete" && !classId) {
|
|
3006
|
-
return {
|
|
3007
|
-
status: "error",
|
|
3008
|
-
message: "Delete requires classId"
|
|
3009
|
-
};
|
|
3010
|
-
}
|
|
3011
|
-
const { create, update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
|
|
3012
|
-
if (!create || !update || !deleteClass2) {
|
|
3013
|
-
return {
|
|
3014
|
-
status: "error",
|
|
3015
|
-
message: "Required actions not available"
|
|
3016
|
-
};
|
|
3017
|
-
}
|
|
3018
|
-
const styleBlocks = collectNonEmptyStyleBlocks(rawStyle);
|
|
3019
|
-
if (action !== "delete" && Object.keys(styleBlocks).length === 0) {
|
|
3020
|
-
throw new Error(
|
|
3021
|
-
'Style must not be empty. Provide plaintext CSS per state.\n\nExample: style.default = "display: flex; flex-direction: column; gap: 1rem;"'
|
|
3022
|
-
);
|
|
3023
|
-
}
|
|
3024
|
-
let convertedByState = {};
|
|
3025
|
-
if (action !== "delete") {
|
|
3026
|
-
const conversionResults = await (0, import_editor_canvas2.convertStyleBlocksToAtomic)(styleBlocks);
|
|
3027
|
-
convertedByState = Object.fromEntries(
|
|
3028
|
-
Object.entries(conversionResults).map(([state, { props, customCss }]) => [
|
|
3029
|
-
state,
|
|
3030
|
-
{ props, customCss: toStoredCustomCss(customCss) }
|
|
3031
|
-
])
|
|
3032
|
-
);
|
|
3033
|
-
}
|
|
3034
|
-
const breakpointValue = breakpoint ?? "desktop";
|
|
3035
|
-
let result = {
|
|
3036
|
-
status: "error",
|
|
3037
|
-
classId: "",
|
|
3038
|
-
message: "unknown error"
|
|
3039
|
-
};
|
|
3040
|
-
try {
|
|
3041
|
-
if (action === "delete") {
|
|
3042
|
-
const deleted = await attemptDelete({
|
|
3043
|
-
classId,
|
|
3044
|
-
stylesProvider: globalClassesStylesProvider
|
|
3045
|
-
});
|
|
3046
|
-
if (deleted) {
|
|
3047
|
-
return { status: "ok", message: `deleted global class with ID ${classId}` };
|
|
3048
|
-
}
|
|
3049
|
-
throw new Error("error deleting class");
|
|
3050
|
-
}
|
|
3051
|
-
let currentAction = action;
|
|
3052
|
-
for await (const [state, { props, customCss }] of Object.entries(convertedByState)) {
|
|
3053
|
-
switch (currentAction) {
|
|
3054
|
-
case "create":
|
|
3055
|
-
const newClassId = await attemptCreate({
|
|
3056
|
-
props,
|
|
3057
|
-
customCss,
|
|
3058
|
-
className: globalClassName,
|
|
3059
|
-
stylesProvider: globalClassesStylesProvider,
|
|
3060
|
-
breakpoint: breakpointValue,
|
|
3061
|
-
state
|
|
3062
|
-
});
|
|
3063
|
-
if (newClassId && currentAction === "create") {
|
|
3064
|
-
currentAction = "modify";
|
|
3065
|
-
classId = newClassId;
|
|
3066
|
-
result = {
|
|
3067
|
-
status: "ok",
|
|
3068
|
-
message: `created global class with ID ${newClassId}`
|
|
3069
|
-
};
|
|
3070
|
-
globalClassesStylesProvider.actions.tracking?.({
|
|
3071
|
-
event: "classCreated",
|
|
3072
|
-
executedBy: "mcp_tool",
|
|
3073
|
-
classId: newClassId
|
|
3074
|
-
});
|
|
3075
|
-
(0, import_editor_mcp2.dispatchMcpStylesAppliedEvent)({ styleValue: props });
|
|
3076
|
-
} else {
|
|
3077
|
-
throw new Error("error creating class");
|
|
3078
|
-
}
|
|
3079
|
-
break;
|
|
3080
|
-
case "modify":
|
|
3081
|
-
const updated = await attemptUpdate({
|
|
3082
|
-
classId,
|
|
3083
|
-
props,
|
|
3084
|
-
customCss,
|
|
3085
|
-
stylesProvider: globalClassesStylesProvider,
|
|
3086
|
-
breakpoint: breakpointValue,
|
|
3087
|
-
state
|
|
3088
|
-
});
|
|
3089
|
-
if (updated) {
|
|
3090
|
-
result = { status: "ok", classId };
|
|
3091
|
-
(0, import_editor_mcp2.dispatchMcpStylesAppliedEvent)({ styleValue: props });
|
|
3092
|
-
} else {
|
|
3093
|
-
throw new Error("error modifying class");
|
|
3094
|
-
}
|
|
3095
|
-
break;
|
|
3096
|
-
default:
|
|
3097
|
-
throw new Error(`Unsupported action ${action}`);
|
|
3098
|
-
}
|
|
3099
|
-
}
|
|
3100
|
-
} catch (error) {
|
|
3101
|
-
return {
|
|
3102
|
-
status: "error",
|
|
3103
|
-
message: `${action} failed: ${error.message || "Unknown error"}`
|
|
3104
|
-
};
|
|
3105
|
-
}
|
|
3106
|
-
return result;
|
|
3107
|
-
};
|
|
3108
|
-
var initManageGlobalClasses = (reg) => {
|
|
3109
|
-
const { addTool } = reg;
|
|
3110
|
-
addTool({
|
|
3111
|
-
name: "manage-global-classes",
|
|
3112
|
-
requiredResources: [
|
|
3113
|
-
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
3114
|
-
{ uri: import_editor_canvas2.BREAKPOINTS_SCHEMA_FULL_URI, description: "Breakpoints list" }
|
|
3115
|
-
],
|
|
3116
|
-
description: `Create or modify global classes for reusable design-system styling. Class names must reflect purpose (e.g. heading-primary, button-cta). Create classes BEFORE applying them. Do NOT create classes for one-off styles.
|
|
3117
|
-
|
|
3118
|
-
IMPORTANT: style must contain plaintext CSS rules per state \u2014 never pass empty strings.
|
|
3119
|
-
CSS is converted server-side in one bulk request; any declaration that cannot be converted is stored as the class custom CSS.
|
|
3120
|
-
|
|
3121
|
-
Example \u2014 creating a flex column class:
|
|
3122
|
-
style.default = "display: flex; flex-direction: column; gap: 1rem;"
|
|
3123
|
-
|
|
3124
|
-
Example \u2014 hover state:
|
|
3125
|
-
style.hover = "opacity: 0.85;"`,
|
|
3126
|
-
schema,
|
|
3127
|
-
outputSchema,
|
|
3128
|
-
handler
|
|
3129
|
-
});
|
|
3130
|
-
};
|
|
3131
|
-
async function attemptCreate(opts) {
|
|
3132
|
-
const { props, customCss, breakpoint, className, stylesProvider, state } = opts;
|
|
3133
|
-
const { create, delete: deleteClass2 } = stylesProvider.actions;
|
|
3134
|
-
if (!className) {
|
|
3135
|
-
throw new Error("Global class name is a required for creation");
|
|
3136
|
-
}
|
|
3137
|
-
if (!create || !deleteClass2) {
|
|
3138
|
-
throw new Error("User is unable to create global classes");
|
|
3139
|
-
}
|
|
3140
|
-
const newClassId = create(className, [
|
|
3141
|
-
{
|
|
3142
|
-
meta: {
|
|
3143
|
-
breakpoint,
|
|
3144
|
-
state: state === "default" ? null : state
|
|
3145
|
-
},
|
|
3146
|
-
custom_css: customCss,
|
|
3147
|
-
props
|
|
3148
|
-
}
|
|
3149
|
-
]);
|
|
3150
|
-
try {
|
|
3151
|
-
await saveGlobalClasses2({ context: "frontend" });
|
|
3152
|
-
return newClassId;
|
|
3153
|
-
} catch {
|
|
3154
|
-
deleteClass2(newClassId);
|
|
3155
|
-
throw new Error("error creating class");
|
|
3156
|
-
}
|
|
3157
|
-
}
|
|
3158
|
-
async function attemptUpdate(opts) {
|
|
3159
|
-
const { props, customCss, breakpoint, classId, stylesProvider, state } = opts;
|
|
3160
|
-
const { updateProps, update } = stylesProvider.actions;
|
|
3161
|
-
if (!classId) {
|
|
3162
|
-
throw new Error("Class ID is required for modification");
|
|
3163
|
-
}
|
|
3164
|
-
if (!updateProps || !update) {
|
|
3165
|
-
throw new Error("User is unable to update global classes");
|
|
3166
|
-
}
|
|
3167
|
-
await loadExistingClasses([classId]);
|
|
3168
|
-
const snapshot = structuredClone(stylesProvider.actions.all());
|
|
3169
|
-
try {
|
|
3170
|
-
updateProps({
|
|
3171
|
-
id: classId,
|
|
3172
|
-
props,
|
|
3173
|
-
custom_css: customCss,
|
|
3174
|
-
meta: {
|
|
3175
|
-
breakpoint,
|
|
3176
|
-
state: state === "default" ? null : state
|
|
3177
|
-
}
|
|
3178
|
-
});
|
|
3179
|
-
await saveGlobalClasses2({ context: "frontend" });
|
|
3180
|
-
return true;
|
|
3181
|
-
} catch {
|
|
3182
|
-
snapshot.forEach((style) => {
|
|
3183
|
-
update({
|
|
3184
|
-
id: style.id,
|
|
3185
|
-
variants: style.variants
|
|
3186
|
-
});
|
|
3187
|
-
});
|
|
3188
|
-
await saveGlobalClasses2({ context: "frontend" });
|
|
3189
|
-
throw new Error("error updating class");
|
|
3190
|
-
}
|
|
3191
|
-
}
|
|
3192
|
-
async function attemptDelete(opts) {
|
|
3193
|
-
const { classId, stylesProvider } = opts;
|
|
3194
|
-
const { delete: deleteClass2, create } = stylesProvider.actions;
|
|
3195
|
-
if (!classId) {
|
|
3196
|
-
throw new Error("Class ID is required for deletion");
|
|
3197
|
-
}
|
|
3198
|
-
if (!deleteClass2 || !create) {
|
|
3199
|
-
throw new Error("User is unable to delete global classes");
|
|
3200
|
-
}
|
|
3201
|
-
const snapshot = structuredClone(stylesProvider.actions.all());
|
|
3202
|
-
const targetClass = snapshot.find((style) => style.id === classId);
|
|
3203
|
-
if (!targetClass) {
|
|
3204
|
-
throw new Error(`Class with ID "${classId}" not found`);
|
|
3205
|
-
}
|
|
3206
|
-
deleteClass2(classId);
|
|
3207
|
-
await saveGlobalClasses2({ context: "frontend" });
|
|
3208
|
-
return true;
|
|
3209
|
-
}
|
|
3210
|
-
function collectNonEmptyStyleBlocks(style) {
|
|
3211
|
-
const blocks = {};
|
|
3212
|
-
Object.entries(style).forEach(([state, cssText]) => {
|
|
3213
|
-
if (cssText?.trim()) {
|
|
3214
|
-
blocks[state] = cssText.trim();
|
|
3215
|
-
}
|
|
3216
|
-
});
|
|
3217
|
-
return blocks;
|
|
3218
|
-
}
|
|
3219
|
-
function toStoredCustomCss(customCss) {
|
|
3220
|
-
if (!customCss?.trim()) {
|
|
3221
|
-
return null;
|
|
3222
|
-
}
|
|
3223
|
-
return { raw: btoa(customCss) };
|
|
3224
|
-
}
|
|
3225
|
-
|
|
3226
3025
|
// src/mcp-integration/index.ts
|
|
3227
3026
|
var initMcpIntegration = (reg, canvasMcpEntry) => {
|
|
3228
3027
|
initMcpApplyUnapplyGlobalClasses(reg);
|
|
3229
3028
|
initMcpApplyGetGlobalClassUsages(reg);
|
|
3230
|
-
|
|
3029
|
+
initManageClassesTool(reg);
|
|
3231
3030
|
initClassesResource(reg, canvasMcpEntry);
|
|
3232
3031
|
};
|
|
3233
3032
|
|
|
@@ -3239,7 +3038,7 @@ var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
|
3239
3038
|
var import_editor_current_user3 = require("@elementor/editor-current-user");
|
|
3240
3039
|
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
3241
3040
|
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
3242
|
-
var
|
|
3041
|
+
var import_store32 = require("@elementor/store");
|
|
3243
3042
|
var pendingSave = null;
|
|
3244
3043
|
function syncWithDocumentSave(panelActions) {
|
|
3245
3044
|
const unsubscribe = syncDirtyState();
|
|
@@ -3248,7 +3047,7 @@ function syncWithDocumentSave(panelActions) {
|
|
|
3248
3047
|
return unsubscribe;
|
|
3249
3048
|
}
|
|
3250
3049
|
function syncDirtyState() {
|
|
3251
|
-
return (0,
|
|
3050
|
+
return (0, import_store32.__subscribeWithSelector)(selectIsDirty, () => {
|
|
3252
3051
|
if (!isDirty()) {
|
|
3253
3052
|
return;
|
|
3254
3053
|
}
|
|
@@ -3291,7 +3090,7 @@ function bindBeforeSaveTemplateAction() {
|
|
|
3291
3090
|
}));
|
|
3292
3091
|
}
|
|
3293
3092
|
function isDirty() {
|
|
3294
|
-
return selectIsDirty((0,
|
|
3093
|
+
return selectIsDirty((0, import_store32.__getState)());
|
|
3295
3094
|
}
|
|
3296
3095
|
|
|
3297
3096
|
// src/sync-with-document.tsx
|
|
@@ -3310,7 +3109,7 @@ function SyncWithDocumentSave() {
|
|
|
3310
3109
|
|
|
3311
3110
|
// src/init.ts
|
|
3312
3111
|
function init() {
|
|
3313
|
-
(0,
|
|
3112
|
+
(0, import_store34.__registerSlice)(slice);
|
|
3314
3113
|
import_editor_embedded_documents_manager.embeddedDocumentsManager.onDocumentLoad((documentId) => {
|
|
3315
3114
|
void addDocumentClasses(documentId);
|
|
3316
3115
|
});
|
|
@@ -3344,7 +3143,7 @@ function init() {
|
|
|
3344
3143
|
getThemeColor: (theme) => theme.palette.global.dark
|
|
3345
3144
|
});
|
|
3346
3145
|
initMcpIntegration(
|
|
3347
|
-
(0,
|
|
3146
|
+
(0, import_editor_mcp2.getMCPByDomain)("classes", {
|
|
3348
3147
|
instructions: "MCP server for management of Elementor global classes",
|
|
3349
3148
|
docs: `Everything related to V4 ( Atomic ) global classes.
|
|
3350
3149
|
# Global classes
|
|
@@ -3353,7 +3152,7 @@ function init() {
|
|
|
3353
3152
|
- Get details of a global class
|
|
3354
3153
|
`
|
|
3355
3154
|
}),
|
|
3356
|
-
(0,
|
|
3155
|
+
(0, import_editor_mcp2.getMCPByDomain)("canvas")
|
|
3357
3156
|
);
|
|
3358
3157
|
}
|
|
3359
3158
|
// Annotate the CommonJS export names for ESM import in node:
|