@elementor/editor-global-classes 3.35.0-340 → 3.35.0-341
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 +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +334 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +340 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -18
- package/src/index.ts +2 -0
- package/src/mcp-integration/classes-resource.ts +8 -2
- package/src/mcp-integration/design-system/design-system-tool.ts +121 -0
- package/src/mcp-integration/index.ts +5 -4
- package/src/mcp-integration/mcp-apply-unapply-global-classes.ts +5 -62
- package/src/mcp-integration/mcp-create-global-class.ts +160 -0
- package/src/mcp-integration/mcp-get-global-class-usages.ts +6 -3
- package/src/mcp-integration/mcp-modify-global-class.ts +129 -0
- package/src/store.ts +4 -1
package/dist/index.mjs
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
injectIntoClassSelectorActions,
|
|
5
|
-
injectIntoCssClassConvert,
|
|
6
|
-
registerStyleProviderToColors
|
|
7
|
-
} from "@elementor/editor-editing-panel";
|
|
8
|
-
import { __registerPanel as registerPanel } from "@elementor/editor-panels";
|
|
9
|
-
import { stylesRepository as stylesRepository2 } from "@elementor/editor-styles-repository";
|
|
10
|
-
import { __registerSlice as registerSlice } from "@elementor/store";
|
|
11
|
-
|
|
12
|
-
// src/components/class-manager/class-manager-button.tsx
|
|
13
|
-
import * as React19 from "react";
|
|
14
|
-
import {
|
|
15
|
-
__useActiveDocument as useActiveDocument2,
|
|
16
|
-
__useActiveDocumentActions as useActiveDocumentActions
|
|
17
|
-
} from "@elementor/editor-documents";
|
|
18
|
-
import { useUserStylesCapability } from "@elementor/editor-styles-repository";
|
|
19
|
-
import { SaveChangesDialog as SaveChangesDialog2, useDialog as useDialog2 } from "@elementor/editor-ui";
|
|
20
|
-
import { IconButton as IconButton5, Tooltip as Tooltip6 } from "@elementor/ui";
|
|
21
|
-
import { __ as __15 } from "@wordpress/i18n";
|
|
1
|
+
// src/mcp-integration/classes-resource.ts
|
|
2
|
+
import { getMCPByDomain } from "@elementor/editor-mcp";
|
|
22
3
|
|
|
23
4
|
// src/global-classes-styles-provider.ts
|
|
24
5
|
import { generateId } from "@elementor/editor-styles";
|
|
@@ -202,7 +183,9 @@ var slice = createSlice({
|
|
|
202
183
|
let customCss = ("custom_css" in payload ? payload.custom_css : variant?.custom_css) ?? null;
|
|
203
184
|
customCss = customCss?.raw ? customCss : null;
|
|
204
185
|
if (variant) {
|
|
205
|
-
|
|
186
|
+
const variantProps = JSON.parse(JSON.stringify(variant.props));
|
|
187
|
+
const payloadProps = JSON.parse(JSON.stringify(payload.props));
|
|
188
|
+
variant.props = mergeProps(variantProps, payloadProps);
|
|
206
189
|
variant.custom_css = customCss;
|
|
207
190
|
style.variants = getNonEmptyVariants(style);
|
|
208
191
|
} else {
|
|
@@ -508,6 +491,49 @@ var subscribeWithStates = (cb) => {
|
|
|
508
491
|
);
|
|
509
492
|
};
|
|
510
493
|
|
|
494
|
+
// src/mcp-integration/classes-resource.ts
|
|
495
|
+
var GLOBAL_CLASSES_URI = "elementor://global-classes";
|
|
496
|
+
var initClassesResource = () => {
|
|
497
|
+
const { mcpServer } = getMCPByDomain("canvas");
|
|
498
|
+
mcpServer.resource(
|
|
499
|
+
"global-classes",
|
|
500
|
+
GLOBAL_CLASSES_URI,
|
|
501
|
+
{
|
|
502
|
+
description: "Global classes list."
|
|
503
|
+
},
|
|
504
|
+
async () => {
|
|
505
|
+
return {
|
|
506
|
+
contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? {} }]
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
globalClassesStylesProvider.subscribe(() => {
|
|
511
|
+
mcpServer.sendResourceListChanged();
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/init.ts
|
|
516
|
+
import { injectIntoLogic } from "@elementor/editor";
|
|
517
|
+
import {
|
|
518
|
+
injectIntoClassSelectorActions,
|
|
519
|
+
injectIntoCssClassConvert,
|
|
520
|
+
registerStyleProviderToColors
|
|
521
|
+
} from "@elementor/editor-editing-panel";
|
|
522
|
+
import { __registerPanel as registerPanel } from "@elementor/editor-panels";
|
|
523
|
+
import { stylesRepository } from "@elementor/editor-styles-repository";
|
|
524
|
+
import { __registerSlice as registerSlice } from "@elementor/store";
|
|
525
|
+
|
|
526
|
+
// src/components/class-manager/class-manager-button.tsx
|
|
527
|
+
import * as React19 from "react";
|
|
528
|
+
import {
|
|
529
|
+
__useActiveDocument as useActiveDocument2,
|
|
530
|
+
__useActiveDocumentActions as useActiveDocumentActions
|
|
531
|
+
} from "@elementor/editor-documents";
|
|
532
|
+
import { useUserStylesCapability } from "@elementor/editor-styles-repository";
|
|
533
|
+
import { SaveChangesDialog as SaveChangesDialog2, useDialog as useDialog2 } from "@elementor/editor-ui";
|
|
534
|
+
import { IconButton as IconButton5, Tooltip as Tooltip6 } from "@elementor/ui";
|
|
535
|
+
import { __ as __15 } from "@wordpress/i18n";
|
|
536
|
+
|
|
511
537
|
// src/hooks/use-prefetch-css-class-usage.ts
|
|
512
538
|
import { useQueryClient } from "@elementor/query";
|
|
513
539
|
|
|
@@ -1928,7 +1954,7 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1928
1954
|
const [classesOrder, reorderClasses] = useReorder(draggedItemId, setDraggedItemId, draggedItemLabel ?? "");
|
|
1929
1955
|
const filteredCssClasses = useFilteredCssClasses();
|
|
1930
1956
|
useEffect2(() => {
|
|
1931
|
-
const
|
|
1957
|
+
const handler3 = (event) => {
|
|
1932
1958
|
if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
|
|
1933
1959
|
event.stopImmediatePropagation();
|
|
1934
1960
|
event.preventDefault();
|
|
@@ -1939,10 +1965,10 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1939
1965
|
dispatch5(slice.actions.undo());
|
|
1940
1966
|
}
|
|
1941
1967
|
};
|
|
1942
|
-
window.addEventListener("keydown",
|
|
1968
|
+
window.addEventListener("keydown", handler3, {
|
|
1943
1969
|
capture: true
|
|
1944
1970
|
});
|
|
1945
|
-
return () => window.removeEventListener("keydown",
|
|
1971
|
+
return () => window.removeEventListener("keydown", handler3);
|
|
1946
1972
|
}, [dispatch5]);
|
|
1947
1973
|
if (!cssClasses?.length) {
|
|
1948
1974
|
return /* @__PURE__ */ React17.createElement(EmptyState, null);
|
|
@@ -2332,80 +2358,10 @@ function PopulateStore() {
|
|
|
2332
2358
|
// src/mcp-integration/index.ts
|
|
2333
2359
|
import { getMCPByDomain as getMCPByDomain2 } from "@elementor/editor-mcp";
|
|
2334
2360
|
|
|
2335
|
-
// src/mcp-integration/classes-resource.ts
|
|
2336
|
-
import { getMCPByDomain } from "@elementor/editor-mcp";
|
|
2337
|
-
var GLOBAL_CLASSES_URI = "elementor://classes";
|
|
2338
|
-
var initClassesResource = () => {
|
|
2339
|
-
const { mcpServer } = getMCPByDomain("classes");
|
|
2340
|
-
mcpServer.resource(
|
|
2341
|
-
"global-classes",
|
|
2342
|
-
GLOBAL_CLASSES_URI,
|
|
2343
|
-
{
|
|
2344
|
-
description: "Global classes list."
|
|
2345
|
-
},
|
|
2346
|
-
async () => {
|
|
2347
|
-
return {
|
|
2348
|
-
contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? {} }]
|
|
2349
|
-
};
|
|
2350
|
-
}
|
|
2351
|
-
);
|
|
2352
|
-
};
|
|
2353
|
-
|
|
2354
2361
|
// src/mcp-integration/mcp-apply-unapply-global-classes.ts
|
|
2355
2362
|
import { doApplyClasses, doGetAppliedClasses, doUnapplyClass } from "@elementor/editor-editing-panel";
|
|
2356
|
-
import { stylesRepository } from "@elementor/editor-styles-repository";
|
|
2357
2363
|
import { z } from "@elementor/schema";
|
|
2358
2364
|
function initMcpApplyUnapplyGlobalClasses(server) {
|
|
2359
|
-
server.addTool({
|
|
2360
|
-
name: "list-all-global-classes",
|
|
2361
|
-
description: `List all classes applied to a specific element
|
|
2362
|
-
|
|
2363
|
-
## When to use this tool:
|
|
2364
|
-
- When a user requests to see which classes or global classes exists.
|
|
2365
|
-
- When you need the list of global classes to allow the user to select from.
|
|
2366
|
-
- At least once before applying or unapplying a class, to ensure the class ID is correct.
|
|
2367
|
-
|
|
2368
|
-
`,
|
|
2369
|
-
outputSchema: {
|
|
2370
|
-
appliedClasses: z.array(
|
|
2371
|
-
z.object({
|
|
2372
|
-
id: z.string().describe("The ID of the class"),
|
|
2373
|
-
label: z.string().describe("The label of the class"),
|
|
2374
|
-
variants: z.array(
|
|
2375
|
-
z.object({
|
|
2376
|
-
meta: z.object({
|
|
2377
|
-
breakpoint: z.string().optional(),
|
|
2378
|
-
state: z.string().optional()
|
|
2379
|
-
}),
|
|
2380
|
-
props: z.record(z.any())
|
|
2381
|
-
})
|
|
2382
|
-
)
|
|
2383
|
-
})
|
|
2384
|
-
)
|
|
2385
|
-
},
|
|
2386
|
-
handler: async () => {
|
|
2387
|
-
const globalClassesProvider = stylesRepository.getProviderByKey("global-classes");
|
|
2388
|
-
if (!globalClassesProvider) {
|
|
2389
|
-
throw new Error("Global classes provider not found");
|
|
2390
|
-
}
|
|
2391
|
-
const result = [];
|
|
2392
|
-
globalClassesProvider.actions.all().forEach((style) => {
|
|
2393
|
-
const { id: id2, label, variants } = style;
|
|
2394
|
-
result.push({
|
|
2395
|
-
id: id2,
|
|
2396
|
-
label,
|
|
2397
|
-
variants: variants.map((variant) => ({
|
|
2398
|
-
meta: {
|
|
2399
|
-
breakpoint: variant.meta.breakpoint,
|
|
2400
|
-
state: variant.meta.state
|
|
2401
|
-
},
|
|
2402
|
-
props: variant.props
|
|
2403
|
-
}))
|
|
2404
|
-
});
|
|
2405
|
-
});
|
|
2406
|
-
return { appliedClasses: result };
|
|
2407
|
-
}
|
|
2408
|
-
});
|
|
2409
2365
|
server.addTool({
|
|
2410
2366
|
schema: {
|
|
2411
2367
|
classId: z.string().describe("The ID of the class to apply"),
|
|
@@ -2419,7 +2375,8 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2419
2375
|
- When you need to add a specific class to an element's applied classes.
|
|
2420
2376
|
|
|
2421
2377
|
## Prerequisites:
|
|
2422
|
-
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates.
|
|
2378
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates.
|
|
2379
|
+
List available at always up-to-date resource 'elementor://global-classes'.
|
|
2423
2380
|
- Make sure you have the correct class ID that you want to apply.`,
|
|
2424
2381
|
handler: async (params) => {
|
|
2425
2382
|
const { classId, elementId } = params;
|
|
@@ -2441,11 +2398,12 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2441
2398
|
- When you need to remove a specific class from an element's applied classes.
|
|
2442
2399
|
|
|
2443
2400
|
## Prerequisites:
|
|
2444
|
-
- Ensure you have the most up-to-date list of classes applied to the element to avoid errors.
|
|
2401
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid errors.
|
|
2402
|
+
The list is available at always up-to-date resource 'elementor://global-classes'.
|
|
2445
2403
|
- Make sure you have the correct class ID that you want to unapply.
|
|
2446
2404
|
|
|
2447
2405
|
<note>
|
|
2448
|
-
If the user want to unapply a class by it's name and not ID,
|
|
2406
|
+
If the user want to unapply a class by it's name and not ID, retreive the id from the list, available at uri elementor://global-classes
|
|
2449
2407
|
</note>
|
|
2450
2408
|
`,
|
|
2451
2409
|
handler: async (params) => {
|
|
@@ -2459,22 +2417,164 @@ If the user want to unapply a class by it's name and not ID, please use the "lis
|
|
|
2459
2417
|
});
|
|
2460
2418
|
}
|
|
2461
2419
|
|
|
2462
|
-
// src/mcp-integration/mcp-
|
|
2420
|
+
// src/mcp-integration/mcp-create-global-class.ts
|
|
2421
|
+
import { STYLE_SCHEMA_URI } from "@elementor/editor-canvas";
|
|
2422
|
+
import { Schema } from "@elementor/editor-props";
|
|
2423
|
+
import { getStylesSchema } from "@elementor/editor-styles";
|
|
2424
|
+
import { Utils } from "@elementor/editor-variables";
|
|
2463
2425
|
import { z as z2 } from "@elementor/schema";
|
|
2426
|
+
var inputSchema = {
|
|
2427
|
+
globalClassName: z2.string().describe("The name of the global class to be created"),
|
|
2428
|
+
props: z2.record(z2.any()).describe(
|
|
2429
|
+
'key-value of style-schema PropValues applied to the global class. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2430
|
+
).default({}),
|
|
2431
|
+
customCss: z2.string().optional().describe(
|
|
2432
|
+
"Additional CSS styles associated with the global class. Use only if you fail to use the schema, specifically backgrounds"
|
|
2433
|
+
),
|
|
2434
|
+
breakpoint: z2.nullable(
|
|
2435
|
+
z2.enum(["desktop", "tablet", "mobile", "laptop", "widescreen", "tablet_extra", "mobile_extra"]).describe("The responsive breakpoint name for which the global class styles should be applied")
|
|
2436
|
+
).default(null).describe("The responsive breakpoint name for which the global class styles should be applied")
|
|
2437
|
+
};
|
|
2438
|
+
var outputSchema = {
|
|
2439
|
+
classId: z2.string().describe("The unique identifier of the newly created global class")
|
|
2440
|
+
};
|
|
2441
|
+
var handler = async (input) => {
|
|
2442
|
+
const customCss = input.customCss ? { raw: btoa(input.customCss) } : null;
|
|
2443
|
+
const { delete: deleteClass2, create } = globalClassesStylesProvider.actions;
|
|
2444
|
+
if (!create || !deleteClass2) {
|
|
2445
|
+
throw new Error("Create action is not available");
|
|
2446
|
+
}
|
|
2447
|
+
const errors = [];
|
|
2448
|
+
const stylesSchema = getStylesSchema();
|
|
2449
|
+
const validProps = Object.keys(stylesSchema);
|
|
2450
|
+
Object.keys(input.props).forEach((key) => {
|
|
2451
|
+
const propType = getStylesSchema()[key];
|
|
2452
|
+
if (!propType) {
|
|
2453
|
+
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2454
|
+
return;
|
|
2455
|
+
}
|
|
2456
|
+
const { valid, jsonSchema } = Schema.validatePropValue(propType, input.props[key]);
|
|
2457
|
+
if (!valid) {
|
|
2458
|
+
errors.push(
|
|
2459
|
+
`- Property "${key}" has invalid value
|
|
2460
|
+
Exact schema: \`\`\`json
|
|
2461
|
+
${jsonSchema}\`\`\`
|
|
2462
|
+
`
|
|
2463
|
+
);
|
|
2464
|
+
}
|
|
2465
|
+
});
|
|
2466
|
+
if (errors.length > 0) {
|
|
2467
|
+
throw new Error(
|
|
2468
|
+
`Errors:
|
|
2469
|
+
${errors.join("\n")}
|
|
2470
|
+
Available Properties: ${validProps.join(
|
|
2471
|
+
", "
|
|
2472
|
+
)}
|
|
2473
|
+
Now that you have this information, update your input and try again`
|
|
2474
|
+
);
|
|
2475
|
+
}
|
|
2476
|
+
Object.keys(input.props).forEach((key) => {
|
|
2477
|
+
input.props[key] = Schema.adjustLlmPropValueSchema(input.props[key], {
|
|
2478
|
+
transformers: Utils.globalVariablesLLMResolvers
|
|
2479
|
+
});
|
|
2480
|
+
});
|
|
2481
|
+
const classId = create(input.globalClassName, [
|
|
2482
|
+
{
|
|
2483
|
+
meta: {
|
|
2484
|
+
breakpoint: input.breakpoint === null ? "desktop" : input.breakpoint,
|
|
2485
|
+
state: null
|
|
2486
|
+
},
|
|
2487
|
+
custom_css: customCss,
|
|
2488
|
+
props: input.props
|
|
2489
|
+
}
|
|
2490
|
+
]);
|
|
2491
|
+
try {
|
|
2492
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2493
|
+
} catch (err) {
|
|
2494
|
+
deleteClass2(classId);
|
|
2495
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2496
|
+
throw new Error(`Failed to create global class, probably invalid schema values.`);
|
|
2497
|
+
}
|
|
2498
|
+
return {
|
|
2499
|
+
classId
|
|
2500
|
+
};
|
|
2501
|
+
};
|
|
2502
|
+
var initCreateGlobalClass = (reg) => {
|
|
2503
|
+
const { addTool } = reg;
|
|
2504
|
+
addTool({
|
|
2505
|
+
requiredResources: [
|
|
2506
|
+
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
2507
|
+
{ uri: STYLE_SCHEMA_URI, description: "Style schema resources" }
|
|
2508
|
+
],
|
|
2509
|
+
description: `Create a new global class within the Elementor editor, allowing users to define reusable styles and properties for consistent design across their website.
|
|
2510
|
+
|
|
2511
|
+
# Prequisites: CRITICAL
|
|
2512
|
+
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
2513
|
+
- Available style properties can be found in the styles schema dynamic resources available from 'canvas' mcp. List the resources to see all available properties.
|
|
2514
|
+
- YOU MUST USE THE STYLE SCHEMA TO BUILD THE "props" PARAMETER CORRECTLY, OTHERWISE THE GLOBAL CLASS CREATION WILL FAIL.
|
|
2515
|
+
- Ensure that the global class name provided does not already exist to avoid duplication.
|
|
2516
|
+
- Read the styles schema resource available from 'canvas' mcp to understand the valid properties and values that can be assigned to the global class.
|
|
2517
|
+
|
|
2518
|
+
## Parameters:
|
|
2519
|
+
- \`globalClassName\` (string, required): The name of the global class to be created.
|
|
2520
|
+
- \`props\` (object, required): A key-value map of style-schema PropValues that define the styles for the global class.
|
|
2521
|
+
- \`breakpoint\` (string | null, optional): The responsive breakpoint for which the styles should be applied. If null, styles apply to all breakpoints.
|
|
2522
|
+
|
|
2523
|
+
## Example usage:
|
|
2524
|
+
\`\`\`json
|
|
2525
|
+
{
|
|
2526
|
+
"globalClassName": "my-new-class",
|
|
2527
|
+
"props": {
|
|
2528
|
+
"color": {
|
|
2529
|
+
"$$type": "color",
|
|
2530
|
+
"value": "#ff0000"
|
|
2531
|
+
},
|
|
2532
|
+
"fontSize": {
|
|
2533
|
+
"$$type": "size",
|
|
2534
|
+
"value": {
|
|
2535
|
+
"size": {
|
|
2536
|
+
"$$type": "number",
|
|
2537
|
+
"value": 2.5
|
|
2538
|
+
},
|
|
2539
|
+
"unit": {
|
|
2540
|
+
"$$type": "string",
|
|
2541
|
+
"value": "em"
|
|
2542
|
+
}
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
},
|
|
2546
|
+
"breakpoint": "desktop"
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
# Next steps:
|
|
2550
|
+
If failed, read the error message carefully, it includes the exact schema that caused the failure for each invalid property.
|
|
2551
|
+
Now that you have this information, update your input and try again.
|
|
2552
|
+
|
|
2553
|
+
\`\`\`
|
|
2554
|
+
`,
|
|
2555
|
+
name: "create-global-class",
|
|
2556
|
+
schema: inputSchema,
|
|
2557
|
+
outputSchema,
|
|
2558
|
+
handler
|
|
2559
|
+
});
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2563
|
+
import { z as z3 } from "@elementor/schema";
|
|
2464
2564
|
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2465
2565
|
const { addTool } = reg;
|
|
2466
2566
|
const globalClassesUsageSchema = {
|
|
2467
|
-
usages:
|
|
2468
|
-
|
|
2469
|
-
classId:
|
|
2567
|
+
usages: z3.array(
|
|
2568
|
+
z3.object({
|
|
2569
|
+
classId: z3.string().describe(
|
|
2470
2570
|
'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
|
|
2471
2571
|
),
|
|
2472
|
-
usages:
|
|
2473
|
-
|
|
2474
|
-
pageId:
|
|
2475
|
-
title:
|
|
2476
|
-
total:
|
|
2477
|
-
elements:
|
|
2572
|
+
usages: z3.array(
|
|
2573
|
+
z3.object({
|
|
2574
|
+
pageId: z3.string().describe("The ID of the page where the class is used"),
|
|
2575
|
+
title: z3.string().describe("The title of the page where the class is used"),
|
|
2576
|
+
total: z3.number().describe("The number of times the class is used on this page"),
|
|
2577
|
+
elements: z3.array(z3.string()).describe("List of element IDs using this class on the page")
|
|
2478
2578
|
})
|
|
2479
2579
|
)
|
|
2480
2580
|
})
|
|
@@ -2482,15 +2582,18 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2482
2582
|
};
|
|
2483
2583
|
addTool({
|
|
2484
2584
|
name: "get-global-class-usages",
|
|
2485
|
-
description: `Retreive the
|
|
2585
|
+
description: `Retreive the usages of global-classes ACCROSS PAGES designed by Elementor editor.
|
|
2486
2586
|
|
|
2487
|
-
## Prequisites:
|
|
2488
|
-
-
|
|
2587
|
+
## Prequisites: CRITICAL
|
|
2588
|
+
- The list of global classes and their applid values is available at resource uri elementor://global-classes
|
|
2489
2589
|
|
|
2490
2590
|
## When to use this tool:
|
|
2491
2591
|
- When a user requests to see where a specific global class is being used accross the site.
|
|
2492
2592
|
- When you need to manage or clean up unused global classes.
|
|
2493
2593
|
- Before deleting a global class, to ensure it is not in use in any other pages.
|
|
2594
|
+
|
|
2595
|
+
## When NOT to use this tool:
|
|
2596
|
+
- For getting the list of global classes, refer to the resource at uri elementor://global-classes
|
|
2494
2597
|
`,
|
|
2495
2598
|
outputSchema: globalClassesUsageSchema,
|
|
2496
2599
|
handler: async () => {
|
|
@@ -2523,14 +2626,134 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2523
2626
|
});
|
|
2524
2627
|
}
|
|
2525
2628
|
|
|
2629
|
+
// src/mcp-integration/mcp-modify-global-class.ts
|
|
2630
|
+
import { BREAKPOINTS_SCHEMA_URI } from "@elementor/editor-canvas";
|
|
2631
|
+
import { Schema as Schema2 } from "@elementor/editor-props";
|
|
2632
|
+
import { getStylesSchema as getStylesSchema2 } from "@elementor/editor-styles";
|
|
2633
|
+
import { Utils as Utils2 } from "@elementor/editor-variables";
|
|
2634
|
+
import { z as z4 } from "@elementor/schema";
|
|
2635
|
+
var schema = {
|
|
2636
|
+
classId: z4.string().describe("The ID of the global class to modify"),
|
|
2637
|
+
props: z4.record(z4.any()).describe(
|
|
2638
|
+
'key-value of style-schema PropValues to update the global class with. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2639
|
+
),
|
|
2640
|
+
breakpoint: z4.nullable(z4.string()).default(null).describe("The responsive breakpoint name for which the global class styles should be applied"),
|
|
2641
|
+
customCss: z4.string().optional().describe("The CSS styles associated with the global class.")
|
|
2642
|
+
};
|
|
2643
|
+
var handler2 = async (params) => {
|
|
2644
|
+
const { classId, props } = params;
|
|
2645
|
+
const customCss = params.customCss ? { raw: btoa(params.customCss) } : null;
|
|
2646
|
+
const { update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
|
|
2647
|
+
if (!update || !deleteClass2) {
|
|
2648
|
+
throw new Error("Update action is not available");
|
|
2649
|
+
}
|
|
2650
|
+
const errors = [];
|
|
2651
|
+
const validProps = Object.keys(getStylesSchema2());
|
|
2652
|
+
Object.keys(props).forEach((key) => {
|
|
2653
|
+
const propType = getStylesSchema2()[key];
|
|
2654
|
+
if (!propType) {
|
|
2655
|
+
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2656
|
+
return;
|
|
2657
|
+
}
|
|
2658
|
+
const { valid, jsonSchema } = Schema2.validatePropValue(propType, props[key]);
|
|
2659
|
+
if (!valid) {
|
|
2660
|
+
errors.push(`- Property "${key}" has invalid value:
|
|
2661
|
+
expected Schema: ${jsonSchema}
|
|
2662
|
+
`);
|
|
2663
|
+
}
|
|
2664
|
+
});
|
|
2665
|
+
if (errors.length > 0) {
|
|
2666
|
+
throw new Error(
|
|
2667
|
+
`Errors:
|
|
2668
|
+
${errors.join("\n")}
|
|
2669
|
+
Available Properties: ${validProps.join(
|
|
2670
|
+
", "
|
|
2671
|
+
)}
|
|
2672
|
+
Now that you have this information, update your input and try again`
|
|
2673
|
+
);
|
|
2674
|
+
}
|
|
2675
|
+
Object.keys(props).forEach((key) => {
|
|
2676
|
+
props[key] = Schema2.adjustLlmPropValueSchema(props[key], {
|
|
2677
|
+
transformers: Utils2.globalVariablesLLMResolvers
|
|
2678
|
+
});
|
|
2679
|
+
});
|
|
2680
|
+
const snapshot = structuredClone(globalClassesStylesProvider.actions.all());
|
|
2681
|
+
try {
|
|
2682
|
+
update({
|
|
2683
|
+
id: classId,
|
|
2684
|
+
variants: [
|
|
2685
|
+
{
|
|
2686
|
+
custom_css: customCss,
|
|
2687
|
+
props,
|
|
2688
|
+
meta: {
|
|
2689
|
+
breakpoint: params.breakpoint === null ? "desktop" : params.breakpoint,
|
|
2690
|
+
state: null
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
]
|
|
2694
|
+
});
|
|
2695
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2696
|
+
} catch (error) {
|
|
2697
|
+
snapshot.forEach((style) => {
|
|
2698
|
+
update({
|
|
2699
|
+
id: style.id,
|
|
2700
|
+
variants: style.variants
|
|
2701
|
+
});
|
|
2702
|
+
});
|
|
2703
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2704
|
+
throw new Error(`Failed to modify global class: ${error.message}`);
|
|
2705
|
+
}
|
|
2706
|
+
return "ok";
|
|
2707
|
+
};
|
|
2708
|
+
var initModifyGlobalClass = (reg) => {
|
|
2709
|
+
const { addTool } = reg;
|
|
2710
|
+
addTool({
|
|
2711
|
+
name: "modify-global-class",
|
|
2712
|
+
requiredResources: [
|
|
2713
|
+
{
|
|
2714
|
+
description: "Breakpoints list",
|
|
2715
|
+
uri: BREAKPOINTS_SCHEMA_URI
|
|
2716
|
+
},
|
|
2717
|
+
{
|
|
2718
|
+
description: "Global classes list",
|
|
2719
|
+
uri: GLOBAL_CLASSES_URI
|
|
2720
|
+
}
|
|
2721
|
+
],
|
|
2722
|
+
description: `Modify an existing global class within the Elementor editor, allowing users to update styles and properties for consistent design across their website.
|
|
2723
|
+
# CRITICAL Prequisites:
|
|
2724
|
+
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
2725
|
+
- Ensure that the global class ID provided exists.
|
|
2726
|
+
- Prefer style schema over custom_css
|
|
2727
|
+
|
|
2728
|
+
## Parameters:
|
|
2729
|
+
- \`classId\` (string, required): The ID of the global class to be modified.
|
|
2730
|
+
- \`props\` (object, required): A key-value map of style-schema PropValues that define the new styles for the global class.
|
|
2731
|
+
- \`customCss\` (string, optional): The CSS styles associated with the global class.
|
|
2732
|
+
|
|
2733
|
+
## Example usage:
|
|
2734
|
+
\`\`\`json
|
|
2735
|
+
{
|
|
2736
|
+
"classId": "existing-class-id",
|
|
2737
|
+
"props": {
|
|
2738
|
+
"color": {
|
|
2739
|
+
"$$type": "color",
|
|
2740
|
+
"value": "#00ff00"
|
|
2741
|
+
},
|
|
2742
|
+
}
|
|
2743
|
+
}\`\`\`
|
|
2744
|
+
`,
|
|
2745
|
+
schema,
|
|
2746
|
+
handler: handler2
|
|
2747
|
+
});
|
|
2748
|
+
};
|
|
2749
|
+
|
|
2526
2750
|
// src/mcp-integration/index.ts
|
|
2527
2751
|
var initMcpIntegration = () => {
|
|
2528
|
-
const reg = getMCPByDomain2("
|
|
2529
|
-
reg.setMCPDescription(
|
|
2530
|
-
"Tools for managing and applying Global CSS classes to elements within the Elementor editor."
|
|
2531
|
-
);
|
|
2752
|
+
const reg = getMCPByDomain2("canvas");
|
|
2532
2753
|
initMcpApplyUnapplyGlobalClasses(reg);
|
|
2533
2754
|
initMcpApplyGetGlobalClassUsages(reg);
|
|
2755
|
+
initCreateGlobalClass(reg);
|
|
2756
|
+
initModifyGlobalClass(reg);
|
|
2534
2757
|
initClassesResource();
|
|
2535
2758
|
};
|
|
2536
2759
|
|
|
@@ -2589,7 +2812,7 @@ function SyncWithDocumentSave() {
|
|
|
2589
2812
|
function init() {
|
|
2590
2813
|
registerSlice(slice);
|
|
2591
2814
|
registerPanel(panel);
|
|
2592
|
-
|
|
2815
|
+
stylesRepository.register(globalClassesStylesProvider);
|
|
2593
2816
|
injectIntoLogic({
|
|
2594
2817
|
id: "global-classes-populate-store",
|
|
2595
2818
|
component: PopulateStore
|
|
@@ -2617,6 +2840,7 @@ function init() {
|
|
|
2617
2840
|
initMcpIntegration();
|
|
2618
2841
|
}
|
|
2619
2842
|
export {
|
|
2843
|
+
GLOBAL_CLASSES_URI,
|
|
2620
2844
|
init
|
|
2621
2845
|
};
|
|
2622
2846
|
//# sourceMappingURL=index.mjs.map
|