@elementor/editor-global-classes 3.33.0-171 → 3.33.0-173
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.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
registerStyleProviderToColors
|
|
7
7
|
} from "@elementor/editor-editing-panel";
|
|
8
8
|
import { __registerPanel as registerPanel } from "@elementor/editor-panels";
|
|
9
|
-
import { stylesRepository } from "@elementor/editor-styles-repository";
|
|
9
|
+
import { stylesRepository as stylesRepository2 } from "@elementor/editor-styles-repository";
|
|
10
10
|
import { __registerSlice as registerSlice } from "@elementor/store";
|
|
11
11
|
|
|
12
12
|
// src/components/class-manager/class-manager-button.tsx
|
|
@@ -2094,6 +2094,173 @@ function PopulateStore() {
|
|
|
2094
2094
|
return null;
|
|
2095
2095
|
}
|
|
2096
2096
|
|
|
2097
|
+
// src/mcp-integration/index.ts
|
|
2098
|
+
import { getMCPByDomain } from "@elementor/editor-mcp";
|
|
2099
|
+
|
|
2100
|
+
// src/mcp-integration/mcp-apply-unapply-global-classes.ts
|
|
2101
|
+
import { doApplyClasses, doGetAppliedClasses, doUnapplyClass } from "@elementor/editor-editing-panel";
|
|
2102
|
+
import { stylesRepository } from "@elementor/editor-styles-repository";
|
|
2103
|
+
import { z } from "@elementor/schema";
|
|
2104
|
+
function initMcpApplyUnapplyGlobalClasses(server) {
|
|
2105
|
+
server.addTool({
|
|
2106
|
+
name: "list-all-global-classes",
|
|
2107
|
+
description: `List all classes applied to a specific element
|
|
2108
|
+
|
|
2109
|
+
## When to use this tool:
|
|
2110
|
+
- When a user requests to see which classes or global classes exists.
|
|
2111
|
+
- When you need the list of global classes to allow the user to select from.
|
|
2112
|
+
|
|
2113
|
+
## Prerequisites:
|
|
2114
|
+
- Ensure you have the correct element ID for which you want to list the applied classes.
|
|
2115
|
+
`,
|
|
2116
|
+
outputSchema: {
|
|
2117
|
+
appliedClasses: z.array(
|
|
2118
|
+
z.object({
|
|
2119
|
+
id: z.string().describe("The ID of the class"),
|
|
2120
|
+
label: z.string().describe("The label of the class")
|
|
2121
|
+
})
|
|
2122
|
+
)
|
|
2123
|
+
},
|
|
2124
|
+
handler: async () => {
|
|
2125
|
+
const globalClassesProvider = stylesRepository.getProviderByKey("global-classes");
|
|
2126
|
+
if (!globalClassesProvider) {
|
|
2127
|
+
throw new Error("Global classes provider not found");
|
|
2128
|
+
}
|
|
2129
|
+
const result = [];
|
|
2130
|
+
globalClassesProvider.actions.all().forEach((style) => {
|
|
2131
|
+
const { id: id2, label } = style;
|
|
2132
|
+
result.push({ id: id2, label });
|
|
2133
|
+
});
|
|
2134
|
+
return { appliedClasses: result };
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
server.addTool({
|
|
2138
|
+
schema: {
|
|
2139
|
+
classId: z.string().describe("The ID of the class to apply"),
|
|
2140
|
+
elementId: z.string().describe("The ID of the element to which the class will be applied")
|
|
2141
|
+
},
|
|
2142
|
+
name: "apply-global-class",
|
|
2143
|
+
description: `Apply a global class to the current element
|
|
2144
|
+
|
|
2145
|
+
## When to use this tool:
|
|
2146
|
+
- When a user requests to apply a global class or a class to an element in the Elementor editor.
|
|
2147
|
+
- When you need to add a specific class to an element's applied classes.
|
|
2148
|
+
|
|
2149
|
+
## Prerequisites:
|
|
2150
|
+
- 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.
|
|
2151
|
+
- Make sure you have the correct class ID that you want to apply.`,
|
|
2152
|
+
handler: async (params) => {
|
|
2153
|
+
const { classId, elementId } = params;
|
|
2154
|
+
const appliedClasses = doGetAppliedClasses(elementId);
|
|
2155
|
+
doApplyClasses(elementId, [...appliedClasses, classId]);
|
|
2156
|
+
return `Class ${classId} applied to element ${elementId} successfully.`;
|
|
2157
|
+
}
|
|
2158
|
+
});
|
|
2159
|
+
server.addTool({
|
|
2160
|
+
name: "unapply-global-class",
|
|
2161
|
+
schema: {
|
|
2162
|
+
classId: z.string().describe("The ID of the class to unapply"),
|
|
2163
|
+
elementId: z.string().describe("The ID of the element from which the class will be unapplied")
|
|
2164
|
+
},
|
|
2165
|
+
description: `Unapply a (global) class from the current element
|
|
2166
|
+
|
|
2167
|
+
## When to use this tool:
|
|
2168
|
+
- When a user requests to unapply a global class or a class from an element in the Elementor editor.
|
|
2169
|
+
- When you need to remove a specific class from an element's applied classes.
|
|
2170
|
+
|
|
2171
|
+
## Prerequisites:
|
|
2172
|
+
- 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.
|
|
2173
|
+
- Make sure you have the correct class ID that you want to unapply.
|
|
2174
|
+
|
|
2175
|
+
<note>
|
|
2176
|
+
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.
|
|
2177
|
+
</note>
|
|
2178
|
+
`,
|
|
2179
|
+
handler: async (params) => {
|
|
2180
|
+
const { classId, elementId } = params;
|
|
2181
|
+
const ok = doUnapplyClass(elementId, classId);
|
|
2182
|
+
if (!ok) {
|
|
2183
|
+
throw new Error(`Class ${classId} is not applied to element ${elementId}, cannot unapply it.`);
|
|
2184
|
+
}
|
|
2185
|
+
return `Class ${classId} unapplied from element ${elementId} successfully.`;
|
|
2186
|
+
}
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2191
|
+
import { z as z2 } from "@elementor/schema";
|
|
2192
|
+
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2193
|
+
const { addTool } = reg;
|
|
2194
|
+
const globalClassesUsageSchema = {
|
|
2195
|
+
usages: z2.array(
|
|
2196
|
+
z2.object({
|
|
2197
|
+
classId: z2.string().describe(
|
|
2198
|
+
'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
|
|
2199
|
+
),
|
|
2200
|
+
usages: z2.array(
|
|
2201
|
+
z2.object({
|
|
2202
|
+
pageId: z2.string().describe("The ID of the page where the class is used"),
|
|
2203
|
+
title: z2.string().describe("The title of the page where the class is used"),
|
|
2204
|
+
total: z2.number().describe("The number of times the class is used on this page"),
|
|
2205
|
+
elements: z2.array(z2.string()).describe("List of element IDs using this class on the page")
|
|
2206
|
+
})
|
|
2207
|
+
)
|
|
2208
|
+
})
|
|
2209
|
+
)
|
|
2210
|
+
};
|
|
2211
|
+
addTool({
|
|
2212
|
+
name: "get-global-class-usages",
|
|
2213
|
+
description: `Retreive the usage details of global classes within the Elementor editor, accross all pages.
|
|
2214
|
+
|
|
2215
|
+
## Prequisites:
|
|
2216
|
+
- Use "list-global-classes" tool to be able to match class IDs to class names/labels.
|
|
2217
|
+
|
|
2218
|
+
## When to use this tool:
|
|
2219
|
+
- When a user requests to see where a specific global class is being used accross the site.
|
|
2220
|
+
- When you need to manage or clean up unused global classes.
|
|
2221
|
+
- Before deleting a global class, to ensure it is not in use in any other pages.
|
|
2222
|
+
`,
|
|
2223
|
+
outputSchema: globalClassesUsageSchema,
|
|
2224
|
+
handler: async () => {
|
|
2225
|
+
const data = await fetchCssClassUsage();
|
|
2226
|
+
const result = {
|
|
2227
|
+
usages: []
|
|
2228
|
+
};
|
|
2229
|
+
Object.entries(data).forEach(
|
|
2230
|
+
([classId, usageDetails]) => {
|
|
2231
|
+
const newEntry = {
|
|
2232
|
+
classId,
|
|
2233
|
+
usages: []
|
|
2234
|
+
};
|
|
2235
|
+
if (typeof usageDetails !== "number") {
|
|
2236
|
+
const { content } = usageDetails;
|
|
2237
|
+
content.forEach((detail) => {
|
|
2238
|
+
newEntry.usages.push({
|
|
2239
|
+
pageId: String(detail.pageId),
|
|
2240
|
+
title: detail.title,
|
|
2241
|
+
total: detail.total,
|
|
2242
|
+
elements: detail.elements
|
|
2243
|
+
});
|
|
2244
|
+
});
|
|
2245
|
+
result.usages.push(newEntry);
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
);
|
|
2249
|
+
return result;
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
// src/mcp-integration/index.ts
|
|
2255
|
+
var initMcpIntegration = () => {
|
|
2256
|
+
const reg = getMCPByDomain("element_classes");
|
|
2257
|
+
reg.setMCPDescription(
|
|
2258
|
+
"Tools for managing and applying Global CSS classes to elements within the Elementor editor."
|
|
2259
|
+
);
|
|
2260
|
+
initMcpApplyUnapplyGlobalClasses(reg);
|
|
2261
|
+
initMcpApplyGetGlobalClassUsages(reg);
|
|
2262
|
+
};
|
|
2263
|
+
|
|
2097
2264
|
// src/sync-with-document.tsx
|
|
2098
2265
|
import { useEffect as useEffect4 } from "react";
|
|
2099
2266
|
import { __privateListenTo as listenTo, v1ReadyEvent } from "@elementor/editor-v1-adapters";
|
|
@@ -2148,7 +2315,7 @@ function SyncWithDocumentSave() {
|
|
|
2148
2315
|
function init() {
|
|
2149
2316
|
registerSlice(slice);
|
|
2150
2317
|
registerPanel(panel);
|
|
2151
|
-
|
|
2318
|
+
stylesRepository2.register(globalClassesStylesProvider);
|
|
2152
2319
|
injectIntoLogic({
|
|
2153
2320
|
id: "global-classes-populate-store",
|
|
2154
2321
|
component: PopulateStore
|
|
@@ -2169,6 +2336,7 @@ function init() {
|
|
|
2169
2336
|
name: "global",
|
|
2170
2337
|
getThemeColor: (theme) => theme.palette.global.dark
|
|
2171
2338
|
});
|
|
2339
|
+
initMcpIntegration();
|
|
2172
2340
|
}
|
|
2173
2341
|
export {
|
|
2174
2342
|
init
|