@elementor/editor-global-classes 3.35.0-469 → 3.35.0-471
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 +250 -271
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +250 -271
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
- package/src/mcp-integration/classes-resource.ts +20 -17
- package/src/mcp-integration/index.ts +5 -5
- package/src/mcp-integration/mcp-apply-unapply-global-classes.ts +19 -6
- package/src/mcp-integration/mcp-manage-global-classes.ts +282 -0
- package/src/mcp-integration/design-system/design-system-tool.ts +0 -121
- package/src/mcp-integration/mcp-create-global-class.ts +0 -164
- package/src/mcp-integration/mcp-modify-global-class.ts +0 -134
package/dist/index.mjs
CHANGED
|
@@ -504,22 +504,26 @@ var subscribeWithStates = (cb) => {
|
|
|
504
504
|
// src/mcp-integration/classes-resource.ts
|
|
505
505
|
var GLOBAL_CLASSES_URI = "elementor://global-classes";
|
|
506
506
|
var initClassesResource = () => {
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
507
|
+
const canvasMcpEntry = getMCPByDomain("canvas");
|
|
508
|
+
const classesMcpEntry = getMCPByDomain("classes");
|
|
509
|
+
[canvasMcpEntry, classesMcpEntry].forEach((entry) => {
|
|
510
|
+
const { mcpServer, resource, waitForReady } = entry;
|
|
511
|
+
resource(
|
|
512
|
+
"global-classes",
|
|
513
|
+
GLOBAL_CLASSES_URI,
|
|
514
|
+
{
|
|
515
|
+
description: "Global classes list."
|
|
516
|
+
},
|
|
517
|
+
async () => {
|
|
518
|
+
return {
|
|
519
|
+
contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? "{}" }]
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
waitForReady().then(() => {
|
|
524
|
+
globalClassesStylesProvider.subscribe(() => {
|
|
525
|
+
mcpServer.sendResourceListChanged();
|
|
526
|
+
});
|
|
523
527
|
});
|
|
524
528
|
});
|
|
525
529
|
};
|
|
@@ -1948,7 +1952,7 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1948
1952
|
const [classesOrder, reorderClasses] = useReorder(draggedItemId, setDraggedItemId, draggedItemLabel ?? "");
|
|
1949
1953
|
const filteredCssClasses = useFilteredCssClasses();
|
|
1950
1954
|
useEffect2(() => {
|
|
1951
|
-
const
|
|
1955
|
+
const handler2 = (event) => {
|
|
1952
1956
|
if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
|
|
1953
1957
|
event.stopImmediatePropagation();
|
|
1954
1958
|
event.preventDefault();
|
|
@@ -1959,10 +1963,10 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1959
1963
|
dispatch5(slice.actions.undo());
|
|
1960
1964
|
}
|
|
1961
1965
|
};
|
|
1962
|
-
window.addEventListener("keydown",
|
|
1966
|
+
window.addEventListener("keydown", handler2, {
|
|
1963
1967
|
capture: true
|
|
1964
1968
|
});
|
|
1965
|
-
return () => window.removeEventListener("keydown",
|
|
1969
|
+
return () => window.removeEventListener("keydown", handler2);
|
|
1966
1970
|
}, [dispatch5]);
|
|
1967
1971
|
if (!cssClasses?.length) {
|
|
1968
1972
|
return /* @__PURE__ */ React17.createElement(EmptyState, null);
|
|
@@ -2369,16 +2373,29 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2369
2373
|
intelligencePriority: 0.7,
|
|
2370
2374
|
speedPriority: 0.8
|
|
2371
2375
|
},
|
|
2372
|
-
description: `Apply a global class to
|
|
2376
|
+
description: `Apply a global class to an element, enabling consistent styling through your design system.
|
|
2373
2377
|
|
|
2374
2378
|
## When to use this tool:
|
|
2375
|
-
|
|
2376
|
-
-
|
|
2379
|
+
**ALWAYS use this IMMEDIATELY AFTER building compositions** to apply the global classes you created beforehand:
|
|
2380
|
+
- After using "build-compositions" tool, apply semantic classes to the created elements
|
|
2381
|
+
- When applying consistent typography styles (heading-primary, text-body, etc.)
|
|
2382
|
+
- When applying theme colors or brand styles (bg-brand, button-cta, etc.)
|
|
2383
|
+
- When ensuring spacing consistency (spacing-section-large, etc.)
|
|
2384
|
+
|
|
2385
|
+
**DO NOT use this tool** for:
|
|
2386
|
+
- Elements that don't share styles with other elements (use inline styles instead)
|
|
2387
|
+
- Layout-specific properties (those should remain inline in stylesConfig)
|
|
2377
2388
|
|
|
2378
2389
|
## Prerequisites:
|
|
2379
|
-
-
|
|
2380
|
-
|
|
2381
|
-
-
|
|
2390
|
+
- **REQUIRED**: Get the list of available global classes from 'elementor://global-classes' resource
|
|
2391
|
+
- **REQUIRED**: Get element IDs from the composition XML returned by "build-compositions" tool
|
|
2392
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates
|
|
2393
|
+
- Make sure you have the correct class ID that you want to apply
|
|
2394
|
+
|
|
2395
|
+
## Best Practices:
|
|
2396
|
+
1. Apply multiple classes to a single element if needed (typography + color + spacing)
|
|
2397
|
+
2. After applying, the tool will remind you to remove duplicate inline styles from elementConfig
|
|
2398
|
+
3. Classes should describe purpose, not implementation (e.g., "heading-primary" not "big-red-text")`,
|
|
2382
2399
|
handler: async (params) => {
|
|
2383
2400
|
const { classId, elementId } = params;
|
|
2384
2401
|
const appliedClasses = doGetAppliedClasses(elementId);
|
|
@@ -2430,168 +2447,22 @@ If the user want to unapply a class by it's name and not ID, retreive the id fro
|
|
|
2430
2447
|
});
|
|
2431
2448
|
}
|
|
2432
2449
|
|
|
2433
|
-
// src/mcp-integration/mcp-create-global-class.ts
|
|
2434
|
-
import { STYLE_SCHEMA_URI } from "@elementor/editor-canvas";
|
|
2435
|
-
import { Schema } from "@elementor/editor-props";
|
|
2436
|
-
import { getStylesSchema } from "@elementor/editor-styles";
|
|
2437
|
-
import { Utils } from "@elementor/editor-variables";
|
|
2438
|
-
import { z as z2 } from "@elementor/schema";
|
|
2439
|
-
var inputSchema = {
|
|
2440
|
-
globalClassName: z2.string().describe("The name of the global class to be created"),
|
|
2441
|
-
props: z2.record(z2.any()).describe(
|
|
2442
|
-
'key-value of style-schema PropValues applied to the global class. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2443
|
-
).default({}),
|
|
2444
|
-
customCss: z2.string().optional().describe(
|
|
2445
|
-
"Additional CSS styles associated with the global class. Use only if you fail to use the schema, specifically backgrounds"
|
|
2446
|
-
),
|
|
2447
|
-
breakpoint: z2.nullable(
|
|
2448
|
-
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")
|
|
2449
|
-
).default(null).describe("The responsive breakpoint name for which the global class styles should be applied")
|
|
2450
|
-
};
|
|
2451
|
-
var outputSchema = {
|
|
2452
|
-
classId: z2.string().describe("The unique identifier of the newly created global class")
|
|
2453
|
-
};
|
|
2454
|
-
var handler = async (input) => {
|
|
2455
|
-
const customCss = input.customCss ? { raw: btoa(input.customCss) } : null;
|
|
2456
|
-
const { delete: deleteClass2, create } = globalClassesStylesProvider.actions;
|
|
2457
|
-
if (!create || !deleteClass2) {
|
|
2458
|
-
throw new Error("Create action is not available");
|
|
2459
|
-
}
|
|
2460
|
-
const errors = [];
|
|
2461
|
-
const stylesSchema = getStylesSchema();
|
|
2462
|
-
const validProps = Object.keys(stylesSchema);
|
|
2463
|
-
Object.keys(input.props).forEach((key) => {
|
|
2464
|
-
const propType = getStylesSchema()[key];
|
|
2465
|
-
if (!propType) {
|
|
2466
|
-
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2467
|
-
return;
|
|
2468
|
-
}
|
|
2469
|
-
const { valid, jsonSchema } = Schema.validatePropValue(propType, input.props[key]);
|
|
2470
|
-
if (!valid) {
|
|
2471
|
-
errors.push(
|
|
2472
|
-
`- Property "${key}" has invalid value
|
|
2473
|
-
Exact schema: \`\`\`json
|
|
2474
|
-
${jsonSchema}\`\`\`
|
|
2475
|
-
`
|
|
2476
|
-
);
|
|
2477
|
-
}
|
|
2478
|
-
});
|
|
2479
|
-
if (errors.length > 0) {
|
|
2480
|
-
throw new Error(
|
|
2481
|
-
`Errors:
|
|
2482
|
-
${errors.join("\n")}
|
|
2483
|
-
Available Properties: ${validProps.join(
|
|
2484
|
-
", "
|
|
2485
|
-
)}
|
|
2486
|
-
Now that you have this information, update your input and try again`
|
|
2487
|
-
);
|
|
2488
|
-
}
|
|
2489
|
-
Object.keys(input.props).forEach((key) => {
|
|
2490
|
-
input.props[key] = Schema.adjustLlmPropValueSchema(input.props[key], {
|
|
2491
|
-
transformers: Utils.globalVariablesLLMResolvers
|
|
2492
|
-
});
|
|
2493
|
-
});
|
|
2494
|
-
const classId = create(input.globalClassName, [
|
|
2495
|
-
{
|
|
2496
|
-
meta: {
|
|
2497
|
-
breakpoint: input.breakpoint === null ? "desktop" : input.breakpoint,
|
|
2498
|
-
state: null
|
|
2499
|
-
},
|
|
2500
|
-
custom_css: customCss,
|
|
2501
|
-
props: input.props
|
|
2502
|
-
}
|
|
2503
|
-
]);
|
|
2504
|
-
try {
|
|
2505
|
-
await saveGlobalClasses({ context: "frontend" });
|
|
2506
|
-
} catch (err) {
|
|
2507
|
-
deleteClass2(classId);
|
|
2508
|
-
await saveGlobalClasses({ context: "frontend" });
|
|
2509
|
-
throw new Error(`Failed to create global class, probably invalid schema values.`);
|
|
2510
|
-
}
|
|
2511
|
-
return {
|
|
2512
|
-
classId
|
|
2513
|
-
};
|
|
2514
|
-
};
|
|
2515
|
-
var initCreateGlobalClass = (reg) => {
|
|
2516
|
-
const { addTool } = reg;
|
|
2517
|
-
addTool({
|
|
2518
|
-
requiredResources: [
|
|
2519
|
-
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
2520
|
-
{ uri: STYLE_SCHEMA_URI, description: "Style schema resources" }
|
|
2521
|
-
],
|
|
2522
|
-
modelPreferences: {
|
|
2523
|
-
intelligencePriority: 0.85,
|
|
2524
|
-
speedPriority: 0.6
|
|
2525
|
-
},
|
|
2526
|
-
description: `Create a new global class within the Elementor editor, allowing users to define reusable styles and properties for consistent design across their website.
|
|
2527
|
-
|
|
2528
|
-
# Prequisites: CRITICAL
|
|
2529
|
-
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
2530
|
-
- Available style properties can be found in the styles schema dynamic resources available from 'canvas' mcp. List the resources to see all available properties.
|
|
2531
|
-
- YOU MUST USE THE STYLE SCHEMA TO BUILD THE "props" PARAMETER CORRECTLY, OTHERWISE THE GLOBAL CLASS CREATION WILL FAIL.
|
|
2532
|
-
- Ensure that the global class name provided does not already exist to avoid duplication.
|
|
2533
|
-
- Read the styles schema resource available from 'canvas' mcp to understand the valid properties and values that can be assigned to the global class.
|
|
2534
|
-
|
|
2535
|
-
## Parameters:
|
|
2536
|
-
- \`globalClassName\` (string, required): The name of the global class to be created.
|
|
2537
|
-
- \`props\` (object, required): A key-value map of style-schema PropValues that define the styles for the global class.
|
|
2538
|
-
- \`breakpoint\` (string | null, optional): The responsive breakpoint for which the styles should be applied. If null, styles apply to all breakpoints.
|
|
2539
|
-
|
|
2540
|
-
## Example usage:
|
|
2541
|
-
\`\`\`json
|
|
2542
|
-
{
|
|
2543
|
-
"globalClassName": "my-new-class",
|
|
2544
|
-
"props": {
|
|
2545
|
-
"color": {
|
|
2546
|
-
"$$type": "color",
|
|
2547
|
-
"value": "#ff0000"
|
|
2548
|
-
},
|
|
2549
|
-
"fontSize": {
|
|
2550
|
-
"$$type": "size",
|
|
2551
|
-
"value": {
|
|
2552
|
-
"size": {
|
|
2553
|
-
"$$type": "number",
|
|
2554
|
-
"value": 2.5
|
|
2555
|
-
},
|
|
2556
|
-
"unit": {
|
|
2557
|
-
"$$type": "string",
|
|
2558
|
-
"value": "em"
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
}
|
|
2562
|
-
},
|
|
2563
|
-
"breakpoint": "desktop"
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
# Next steps:
|
|
2567
|
-
If failed, read the error message carefully, it includes the exact schema that caused the failure for each invalid property.
|
|
2568
|
-
Now that you have this information, update your input and try again.
|
|
2569
|
-
|
|
2570
|
-
\`\`\`
|
|
2571
|
-
`,
|
|
2572
|
-
name: "create-global-class",
|
|
2573
|
-
schema: inputSchema,
|
|
2574
|
-
outputSchema,
|
|
2575
|
-
handler
|
|
2576
|
-
});
|
|
2577
|
-
};
|
|
2578
|
-
|
|
2579
2450
|
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2580
|
-
import { z as
|
|
2451
|
+
import { z as z2 } from "@elementor/schema";
|
|
2581
2452
|
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2582
2453
|
const { addTool } = reg;
|
|
2583
2454
|
const globalClassesUsageSchema = {
|
|
2584
|
-
usages:
|
|
2585
|
-
|
|
2586
|
-
classId:
|
|
2455
|
+
usages: z2.array(
|
|
2456
|
+
z2.object({
|
|
2457
|
+
classId: z2.string().describe(
|
|
2587
2458
|
'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
|
|
2588
2459
|
),
|
|
2589
|
-
usages:
|
|
2590
|
-
|
|
2591
|
-
pageId:
|
|
2592
|
-
title:
|
|
2593
|
-
total:
|
|
2594
|
-
elements:
|
|
2460
|
+
usages: z2.array(
|
|
2461
|
+
z2.object({
|
|
2462
|
+
pageId: z2.string().describe("The ID of the page where the class is used"),
|
|
2463
|
+
title: z2.string().describe("The title of the page where the class is used"),
|
|
2464
|
+
total: z2.number().describe("The number of times the class is used on this page"),
|
|
2465
|
+
elements: z2.array(z2.string()).describe("List of element IDs using this class on the page")
|
|
2595
2466
|
})
|
|
2596
2467
|
)
|
|
2597
2468
|
})
|
|
@@ -2647,139 +2518,247 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2647
2518
|
});
|
|
2648
2519
|
}
|
|
2649
2520
|
|
|
2650
|
-
// src/mcp-integration/mcp-
|
|
2651
|
-
import { BREAKPOINTS_SCHEMA_URI } from "@elementor/editor-canvas";
|
|
2652
|
-
import { Schema
|
|
2653
|
-
import { getStylesSchema
|
|
2654
|
-
import {
|
|
2655
|
-
import { z as z4 } from "@elementor/schema";
|
|
2521
|
+
// src/mcp-integration/mcp-manage-global-classes.ts
|
|
2522
|
+
import { BREAKPOINTS_SCHEMA_URI, STYLE_SCHEMA_URI } from "@elementor/editor-canvas";
|
|
2523
|
+
import { Schema } from "@elementor/editor-props";
|
|
2524
|
+
import { getStylesSchema } from "@elementor/editor-styles";
|
|
2525
|
+
import { z as z3 } from "@elementor/schema";
|
|
2656
2526
|
var schema = {
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2527
|
+
action: z3.enum(["create", "modify", "delete"]).describe("Operation to perform"),
|
|
2528
|
+
classId: z3.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
|
|
2529
|
+
globalClassName: z3.string().optional().describe("Global class name (required for create)"),
|
|
2530
|
+
props: z3.record(z3.any()).describe(
|
|
2531
|
+
'key-value of style-schema PropValues. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2660
2532
|
),
|
|
2661
|
-
breakpoint:
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2533
|
+
breakpoint: z3.nullable(z3.string().describe("Responsive breakpoint name for styles. Defaults to desktop (null).")).default(null).describe("Responsive breakpoint name for styles. Defaults to desktop (null).")
|
|
2534
|
+
};
|
|
2535
|
+
var outputSchema = {
|
|
2536
|
+
status: z3.enum(["ok", "error"]).describe("Operation status"),
|
|
2537
|
+
classId: z3.string().optional().describe("Class ID (returned on create success)"),
|
|
2538
|
+
message: z3.string().optional().describe("Error details if status is error")
|
|
2539
|
+
};
|
|
2540
|
+
var handler = async (input) => {
|
|
2541
|
+
const { action, classId, globalClassName, props, breakpoint } = input;
|
|
2542
|
+
if (action === "create" && !globalClassName) {
|
|
2543
|
+
return {
|
|
2544
|
+
status: "error",
|
|
2545
|
+
message: "Create requires globalClassName"
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
if (action === "modify" && !classId) {
|
|
2549
|
+
return {
|
|
2550
|
+
status: "error",
|
|
2551
|
+
message: "Modify requires classId"
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
if (action === "delete" && !classId) {
|
|
2555
|
+
return {
|
|
2556
|
+
status: "error",
|
|
2557
|
+
message: "Delete requires classId"
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
const { create, update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
|
|
2561
|
+
if (!create || !update || !deleteClass2) {
|
|
2562
|
+
return {
|
|
2563
|
+
status: "error",
|
|
2564
|
+
message: "Required actions not available"
|
|
2565
|
+
};
|
|
2670
2566
|
}
|
|
2671
2567
|
const errors = [];
|
|
2672
|
-
const
|
|
2568
|
+
const stylesSchema = getStylesSchema();
|
|
2569
|
+
const validProps = Object.keys(stylesSchema);
|
|
2673
2570
|
Object.keys(props).forEach((key) => {
|
|
2674
|
-
const propType =
|
|
2571
|
+
const propType = stylesSchema[key];
|
|
2675
2572
|
if (!propType) {
|
|
2676
2573
|
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2677
2574
|
return;
|
|
2678
2575
|
}
|
|
2679
|
-
const { valid, jsonSchema } =
|
|
2576
|
+
const { valid, jsonSchema } = Schema.validatePropValue(propType, props[key]);
|
|
2680
2577
|
if (!valid) {
|
|
2681
|
-
errors.push(`- Property "${key}" has invalid value
|
|
2682
|
-
|
|
2578
|
+
errors.push(`- Property "${key}" has invalid value
|
|
2579
|
+
Expected schema: ${jsonSchema}
|
|
2683
2580
|
`);
|
|
2684
2581
|
}
|
|
2685
2582
|
});
|
|
2686
2583
|
if (errors.length > 0) {
|
|
2687
|
-
|
|
2688
|
-
|
|
2584
|
+
return {
|
|
2585
|
+
status: "error",
|
|
2586
|
+
message: `Validation errors:
|
|
2689
2587
|
${errors.join("\n")}
|
|
2690
2588
|
Available Properties: ${validProps.join(
|
|
2691
2589
|
", "
|
|
2692
2590
|
)}
|
|
2693
|
-
|
|
2694
|
-
|
|
2591
|
+
Update your input and try again.`
|
|
2592
|
+
};
|
|
2695
2593
|
}
|
|
2594
|
+
const Utils = window.elementorV2.editorVariables.Utils;
|
|
2696
2595
|
Object.keys(props).forEach((key) => {
|
|
2697
|
-
props[key] =
|
|
2698
|
-
transformers:
|
|
2596
|
+
props[key] = Schema.adjustLlmPropValueSchema(props[key], {
|
|
2597
|
+
transformers: Utils.globalVariablesLLMResolvers
|
|
2699
2598
|
});
|
|
2700
2599
|
});
|
|
2701
|
-
const
|
|
2600
|
+
const breakpointValue = breakpoint ?? "desktop";
|
|
2702
2601
|
try {
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
{
|
|
2707
|
-
custom_css: customCss,
|
|
2602
|
+
switch (action) {
|
|
2603
|
+
case "create":
|
|
2604
|
+
const newClassId = await attemptCreate({
|
|
2708
2605
|
props,
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2606
|
+
className: globalClassName,
|
|
2607
|
+
stylesProvider: globalClassesStylesProvider,
|
|
2608
|
+
breakpoint: breakpointValue
|
|
2609
|
+
});
|
|
2610
|
+
return newClassId ? {
|
|
2611
|
+
status: "ok",
|
|
2612
|
+
message: `created global class with ID ${newClassId}`
|
|
2613
|
+
} : {
|
|
2614
|
+
status: "error",
|
|
2615
|
+
message: "error creating class"
|
|
2616
|
+
};
|
|
2617
|
+
case "modify":
|
|
2618
|
+
const updated = await attemptUpdate({
|
|
2619
|
+
classId,
|
|
2620
|
+
props,
|
|
2621
|
+
stylesProvider: globalClassesStylesProvider,
|
|
2622
|
+
breakpoint: breakpointValue
|
|
2623
|
+
});
|
|
2624
|
+
return updated ? { status: "ok", classId } : {
|
|
2625
|
+
status: "error",
|
|
2626
|
+
message: "error modifying class"
|
|
2627
|
+
};
|
|
2628
|
+
case "delete":
|
|
2629
|
+
const deleted = await attemptDelete({
|
|
2630
|
+
classId,
|
|
2631
|
+
stylesProvider: globalClassesStylesProvider
|
|
2632
|
+
});
|
|
2633
|
+
return deleted ? { status: "ok", message: `deleted global class with ID ${classId}` } : {
|
|
2634
|
+
status: "error",
|
|
2635
|
+
message: "error deleting class"
|
|
2636
|
+
};
|
|
2637
|
+
}
|
|
2717
2638
|
} catch (error) {
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
});
|
|
2723
|
-
});
|
|
2724
|
-
await saveGlobalClasses({ context: "frontend" });
|
|
2725
|
-
throw new Error(`Failed to modify global class: ${error.message}`);
|
|
2639
|
+
return {
|
|
2640
|
+
status: "error",
|
|
2641
|
+
message: `${action} failed: ${error.message || "Unknown error"}`
|
|
2642
|
+
};
|
|
2726
2643
|
}
|
|
2727
|
-
return "ok";
|
|
2728
2644
|
};
|
|
2729
|
-
var
|
|
2645
|
+
var initManageGlobalClasses = (reg) => {
|
|
2730
2646
|
const { addTool } = reg;
|
|
2731
2647
|
addTool({
|
|
2732
|
-
name: "
|
|
2648
|
+
name: "manage-global-classes",
|
|
2733
2649
|
requiredResources: [
|
|
2734
|
-
{
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
},
|
|
2738
|
-
{
|
|
2739
|
-
description: "Global classes list",
|
|
2740
|
-
uri: GLOBAL_CLASSES_URI
|
|
2741
|
-
}
|
|
2650
|
+
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
2651
|
+
{ uri: STYLE_SCHEMA_URI, description: "Style schema resources" },
|
|
2652
|
+
{ uri: BREAKPOINTS_SCHEMA_URI, description: "Breakpoints list" }
|
|
2742
2653
|
],
|
|
2743
2654
|
modelPreferences: {
|
|
2744
|
-
hints: [{ name: "claude-sonnet-4-5" }],
|
|
2745
2655
|
intelligencePriority: 0.85,
|
|
2746
2656
|
speedPriority: 0.6
|
|
2747
2657
|
},
|
|
2748
|
-
description: `
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
- \`customCss\` (string, optional): The CSS styles associated with the global class.
|
|
2758
|
-
|
|
2759
|
-
## Example usage:
|
|
2760
|
-
\`\`\`json
|
|
2761
|
-
{
|
|
2762
|
-
"classId": "existing-class-id",
|
|
2763
|
-
"props": {
|
|
2764
|
-
"color": {
|
|
2765
|
-
"$$type": "color",
|
|
2766
|
-
"value": "#00ff00"
|
|
2767
|
-
},
|
|
2768
|
-
}
|
|
2769
|
-
}\`\`\`
|
|
2770
|
-
`,
|
|
2658
|
+
description: `Manages global classes (create/modify) in Elementor editor. Check [elementor://global-classes] and style schemas first.
|
|
2659
|
+
|
|
2660
|
+
CREATE: Requires globalClassName, props. Use semantic naming (heading-primary, button-cta, text-muted). Check existing classes to avoid duplicates. ALWAYS create global classes BEFORE compositions for reusable styles.
|
|
2661
|
+
MODIFY: Requires classId, props. Get classId from [elementor://global-classes] resource.
|
|
2662
|
+
|
|
2663
|
+
Naming pattern: [element-type]-[purpose/variant]-[modifier]
|
|
2664
|
+
DO NOT create global classes for: one-off styles, layout-specific properties.
|
|
2665
|
+
|
|
2666
|
+
Use style schema at [elementor://styles/schema/{category}] for valid props. Errors include exact schema mismatch details.`,
|
|
2771
2667
|
schema,
|
|
2772
|
-
|
|
2668
|
+
outputSchema,
|
|
2669
|
+
handler
|
|
2773
2670
|
});
|
|
2774
2671
|
};
|
|
2672
|
+
async function attemptCreate(opts) {
|
|
2673
|
+
const { props, breakpoint, className, stylesProvider } = opts;
|
|
2674
|
+
const { create, delete: deleteClass2 } = stylesProvider.actions;
|
|
2675
|
+
if (!className) {
|
|
2676
|
+
throw new Error("Global class name is a required for creation");
|
|
2677
|
+
}
|
|
2678
|
+
if (!create || !deleteClass2) {
|
|
2679
|
+
throw new Error("User is unable to create global classes");
|
|
2680
|
+
}
|
|
2681
|
+
const newClassId = create(className, [
|
|
2682
|
+
{
|
|
2683
|
+
meta: {
|
|
2684
|
+
breakpoint,
|
|
2685
|
+
state: null
|
|
2686
|
+
},
|
|
2687
|
+
custom_css: null,
|
|
2688
|
+
props
|
|
2689
|
+
}
|
|
2690
|
+
]);
|
|
2691
|
+
try {
|
|
2692
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2693
|
+
return newClassId;
|
|
2694
|
+
} catch {
|
|
2695
|
+
deleteClass2(newClassId);
|
|
2696
|
+
return null;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
async function attemptUpdate(opts) {
|
|
2700
|
+
const { props, breakpoint, classId, stylesProvider } = opts;
|
|
2701
|
+
const { updateProps, update } = stylesProvider.actions;
|
|
2702
|
+
if (!classId) {
|
|
2703
|
+
throw new Error("Class ID is required for modification");
|
|
2704
|
+
}
|
|
2705
|
+
if (!updateProps || !update) {
|
|
2706
|
+
throw new Error("User is unable to update global classes");
|
|
2707
|
+
}
|
|
2708
|
+
const snapshot = structuredClone(stylesProvider.actions.all());
|
|
2709
|
+
try {
|
|
2710
|
+
updateProps({
|
|
2711
|
+
id: classId,
|
|
2712
|
+
props,
|
|
2713
|
+
meta: {
|
|
2714
|
+
breakpoint,
|
|
2715
|
+
state: null
|
|
2716
|
+
}
|
|
2717
|
+
});
|
|
2718
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2719
|
+
return true;
|
|
2720
|
+
} catch {
|
|
2721
|
+
snapshot.forEach((style) => {
|
|
2722
|
+
update({
|
|
2723
|
+
id: style.id,
|
|
2724
|
+
variants: style.variants
|
|
2725
|
+
});
|
|
2726
|
+
});
|
|
2727
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2728
|
+
return false;
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
async function attemptDelete(opts) {
|
|
2732
|
+
const { classId, stylesProvider } = opts;
|
|
2733
|
+
const { delete: deleteClass2, create } = stylesProvider.actions;
|
|
2734
|
+
if (!classId) {
|
|
2735
|
+
throw new Error("Class ID is required for deletion");
|
|
2736
|
+
}
|
|
2737
|
+
if (!deleteClass2 || !create) {
|
|
2738
|
+
throw new Error("User is unable to delete global classes");
|
|
2739
|
+
}
|
|
2740
|
+
const snapshot = structuredClone(stylesProvider.actions.all());
|
|
2741
|
+
const targetClass = snapshot.find((style) => style.id === classId);
|
|
2742
|
+
if (!targetClass) {
|
|
2743
|
+
throw new Error(`Class with ID "${classId}" not found`);
|
|
2744
|
+
}
|
|
2745
|
+
try {
|
|
2746
|
+
deleteClass2(classId);
|
|
2747
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2748
|
+
return true;
|
|
2749
|
+
} catch {
|
|
2750
|
+
return false;
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2775
2753
|
|
|
2776
2754
|
// src/mcp-integration/index.ts
|
|
2777
2755
|
var initMcpIntegration = () => {
|
|
2778
|
-
const reg = getMCPByDomain2("
|
|
2756
|
+
const reg = getMCPByDomain2("classes", {
|
|
2757
|
+
instructions: "MCP server for management of Elementor global classes"
|
|
2758
|
+
});
|
|
2779
2759
|
initMcpApplyUnapplyGlobalClasses(reg);
|
|
2780
2760
|
initMcpApplyGetGlobalClassUsages(reg);
|
|
2781
|
-
|
|
2782
|
-
initModifyGlobalClass(reg);
|
|
2761
|
+
initManageGlobalClasses(reg);
|
|
2783
2762
|
initClassesResource();
|
|
2784
2763
|
};
|
|
2785
2764
|
|