@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 +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
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { STYLE_SCHEMA_URI } from '@elementor/editor-canvas';
|
|
2
|
-
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
3
|
-
import { Schema } from '@elementor/editor-props';
|
|
4
|
-
import { getStylesSchema } from '@elementor/editor-styles';
|
|
5
|
-
import { Utils } from '@elementor/editor-variables';
|
|
6
|
-
import { z } from '@elementor/schema';
|
|
7
|
-
|
|
8
|
-
import { globalClassesStylesProvider } from '../global-classes-styles-provider';
|
|
9
|
-
import { saveGlobalClasses } from '../save-global-classes';
|
|
10
|
-
import { GLOBAL_CLASSES_URI } from './classes-resource';
|
|
11
|
-
|
|
12
|
-
export const inputSchema = {
|
|
13
|
-
globalClassName: z.string().describe( 'The name of the global class to be created' ),
|
|
14
|
-
props: z
|
|
15
|
-
.record( z.any() )
|
|
16
|
-
.describe(
|
|
17
|
-
'key-value of style-schema PropValues applied to the global class. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
18
|
-
)
|
|
19
|
-
.default( {} ),
|
|
20
|
-
customCss: z
|
|
21
|
-
.string()
|
|
22
|
-
.optional()
|
|
23
|
-
.describe(
|
|
24
|
-
'Additional CSS styles associated with the global class. Use only if you fail to use the schema, specifically backgrounds'
|
|
25
|
-
),
|
|
26
|
-
breakpoint: z
|
|
27
|
-
.nullable(
|
|
28
|
-
z
|
|
29
|
-
.enum( [ 'desktop', 'tablet', 'mobile', 'laptop', 'widescreen', 'tablet_extra', 'mobile_extra' ] )
|
|
30
|
-
.describe( 'The responsive breakpoint name for which the global class styles should be applied' )
|
|
31
|
-
)
|
|
32
|
-
.default( null )
|
|
33
|
-
.describe( 'The responsive breakpoint name for which the global class styles should be applied' ),
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const outputSchema = {
|
|
37
|
-
classId: z.string().describe( 'The unique identifier of the newly created global class' ),
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
type InputSchema = z.infer< ReturnType< typeof z.object< typeof inputSchema > > >;
|
|
41
|
-
type OutputSchema = z.infer< ReturnType< typeof z.object< typeof outputSchema > > >;
|
|
42
|
-
|
|
43
|
-
export const handler = async ( input: InputSchema ): Promise< OutputSchema > => {
|
|
44
|
-
const customCss = input.customCss ? { raw: btoa( input.customCss ) } : null;
|
|
45
|
-
const { delete: deleteClass, create } = globalClassesStylesProvider.actions;
|
|
46
|
-
if ( ! create || ! deleteClass ) {
|
|
47
|
-
throw new Error( 'Create action is not available' );
|
|
48
|
-
}
|
|
49
|
-
const errors: string[] = [];
|
|
50
|
-
const stylesSchema = getStylesSchema();
|
|
51
|
-
const validProps = Object.keys( stylesSchema );
|
|
52
|
-
|
|
53
|
-
Object.keys( input.props ).forEach( ( key ) => {
|
|
54
|
-
const propType = getStylesSchema()[ key ];
|
|
55
|
-
if ( ! propType ) {
|
|
56
|
-
errors.push( `Property "${ key }" does not exist in styles schema.` );
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const { valid, jsonSchema } = Schema.validatePropValue( propType, input.props[ key ] );
|
|
60
|
-
if ( ! valid ) {
|
|
61
|
-
errors.push(
|
|
62
|
-
`- Property "${ key }" has invalid value\n Exact schema: \`\`\`json\n${ jsonSchema }\`\`\`\n`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
} );
|
|
66
|
-
if ( errors.length > 0 ) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`Errors:\n${ errors.join( '\n' ) }\nAvailable Properties: ${ validProps.join(
|
|
69
|
-
', '
|
|
70
|
-
) }\nNow that you have this information, update your input and try again`
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
Object.keys( input.props ).forEach( ( key ) => {
|
|
74
|
-
input.props[ key ] = Schema.adjustLlmPropValueSchema( input.props[ key ], {
|
|
75
|
-
transformers: Utils.globalVariablesLLMResolvers,
|
|
76
|
-
} );
|
|
77
|
-
} );
|
|
78
|
-
const classId = create( input.globalClassName, [
|
|
79
|
-
{
|
|
80
|
-
meta: {
|
|
81
|
-
breakpoint: input.breakpoint === null ? 'desktop' : input.breakpoint,
|
|
82
|
-
state: null,
|
|
83
|
-
},
|
|
84
|
-
custom_css: customCss,
|
|
85
|
-
props: input.props,
|
|
86
|
-
},
|
|
87
|
-
] );
|
|
88
|
-
try {
|
|
89
|
-
await saveGlobalClasses( { context: 'frontend' } );
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
|
-
} catch ( err ) {
|
|
92
|
-
deleteClass( classId );
|
|
93
|
-
await saveGlobalClasses( { context: 'frontend' } );
|
|
94
|
-
throw new Error( `Failed to create global class, probably invalid schema values.` );
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
classId,
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const initCreateGlobalClass = ( reg: MCPRegistryEntry ) => {
|
|
102
|
-
const { addTool } = reg;
|
|
103
|
-
|
|
104
|
-
addTool( {
|
|
105
|
-
requiredResources: [
|
|
106
|
-
{ uri: GLOBAL_CLASSES_URI, description: 'Global classes list' },
|
|
107
|
-
{ uri: STYLE_SCHEMA_URI, description: 'Style schema resources' },
|
|
108
|
-
],
|
|
109
|
-
modelPreferences: {
|
|
110
|
-
intelligencePriority: 0.85,
|
|
111
|
-
speedPriority: 0.6,
|
|
112
|
-
},
|
|
113
|
-
description: `Create a new global class within the Elementor editor, allowing users to define reusable styles and properties for consistent design across their website.
|
|
114
|
-
|
|
115
|
-
# Prequisites: CRITICAL
|
|
116
|
-
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
117
|
-
- Available style properties can be found in the styles schema dynamic resources available from 'canvas' mcp. List the resources to see all available properties.
|
|
118
|
-
- YOU MUST USE THE STYLE SCHEMA TO BUILD THE "props" PARAMETER CORRECTLY, OTHERWISE THE GLOBAL CLASS CREATION WILL FAIL.
|
|
119
|
-
- Ensure that the global class name provided does not already exist to avoid duplication.
|
|
120
|
-
- Read the styles schema resource available from 'canvas' mcp to understand the valid properties and values that can be assigned to the global class.
|
|
121
|
-
|
|
122
|
-
## Parameters:
|
|
123
|
-
- \`globalClassName\` (string, required): The name of the global class to be created.
|
|
124
|
-
- \`props\` (object, required): A key-value map of style-schema PropValues that define the styles for the global class.
|
|
125
|
-
- \`breakpoint\` (string | null, optional): The responsive breakpoint for which the styles should be applied. If null, styles apply to all breakpoints.
|
|
126
|
-
|
|
127
|
-
## Example usage:
|
|
128
|
-
\`\`\`json
|
|
129
|
-
{
|
|
130
|
-
"globalClassName": "my-new-class",
|
|
131
|
-
"props": {
|
|
132
|
-
"color": {
|
|
133
|
-
"$$type": "color",
|
|
134
|
-
"value": "#ff0000"
|
|
135
|
-
},
|
|
136
|
-
"fontSize": {
|
|
137
|
-
"$$type": "size",
|
|
138
|
-
"value": {
|
|
139
|
-
"size": {
|
|
140
|
-
"$$type": "number",
|
|
141
|
-
"value": 2.5
|
|
142
|
-
},
|
|
143
|
-
"unit": {
|
|
144
|
-
"$$type": "string",
|
|
145
|
-
"value": "em"
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
"breakpoint": "desktop"
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
# Next steps:
|
|
154
|
-
If failed, read the error message carefully, it includes the exact schema that caused the failure for each invalid property.
|
|
155
|
-
Now that you have this information, update your input and try again.
|
|
156
|
-
|
|
157
|
-
\`\`\`
|
|
158
|
-
`,
|
|
159
|
-
name: 'create-global-class',
|
|
160
|
-
schema: inputSchema,
|
|
161
|
-
outputSchema,
|
|
162
|
-
handler,
|
|
163
|
-
} );
|
|
164
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { BREAKPOINTS_SCHEMA_URI } from '@elementor/editor-canvas';
|
|
2
|
-
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
3
|
-
import { Schema } from '@elementor/editor-props';
|
|
4
|
-
import { type BreakpointId } from '@elementor/editor-responsive';
|
|
5
|
-
import { getStylesSchema } from '@elementor/editor-styles';
|
|
6
|
-
import { Utils } from '@elementor/editor-variables';
|
|
7
|
-
import { z } from '@elementor/schema';
|
|
8
|
-
|
|
9
|
-
import { globalClassesStylesProvider } from '../global-classes-styles-provider';
|
|
10
|
-
import { saveGlobalClasses } from '../save-global-classes';
|
|
11
|
-
import { GLOBAL_CLASSES_URI } from './classes-resource';
|
|
12
|
-
|
|
13
|
-
const schema = {
|
|
14
|
-
classId: z.string().describe( 'The ID of the global class to modify' ),
|
|
15
|
-
props: z
|
|
16
|
-
.record( z.any() )
|
|
17
|
-
.describe(
|
|
18
|
-
'key-value of style-schema PropValues to update the global class with. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
19
|
-
),
|
|
20
|
-
breakpoint: z
|
|
21
|
-
.nullable( z.string() )
|
|
22
|
-
.default( null )
|
|
23
|
-
.describe( 'The responsive breakpoint name for which the global class styles should be applied' ),
|
|
24
|
-
customCss: z.string().optional().describe( 'The CSS styles associated with the global class.' ),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const handler = async ( params: z.infer< ReturnType< typeof z.object< typeof schema > > > ) => {
|
|
28
|
-
const { classId, props } = params;
|
|
29
|
-
const customCss = params.customCss ? { raw: btoa( params.customCss ) } : null;
|
|
30
|
-
const { update, delete: deleteClass } = globalClassesStylesProvider.actions;
|
|
31
|
-
if ( ! update || ! deleteClass ) {
|
|
32
|
-
throw new Error( 'Update action is not available' );
|
|
33
|
-
}
|
|
34
|
-
const errors: string[] = [];
|
|
35
|
-
const validProps = Object.keys( getStylesSchema() );
|
|
36
|
-
Object.keys( props ).forEach( ( key ) => {
|
|
37
|
-
const propType = getStylesSchema()[ key ];
|
|
38
|
-
if ( ! propType ) {
|
|
39
|
-
errors.push( `Property "${ key }" does not exist in styles schema.` );
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const { valid, jsonSchema } = Schema.validatePropValue( propType, props[ key ] );
|
|
43
|
-
if ( ! valid ) {
|
|
44
|
-
errors.push( `- Property "${ key }" has invalid value:\n expected Schema: ${ jsonSchema }\n` );
|
|
45
|
-
}
|
|
46
|
-
} );
|
|
47
|
-
if ( errors.length > 0 ) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`Errors:\n${ errors.join( '\n' ) }\nAvailable Properties: ${ validProps.join(
|
|
50
|
-
', '
|
|
51
|
-
) }\nNow that you have this information, update your input and try again`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
Object.keys( props ).forEach( ( key ) => {
|
|
55
|
-
props[ key ] = Schema.adjustLlmPropValueSchema( props[ key ], {
|
|
56
|
-
transformers: Utils.globalVariablesLLMResolvers,
|
|
57
|
-
} );
|
|
58
|
-
} );
|
|
59
|
-
const snapshot = structuredClone( globalClassesStylesProvider.actions.all() );
|
|
60
|
-
try {
|
|
61
|
-
update( {
|
|
62
|
-
id: classId,
|
|
63
|
-
variants: [
|
|
64
|
-
{
|
|
65
|
-
custom_css: customCss,
|
|
66
|
-
props,
|
|
67
|
-
meta: {
|
|
68
|
-
breakpoint: params.breakpoint === null ? 'desktop' : ( params.breakpoint as BreakpointId ),
|
|
69
|
-
state: null,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
} );
|
|
74
|
-
await saveGlobalClasses( { context: 'frontend' } );
|
|
75
|
-
} catch ( error ) {
|
|
76
|
-
snapshot.forEach( ( style ) => {
|
|
77
|
-
update( {
|
|
78
|
-
id: style.id,
|
|
79
|
-
variants: style.variants,
|
|
80
|
-
} );
|
|
81
|
-
} );
|
|
82
|
-
await saveGlobalClasses( { context: 'frontend' } );
|
|
83
|
-
throw new Error( `Failed to modify global class: ${ ( error as Error ).message }` );
|
|
84
|
-
}
|
|
85
|
-
return 'ok';
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const initModifyGlobalClass = ( reg: MCPRegistryEntry ) => {
|
|
89
|
-
const { addTool } = reg;
|
|
90
|
-
|
|
91
|
-
addTool( {
|
|
92
|
-
name: 'modify-global-class',
|
|
93
|
-
requiredResources: [
|
|
94
|
-
{
|
|
95
|
-
description: 'Breakpoints list',
|
|
96
|
-
uri: BREAKPOINTS_SCHEMA_URI,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
description: 'Global classes list',
|
|
100
|
-
uri: GLOBAL_CLASSES_URI,
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
modelPreferences: {
|
|
104
|
-
hints: [ { name: 'claude-sonnet-4-5' } ],
|
|
105
|
-
intelligencePriority: 0.85,
|
|
106
|
-
speedPriority: 0.6,
|
|
107
|
-
},
|
|
108
|
-
description: `Modify an existing global class within the Elementor editor, allowing users to update styles and properties for consistent design across their website.
|
|
109
|
-
# CRITICAL Prequisites:
|
|
110
|
-
- Read the style schema at [elementor://styles/schema/{category}] to understand the valid properties and values that can be assigned to the global class.
|
|
111
|
-
- Ensure that the global class ID provided exists.
|
|
112
|
-
- Prefer style schema over custom_css
|
|
113
|
-
|
|
114
|
-
## Parameters:
|
|
115
|
-
- \`classId\` (string, required): The ID of the global class to be modified.
|
|
116
|
-
- \`props\` (object, required): A key-value map of style-schema PropValues that define the new styles for the global class.
|
|
117
|
-
- \`customCss\` (string, optional): The CSS styles associated with the global class.
|
|
118
|
-
|
|
119
|
-
## Example usage:
|
|
120
|
-
\`\`\`json
|
|
121
|
-
{
|
|
122
|
-
"classId": "existing-class-id",
|
|
123
|
-
"props": {
|
|
124
|
-
"color": {
|
|
125
|
-
"$$type": "color",
|
|
126
|
-
"value": "#00ff00"
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
}\`\`\`
|
|
130
|
-
`,
|
|
131
|
-
schema,
|
|
132
|
-
handler,
|
|
133
|
-
} );
|
|
134
|
-
};
|