@elementor/editor-global-classes 3.35.0-340 → 3.35.0-342
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.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -30,24 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
GLOBAL_CLASSES_URI: () => GLOBAL_CLASSES_URI,
|
|
33
34
|
init: () => init
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(index_exports);
|
|
36
37
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
39
|
-
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
40
|
-
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
41
|
-
var import_editor_styles_repository6 = require("@elementor/editor-styles-repository");
|
|
42
|
-
var import_store26 = require("@elementor/store");
|
|
43
|
-
|
|
44
|
-
// src/components/class-manager/class-manager-button.tsx
|
|
45
|
-
var React19 = __toESM(require("react"));
|
|
46
|
-
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
47
|
-
var import_editor_styles_repository3 = require("@elementor/editor-styles-repository");
|
|
48
|
-
var import_editor_ui9 = require("@elementor/editor-ui");
|
|
49
|
-
var import_ui16 = require("@elementor/ui");
|
|
50
|
-
var import_i18n15 = require("@wordpress/i18n");
|
|
38
|
+
// src/mcp-integration/classes-resource.ts
|
|
39
|
+
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
51
40
|
|
|
52
41
|
// src/global-classes-styles-provider.ts
|
|
53
42
|
var import_editor_styles2 = require("@elementor/editor-styles");
|
|
@@ -222,7 +211,9 @@ var slice = (0, import_store.__createSlice)({
|
|
|
222
211
|
let customCss = ("custom_css" in payload ? payload.custom_css : variant?.custom_css) ?? null;
|
|
223
212
|
customCss = customCss?.raw ? customCss : null;
|
|
224
213
|
if (variant) {
|
|
225
|
-
|
|
214
|
+
const variantProps = JSON.parse(JSON.stringify(variant.props));
|
|
215
|
+
const payloadProps = JSON.parse(JSON.stringify(payload.props));
|
|
216
|
+
variant.props = (0, import_editor_props.mergeProps)(variantProps, payloadProps);
|
|
226
217
|
variant.custom_css = customCss;
|
|
227
218
|
style.variants = getNonEmptyVariants(style);
|
|
228
219
|
} else {
|
|
@@ -528,6 +519,42 @@ var subscribeWithStates = (cb) => {
|
|
|
528
519
|
);
|
|
529
520
|
};
|
|
530
521
|
|
|
522
|
+
// src/mcp-integration/classes-resource.ts
|
|
523
|
+
var GLOBAL_CLASSES_URI = "elementor://global-classes";
|
|
524
|
+
var initClassesResource = () => {
|
|
525
|
+
const { mcpServer } = (0, import_editor_mcp.getMCPByDomain)("canvas");
|
|
526
|
+
mcpServer.resource(
|
|
527
|
+
"global-classes",
|
|
528
|
+
GLOBAL_CLASSES_URI,
|
|
529
|
+
{
|
|
530
|
+
description: "Global classes list."
|
|
531
|
+
},
|
|
532
|
+
async () => {
|
|
533
|
+
return {
|
|
534
|
+
contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? {} }]
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
);
|
|
538
|
+
globalClassesStylesProvider.subscribe(() => {
|
|
539
|
+
mcpServer.sendResourceListChanged();
|
|
540
|
+
});
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// src/init.ts
|
|
544
|
+
var import_editor = require("@elementor/editor");
|
|
545
|
+
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
546
|
+
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
547
|
+
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
548
|
+
var import_store26 = require("@elementor/store");
|
|
549
|
+
|
|
550
|
+
// src/components/class-manager/class-manager-button.tsx
|
|
551
|
+
var React19 = __toESM(require("react"));
|
|
552
|
+
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
553
|
+
var import_editor_styles_repository3 = require("@elementor/editor-styles-repository");
|
|
554
|
+
var import_editor_ui9 = require("@elementor/editor-ui");
|
|
555
|
+
var import_ui16 = require("@elementor/ui");
|
|
556
|
+
var import_i18n15 = require("@wordpress/i18n");
|
|
557
|
+
|
|
531
558
|
// src/hooks/use-prefetch-css-class-usage.ts
|
|
532
559
|
var import_query = require("@elementor/query");
|
|
533
560
|
|
|
@@ -1872,7 +1899,7 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1872
1899
|
const [classesOrder, reorderClasses] = useReorder(draggedItemId, setDraggedItemId, draggedItemLabel ?? "");
|
|
1873
1900
|
const filteredCssClasses = useFilteredCssClasses();
|
|
1874
1901
|
(0, import_react7.useEffect)(() => {
|
|
1875
|
-
const
|
|
1902
|
+
const handler3 = (event) => {
|
|
1876
1903
|
if (event.key === "z" && (event.ctrlKey || event.metaKey)) {
|
|
1877
1904
|
event.stopImmediatePropagation();
|
|
1878
1905
|
event.preventDefault();
|
|
@@ -1883,10 +1910,10 @@ var GlobalClassesList = ({ disabled }) => {
|
|
|
1883
1910
|
dispatch5(slice.actions.undo());
|
|
1884
1911
|
}
|
|
1885
1912
|
};
|
|
1886
|
-
window.addEventListener("keydown",
|
|
1913
|
+
window.addEventListener("keydown", handler3, {
|
|
1887
1914
|
capture: true
|
|
1888
1915
|
});
|
|
1889
|
-
return () => window.removeEventListener("keydown",
|
|
1916
|
+
return () => window.removeEventListener("keydown", handler3);
|
|
1890
1917
|
}, [dispatch5]);
|
|
1891
1918
|
if (!cssClasses?.length) {
|
|
1892
1919
|
return /* @__PURE__ */ React17.createElement(EmptyState, null);
|
|
@@ -2276,80 +2303,10 @@ function PopulateStore() {
|
|
|
2276
2303
|
// src/mcp-integration/index.ts
|
|
2277
2304
|
var import_editor_mcp2 = require("@elementor/editor-mcp");
|
|
2278
2305
|
|
|
2279
|
-
// src/mcp-integration/classes-resource.ts
|
|
2280
|
-
var import_editor_mcp = require("@elementor/editor-mcp");
|
|
2281
|
-
var GLOBAL_CLASSES_URI = "elementor://classes";
|
|
2282
|
-
var initClassesResource = () => {
|
|
2283
|
-
const { mcpServer } = (0, import_editor_mcp.getMCPByDomain)("classes");
|
|
2284
|
-
mcpServer.resource(
|
|
2285
|
-
"global-classes",
|
|
2286
|
-
GLOBAL_CLASSES_URI,
|
|
2287
|
-
{
|
|
2288
|
-
description: "Global classes list."
|
|
2289
|
-
},
|
|
2290
|
-
async () => {
|
|
2291
|
-
return {
|
|
2292
|
-
contents: [{ uri: GLOBAL_CLASSES_URI, text: localStorage["elementor-global-classes"] ?? {} }]
|
|
2293
|
-
};
|
|
2294
|
-
}
|
|
2295
|
-
);
|
|
2296
|
-
};
|
|
2297
|
-
|
|
2298
2306
|
// src/mcp-integration/mcp-apply-unapply-global-classes.ts
|
|
2299
2307
|
var import_editor_editing_panel = require("@elementor/editor-editing-panel");
|
|
2300
|
-
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
2301
2308
|
var import_schema = require("@elementor/schema");
|
|
2302
2309
|
function initMcpApplyUnapplyGlobalClasses(server) {
|
|
2303
|
-
server.addTool({
|
|
2304
|
-
name: "list-all-global-classes",
|
|
2305
|
-
description: `List all classes applied to a specific element
|
|
2306
|
-
|
|
2307
|
-
## When to use this tool:
|
|
2308
|
-
- When a user requests to see which classes or global classes exists.
|
|
2309
|
-
- When you need the list of global classes to allow the user to select from.
|
|
2310
|
-
- At least once before applying or unapplying a class, to ensure the class ID is correct.
|
|
2311
|
-
|
|
2312
|
-
`,
|
|
2313
|
-
outputSchema: {
|
|
2314
|
-
appliedClasses: import_schema.z.array(
|
|
2315
|
-
import_schema.z.object({
|
|
2316
|
-
id: import_schema.z.string().describe("The ID of the class"),
|
|
2317
|
-
label: import_schema.z.string().describe("The label of the class"),
|
|
2318
|
-
variants: import_schema.z.array(
|
|
2319
|
-
import_schema.z.object({
|
|
2320
|
-
meta: import_schema.z.object({
|
|
2321
|
-
breakpoint: import_schema.z.string().optional(),
|
|
2322
|
-
state: import_schema.z.string().optional()
|
|
2323
|
-
}),
|
|
2324
|
-
props: import_schema.z.record(import_schema.z.any())
|
|
2325
|
-
})
|
|
2326
|
-
)
|
|
2327
|
-
})
|
|
2328
|
-
)
|
|
2329
|
-
},
|
|
2330
|
-
handler: async () => {
|
|
2331
|
-
const globalClassesProvider = import_editor_styles_repository5.stylesRepository.getProviderByKey("global-classes");
|
|
2332
|
-
if (!globalClassesProvider) {
|
|
2333
|
-
throw new Error("Global classes provider not found");
|
|
2334
|
-
}
|
|
2335
|
-
const result = [];
|
|
2336
|
-
globalClassesProvider.actions.all().forEach((style) => {
|
|
2337
|
-
const { id: id2, label, variants } = style;
|
|
2338
|
-
result.push({
|
|
2339
|
-
id: id2,
|
|
2340
|
-
label,
|
|
2341
|
-
variants: variants.map((variant) => ({
|
|
2342
|
-
meta: {
|
|
2343
|
-
breakpoint: variant.meta.breakpoint,
|
|
2344
|
-
state: variant.meta.state
|
|
2345
|
-
},
|
|
2346
|
-
props: variant.props
|
|
2347
|
-
}))
|
|
2348
|
-
});
|
|
2349
|
-
});
|
|
2350
|
-
return { appliedClasses: result };
|
|
2351
|
-
}
|
|
2352
|
-
});
|
|
2353
2310
|
server.addTool({
|
|
2354
2311
|
schema: {
|
|
2355
2312
|
classId: import_schema.z.string().describe("The ID of the class to apply"),
|
|
@@ -2363,7 +2320,8 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2363
2320
|
- When you need to add a specific class to an element's applied classes.
|
|
2364
2321
|
|
|
2365
2322
|
## Prerequisites:
|
|
2366
|
-
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates.
|
|
2323
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates.
|
|
2324
|
+
List available at always up-to-date resource 'elementor://global-classes'.
|
|
2367
2325
|
- Make sure you have the correct class ID that you want to apply.`,
|
|
2368
2326
|
handler: async (params) => {
|
|
2369
2327
|
const { classId, elementId } = params;
|
|
@@ -2385,11 +2343,12 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2385
2343
|
- When you need to remove a specific class from an element's applied classes.
|
|
2386
2344
|
|
|
2387
2345
|
## Prerequisites:
|
|
2388
|
-
- Ensure you have the most up-to-date list of classes applied to the element to avoid errors.
|
|
2346
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid errors.
|
|
2347
|
+
The list is available at always up-to-date resource 'elementor://global-classes'.
|
|
2389
2348
|
- Make sure you have the correct class ID that you want to unapply.
|
|
2390
2349
|
|
|
2391
2350
|
<note>
|
|
2392
|
-
If the user want to unapply a class by it's name and not ID,
|
|
2351
|
+
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
|
|
2393
2352
|
</note>
|
|
2394
2353
|
`,
|
|
2395
2354
|
handler: async (params) => {
|
|
@@ -2403,22 +2362,164 @@ If the user want to unapply a class by it's name and not ID, please use the "lis
|
|
|
2403
2362
|
});
|
|
2404
2363
|
}
|
|
2405
2364
|
|
|
2406
|
-
// src/mcp-integration/mcp-
|
|
2365
|
+
// src/mcp-integration/mcp-create-global-class.ts
|
|
2366
|
+
var import_editor_canvas = require("@elementor/editor-canvas");
|
|
2367
|
+
var import_editor_props2 = require("@elementor/editor-props");
|
|
2368
|
+
var import_editor_styles3 = require("@elementor/editor-styles");
|
|
2369
|
+
var import_editor_variables = require("@elementor/editor-variables");
|
|
2407
2370
|
var import_schema2 = require("@elementor/schema");
|
|
2371
|
+
var inputSchema = {
|
|
2372
|
+
globalClassName: import_schema2.z.string().describe("The name of the global class to be created"),
|
|
2373
|
+
props: import_schema2.z.record(import_schema2.z.any()).describe(
|
|
2374
|
+
'key-value of style-schema PropValues applied to the global class. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2375
|
+
).default({}),
|
|
2376
|
+
customCss: import_schema2.z.string().optional().describe(
|
|
2377
|
+
"Additional CSS styles associated with the global class. Use only if you fail to use the schema, specifically backgrounds"
|
|
2378
|
+
),
|
|
2379
|
+
breakpoint: import_schema2.z.nullable(
|
|
2380
|
+
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")
|
|
2381
|
+
).default(null).describe("The responsive breakpoint name for which the global class styles should be applied")
|
|
2382
|
+
};
|
|
2383
|
+
var outputSchema = {
|
|
2384
|
+
classId: import_schema2.z.string().describe("The unique identifier of the newly created global class")
|
|
2385
|
+
};
|
|
2386
|
+
var handler = async (input) => {
|
|
2387
|
+
const customCss = input.customCss ? { raw: btoa(input.customCss) } : null;
|
|
2388
|
+
const { delete: deleteClass2, create } = globalClassesStylesProvider.actions;
|
|
2389
|
+
if (!create || !deleteClass2) {
|
|
2390
|
+
throw new Error("Create action is not available");
|
|
2391
|
+
}
|
|
2392
|
+
const errors = [];
|
|
2393
|
+
const stylesSchema = (0, import_editor_styles3.getStylesSchema)();
|
|
2394
|
+
const validProps = Object.keys(stylesSchema);
|
|
2395
|
+
Object.keys(input.props).forEach((key) => {
|
|
2396
|
+
const propType = (0, import_editor_styles3.getStylesSchema)()[key];
|
|
2397
|
+
if (!propType) {
|
|
2398
|
+
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2399
|
+
return;
|
|
2400
|
+
}
|
|
2401
|
+
const { valid, jsonSchema } = import_editor_props2.Schema.validatePropValue(propType, input.props[key]);
|
|
2402
|
+
if (!valid) {
|
|
2403
|
+
errors.push(
|
|
2404
|
+
`- Property "${key}" has invalid value
|
|
2405
|
+
Exact schema: \`\`\`json
|
|
2406
|
+
${jsonSchema}\`\`\`
|
|
2407
|
+
`
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2410
|
+
});
|
|
2411
|
+
if (errors.length > 0) {
|
|
2412
|
+
throw new Error(
|
|
2413
|
+
`Errors:
|
|
2414
|
+
${errors.join("\n")}
|
|
2415
|
+
Available Properties: ${validProps.join(
|
|
2416
|
+
", "
|
|
2417
|
+
)}
|
|
2418
|
+
Now that you have this information, update your input and try again`
|
|
2419
|
+
);
|
|
2420
|
+
}
|
|
2421
|
+
Object.keys(input.props).forEach((key) => {
|
|
2422
|
+
input.props[key] = import_editor_props2.Schema.adjustLlmPropValueSchema(input.props[key], {
|
|
2423
|
+
transformers: import_editor_variables.Utils.globalVariablesLLMResolvers
|
|
2424
|
+
});
|
|
2425
|
+
});
|
|
2426
|
+
const classId = create(input.globalClassName, [
|
|
2427
|
+
{
|
|
2428
|
+
meta: {
|
|
2429
|
+
breakpoint: input.breakpoint === null ? "desktop" : input.breakpoint,
|
|
2430
|
+
state: null
|
|
2431
|
+
},
|
|
2432
|
+
custom_css: customCss,
|
|
2433
|
+
props: input.props
|
|
2434
|
+
}
|
|
2435
|
+
]);
|
|
2436
|
+
try {
|
|
2437
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2438
|
+
} catch (err) {
|
|
2439
|
+
deleteClass2(classId);
|
|
2440
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2441
|
+
throw new Error(`Failed to create global class, probably invalid schema values.`);
|
|
2442
|
+
}
|
|
2443
|
+
return {
|
|
2444
|
+
classId
|
|
2445
|
+
};
|
|
2446
|
+
};
|
|
2447
|
+
var initCreateGlobalClass = (reg) => {
|
|
2448
|
+
const { addTool } = reg;
|
|
2449
|
+
addTool({
|
|
2450
|
+
requiredResources: [
|
|
2451
|
+
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
2452
|
+
{ uri: import_editor_canvas.STYLE_SCHEMA_URI, description: "Style schema resources" }
|
|
2453
|
+
],
|
|
2454
|
+
description: `Create a new global class within the Elementor editor, allowing users to define reusable styles and properties for consistent design across their website.
|
|
2455
|
+
|
|
2456
|
+
# Prequisites: CRITICAL
|
|
2457
|
+
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
2458
|
+
- Available style properties can be found in the styles schema dynamic resources available from 'canvas' mcp. List the resources to see all available properties.
|
|
2459
|
+
- YOU MUST USE THE STYLE SCHEMA TO BUILD THE "props" PARAMETER CORRECTLY, OTHERWISE THE GLOBAL CLASS CREATION WILL FAIL.
|
|
2460
|
+
- Ensure that the global class name provided does not already exist to avoid duplication.
|
|
2461
|
+
- Read the styles schema resource available from 'canvas' mcp to understand the valid properties and values that can be assigned to the global class.
|
|
2462
|
+
|
|
2463
|
+
## Parameters:
|
|
2464
|
+
- \`globalClassName\` (string, required): The name of the global class to be created.
|
|
2465
|
+
- \`props\` (object, required): A key-value map of style-schema PropValues that define the styles for the global class.
|
|
2466
|
+
- \`breakpoint\` (string | null, optional): The responsive breakpoint for which the styles should be applied. If null, styles apply to all breakpoints.
|
|
2467
|
+
|
|
2468
|
+
## Example usage:
|
|
2469
|
+
\`\`\`json
|
|
2470
|
+
{
|
|
2471
|
+
"globalClassName": "my-new-class",
|
|
2472
|
+
"props": {
|
|
2473
|
+
"color": {
|
|
2474
|
+
"$$type": "color",
|
|
2475
|
+
"value": "#ff0000"
|
|
2476
|
+
},
|
|
2477
|
+
"fontSize": {
|
|
2478
|
+
"$$type": "size",
|
|
2479
|
+
"value": {
|
|
2480
|
+
"size": {
|
|
2481
|
+
"$$type": "number",
|
|
2482
|
+
"value": 2.5
|
|
2483
|
+
},
|
|
2484
|
+
"unit": {
|
|
2485
|
+
"$$type": "string",
|
|
2486
|
+
"value": "em"
|
|
2487
|
+
}
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
},
|
|
2491
|
+
"breakpoint": "desktop"
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
# Next steps:
|
|
2495
|
+
If failed, read the error message carefully, it includes the exact schema that caused the failure for each invalid property.
|
|
2496
|
+
Now that you have this information, update your input and try again.
|
|
2497
|
+
|
|
2498
|
+
\`\`\`
|
|
2499
|
+
`,
|
|
2500
|
+
name: "create-global-class",
|
|
2501
|
+
schema: inputSchema,
|
|
2502
|
+
outputSchema,
|
|
2503
|
+
handler
|
|
2504
|
+
});
|
|
2505
|
+
};
|
|
2506
|
+
|
|
2507
|
+
// src/mcp-integration/mcp-get-global-class-usages.ts
|
|
2508
|
+
var import_schema3 = require("@elementor/schema");
|
|
2408
2509
|
function initMcpApplyGetGlobalClassUsages(reg) {
|
|
2409
2510
|
const { addTool } = reg;
|
|
2410
2511
|
const globalClassesUsageSchema = {
|
|
2411
|
-
usages:
|
|
2412
|
-
|
|
2413
|
-
classId:
|
|
2512
|
+
usages: import_schema3.z.array(
|
|
2513
|
+
import_schema3.z.object({
|
|
2514
|
+
classId: import_schema3.z.string().describe(
|
|
2414
2515
|
'The ID of the class, not visible to the user. To retreive the name of the class, use the "list-global-classes" tool'
|
|
2415
2516
|
),
|
|
2416
|
-
usages:
|
|
2417
|
-
|
|
2418
|
-
pageId:
|
|
2419
|
-
title:
|
|
2420
|
-
total:
|
|
2421
|
-
elements:
|
|
2517
|
+
usages: import_schema3.z.array(
|
|
2518
|
+
import_schema3.z.object({
|
|
2519
|
+
pageId: import_schema3.z.string().describe("The ID of the page where the class is used"),
|
|
2520
|
+
title: import_schema3.z.string().describe("The title of the page where the class is used"),
|
|
2521
|
+
total: import_schema3.z.number().describe("The number of times the class is used on this page"),
|
|
2522
|
+
elements: import_schema3.z.array(import_schema3.z.string()).describe("List of element IDs using this class on the page")
|
|
2422
2523
|
})
|
|
2423
2524
|
)
|
|
2424
2525
|
})
|
|
@@ -2426,15 +2527,18 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2426
2527
|
};
|
|
2427
2528
|
addTool({
|
|
2428
2529
|
name: "get-global-class-usages",
|
|
2429
|
-
description: `Retreive the
|
|
2530
|
+
description: `Retreive the usages of global-classes ACCROSS PAGES designed by Elementor editor.
|
|
2430
2531
|
|
|
2431
|
-
## Prequisites:
|
|
2432
|
-
-
|
|
2532
|
+
## Prequisites: CRITICAL
|
|
2533
|
+
- The list of global classes and their applid values is available at resource uri elementor://global-classes
|
|
2433
2534
|
|
|
2434
2535
|
## When to use this tool:
|
|
2435
2536
|
- When a user requests to see where a specific global class is being used accross the site.
|
|
2436
2537
|
- When you need to manage or clean up unused global classes.
|
|
2437
2538
|
- Before deleting a global class, to ensure it is not in use in any other pages.
|
|
2539
|
+
|
|
2540
|
+
## When NOT to use this tool:
|
|
2541
|
+
- For getting the list of global classes, refer to the resource at uri elementor://global-classes
|
|
2438
2542
|
`,
|
|
2439
2543
|
outputSchema: globalClassesUsageSchema,
|
|
2440
2544
|
handler: async () => {
|
|
@@ -2467,14 +2571,134 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2467
2571
|
});
|
|
2468
2572
|
}
|
|
2469
2573
|
|
|
2574
|
+
// src/mcp-integration/mcp-modify-global-class.ts
|
|
2575
|
+
var import_editor_canvas2 = require("@elementor/editor-canvas");
|
|
2576
|
+
var import_editor_props3 = require("@elementor/editor-props");
|
|
2577
|
+
var import_editor_styles4 = require("@elementor/editor-styles");
|
|
2578
|
+
var import_editor_variables2 = require("@elementor/editor-variables");
|
|
2579
|
+
var import_schema4 = require("@elementor/schema");
|
|
2580
|
+
var schema = {
|
|
2581
|
+
classId: import_schema4.z.string().describe("The ID of the global class to modify"),
|
|
2582
|
+
props: import_schema4.z.record(import_schema4.z.any()).describe(
|
|
2583
|
+
'key-value of style-schema PropValues to update the global class with. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
2584
|
+
),
|
|
2585
|
+
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"),
|
|
2586
|
+
customCss: import_schema4.z.string().optional().describe("The CSS styles associated with the global class.")
|
|
2587
|
+
};
|
|
2588
|
+
var handler2 = async (params) => {
|
|
2589
|
+
const { classId, props } = params;
|
|
2590
|
+
const customCss = params.customCss ? { raw: btoa(params.customCss) } : null;
|
|
2591
|
+
const { update, delete: deleteClass2 } = globalClassesStylesProvider.actions;
|
|
2592
|
+
if (!update || !deleteClass2) {
|
|
2593
|
+
throw new Error("Update action is not available");
|
|
2594
|
+
}
|
|
2595
|
+
const errors = [];
|
|
2596
|
+
const validProps = Object.keys((0, import_editor_styles4.getStylesSchema)());
|
|
2597
|
+
Object.keys(props).forEach((key) => {
|
|
2598
|
+
const propType = (0, import_editor_styles4.getStylesSchema)()[key];
|
|
2599
|
+
if (!propType) {
|
|
2600
|
+
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
2601
|
+
return;
|
|
2602
|
+
}
|
|
2603
|
+
const { valid, jsonSchema } = import_editor_props3.Schema.validatePropValue(propType, props[key]);
|
|
2604
|
+
if (!valid) {
|
|
2605
|
+
errors.push(`- Property "${key}" has invalid value:
|
|
2606
|
+
expected Schema: ${jsonSchema}
|
|
2607
|
+
`);
|
|
2608
|
+
}
|
|
2609
|
+
});
|
|
2610
|
+
if (errors.length > 0) {
|
|
2611
|
+
throw new Error(
|
|
2612
|
+
`Errors:
|
|
2613
|
+
${errors.join("\n")}
|
|
2614
|
+
Available Properties: ${validProps.join(
|
|
2615
|
+
", "
|
|
2616
|
+
)}
|
|
2617
|
+
Now that you have this information, update your input and try again`
|
|
2618
|
+
);
|
|
2619
|
+
}
|
|
2620
|
+
Object.keys(props).forEach((key) => {
|
|
2621
|
+
props[key] = import_editor_props3.Schema.adjustLlmPropValueSchema(props[key], {
|
|
2622
|
+
transformers: import_editor_variables2.Utils.globalVariablesLLMResolvers
|
|
2623
|
+
});
|
|
2624
|
+
});
|
|
2625
|
+
const snapshot = structuredClone(globalClassesStylesProvider.actions.all());
|
|
2626
|
+
try {
|
|
2627
|
+
update({
|
|
2628
|
+
id: classId,
|
|
2629
|
+
variants: [
|
|
2630
|
+
{
|
|
2631
|
+
custom_css: customCss,
|
|
2632
|
+
props,
|
|
2633
|
+
meta: {
|
|
2634
|
+
breakpoint: params.breakpoint === null ? "desktop" : params.breakpoint,
|
|
2635
|
+
state: null
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
]
|
|
2639
|
+
});
|
|
2640
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2641
|
+
} catch (error) {
|
|
2642
|
+
snapshot.forEach((style) => {
|
|
2643
|
+
update({
|
|
2644
|
+
id: style.id,
|
|
2645
|
+
variants: style.variants
|
|
2646
|
+
});
|
|
2647
|
+
});
|
|
2648
|
+
await saveGlobalClasses({ context: "frontend" });
|
|
2649
|
+
throw new Error(`Failed to modify global class: ${error.message}`);
|
|
2650
|
+
}
|
|
2651
|
+
return "ok";
|
|
2652
|
+
};
|
|
2653
|
+
var initModifyGlobalClass = (reg) => {
|
|
2654
|
+
const { addTool } = reg;
|
|
2655
|
+
addTool({
|
|
2656
|
+
name: "modify-global-class",
|
|
2657
|
+
requiredResources: [
|
|
2658
|
+
{
|
|
2659
|
+
description: "Breakpoints list",
|
|
2660
|
+
uri: import_editor_canvas2.BREAKPOINTS_SCHEMA_URI
|
|
2661
|
+
},
|
|
2662
|
+
{
|
|
2663
|
+
description: "Global classes list",
|
|
2664
|
+
uri: GLOBAL_CLASSES_URI
|
|
2665
|
+
}
|
|
2666
|
+
],
|
|
2667
|
+
description: `Modify an existing global class within the Elementor editor, allowing users to update styles and properties for consistent design across their website.
|
|
2668
|
+
# CRITICAL Prequisites:
|
|
2669
|
+
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
2670
|
+
- Ensure that the global class ID provided exists.
|
|
2671
|
+
- Prefer style schema over custom_css
|
|
2672
|
+
|
|
2673
|
+
## Parameters:
|
|
2674
|
+
- \`classId\` (string, required): The ID of the global class to be modified.
|
|
2675
|
+
- \`props\` (object, required): A key-value map of style-schema PropValues that define the new styles for the global class.
|
|
2676
|
+
- \`customCss\` (string, optional): The CSS styles associated with the global class.
|
|
2677
|
+
|
|
2678
|
+
## Example usage:
|
|
2679
|
+
\`\`\`json
|
|
2680
|
+
{
|
|
2681
|
+
"classId": "existing-class-id",
|
|
2682
|
+
"props": {
|
|
2683
|
+
"color": {
|
|
2684
|
+
"$$type": "color",
|
|
2685
|
+
"value": "#00ff00"
|
|
2686
|
+
},
|
|
2687
|
+
}
|
|
2688
|
+
}\`\`\`
|
|
2689
|
+
`,
|
|
2690
|
+
schema,
|
|
2691
|
+
handler: handler2
|
|
2692
|
+
});
|
|
2693
|
+
};
|
|
2694
|
+
|
|
2470
2695
|
// src/mcp-integration/index.ts
|
|
2471
2696
|
var initMcpIntegration = () => {
|
|
2472
|
-
const reg = (0, import_editor_mcp2.getMCPByDomain)("
|
|
2473
|
-
reg.setMCPDescription(
|
|
2474
|
-
"Tools for managing and applying Global CSS classes to elements within the Elementor editor."
|
|
2475
|
-
);
|
|
2697
|
+
const reg = (0, import_editor_mcp2.getMCPByDomain)("canvas");
|
|
2476
2698
|
initMcpApplyUnapplyGlobalClasses(reg);
|
|
2477
2699
|
initMcpApplyGetGlobalClassUsages(reg);
|
|
2700
|
+
initCreateGlobalClass(reg);
|
|
2701
|
+
initModifyGlobalClass(reg);
|
|
2478
2702
|
initClassesResource();
|
|
2479
2703
|
};
|
|
2480
2704
|
|
|
@@ -2533,7 +2757,7 @@ function SyncWithDocumentSave() {
|
|
|
2533
2757
|
function init() {
|
|
2534
2758
|
(0, import_store26.__registerSlice)(slice);
|
|
2535
2759
|
(0, import_editor_panels2.__registerPanel)(panel);
|
|
2536
|
-
|
|
2760
|
+
import_editor_styles_repository5.stylesRepository.register(globalClassesStylesProvider);
|
|
2537
2761
|
(0, import_editor.injectIntoLogic)({
|
|
2538
2762
|
id: "global-classes-populate-store",
|
|
2539
2763
|
component: PopulateStore
|
|
@@ -2562,6 +2786,7 @@ function init() {
|
|
|
2562
2786
|
}
|
|
2563
2787
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2564
2788
|
0 && (module.exports = {
|
|
2789
|
+
GLOBAL_CLASSES_URI,
|
|
2565
2790
|
init
|
|
2566
2791
|
});
|
|
2567
2792
|
//# sourceMappingURL=index.js.map
|