@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-global-classes",
|
|
3
|
-
"version": "3.35.0-
|
|
3
|
+
"version": "3.35.0-472",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,28 +39,28 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "3.35.0-
|
|
43
|
-
"@elementor/editor-current-user": "3.35.0-
|
|
44
|
-
"@elementor/editor-documents": "3.35.0-
|
|
45
|
-
"@elementor/editor-editing-panel": "3.35.0-
|
|
46
|
-
"@elementor/editor-mcp": "3.35.0-
|
|
47
|
-
"@elementor/editor-panels": "3.35.0-
|
|
48
|
-
"@elementor/editor-props": "3.35.0-
|
|
49
|
-
"@elementor/editor-variables": "3.35.0-
|
|
50
|
-
"@elementor/editor-styles": "3.35.0-
|
|
51
|
-
"@elementor/editor-canvas": "3.35.0-
|
|
52
|
-
"@elementor/editor-styles-repository": "3.35.0-
|
|
53
|
-
"@elementor/editor-ui": "3.35.0-
|
|
54
|
-
"@elementor/editor-v1-adapters": "3.35.0-
|
|
55
|
-
"@elementor/http-client": "3.35.0-
|
|
42
|
+
"@elementor/editor": "3.35.0-472",
|
|
43
|
+
"@elementor/editor-current-user": "3.35.0-472",
|
|
44
|
+
"@elementor/editor-documents": "3.35.0-472",
|
|
45
|
+
"@elementor/editor-editing-panel": "3.35.0-472",
|
|
46
|
+
"@elementor/editor-mcp": "3.35.0-472",
|
|
47
|
+
"@elementor/editor-panels": "3.35.0-472",
|
|
48
|
+
"@elementor/editor-props": "3.35.0-472",
|
|
49
|
+
"@elementor/editor-variables": "3.35.0-472",
|
|
50
|
+
"@elementor/editor-styles": "3.35.0-472",
|
|
51
|
+
"@elementor/editor-canvas": "3.35.0-472",
|
|
52
|
+
"@elementor/editor-styles-repository": "3.35.0-472",
|
|
53
|
+
"@elementor/editor-ui": "3.35.0-472",
|
|
54
|
+
"@elementor/editor-v1-adapters": "3.35.0-472",
|
|
55
|
+
"@elementor/http-client": "3.35.0-472",
|
|
56
56
|
"@elementor/icons": "^1.63.0",
|
|
57
|
-
"@elementor/query": "3.35.0-
|
|
58
|
-
"@elementor/schema": "3.35.0-
|
|
59
|
-
"@elementor/store": "3.35.0-
|
|
57
|
+
"@elementor/query": "3.35.0-472",
|
|
58
|
+
"@elementor/schema": "3.35.0-472",
|
|
59
|
+
"@elementor/store": "3.35.0-472",
|
|
60
60
|
"@elementor/ui": "1.36.17",
|
|
61
|
-
"@elementor/utils": "3.35.0-
|
|
61
|
+
"@elementor/utils": "3.35.0-472",
|
|
62
62
|
"@wordpress/i18n": "^5.13.0",
|
|
63
|
-
"@elementor/mixpanel": "3.35.0-
|
|
63
|
+
"@elementor/mixpanel": "3.35.0-472"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"react": "^18.3.1",
|
|
@@ -5,24 +5,27 @@ import { globalClassesStylesProvider } from '../global-classes-styles-provider';
|
|
|
5
5
|
export const GLOBAL_CLASSES_URI = 'elementor://global-classes';
|
|
6
6
|
|
|
7
7
|
export const initClassesResource = () => {
|
|
8
|
-
const
|
|
8
|
+
const canvasMcpEntry = getMCPByDomain( 'canvas' );
|
|
9
|
+
const classesMcpEntry = getMCPByDomain( 'classes' );
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
[ canvasMcpEntry, classesMcpEntry ].forEach( ( entry ) => {
|
|
12
|
+
const { mcpServer, resource, waitForReady } = entry;
|
|
13
|
+
resource(
|
|
14
|
+
'global-classes',
|
|
15
|
+
GLOBAL_CLASSES_URI,
|
|
16
|
+
{
|
|
17
|
+
description: 'Global classes list.',
|
|
18
|
+
},
|
|
19
|
+
async () => {
|
|
20
|
+
return {
|
|
21
|
+
contents: [ { uri: GLOBAL_CLASSES_URI, text: localStorage[ 'elementor-global-classes' ] ?? '{}' } ],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
waitForReady().then( () => {
|
|
26
|
+
globalClassesStylesProvider.subscribe( () => {
|
|
27
|
+
mcpServer.sendResourceListChanged();
|
|
28
|
+
} );
|
|
26
29
|
} );
|
|
27
30
|
} );
|
|
28
31
|
};
|
|
@@ -2,15 +2,15 @@ import { getMCPByDomain } from '@elementor/editor-mcp';
|
|
|
2
2
|
|
|
3
3
|
import { initClassesResource } from './classes-resource';
|
|
4
4
|
import initMcpApplyUnapplyGlobalClasses from './mcp-apply-unapply-global-classes';
|
|
5
|
-
import { initCreateGlobalClass } from './mcp-create-global-class';
|
|
6
5
|
import initMcpApplyGetGlobalClassUsages from './mcp-get-global-class-usages';
|
|
7
|
-
import {
|
|
6
|
+
import { initManageGlobalClasses } from './mcp-manage-global-classes';
|
|
8
7
|
|
|
9
8
|
export const initMcpIntegration = () => {
|
|
10
|
-
const reg = getMCPByDomain( '
|
|
9
|
+
const reg = getMCPByDomain( 'classes', {
|
|
10
|
+
instructions: 'MCP server for management of Elementor global classes',
|
|
11
|
+
} );
|
|
11
12
|
initMcpApplyUnapplyGlobalClasses( reg );
|
|
12
13
|
initMcpApplyGetGlobalClassUsages( reg );
|
|
13
|
-
|
|
14
|
-
initModifyGlobalClass( reg );
|
|
14
|
+
initManageGlobalClasses( reg );
|
|
15
15
|
initClassesResource();
|
|
16
16
|
};
|
|
@@ -16,16 +16,29 @@ export default function initMcpApplyUnapplyGlobalClasses( server: MCPRegistryEnt
|
|
|
16
16
|
intelligencePriority: 0.7,
|
|
17
17
|
speedPriority: 0.8,
|
|
18
18
|
},
|
|
19
|
-
description: `Apply a global class to
|
|
19
|
+
description: `Apply a global class to an element, enabling consistent styling through your design system.
|
|
20
20
|
|
|
21
21
|
## When to use this tool:
|
|
22
|
-
|
|
23
|
-
-
|
|
22
|
+
**ALWAYS use this IMMEDIATELY AFTER building compositions** to apply the global classes you created beforehand:
|
|
23
|
+
- After using "build-compositions" tool, apply semantic classes to the created elements
|
|
24
|
+
- When applying consistent typography styles (heading-primary, text-body, etc.)
|
|
25
|
+
- When applying theme colors or brand styles (bg-brand, button-cta, etc.)
|
|
26
|
+
- When ensuring spacing consistency (spacing-section-large, etc.)
|
|
27
|
+
|
|
28
|
+
**DO NOT use this tool** for:
|
|
29
|
+
- Elements that don't share styles with other elements (use inline styles instead)
|
|
30
|
+
- Layout-specific properties (those should remain inline in stylesConfig)
|
|
24
31
|
|
|
25
32
|
## Prerequisites:
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
-
|
|
33
|
+
- **REQUIRED**: Get the list of available global classes from 'elementor://global-classes' resource
|
|
34
|
+
- **REQUIRED**: Get element IDs from the composition XML returned by "build-compositions" tool
|
|
35
|
+
- Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates
|
|
36
|
+
- Make sure you have the correct class ID that you want to apply
|
|
37
|
+
|
|
38
|
+
## Best Practices:
|
|
39
|
+
1. Apply multiple classes to a single element if needed (typography + color + spacing)
|
|
40
|
+
2. After applying, the tool will remind you to remove duplicate inline styles from elementConfig
|
|
41
|
+
3. Classes should describe purpose, not implementation (e.g., "heading-primary" not "big-red-text")`,
|
|
29
42
|
handler: async ( params ) => {
|
|
30
43
|
const { classId, elementId } = params;
|
|
31
44
|
const appliedClasses = doGetAppliedClasses( elementId );
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { BREAKPOINTS_SCHEMA_URI, STYLE_SCHEMA_URI } from '@elementor/editor-canvas';
|
|
2
|
+
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
3
|
+
import { type Props, Schema } from '@elementor/editor-props';
|
|
4
|
+
import { type BreakpointId } from '@elementor/editor-responsive';
|
|
5
|
+
import { getStylesSchema } from '@elementor/editor-styles';
|
|
6
|
+
import { type StylesProvider } from '@elementor/editor-styles-repository';
|
|
7
|
+
import { type Utils as IUtils } from '@elementor/editor-variables';
|
|
8
|
+
import { z } from '@elementor/schema';
|
|
9
|
+
|
|
10
|
+
import { globalClassesStylesProvider } from '../global-classes-styles-provider';
|
|
11
|
+
import { saveGlobalClasses } from '../save-global-classes';
|
|
12
|
+
import { GLOBAL_CLASSES_URI } from './classes-resource';
|
|
13
|
+
|
|
14
|
+
// TODO: see https://elementor.atlassian.net/browse/ED-22513 for better cross-module access
|
|
15
|
+
type XElementor = z.infer< z.ZodAny >;
|
|
16
|
+
|
|
17
|
+
const schema = {
|
|
18
|
+
action: z.enum( [ 'create', 'modify', 'delete' ] ).describe( 'Operation to perform' ),
|
|
19
|
+
classId: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe( 'Global class ID (required for modify). Get from elementor://global-classes resource.' ),
|
|
23
|
+
globalClassName: z.string().optional().describe( 'Global class name (required for create)' ),
|
|
24
|
+
props: z
|
|
25
|
+
.record( z.any() )
|
|
26
|
+
.describe(
|
|
27
|
+
'key-value of style-schema PropValues. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
|
|
28
|
+
),
|
|
29
|
+
breakpoint: z
|
|
30
|
+
.nullable( z.string().describe( 'Responsive breakpoint name for styles. Defaults to desktop (null).' ) )
|
|
31
|
+
.default( null )
|
|
32
|
+
.describe( 'Responsive breakpoint name for styles. Defaults to desktop (null).' ),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const outputSchema = {
|
|
36
|
+
status: z.enum( [ 'ok', 'error' ] ).describe( 'Operation status' ),
|
|
37
|
+
classId: z.string().optional().describe( 'Class ID (returned on create success)' ),
|
|
38
|
+
message: z.string().optional().describe( 'Error details if status is error' ),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type InputSchema = z.infer< ReturnType< typeof z.object< typeof schema > > >;
|
|
42
|
+
type OutputSchema = z.infer< ReturnType< typeof z.object< typeof outputSchema > > >;
|
|
43
|
+
|
|
44
|
+
const handler = async ( input: InputSchema ): Promise< OutputSchema > => {
|
|
45
|
+
const { action, classId, globalClassName, props, breakpoint } = input;
|
|
46
|
+
|
|
47
|
+
if ( action === 'create' && ! globalClassName ) {
|
|
48
|
+
return {
|
|
49
|
+
status: 'error',
|
|
50
|
+
message: 'Create requires globalClassName',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if ( action === 'modify' && ! classId ) {
|
|
55
|
+
return {
|
|
56
|
+
status: 'error',
|
|
57
|
+
message: 'Modify requires classId',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if ( action === 'delete' && ! classId ) {
|
|
62
|
+
return {
|
|
63
|
+
status: 'error',
|
|
64
|
+
message: 'Delete requires classId',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { create, update, delete: deleteClass } = globalClassesStylesProvider.actions;
|
|
69
|
+
if ( ! create || ! update || ! deleteClass ) {
|
|
70
|
+
return {
|
|
71
|
+
status: 'error',
|
|
72
|
+
message: 'Required actions not available',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const errors: string[] = [];
|
|
77
|
+
const stylesSchema = getStylesSchema();
|
|
78
|
+
const validProps = Object.keys( stylesSchema );
|
|
79
|
+
|
|
80
|
+
Object.keys( props ).forEach( ( key ) => {
|
|
81
|
+
const propType = stylesSchema[ key ];
|
|
82
|
+
if ( ! propType ) {
|
|
83
|
+
errors.push( `Property "${ key }" does not exist in styles schema.` );
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const { valid, jsonSchema } = Schema.validatePropValue( propType, props[ key ] );
|
|
87
|
+
if ( ! valid ) {
|
|
88
|
+
errors.push( `- Property "${ key }" has invalid value\n Expected schema: ${ jsonSchema }\n` );
|
|
89
|
+
}
|
|
90
|
+
} );
|
|
91
|
+
|
|
92
|
+
if ( errors.length > 0 ) {
|
|
93
|
+
return {
|
|
94
|
+
status: 'error',
|
|
95
|
+
message: `Validation errors:\n${ errors.join( '\n' ) }\nAvailable Properties: ${ validProps.join(
|
|
96
|
+
', '
|
|
97
|
+
) }\nUpdate your input and try again.`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// TODO: see https://elementor.atlassian.net/browse/ED-22513 for better cross-module access
|
|
102
|
+
const Utils = ( ( ( window as XElementor ).elementorV2 as XElementor ).editorVariables as XElementor )
|
|
103
|
+
.Utils as typeof IUtils;
|
|
104
|
+
Object.keys( props ).forEach( ( key ) => {
|
|
105
|
+
props[ key ] = Schema.adjustLlmPropValueSchema( props[ key ], {
|
|
106
|
+
transformers: Utils.globalVariablesLLMResolvers,
|
|
107
|
+
} );
|
|
108
|
+
} );
|
|
109
|
+
|
|
110
|
+
const breakpointValue = breakpoint ?? 'desktop';
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
switch ( action ) {
|
|
114
|
+
case 'create':
|
|
115
|
+
const newClassId = await attemptCreate( {
|
|
116
|
+
props,
|
|
117
|
+
className: globalClassName,
|
|
118
|
+
stylesProvider: globalClassesStylesProvider,
|
|
119
|
+
breakpoint: breakpointValue as BreakpointId,
|
|
120
|
+
} );
|
|
121
|
+
return newClassId
|
|
122
|
+
? {
|
|
123
|
+
status: 'ok',
|
|
124
|
+
message: `created global class with ID ${ newClassId }`,
|
|
125
|
+
}
|
|
126
|
+
: {
|
|
127
|
+
status: 'error',
|
|
128
|
+
message: 'error creating class',
|
|
129
|
+
};
|
|
130
|
+
case 'modify':
|
|
131
|
+
const updated = await attemptUpdate( {
|
|
132
|
+
classId,
|
|
133
|
+
props,
|
|
134
|
+
stylesProvider: globalClassesStylesProvider,
|
|
135
|
+
breakpoint: breakpointValue as BreakpointId,
|
|
136
|
+
} );
|
|
137
|
+
return updated
|
|
138
|
+
? { status: 'ok', classId }
|
|
139
|
+
: {
|
|
140
|
+
status: 'error',
|
|
141
|
+
message: 'error modifying class',
|
|
142
|
+
};
|
|
143
|
+
case 'delete':
|
|
144
|
+
const deleted = await attemptDelete( {
|
|
145
|
+
classId,
|
|
146
|
+
stylesProvider: globalClassesStylesProvider,
|
|
147
|
+
} );
|
|
148
|
+
return deleted
|
|
149
|
+
? { status: 'ok', message: `deleted global class with ID ${ classId }` }
|
|
150
|
+
: {
|
|
151
|
+
status: 'error',
|
|
152
|
+
message: 'error deleting class',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
} catch ( error ) {
|
|
156
|
+
return {
|
|
157
|
+
status: 'error',
|
|
158
|
+
message: `${ action } failed: ${ ( error as Error ).message || 'Unknown error' }`,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export const initManageGlobalClasses = ( reg: MCPRegistryEntry ) => {
|
|
164
|
+
const { addTool } = reg;
|
|
165
|
+
|
|
166
|
+
addTool( {
|
|
167
|
+
name: 'manage-global-classes',
|
|
168
|
+
requiredResources: [
|
|
169
|
+
{ uri: GLOBAL_CLASSES_URI, description: 'Global classes list' },
|
|
170
|
+
{ uri: STYLE_SCHEMA_URI, description: 'Style schema resources' },
|
|
171
|
+
{ uri: BREAKPOINTS_SCHEMA_URI, description: 'Breakpoints list' },
|
|
172
|
+
],
|
|
173
|
+
modelPreferences: {
|
|
174
|
+
intelligencePriority: 0.85,
|
|
175
|
+
speedPriority: 0.6,
|
|
176
|
+
},
|
|
177
|
+
description: `Manages global classes (create/modify) in Elementor editor. Check [elementor://global-classes] and style schemas first.
|
|
178
|
+
|
|
179
|
+
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.
|
|
180
|
+
MODIFY: Requires classId, props. Get classId from [elementor://global-classes] resource.
|
|
181
|
+
|
|
182
|
+
Naming pattern: [element-type]-[purpose/variant]-[modifier]
|
|
183
|
+
DO NOT create global classes for: one-off styles, layout-specific properties.
|
|
184
|
+
|
|
185
|
+
Use style schema at [elementor://styles/schema/{category}] for valid props. Errors include exact schema mismatch details.`,
|
|
186
|
+
schema,
|
|
187
|
+
outputSchema,
|
|
188
|
+
handler,
|
|
189
|
+
} );
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
type Opts = {
|
|
193
|
+
stylesProvider: StylesProvider;
|
|
194
|
+
className?: string;
|
|
195
|
+
classId?: string;
|
|
196
|
+
breakpoint: BreakpointId;
|
|
197
|
+
props: Props;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
async function attemptCreate( opts: Opts ) {
|
|
201
|
+
const { props, breakpoint, className, stylesProvider } = opts;
|
|
202
|
+
const { create, delete: deleteClass } = stylesProvider.actions;
|
|
203
|
+
if ( ! className ) {
|
|
204
|
+
throw new Error( 'Global class name is a required for creation' );
|
|
205
|
+
}
|
|
206
|
+
if ( ! create || ! deleteClass ) {
|
|
207
|
+
throw new Error( 'User is unable to create global classes' );
|
|
208
|
+
}
|
|
209
|
+
const newClassId = create( className, [
|
|
210
|
+
{
|
|
211
|
+
meta: {
|
|
212
|
+
breakpoint,
|
|
213
|
+
state: null,
|
|
214
|
+
},
|
|
215
|
+
custom_css: null,
|
|
216
|
+
props,
|
|
217
|
+
},
|
|
218
|
+
] );
|
|
219
|
+
try {
|
|
220
|
+
await saveGlobalClasses( { context: 'frontend' } );
|
|
221
|
+
return newClassId;
|
|
222
|
+
} catch {
|
|
223
|
+
deleteClass( newClassId );
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function attemptUpdate( opts: Opts ) {
|
|
229
|
+
const { props, breakpoint, classId, stylesProvider } = opts;
|
|
230
|
+
const { updateProps, update } = stylesProvider.actions;
|
|
231
|
+
if ( ! classId ) {
|
|
232
|
+
throw new Error( 'Class ID is required for modification' );
|
|
233
|
+
}
|
|
234
|
+
if ( ! updateProps || ! update ) {
|
|
235
|
+
throw new Error( 'User is unable to update global classes' );
|
|
236
|
+
}
|
|
237
|
+
const snapshot = structuredClone( stylesProvider.actions.all() );
|
|
238
|
+
try {
|
|
239
|
+
updateProps( {
|
|
240
|
+
id: classId,
|
|
241
|
+
props,
|
|
242
|
+
meta: {
|
|
243
|
+
breakpoint,
|
|
244
|
+
state: null,
|
|
245
|
+
},
|
|
246
|
+
} );
|
|
247
|
+
await saveGlobalClasses( { context: 'frontend' } );
|
|
248
|
+
return true;
|
|
249
|
+
} catch {
|
|
250
|
+
snapshot.forEach( ( style ) => {
|
|
251
|
+
update( {
|
|
252
|
+
id: style.id,
|
|
253
|
+
variants: style.variants,
|
|
254
|
+
} );
|
|
255
|
+
} );
|
|
256
|
+
await saveGlobalClasses( { context: 'frontend' } );
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function attemptDelete( opts: Pick< Opts, 'classId' | 'stylesProvider' > ) {
|
|
262
|
+
const { classId, stylesProvider } = opts;
|
|
263
|
+
const { delete: deleteClass, create } = stylesProvider.actions;
|
|
264
|
+
if ( ! classId ) {
|
|
265
|
+
throw new Error( 'Class ID is required for deletion' );
|
|
266
|
+
}
|
|
267
|
+
if ( ! deleteClass || ! create ) {
|
|
268
|
+
throw new Error( 'User is unable to delete global classes' );
|
|
269
|
+
}
|
|
270
|
+
const snapshot = structuredClone( stylesProvider.actions.all() );
|
|
271
|
+
const targetClass = snapshot.find( ( style ) => style.id === classId );
|
|
272
|
+
if ( ! targetClass ) {
|
|
273
|
+
throw new Error( `Class with ID "${ classId }" not found` );
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
deleteClass( classId );
|
|
277
|
+
await saveGlobalClasses( { context: 'frontend' } );
|
|
278
|
+
return true;
|
|
279
|
+
} catch {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { STYLE_SCHEMA_URI } from '@elementor/editor-canvas';
|
|
2
|
-
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
3
|
-
import { GLOBAL_VARIABLES_URI, service } from '@elementor/editor-variables';
|
|
4
|
-
import { z } from '@elementor/schema';
|
|
5
|
-
|
|
6
|
-
import { GLOBAL_CLASSES_URI } from '../classes-resource';
|
|
7
|
-
import { handler, inputSchema as globalClassInputSchema } from '../mcp-create-global-class';
|
|
8
|
-
|
|
9
|
-
export const initDesignSystemTool = ( reg: MCPRegistryEntry ) => {
|
|
10
|
-
const { addTool } = reg;
|
|
11
|
-
|
|
12
|
-
const schema = {
|
|
13
|
-
globalVariables: z
|
|
14
|
-
.array(
|
|
15
|
-
z.object( {
|
|
16
|
-
variableName: z.string().describe( 'The name of the global variable.' ),
|
|
17
|
-
variableType: z
|
|
18
|
-
.enum( [ 'global-color-variable', 'global-font-variable' ] )
|
|
19
|
-
.describe( 'The type of the global variable.' ),
|
|
20
|
-
value: z
|
|
21
|
-
.string()
|
|
22
|
-
.describe(
|
|
23
|
-
'The value of the global variable. For colors, use css applicable format. For fonts, use the font family name.'
|
|
24
|
-
),
|
|
25
|
-
} )
|
|
26
|
-
)
|
|
27
|
-
.default( [] ),
|
|
28
|
-
globalClasses: z.array( z.object( globalClassInputSchema ) ).default( [] ),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
addTool( {
|
|
32
|
-
name: 'design-system',
|
|
33
|
-
requiredResources: [
|
|
34
|
-
{ uri: STYLE_SCHEMA_URI, description: 'Style schema template resource' },
|
|
35
|
-
{ uri: GLOBAL_CLASSES_URI, description: 'Global classes list' },
|
|
36
|
-
{ uri: GLOBAL_VARIABLES_URI, description: 'Global variables list' },
|
|
37
|
-
],
|
|
38
|
-
description: `Manages or Creates a comprehensive design system based on user requirements.
|
|
39
|
-
# CRITICAL PRE-REQUISITES:
|
|
40
|
-
- Must read the style schema at dynamic resource list ${ STYLE_SCHEMA_URI } to understand the valid properties and values that can be assigned to global classes and variables.
|
|
41
|
-
- Must get the existing global classes from always up-to-date resource ${ GLOBAL_CLASSES_URI } to avoid duplication when creating new global classes.
|
|
42
|
-
- Must get the existing global variables from always up-to-date resource 'elementor://global-variables' to avoid duplication when creating new global variables.
|
|
43
|
-
|
|
44
|
-
# IMPORTANT
|
|
45
|
-
- DO NOT create variables if already existing variables can be re-used.
|
|
46
|
-
- DO NOT create global classes if already existing global classes can be re-used.
|
|
47
|
-
|
|
48
|
-
# When to use this tool:
|
|
49
|
-
- When a user requests to create or manage a design system for their website.
|
|
50
|
-
- When you need to generate a cohesive set of design tokens, styles, and global classes.
|
|
51
|
-
|
|
52
|
-
# When NOT to use this tool:
|
|
53
|
-
- For simple style adjustments or individual component styling, use the appropriate styling tools instead.
|
|
54
|
-
- For modifications or creations of small amount of global classes, use the "create-global-class" or "modify-global-class" tools instead.
|
|
55
|
-
- When you need to create or modify global variables only, use the "create-global-variable" or "modify-global-variable" tools instead.
|
|
56
|
-
|
|
57
|
-
# Parameters:
|
|
58
|
-
- \`globalClasses\` (array, optional): A list of global classes to be created or updated. Each class should include a name and a set of style-schema PropValues.
|
|
59
|
-
- \`globalVariables\` (array, optional): A list of global variables to be created or updated. Each variable should include a name, type, and value.
|
|
60
|
-
|
|
61
|
-
# You Goal
|
|
62
|
-
Every design system has a set of global variables and global classes.
|
|
63
|
-
Your goal is to make sure the user has enough global classes to re-use across the site, and that the global variables are defined to support these classes.
|
|
64
|
-
Most sites would need classes for:
|
|
65
|
-
- Headings (at least 3 levels)
|
|
66
|
-
- Texts (default, emphasis, info, etc).
|
|
67
|
-
- Buttons (primary, secondary, etc).
|
|
68
|
-
- Containers (cards, sections, etc).
|
|
69
|
-
- Banners (important messages, alerts, etc).
|
|
70
|
-
- Hero sections (main site intro, etc).
|
|
71
|
-
|
|
72
|
-
Global Classes SHOULD HAVE meaningful names that reflect their purpose and usage.
|
|
73
|
-
Global Classes SHOULD HAVE PROPERTIES.
|
|
74
|
-
|
|
75
|
-
DO NOT PROVIDE EMPTY OBJECTS
|
|
76
|
-
|
|
77
|
-
Example partial design system input:
|
|
78
|
-
\`\`\`json
|
|
79
|
-
{
|
|
80
|
-
"globalVariables": [{variableName: 'secondary-text', variableType: 'global-color-variable', value: '#666666'}],
|
|
81
|
-
"globalClasses": [
|
|
82
|
-
{
|
|
83
|
-
"globalClassName": "info-text",
|
|
84
|
-
"props": {
|
|
85
|
-
"background": {
|
|
86
|
-
"$$type": "background",
|
|
87
|
-
"value": {
|
|
88
|
-
"color": {
|
|
89
|
-
"$$type": "global-color-variable",
|
|
90
|
-
"value": "secondary-text"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
} ]
|
|
96
|
-
}
|
|
97
|
-
\`\`\`
|
|
98
|
-
|
|
99
|
-
You are encouraged to create even more if required to cover user requirements.
|
|
100
|
-
Before you create any class, make sure there is not already an existing class that supports the same purpose, by checking the resource at uri elementor://global-classes
|
|
101
|
-
|
|
102
|
-
Before creating global variables, read the list, in many cases there are already existing variables that can be re-used. The list is available at resource uri elementor://global-variables
|
|
103
|
-
`,
|
|
104
|
-
schema,
|
|
105
|
-
handler: async ( params ) => {
|
|
106
|
-
const { globalClasses, globalVariables } = params;
|
|
107
|
-
for ( const globalVariable of globalVariables ) {
|
|
108
|
-
const { variableName, variableType, value } = globalVariable;
|
|
109
|
-
service.create( {
|
|
110
|
-
label: variableName,
|
|
111
|
-
type: variableType,
|
|
112
|
-
value,
|
|
113
|
-
} );
|
|
114
|
-
}
|
|
115
|
-
for ( const globalClass of globalClasses ) {
|
|
116
|
-
await handler( globalClass );
|
|
117
|
-
}
|
|
118
|
-
return 'done';
|
|
119
|
-
},
|
|
120
|
-
} );
|
|
121
|
-
};
|