@elementor/editor-global-classes 3.35.0-470 → 3.35.0-472

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 CHANGED
@@ -532,22 +532,26 @@ var subscribeWithStates = (cb) => {
532
532
  // src/mcp-integration/classes-resource.ts
533
533
  var GLOBAL_CLASSES_URI = "elementor://global-classes";
534
534
  var initClassesResource = () => {
535
- const { mcpServer, resource, waitForReady } = (0, import_editor_mcp.getMCPByDomain)("canvas");
536
- resource(
537
- "global-classes",
538
- GLOBAL_CLASSES_URI,
539
- {
540
- description: "Global classes list."
541
- },
542
- async () => {
543
- return {
544
- contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? {} }]
545
- };
546
- }
547
- );
548
- waitForReady().then(() => {
549
- globalClassesStylesProvider.subscribe(() => {
550
- mcpServer.sendResourceListChanged();
535
+ const canvasMcpEntry = (0, import_editor_mcp.getMCPByDomain)("canvas");
536
+ const classesMcpEntry = (0, import_editor_mcp.getMCPByDomain)("classes");
537
+ [canvasMcpEntry, classesMcpEntry].forEach((entry) => {
538
+ const { mcpServer, resource, waitForReady } = entry;
539
+ resource(
540
+ "global-classes",
541
+ GLOBAL_CLASSES_URI,
542
+ {
543
+ description: "Global classes list."
544
+ },
545
+ async () => {
546
+ return {
547
+ contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? "{}" }]
548
+ };
549
+ }
550
+ );
551
+ waitForReady().then(() => {
552
+ globalClassesStylesProvider.subscribe(() => {
553
+ mcpServer.sendResourceListChanged();
554
+ });
551
555
  });
552
556
  });
553
557
  };
@@ -1901,7 +1905,7 @@ var GlobalClassesList = ({ disabled }) => {
1901
1905
  const [classesOrder, reorderClasses] = useReorder(draggedItemId, setDraggedItemId, draggedItemLabel ?? "");
1902
1906
  const filteredCssClasses = useFilteredCssClasses();
1903
1907
  (0, import_react7.useEffect)(() => {
1904
- const handler3 = (event) => {
1908
+ const handler2 = (event) => {
1905
1909
  if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
1906
1910
  event.stopImmediatePropagation();
1907
1911
  event.preventDefault();
@@ -1912,10 +1916,10 @@ var GlobalClassesList = ({ disabled }) => {
1912
1916
  dispatch5(slice.actions.undo());
1913
1917
  }
1914
1918
  };
1915
- window.addEventListener("keydown", handler3, {
1919
+ window.addEventListener("keydown", handler2, {
1916
1920
  capture: true
1917
1921
  });
1918
- return () => window.removeEventListener("keydown", handler3);
1922
+ return () => window.removeEventListener("keydown", handler2);
1919
1923
  }, [dispatch5]);
1920
1924
  if (!cssClasses?.length) {
1921
1925
  return /* @__PURE__ */ React17.createElement(EmptyState, null);
@@ -2322,16 +2326,29 @@ function initMcpApplyUnapplyGlobalClasses(server) {
2322
2326
  intelligencePriority: 0.7,
2323
2327
  speedPriority: 0.8
2324
2328
  },
2325
- description: `Apply a global class to the current element
2329
+ description: `Apply a global class to an element, enabling consistent styling through your design system.
2326
2330
 
2327
2331
  ## When to use this tool:
2328
- - When a user requests to apply a global class or a class to an element in the Elementor editor.
2329
- - When you need to add a specific class to an element's applied classes.
2332
+ **ALWAYS use this IMMEDIATELY AFTER building compositions** to apply the global classes you created beforehand:
2333
+ - After using "build-compositions" tool, apply semantic classes to the created elements
2334
+ - When applying consistent typography styles (heading-primary, text-body, etc.)
2335
+ - When applying theme colors or brand styles (bg-brand, button-cta, etc.)
2336
+ - When ensuring spacing consistency (spacing-section-large, etc.)
2337
+
2338
+ **DO NOT use this tool** for:
2339
+ - Elements that don't share styles with other elements (use inline styles instead)
2340
+ - Layout-specific properties (those should remain inline in stylesConfig)
2330
2341
 
2331
2342
  ## Prerequisites:
2332
- - Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates.
2333
- List available at always up-to-date resource 'elementor://global-classes'.
2334
- - Make sure you have the correct class ID that you want to apply.`,
2343
+ - **REQUIRED**: Get the list of available global classes from 'elementor://global-classes' resource
2344
+ - **REQUIRED**: Get element IDs from the composition XML returned by "build-compositions" tool
2345
+ - Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates
2346
+ - Make sure you have the correct class ID that you want to apply
2347
+
2348
+ ## Best Practices:
2349
+ 1. Apply multiple classes to a single element if needed (typography + color + spacing)
2350
+ 2. After applying, the tool will remind you to remove duplicate inline styles from elementConfig
2351
+ 3. Classes should describe purpose, not implementation (e.g., "heading-primary" not "big-red-text")`,
2335
2352
  handler: async (params) => {
2336
2353
  const { classId, elementId } = params;
2337
2354
  const appliedClasses = (0, import_editor_editing_panel.doGetAppliedClasses)(elementId);
@@ -2383,168 +2400,22 @@ If the user want to unapply a class by it's name and not ID, retreive the id fro
2383
2400
  });
2384
2401
  }
2385
2402
 
2386
- // src/mcp-integration/mcp-create-global-class.ts
2387
- var import_editor_canvas = require("@elementor/editor-canvas");
2388
- var import_editor_props = require("@elementor/editor-props");
2389
- var import_editor_styles3 = require("@elementor/editor-styles");
2390
- var import_editor_variables = require("@elementor/editor-variables");
2391
- var import_schema2 = require("@elementor/schema");
2392
- var inputSchema = {
2393
- globalClassName: import_schema2.z.string().describe("The name of the global class to be created"),
2394
- props: import_schema2.z.record(import_schema2.z.any()).describe(
2395
- 'key-value of style-schema PropValues applied to the global class. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
2396
- ).default({}),
2397
- customCss: import_schema2.z.string().optional().describe(
2398
- "Additional CSS styles associated with the global class. Use only if you fail to use the schema, specifically backgrounds"
2399
- ),
2400
- breakpoint: import_schema2.z.nullable(
2401
- import_schema2.z.enum(["desktop", "tablet", "mobile", "laptop", "widescreen", "tablet_extra", "mobile_extra"]).describe("The responsive breakpoint name for which the global class styles should be applied")
2402
- ).default(null).describe("The responsive breakpoint name for which the global class styles should be applied")
2403
- };
2404
- var outputSchema = {
2405
- classId: import_schema2.z.string().describe("The unique identifier of the newly created global class")
2406
- };
2407
- var handler = async (input) => {
2408
- const customCss = input.customCss ? { raw: btoa(input.customCss) } : null;
2409
- const { delete: deleteClass2, create } = globalClassesStylesProvider.actions;
2410
- if (!create || !deleteClass2) {
2411
- throw new Error("Create action is not available");
2412
- }
2413
- const errors = [];
2414
- const stylesSchema = (0, import_editor_styles3.getStylesSchema)();
2415
- const validProps = Object.keys(stylesSchema);
2416
- Object.keys(input.props).forEach((key) => {
2417
- const propType = (0, import_editor_styles3.getStylesSchema)()[key];
2418
- if (!propType) {
2419
- errors.push(`Property "${key}" does not exist in styles schema.`);
2420
- return;
2421
- }
2422
- const { valid, jsonSchema } = import_editor_props.Schema.validatePropValue(propType, input.props[key]);
2423
- if (!valid) {
2424
- errors.push(
2425
- `- Property "${key}" has invalid value
2426
- Exact schema: \`\`\`json
2427
- ${jsonSchema}\`\`\`
2428
- `
2429
- );
2430
- }
2431
- });
2432
- if (errors.length > 0) {
2433
- throw new Error(
2434
- `Errors:
2435
- ${errors.join("\n")}
2436
- Available Properties: ${validProps.join(
2437
- ", "
2438
- )}
2439
- Now that you have this information, update your input and try again`
2440
- );
2441
- }
2442
- Object.keys(input.props).forEach((key) => {
2443
- input.props[key] = import_editor_props.Schema.adjustLlmPropValueSchema(input.props[key], {
2444
- transformers: import_editor_variables.Utils.globalVariablesLLMResolvers
2445
- });
2446
- });
2447
- const classId = create(input.globalClassName, [
2448
- {
2449
- meta: {
2450
- breakpoint: input.breakpoint === null ? "desktop" : input.breakpoint,
2451
- state: null
2452
- },
2453
- custom_css: customCss,
2454
- props: input.props
2455
- }
2456
- ]);
2457
- try {
2458
- await saveGlobalClasses({ context: "frontend" });
2459
- } catch (err) {
2460
- deleteClass2(classId);
2461
- await saveGlobalClasses({ context: "frontend" });
2462
- throw new Error(`Failed to create global class, probably invalid schema values.`);
2463
- }
2464
- return {
2465
- classId
2466
- };
2467
- };
2468
- var initCreateGlobalClass = (reg) => {
2469
- const { addTool } = reg;
2470
- addTool({
2471
- requiredResources: [
2472
- { uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
2473
- { uri: import_editor_canvas.STYLE_SCHEMA_URI, description: "Style schema resources" }
2474
- ],
2475
- modelPreferences: {
2476
- intelligencePriority: 0.85,
2477
- speedPriority: 0.6
2478
- },
2479
- description: `Create a new global class within the Elementor editor, allowing users to define reusable styles and properties for consistent design across their website.
2480
-
2481
- # Prequisites: CRITICAL
2482
- - Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
2483
- - Available style properties can be found in the styles schema dynamic resources available from 'canvas' mcp. List the resources to see all available properties.
2484
- - YOU MUST USE THE STYLE SCHEMA TO BUILD THE "props" PARAMETER CORRECTLY, OTHERWISE THE GLOBAL CLASS CREATION WILL FAIL.
2485
- - Ensure that the global class name provided does not already exist to avoid duplication.
2486
- - Read the styles schema resource available from 'canvas' mcp to understand the valid properties and values that can be assigned to the global class.
2487
-
2488
- ## Parameters:
2489
- - \`globalClassName\` (string, required): The name of the global class to be created.
2490
- - \`props\` (object, required): A key-value map of style-schema PropValues that define the styles for the global class.
2491
- - \`breakpoint\` (string | null, optional): The responsive breakpoint for which the styles should be applied. If null, styles apply to all breakpoints.
2492
-
2493
- ## Example usage:
2494
- \`\`\`json
2495
- {
2496
- "globalClassName": "my-new-class",
2497
- "props": {
2498
- "color": {
2499
- "$$type": "color",
2500
- "value": "#ff0000"
2501
- },
2502
- "fontSize": {
2503
- "$$type": "size",
2504
- "value": {
2505
- "size": {
2506
- "$$type": "number",
2507
- "value": 2.5
2508
- },
2509
- "unit": {
2510
- "$$type": "string",
2511
- "value": "em"
2512
- }
2513
- }
2514
- }
2515
- },
2516
- "breakpoint": "desktop"
2517
- }
2518
-
2519
- # Next steps:
2520
- If failed, read the error message carefully, it includes the exact schema that caused the failure for each invalid property.
2521
- Now that you have this information, update your input and try again.
2522
-
2523
- \`\`\`
2524
- `,
2525
- name: "create-global-class",
2526
- schema: inputSchema,
2527
- outputSchema,
2528
- handler
2529
- });
2530
- };
2531
-
2532
2403
  // src/mcp-integration/mcp-get-global-class-usages.ts
2533
- var import_schema3 = require("@elementor/schema");
2404
+ var import_schema2 = require("@elementor/schema");
2534
2405
  function initMcpApplyGetGlobalClassUsages(reg) {
2535
2406
  const { addTool } = reg;
2536
2407
  const globalClassesUsageSchema = {
2537
- usages: import_schema3.z.array(
2538
- import_schema3.z.object({
2539
- classId: import_schema3.z.string().describe(
2408
+ usages: import_schema2.z.array(
2409
+ import_schema2.z.object({
2410
+ classId: import_schema2.z.string().describe(
2540
2411
  'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
2541
2412
  ),
2542
- usages: import_schema3.z.array(
2543
- import_schema3.z.object({
2544
- pageId: import_schema3.z.string().describe("The ID of the page where the class is used"),
2545
- title: import_schema3.z.string().describe("The title of the page where the class is used"),
2546
- total: import_schema3.z.number().describe("The number of times the class is used on this page"),
2547
- elements: import_schema3.z.array(import_schema3.z.string()).describe("List of element IDs using this class on the page")
2413
+ usages: import_schema2.z.array(
2414
+ import_schema2.z.object({
2415
+ pageId: import_schema2.z.string().describe("The ID of the page where the class is used"),
2416
+ title: import_schema2.z.string().describe("The title of the page where the class is used"),
2417
+ total: import_schema2.z.number().describe("The number of times the class is used on this page"),
2418
+ elements: import_schema2.z.array(import_schema2.z.string()).describe("List of element IDs using this class on the page")
2548
2419
  })
2549
2420
  )
2550
2421
  })
@@ -2600,139 +2471,247 @@ function initMcpApplyGetGlobalClassUsages(reg) {
2600
2471
  });
2601
2472
  }
2602
2473
 
2603
- // src/mcp-integration/mcp-modify-global-class.ts
2604
- var import_editor_canvas2 = require("@elementor/editor-canvas");
2605
- var import_editor_props2 = require("@elementor/editor-props");
2606
- var import_editor_styles4 = require("@elementor/editor-styles");
2607
- var import_editor_variables2 = require("@elementor/editor-variables");
2608
- var import_schema4 = require("@elementor/schema");
2474
+ // src/mcp-integration/mcp-manage-global-classes.ts
2475
+ var import_editor_canvas = require("@elementor/editor-canvas");
2476
+ var import_editor_props = require("@elementor/editor-props");
2477
+ var import_editor_styles3 = require("@elementor/editor-styles");
2478
+ var import_schema3 = require("@elementor/schema");
2609
2479
  var schema = {
2610
- classId: import_schema4.z.string().describe("The ID of the global class to modify"),
2611
- props: import_schema4.z.record(import_schema4.z.any()).describe(
2612
- 'key-value of style-schema PropValues to update the global class with. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
2480
+ action: import_schema3.z.enum(["create", "modify", "delete"]).describe("Operation to perform"),
2481
+ classId: import_schema3.z.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
2482
+ globalClassName: import_schema3.z.string().optional().describe("Global class name (required for create)"),
2483
+ props: import_schema3.z.record(import_schema3.z.any()).describe(
2484
+ 'key-value of style-schema PropValues. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
2613
2485
  ),
2614
- breakpoint: import_schema4.z.nullable(import_schema4.z.string()).default(null).describe("The responsive breakpoint name for which the global class styles should be applied"),
2615
- customCss: import_schema4.z.string().optional().describe("The CSS styles associated with the global class.")
2616
- };
2617
- var handler2 = async (params) => {
2618
- const { classId, props } = params;
2619
- const customCss = params.customCss ? { raw: btoa(params.customCss) } : null;
2620
- const { update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
2621
- if (!update || !deleteClass2) {
2622
- throw new Error("Update action is not available");
2486
+ 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).")
2487
+ };
2488
+ var outputSchema = {
2489
+ status: import_schema3.z.enum(["ok", "error"]).describe("Operation status"),
2490
+ classId: import_schema3.z.string().optional().describe("Class ID (returned on create success)"),
2491
+ message: import_schema3.z.string().optional().describe("Error details if status is error")
2492
+ };
2493
+ var handler = async (input) => {
2494
+ const { action, classId, globalClassName, props, breakpoint } = input;
2495
+ if (action === "create" && !globalClassName) {
2496
+ return {
2497
+ status: "error",
2498
+ message: "Create requires globalClassName"
2499
+ };
2500
+ }
2501
+ if (action === "modify" && !classId) {
2502
+ return {
2503
+ status: "error",
2504
+ message: "Modify requires classId"
2505
+ };
2506
+ }
2507
+ if (action === "delete" && !classId) {
2508
+ return {
2509
+ status: "error",
2510
+ message: "Delete requires classId"
2511
+ };
2512
+ }
2513
+ const { create, update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
2514
+ if (!create || !update || !deleteClass2) {
2515
+ return {
2516
+ status: "error",
2517
+ message: "Required actions not available"
2518
+ };
2623
2519
  }
2624
2520
  const errors = [];
2625
- const validProps = Object.keys((0, import_editor_styles4.getStylesSchema)());
2521
+ const stylesSchema = (0, import_editor_styles3.getStylesSchema)();
2522
+ const validProps = Object.keys(stylesSchema);
2626
2523
  Object.keys(props).forEach((key) => {
2627
- const propType = (0, import_editor_styles4.getStylesSchema)()[key];
2524
+ const propType = stylesSchema[key];
2628
2525
  if (!propType) {
2629
2526
  errors.push(`Property "${key}" does not exist in styles schema.`);
2630
2527
  return;
2631
2528
  }
2632
- const { valid, jsonSchema } = import_editor_props2.Schema.validatePropValue(propType, props[key]);
2529
+ const { valid, jsonSchema } = import_editor_props.Schema.validatePropValue(propType, props[key]);
2633
2530
  if (!valid) {
2634
- errors.push(`- Property "${key}" has invalid value:
2635
- expected Schema: ${jsonSchema}
2531
+ errors.push(`- Property "${key}" has invalid value
2532
+ Expected schema: ${jsonSchema}
2636
2533
  `);
2637
2534
  }
2638
2535
  });
2639
2536
  if (errors.length > 0) {
2640
- throw new Error(
2641
- `Errors:
2537
+ return {
2538
+ status: "error",
2539
+ message: `Validation errors:
2642
2540
  ${errors.join("\n")}
2643
2541
  Available Properties: ${validProps.join(
2644
2542
  ", "
2645
2543
  )}
2646
- Now that you have this information, update your input and try again`
2647
- );
2544
+ Update your input and try again.`
2545
+ };
2648
2546
  }
2547
+ const Utils = window.elementorV2.editorVariables.Utils;
2649
2548
  Object.keys(props).forEach((key) => {
2650
- props[key] = import_editor_props2.Schema.adjustLlmPropValueSchema(props[key], {
2651
- transformers: import_editor_variables2.Utils.globalVariablesLLMResolvers
2549
+ props[key] = import_editor_props.Schema.adjustLlmPropValueSchema(props[key], {
2550
+ transformers: Utils.globalVariablesLLMResolvers
2652
2551
  });
2653
2552
  });
2654
- const snapshot = structuredClone(globalClassesStylesProvider.actions.all());
2553
+ const breakpointValue = breakpoint ?? "desktop";
2655
2554
  try {
2656
- update({
2657
- id: classId,
2658
- variants: [
2659
- {
2660
- custom_css: customCss,
2555
+ switch (action) {
2556
+ case "create":
2557
+ const newClassId = await attemptCreate({
2661
2558
  props,
2662
- meta: {
2663
- breakpoint: params.breakpoint === null ? "desktop" : params.breakpoint,
2664
- state: null
2665
- }
2666
- }
2667
- ]
2668
- });
2669
- await saveGlobalClasses({ context: "frontend" });
2559
+ className: globalClassName,
2560
+ stylesProvider: globalClassesStylesProvider,
2561
+ breakpoint: breakpointValue
2562
+ });
2563
+ return newClassId ? {
2564
+ status: "ok",
2565
+ message: `created global class with ID ${newClassId}`
2566
+ } : {
2567
+ status: "error",
2568
+ message: "error creating class"
2569
+ };
2570
+ case "modify":
2571
+ const updated = await attemptUpdate({
2572
+ classId,
2573
+ props,
2574
+ stylesProvider: globalClassesStylesProvider,
2575
+ breakpoint: breakpointValue
2576
+ });
2577
+ return updated ? { status: "ok", classId } : {
2578
+ status: "error",
2579
+ message: "error modifying class"
2580
+ };
2581
+ case "delete":
2582
+ const deleted = await attemptDelete({
2583
+ classId,
2584
+ stylesProvider: globalClassesStylesProvider
2585
+ });
2586
+ return deleted ? { status: "ok", message: `deleted global class with ID ${classId}` } : {
2587
+ status: "error",
2588
+ message: "error deleting class"
2589
+ };
2590
+ }
2670
2591
  } catch (error) {
2671
- snapshot.forEach((style) => {
2672
- update({
2673
- id: style.id,
2674
- variants: style.variants
2675
- });
2676
- });
2677
- await saveGlobalClasses({ context: "frontend" });
2678
- throw new Error(`Failed to modify global class: ${error.message}`);
2592
+ return {
2593
+ status: "error",
2594
+ message: `${action} failed: ${error.message || "Unknown error"}`
2595
+ };
2679
2596
  }
2680
- return "ok";
2681
2597
  };
2682
- var initModifyGlobalClass = (reg) => {
2598
+ var initManageGlobalClasses = (reg) => {
2683
2599
  const { addTool } = reg;
2684
2600
  addTool({
2685
- name: "modify-global-class",
2601
+ name: "manage-global-classes",
2686
2602
  requiredResources: [
2687
- {
2688
- description: "Breakpoints list",
2689
- uri: import_editor_canvas2.BREAKPOINTS_SCHEMA_URI
2690
- },
2691
- {
2692
- description: "Global classes list",
2693
- uri: GLOBAL_CLASSES_URI
2694
- }
2603
+ { uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
2604
+ { uri: import_editor_canvas.STYLE_SCHEMA_URI, description: "Style schema resources" },
2605
+ { uri: import_editor_canvas.BREAKPOINTS_SCHEMA_URI, description: "Breakpoints list" }
2695
2606
  ],
2696
2607
  modelPreferences: {
2697
- hints: [{ name: "claude-sonnet-4-5" }],
2698
2608
  intelligencePriority: 0.85,
2699
2609
  speedPriority: 0.6
2700
2610
  },
2701
- description: `Modify an existing global class within the Elementor editor, allowing users to update styles and properties for consistent design across their website.
2702
- # CRITICAL Prequisites:
2703
- - Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
2704
- - Ensure that the global class ID provided exists.
2705
- - Prefer style schema over custom_css
2706
-
2707
- ## Parameters:
2708
- - \`classId\` (string, required): The ID of the global class to be modified.
2709
- - \`props\` (object, required): A key-value map of style-schema PropValues that define the new styles for the global class.
2710
- - \`customCss\` (string, optional): The CSS styles associated with the global class.
2711
-
2712
- ## Example usage:
2713
- \`\`\`json
2714
- {
2715
- "classId": "existing-class-id",
2716
- "props": {
2717
- "color": {
2718
- "$$type": "color",
2719
- "value": "#00ff00"
2720
- },
2721
- }
2722
- }\`\`\`
2723
- `,
2611
+ description: `Manages global classes (create/modify) in Elementor editor. Check [elementor://global-classes] and style schemas first.
2612
+
2613
+ 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.
2614
+ MODIFY: Requires classId, props. Get classId from [elementor://global-classes] resource.
2615
+
2616
+ Naming pattern: [element-type]-[purpose/variant]-[modifier]
2617
+ DO NOT create global classes for: one-off styles, layout-specific properties.
2618
+
2619
+ Use style schema at [elementor://styles/schema/{category}] for valid props. Errors include exact schema mismatch details.`,
2724
2620
  schema,
2725
- handler: handler2
2621
+ outputSchema,
2622
+ handler
2726
2623
  });
2727
2624
  };
2625
+ async function attemptCreate(opts) {
2626
+ const { props, breakpoint, className, stylesProvider } = opts;
2627
+ const { create, delete: deleteClass2 } = stylesProvider.actions;
2628
+ if (!className) {
2629
+ throw new Error("Global class name is a required for creation");
2630
+ }
2631
+ if (!create || !deleteClass2) {
2632
+ throw new Error("User is unable to create global classes");
2633
+ }
2634
+ const newClassId = create(className, [
2635
+ {
2636
+ meta: {
2637
+ breakpoint,
2638
+ state: null
2639
+ },
2640
+ custom_css: null,
2641
+ props
2642
+ }
2643
+ ]);
2644
+ try {
2645
+ await saveGlobalClasses({ context: "frontend" });
2646
+ return newClassId;
2647
+ } catch {
2648
+ deleteClass2(newClassId);
2649
+ return null;
2650
+ }
2651
+ }
2652
+ async function attemptUpdate(opts) {
2653
+ const { props, breakpoint, classId, stylesProvider } = opts;
2654
+ const { updateProps, update } = stylesProvider.actions;
2655
+ if (!classId) {
2656
+ throw new Error("Class ID is required for modification");
2657
+ }
2658
+ if (!updateProps || !update) {
2659
+ throw new Error("User is unable to update global classes");
2660
+ }
2661
+ const snapshot = structuredClone(stylesProvider.actions.all());
2662
+ try {
2663
+ updateProps({
2664
+ id: classId,
2665
+ props,
2666
+ meta: {
2667
+ breakpoint,
2668
+ state: null
2669
+ }
2670
+ });
2671
+ await saveGlobalClasses({ context: "frontend" });
2672
+ return true;
2673
+ } catch {
2674
+ snapshot.forEach((style) => {
2675
+ update({
2676
+ id: style.id,
2677
+ variants: style.variants
2678
+ });
2679
+ });
2680
+ await saveGlobalClasses({ context: "frontend" });
2681
+ return false;
2682
+ }
2683
+ }
2684
+ async function attemptDelete(opts) {
2685
+ const { classId, stylesProvider } = opts;
2686
+ const { delete: deleteClass2, create } = stylesProvider.actions;
2687
+ if (!classId) {
2688
+ throw new Error("Class ID is required for deletion");
2689
+ }
2690
+ if (!deleteClass2 || !create) {
2691
+ throw new Error("User is unable to delete global classes");
2692
+ }
2693
+ const snapshot = structuredClone(stylesProvider.actions.all());
2694
+ const targetClass = snapshot.find((style) => style.id === classId);
2695
+ if (!targetClass) {
2696
+ throw new Error(`Class with ID "${classId}" not found`);
2697
+ }
2698
+ try {
2699
+ deleteClass2(classId);
2700
+ await saveGlobalClasses({ context: "frontend" });
2701
+ return true;
2702
+ } catch {
2703
+ return false;
2704
+ }
2705
+ }
2728
2706
 
2729
2707
  // src/mcp-integration/index.ts
2730
2708
  var initMcpIntegration = () => {
2731
- const reg = (0, import_editor_mcp2.getMCPByDomain)("canvas");
2709
+ const reg = (0, import_editor_mcp2.getMCPByDomain)("classes", {
2710
+ instructions: "MCP server for management of Elementor global classes"
2711
+ });
2732
2712
  initMcpApplyUnapplyGlobalClasses(reg);
2733
2713
  initMcpApplyGetGlobalClassUsages(reg);
2734
- initCreateGlobalClass(reg);
2735
- initModifyGlobalClass(reg);
2714
+ initManageGlobalClasses(reg);
2736
2715
  initClassesResource();
2737
2716
  };
2738
2717