@elementor/editor-global-classes 3.33.0-172 → 3.33.0-174
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 +174 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -15
- package/src/init.ts +3 -0
- package/src/mcp-integration/index.ts +13 -0
- package/src/mcp-integration/mcp-apply-unapply-global-classes.ts +92 -0
- package/src/mcp-integration/mcp-get-global-class-usages.ts +72 -0
package/dist/index.js
CHANGED
|
@@ -36,9 +36,9 @@ module.exports = __toCommonJS(index_exports);
|
|
|
36
36
|
|
|
37
37
|
// src/init.ts
|
|
38
38
|
var import_editor = require("@elementor/editor");
|
|
39
|
-
var
|
|
39
|
+
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
40
40
|
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
41
|
-
var
|
|
41
|
+
var import_editor_styles_repository6 = require("@elementor/editor-styles-repository");
|
|
42
42
|
var import_store24 = require("@elementor/store");
|
|
43
43
|
|
|
44
44
|
// src/components/class-manager/class-manager-button.tsx
|
|
@@ -2038,6 +2038,173 @@ function PopulateStore() {
|
|
|
2038
2038
|
return null;
|
|
2039
2039
|
}
|
|
2040
2040
|
|
|
2041
|
+
// src/mcp-integration/index.ts
|
|
2042
|
+
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
2043
|
+
|
|
2044
|
+
// src/mcp-integration/mcp-apply-unapply-global-classes.ts
|
|
2045
|
+
var import_editor_editing_panel = require("@elementor/editor-editing-panel");
|
|
2046
|
+
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
2047
|
+
var import_schema = require("@elementor/schema");
|
|
2048
|
+
function initMcpApplyUnapplyGlobalClasses(server) {
|
|
2049
|
+
server.addTool({
|
|
2050
|
+
name: "list-all-global-classes",
|
|
2051
|
+
description: `List all classes applied to a specific element
|
|
2052
|
+
|
|
2053
|
+
## When to use this tool:
|
|
2054
|
+
- When a user requests to see which classes or global classes exists.
|
|
2055
|
+
- When you need the list of global classes to allow the user to select from.
|
|
2056
|
+
|
|
2057
|
+
## Prerequisites:
|
|
2058
|
+
- Ensure you have the correct element ID for which you want to list the applied classes.
|
|
2059
|
+
`,
|
|
2060
|
+
outputSchema: {
|
|
2061
|
+
appliedClasses: import_schema.z.array(
|
|
2062
|
+
import_schema.z.object({
|
|
2063
|
+
id: import_schema.z.string().describe("The ID of the class"),
|
|
2064
|
+
label: import_schema.z.string().describe("The label of the class")
|
|
2065
|
+
})
|
|
2066
|
+
)
|
|
2067
|
+
},
|
|
2068
|
+
handler: async () => {
|
|
2069
|
+
const globalClassesProvider = import_editor_styles_repository5.stylesRepository.getProviderByKey("global-classes");
|
|
2070
|
+
if (!globalClassesProvider) {
|
|
2071
|
+
throw new Error("Global classes provider not found");
|
|
2072
|
+
}
|
|
2073
|
+
const result = [];
|
|
2074
|
+
globalClassesProvider.actions.all().forEach((style) => {
|
|
2075
|
+
const { id: id2, label } = style;
|
|
2076
|
+
result.push({ id: id2, label });
|
|
2077
|
+
});
|
|
2078
|
+
return { appliedClasses: result };
|
|
2079
|
+
}
|
|
2080
|
+
});
|
|
2081
|
+
server.addTool({
|
|
2082
|
+
schema: {
|
|
2083
|
+
classId: import_schema.z.string().describe("The ID of the class to apply"),
|
|
2084
|
+
elementId: import_schema.z.string().describe("The ID of the element to which the class will be applied")
|
|
2085
|
+
},
|
|
2086
|
+
name: "apply-global-class",
|
|
2087
|
+
description: `Apply a global class to the current element
|
|
2088
|
+
|
|
2089
|
+
## When to use this tool:
|
|
2090
|
+
- When a user requests to apply a global class or a class to an element in the Elementor editor.
|
|
2091
|
+
- When you need to add a specific class to an element's applied classes.
|
|
2092
|
+
|
|
2093
|
+
## Prerequisites:
|
|
2094
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates. You can use the "list-applied-classes" tool to fetch the current classes.
|
|
2095
|
+
- Make sure you have the correct class ID that you want to apply.`,
|
|
2096
|
+
handler: async (params) => {
|
|
2097
|
+
const { classId, elementId } = params;
|
|
2098
|
+
const appliedClasses = (0, import_editor_editing_panel.doGetAppliedClasses)(elementId);
|
|
2099
|
+
(0, import_editor_editing_panel.doApplyClasses)(elementId, [...appliedClasses, classId]);
|
|
2100
|
+
return `Class ${classId} applied to element ${elementId} successfully.`;
|
|
2101
|
+
}
|
|
2102
|
+
});
|
|
2103
|
+
server.addTool({
|
|
2104
|
+
name: "unapply-global-class",
|
|
2105
|
+
schema: {
|
|
2106
|
+
classId: import_schema.z.string().describe("The ID of the class to unapply"),
|
|
2107
|
+
elementId: import_schema.z.string().describe("The ID of the element from which the class will be unapplied")
|
|
2108
|
+
},
|
|
2109
|
+
description: `Unapply a (global) class from the current element
|
|
2110
|
+
|
|
2111
|
+
## When to use this tool:
|
|
2112
|
+
- When a user requests to unapply a global class or a class from an element in the Elementor editor.
|
|
2113
|
+
- When you need to remove a specific class from an element's applied classes.
|
|
2114
|
+
|
|
2115
|
+
## Prerequisites:
|
|
2116
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid errors. You can use the "list-global-classes" tool to fetch the all classes applied to all elements.
|
|
2117
|
+
- Make sure you have the correct class ID that you want to unapply.
|
|
2118
|
+
|
|
2119
|
+
<note>
|
|
2120
|
+
If the user want to unapply a class by it's name and not ID, please use the "list-global-classes" tool to get the class ID from the name first.
|
|
2121
|
+
</note>
|
|
2122
|
+
`,
|
|
2123
|
+
handler: async (params) => {
|
|
2124
|
+
const { classId, elementId } = params;
|
|
2125
|
+
const ok = (0, import_editor_editing_panel.doUnapplyClass)(elementId, classId);
|
|
2126
|
+
if (!ok) {
|
|
2127
|
+
throw new Error(`Class ${classId} is not applied to element ${elementId}, cannot unapply it.`);
|
|
2128
|
+
}
|
|
2129
|
+
return `Class ${classId} unapplied from element ${elementId} successfully.`;
|
|
2130
|
+
}
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2135
|
+
var import_schema2 = require("@elementor/schema");
|
|
2136
|
+
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2137
|
+
const { addTool } = reg;
|
|
2138
|
+
const globalClassesUsageSchema = {
|
|
2139
|
+
usages: import_schema2.z.array(
|
|
2140
|
+
import_schema2.z.object({
|
|
2141
|
+
classId: import_schema2.z.string().describe(
|
|
2142
|
+
'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
|
|
2143
|
+
),
|
|
2144
|
+
usages: import_schema2.z.array(
|
|
2145
|
+
import_schema2.z.object({
|
|
2146
|
+
pageId: import_schema2.z.string().describe("The ID of the page where the class is used"),
|
|
2147
|
+
title: import_schema2.z.string().describe("The title of the page where the class is used"),
|
|
2148
|
+
total: import_schema2.z.number().describe("The number of times the class is used on this page"),
|
|
2149
|
+
elements: import_schema2.z.array(import_schema2.z.string()).describe("List of element IDs using this class on the page")
|
|
2150
|
+
})
|
|
2151
|
+
)
|
|
2152
|
+
})
|
|
2153
|
+
)
|
|
2154
|
+
};
|
|
2155
|
+
addTool({
|
|
2156
|
+
name: "get-global-class-usages",
|
|
2157
|
+
description: `Retreive the usage details of global classes within the Elementor editor, accross all pages.
|
|
2158
|
+
|
|
2159
|
+
## Prequisites:
|
|
2160
|
+
- Use "list-global-classes" tool to be able to match class IDs to class names/labels.
|
|
2161
|
+
|
|
2162
|
+
## When to use this tool:
|
|
2163
|
+
- When a user requests to see where a specific global class is being used accross the site.
|
|
2164
|
+
- When you need to manage or clean up unused global classes.
|
|
2165
|
+
- Before deleting a global class, to ensure it is not in use in any other pages.
|
|
2166
|
+
`,
|
|
2167
|
+
outputSchema: globalClassesUsageSchema,
|
|
2168
|
+
handler: async () => {
|
|
2169
|
+
const data = await fetchCssClassUsage();
|
|
2170
|
+
const result = {
|
|
2171
|
+
usages: []
|
|
2172
|
+
};
|
|
2173
|
+
Object.entries(data).forEach(
|
|
2174
|
+
([classId, usageDetails]) => {
|
|
2175
|
+
const newEntry = {
|
|
2176
|
+
classId,
|
|
2177
|
+
usages: []
|
|
2178
|
+
};
|
|
2179
|
+
if (typeof usageDetails !== "number") {
|
|
2180
|
+
const { content } = usageDetails;
|
|
2181
|
+
content.forEach((detail) => {
|
|
2182
|
+
newEntry.usages.push({
|
|
2183
|
+
pageId: String(detail.pageId),
|
|
2184
|
+
title: detail.title,
|
|
2185
|
+
total: detail.total,
|
|
2186
|
+
elements: detail.elements
|
|
2187
|
+
});
|
|
2188
|
+
});
|
|
2189
|
+
result.usages.push(newEntry);
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
);
|
|
2193
|
+
return result;
|
|
2194
|
+
}
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2198
|
+
// src/mcp-integration/index.ts
|
|
2199
|
+
var initMcpIntegration = () => {
|
|
2200
|
+
const reg = (0, import_editor_mcp.getMCPByDomain)("element_classes");
|
|
2201
|
+
reg.setMCPDescription(
|
|
2202
|
+
"Tools for managing and applying Global CSS classes to elements within the Elementor editor."
|
|
2203
|
+
);
|
|
2204
|
+
initMcpApplyUnapplyGlobalClasses(reg);
|
|
2205
|
+
initMcpApplyGetGlobalClassUsages(reg);
|
|
2206
|
+
};
|
|
2207
|
+
|
|
2041
2208
|
// src/sync-with-document.tsx
|
|
2042
2209
|
var import_react10 = require("react");
|
|
2043
2210
|
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
@@ -2092,7 +2259,7 @@ function SyncWithDocumentSave() {
|
|
|
2092
2259
|
function init() {
|
|
2093
2260
|
(0, import_store24.__registerSlice)(slice);
|
|
2094
2261
|
(0, import_editor_panels2.__registerPanel)(panel);
|
|
2095
|
-
|
|
2262
|
+
import_editor_styles_repository6.stylesRepository.register(globalClassesStylesProvider);
|
|
2096
2263
|
(0, import_editor.injectIntoLogic)({
|
|
2097
2264
|
id: "global-classes-populate-store",
|
|
2098
2265
|
component: PopulateStore
|
|
@@ -2101,18 +2268,19 @@ function init() {
|
|
|
2101
2268
|
id: "global-classes-sync-with-document",
|
|
2102
2269
|
component: SyncWithDocumentSave
|
|
2103
2270
|
});
|
|
2104
|
-
(0,
|
|
2271
|
+
(0, import_editor_editing_panel2.injectIntoCssClassConvert)({
|
|
2105
2272
|
id: "global-classes-convert-from-local-class",
|
|
2106
2273
|
component: ConvertLocalClassToGlobalClass
|
|
2107
2274
|
});
|
|
2108
|
-
(0,
|
|
2275
|
+
(0, import_editor_editing_panel2.injectIntoClassSelectorActions)({
|
|
2109
2276
|
id: "global-classes-manager-button",
|
|
2110
2277
|
component: ClassManagerButton
|
|
2111
2278
|
});
|
|
2112
|
-
(0,
|
|
2279
|
+
(0, import_editor_editing_panel2.registerStyleProviderToColors)(GLOBAL_CLASSES_PROVIDER_KEY, {
|
|
2113
2280
|
name: "global",
|
|
2114
2281
|
getThemeColor: (theme) => theme.palette.global.dark
|
|
2115
2282
|
});
|
|
2283
|
+
initMcpIntegration();
|
|
2116
2284
|
}
|
|
2117
2285
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2118
2286
|
0 && (module.exports = {
|