@elementor/editor-canvas 4.2.0-931 → 4.2.0-933
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 +18 -7
- package/dist/index.d.ts +18 -7
- package/dist/index.js +243 -282
- package/dist/index.mjs +227 -266
- package/package.json +19 -18
- package/src/composition-builder/composition-builder.ts +2 -9
- package/src/index.ts +7 -1
- package/src/mcp/canvas-mcp.ts +3 -0
- package/src/mcp/mcp-description.ts +9 -13
- package/src/mcp/resources/widgets-schema-resource.ts +1 -41
- package/src/mcp/tools/build-composition/prompt.ts +12 -13
- package/src/mcp/tools/build-composition/schema.ts +5 -12
- package/src/mcp/tools/build-composition/tool.ts +25 -3
- package/src/mcp/tools/configure-element/prompt.ts +22 -44
- package/src/mcp/tools/configure-element/schema.ts +12 -6
- package/src/mcp/tools/configure-element/tool.ts +43 -38
- package/src/mcp/utils/__tests__/convert-css-to-atomic.test.ts +109 -0
- package/src/mcp/utils/__tests__/do-update-element-property.test.ts +39 -1
- package/src/mcp/utils/convert-css-to-atomic.ts +39 -0
- package/src/mcp/utils/do-update-element-property.ts +3 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-canvas",
|
|
3
3
|
"description": "Elementor Editor Canvas",
|
|
4
|
-
"version": "4.2.0-
|
|
4
|
+
"version": "4.2.0-933",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,25 +37,26 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor": "4.2.0-
|
|
40
|
+
"@elementor/editor": "4.2.0-933",
|
|
41
41
|
"dompurify": "^3.2.6",
|
|
42
|
-
"@elementor/editor-controls": "4.2.0-
|
|
43
|
-
"@elementor/editor-documents": "4.2.0-
|
|
44
|
-
"@elementor/editor-elements": "4.2.0-
|
|
45
|
-
"@elementor/editor-interactions": "4.2.0-
|
|
46
|
-
"@elementor/editor-mcp": "4.2.0-
|
|
47
|
-
"@elementor/editor-notifications": "4.2.0-
|
|
48
|
-
"@elementor/editor-props": "4.2.0-
|
|
49
|
-
"@elementor/editor-responsive": "4.2.0-
|
|
50
|
-
"@elementor/editor-styles": "4.2.0-
|
|
51
|
-
"@elementor/editor-styles-repository": "4.2.0-
|
|
52
|
-
"@elementor/editor-ui": "4.2.0-
|
|
53
|
-
"@elementor/editor-v1-adapters": "4.2.0-
|
|
54
|
-
"@elementor/
|
|
55
|
-
"@elementor/
|
|
42
|
+
"@elementor/editor-controls": "4.2.0-933",
|
|
43
|
+
"@elementor/editor-documents": "4.2.0-933",
|
|
44
|
+
"@elementor/editor-elements": "4.2.0-933",
|
|
45
|
+
"@elementor/editor-interactions": "4.2.0-933",
|
|
46
|
+
"@elementor/editor-mcp": "4.2.0-933",
|
|
47
|
+
"@elementor/editor-notifications": "4.2.0-933",
|
|
48
|
+
"@elementor/editor-props": "4.2.0-933",
|
|
49
|
+
"@elementor/editor-responsive": "4.2.0-933",
|
|
50
|
+
"@elementor/editor-styles": "4.2.0-933",
|
|
51
|
+
"@elementor/editor-styles-repository": "4.2.0-933",
|
|
52
|
+
"@elementor/editor-ui": "4.2.0-933",
|
|
53
|
+
"@elementor/editor-v1-adapters": "4.2.0-933",
|
|
54
|
+
"@elementor/http-client": "4.2.0-933",
|
|
55
|
+
"@elementor/schema": "4.2.0-933",
|
|
56
|
+
"@elementor/twing": "4.2.0-933",
|
|
56
57
|
"@elementor/ui": "1.37.5",
|
|
57
|
-
"@elementor/utils": "4.2.0-
|
|
58
|
-
"@elementor/wp-media": "4.2.0-
|
|
58
|
+
"@elementor/utils": "4.2.0-933",
|
|
59
|
+
"@elementor/wp-media": "4.2.0-933",
|
|
59
60
|
"@floating-ui/react": "^0.27.5",
|
|
60
61
|
"@wordpress/i18n": "^5.13.0"
|
|
61
62
|
},
|
|
@@ -13,7 +13,6 @@ import { type z } from '@elementor/schema';
|
|
|
13
13
|
|
|
14
14
|
import { doUpdateElementProperty } from '../mcp/utils/do-update-element-property';
|
|
15
15
|
import { mergeCustomCssText } from '../mcp/utils/merge-custom-css';
|
|
16
|
-
import { validateInput } from '../mcp/utils/validate-input';
|
|
17
16
|
import { RequiredChildrenEnforcer } from './utils/required-children-enforcer';
|
|
18
17
|
import { getRequiredDefaultChildTemplates } from './utils/required-default-child-tags';
|
|
19
18
|
|
|
@@ -223,20 +222,14 @@ export class CompositionBuilder {
|
|
|
223
222
|
}
|
|
224
223
|
|
|
225
224
|
const styleConfig = this.elementStylesConfig[ configId ];
|
|
226
|
-
|
|
225
|
+
const hasInvalidStyles = false;
|
|
227
226
|
if ( styleConfig ) {
|
|
228
227
|
const validStylesPropValues: Record< string, AnyValue > = {};
|
|
229
228
|
for ( const [ styleName, stylePropValue ] of Object.entries( styleConfig ) ) {
|
|
230
229
|
if ( styleName === '$intention' ) {
|
|
231
230
|
continue;
|
|
232
|
-
}
|
|
233
|
-
const { valid, errors: validationErrors } = validateInput.validateStyles( {
|
|
234
|
-
[ styleName ]: stylePropValue,
|
|
235
|
-
} );
|
|
236
|
-
if ( ! valid ) {
|
|
237
|
-
hasInvalidStyles = true;
|
|
238
|
-
styleErrors.push( ...( validationErrors || [] ) );
|
|
239
231
|
} else {
|
|
232
|
+
// skipping actual validation - properies comes from the server
|
|
240
233
|
validStylesPropValues[ styleName ] = stylePropValue;
|
|
241
234
|
}
|
|
242
235
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export { BREAKPOINTS_SCHEMA_URI, BREAKPOINTS_SCHEMA_FULL_URI } from './mcp/resources/breakpoints-resource';
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
convertCssToAtomic,
|
|
4
|
+
convertStyleBlocksToAtomic,
|
|
5
|
+
type CssConversionResult,
|
|
6
|
+
type StyleBlock,
|
|
7
|
+
type StyleDeclarations,
|
|
8
|
+
} from './mcp/utils/convert-css-to-atomic';
|
|
3
9
|
|
|
4
10
|
export { init } from './init';
|
|
5
11
|
export { isAtomicWidget } from './utils/command-utils';
|
package/src/mcp/canvas-mcp.ts
CHANGED
|
@@ -15,6 +15,9 @@ import { initGetElementConfigTool } from './tools/get-element-config/tool';
|
|
|
15
15
|
import { getDynamicTagNamesByCategories } from './utils/resolve-dynamic-tag';
|
|
16
16
|
|
|
17
17
|
export const initCanvasMcp = ( reg: MCPRegistryEntry ) => {
|
|
18
|
+
// TODO: Remove this comment once 4.2 released
|
|
19
|
+
// NOTE: Style schema removed in favor of css-to-schema functionality [ED-24441]
|
|
20
|
+
// Reference code can be found at any commit prior to `d338e816f0c97b90b52fe2f1ef0bfe2aad816ab0`
|
|
18
21
|
Schema.setDynamicTagNamesResolver( getDynamicTagNamesByCategories );
|
|
19
22
|
initWidgetsSchemaResource( reg );
|
|
20
23
|
initAvailableWidgetsResource( reg );
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WIDGET_SCHEMA_URI } from './resources/widgets-schema-resource';
|
|
2
2
|
|
|
3
3
|
const ELEMENT_SCHEMA_URI = WIDGET_SCHEMA_URI.replace( '{widgetType}', 'element-schema' );
|
|
4
4
|
|
|
@@ -21,7 +21,6 @@ The \`$$type\` defines how Elementor interprets the value. Providing the correct
|
|
|
21
21
|
- **Global Variables**: Reusable colors, sizes, and fonts (\`elementor://global-variables\`)
|
|
22
22
|
- **Global Classes**: Reusable style sets that can be applied to elements (\`elementor://global-classes\`)
|
|
23
23
|
- **Widget Schemas**: Configuration options for each widget type (\`${ WIDGET_SCHEMA_URI }\`)
|
|
24
|
-
- **Style Schema**: Common styles shared across all widgets and containers (\`${ STYLE_SCHEMA_URI }\`)
|
|
25
24
|
|
|
26
25
|
# Building Compositions with build_composition
|
|
27
26
|
|
|
@@ -70,28 +69,25 @@ Map each configuration-id to its widget properties using PropValues:
|
|
|
70
69
|
}
|
|
71
70
|
\`\`\`
|
|
72
71
|
|
|
73
|
-
### 6. Create
|
|
74
|
-
Map each configuration-id to
|
|
75
|
-
-
|
|
76
|
-
- Example using global variable:
|
|
72
|
+
### 6. Create style
|
|
73
|
+
Map each configuration-id to raw CSS declarations (property → value strings). The server converts them to native styles and stores any unconvertible declarations as the element custom CSS.
|
|
74
|
+
- Example:
|
|
77
75
|
\`\`\`json
|
|
78
76
|
{
|
|
79
|
-
"heading-1":
|
|
80
|
-
"color": { "$$type": "global-color-variable", "value": "primary-color-id" },
|
|
81
|
-
"font-size": { "$$type": "size", "value": "2rem" }
|
|
77
|
+
"heading-1": "color: #1a1a1a; font-size: 2rem;"
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
80
|
\`\`\`
|
|
85
81
|
|
|
86
82
|
### 7. Execute build_composition
|
|
87
|
-
Call the tool with your XML structure, elementConfig, and
|
|
83
|
+
Call the tool with your XML structure, elementConfig, and style. The response will contain the created element IDs.
|
|
88
84
|
At the response you will also find llm_instructions for you to do afterwards, read and follow them!
|
|
89
85
|
|
|
90
86
|
## Key Points
|
|
91
87
|
|
|
92
88
|
- **PropValue Types**: Arrays that accept union types are typed as mixed arrays
|
|
93
|
-
- **Visual Sizing**: Widget sizes MUST be defined
|
|
94
|
-
- **Global Variables**: Reference by
|
|
89
|
+
- **Visual Sizing**: Widget sizes MUST be defined via the style parameter (raw CSS). Widget properties like image "size" control resolution, not visual appearance
|
|
90
|
+
- **Global Variables**: Reference by label/name: (e.g. var(--card-background-color)
|
|
95
91
|
- **Naming Conventions**: Use meaningful, purpose-based names (e.g., "primary-button", "heading-large"), not value-based names (e.g., "blue-style", "20px-padding")
|
|
96
92
|
|
|
97
93
|
## Example: e-image PropValue Structure
|
|
@@ -109,5 +105,5 @@ At the response you will also find llm_instructions for you to do afterwards, re
|
|
|
109
105
|
}
|
|
110
106
|
}
|
|
111
107
|
\`\`\`
|
|
112
|
-
Note: The "size" property controls image resolution/loading, not visual size. Set visual dimensions
|
|
108
|
+
Note: The "size" property controls image resolution/loading, not visual size. Set visual dimensions via the style parameter (raw CSS).
|
|
113
109
|
`;
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
type TransformablePropType,
|
|
10
10
|
type UnionPropType,
|
|
11
11
|
} from '@elementor/editor-props';
|
|
12
|
-
import { getStylesSchema } from '@elementor/editor-styles';
|
|
13
12
|
|
|
14
13
|
import { getRequiredDefaultChildTypes } from '../../composition-builder/utils/required-default-child-tags';
|
|
15
14
|
import { hasV3Controls, isWidgetAvailableForLLM } from '../utils/element-data-util';
|
|
@@ -61,7 +60,6 @@ export const CANVAS_SERVER_NAME = 'editor-canvas';
|
|
|
61
60
|
export const WIDGET_SCHEMA_URI = 'elementor://widgets/schema/{widgetType}';
|
|
62
61
|
export const WIDGET_SCHEMA_FULL_URI = `${ CANVAS_SERVER_NAME }_${ WIDGET_SCHEMA_URI }`;
|
|
63
62
|
export const STYLE_SCHEMA_URI = 'elementor://styles/schema/{category}';
|
|
64
|
-
export const STYLE_SCHEMA_FULL_URI = `${ CANVAS_SERVER_NAME }_${ STYLE_SCHEMA_URI }`;
|
|
65
63
|
export const BEST_PRACTICES_URI = 'elementor://styles/best-practices';
|
|
66
64
|
export const BEST_PRACTICES_FULL_URI = `${ CANVAS_SERVER_NAME }_${ BEST_PRACTICES_URI }`;
|
|
67
65
|
|
|
@@ -83,8 +81,7 @@ export const initWidgetsSchemaResource = ( reg: MCPRegistryEntry ) => {
|
|
|
83
81
|
Prefer using "em" and "rem" values for text-related sizes, padding and spacing. Use percentages for dynamic sizing relative to parent containers.
|
|
84
82
|
This flexboxes are by default "flex" with "stretch" alignment. To ensure proper layout, define the "justify-content" and "align-items" as in the schema.
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
The css string must follow standard CSS syntax, with properties and values separated by semicolons, no selectors, or nesting rules allowed.
|
|
84
|
+
Styling is provided as raw CSS. The css string must follow standard CSS syntax, with properties and values separated by semicolons, no selectors, or nesting rules allowed.
|
|
88
85
|
|
|
89
86
|
** CRITICAL - VARIABLES **
|
|
90
87
|
When using global variables, ensure that the variables are defined in the ${ 'elementor://global-variables' } resource.
|
|
@@ -97,43 +94,6 @@ Variables from the user context ARE NOT SUPPORTED AND WILL RESOLVE IN ERROR.
|
|
|
97
94
|
}
|
|
98
95
|
);
|
|
99
96
|
|
|
100
|
-
resource(
|
|
101
|
-
'styles-schema',
|
|
102
|
-
new ResourceTemplate( STYLE_SCHEMA_URI, {
|
|
103
|
-
list: () => {
|
|
104
|
-
const categories = [ ...Object.keys( getStylesSchema() ) ].filter( ( category ) => category !== 'all' );
|
|
105
|
-
return {
|
|
106
|
-
resources: categories.map( ( category ) => ( {
|
|
107
|
-
uri: `elementor://styles/schema/${ category }`,
|
|
108
|
-
name: 'Style schema for ' + category,
|
|
109
|
-
} ) ),
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
} ),
|
|
113
|
-
{
|
|
114
|
-
description: 'Common styles schema for the specified category (applicable for V4 elements only)',
|
|
115
|
-
},
|
|
116
|
-
async ( uri, variables ) => {
|
|
117
|
-
const category = typeof variables.category === 'string' ? variables.category : variables.category?.[ 0 ];
|
|
118
|
-
const stylesSchema = getStylesSchema()[ category ];
|
|
119
|
-
if ( ! stylesSchema ) {
|
|
120
|
-
throw new Error( `No styles schema found for category: ${ category }` );
|
|
121
|
-
}
|
|
122
|
-
const asJson = Schema.propTypeToJsonSchema( stylesSchema as PropType );
|
|
123
|
-
return {
|
|
124
|
-
contents: [
|
|
125
|
-
{
|
|
126
|
-
uri: uri.toString(),
|
|
127
|
-
mimeType: 'application/json',
|
|
128
|
-
text: JSON.stringify(
|
|
129
|
-
Schema.enrichWithIntention( asJson, 'Desired CSS in format "property: value;"' )
|
|
130
|
-
),
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
|
|
137
97
|
resource(
|
|
138
98
|
'widget-schema-by-type',
|
|
139
99
|
new ResourceTemplate( WIDGET_SCHEMA_URI, {
|
|
@@ -18,7 +18,7 @@ export const generatePrompt = () => {
|
|
|
18
18
|
This tool support v4 elements only
|
|
19
19
|
|
|
20
20
|
# WORKFLOW
|
|
21
|
-
1. Check/create global classes via "
|
|
21
|
+
1. Check/create global classes via "manage-global-classes" tool
|
|
22
22
|
2. Build composition (THIS TOOL) - minimal inline styles
|
|
23
23
|
3. Apply classes via "apply-global-class" tool
|
|
24
24
|
|
|
@@ -36,8 +36,9 @@ Some elements have internal tree structures (nesting). When using these elements
|
|
|
36
36
|
- \`allowed_parents\` lists which element types this element can be placed inside
|
|
37
37
|
|
|
38
38
|
# CONFIGURATION
|
|
39
|
-
- Map configuration-id → elementConfig (props) +
|
|
40
|
-
-
|
|
39
|
+
- Map configuration-id → elementConfig (props) + style (raw CSS declarations)
|
|
40
|
+
- elementConfig PropValues require \`$$type\` matching schema
|
|
41
|
+
- style is raw CSS (property → value strings); the server converts it to native styles and stores any unconvertible declarations as the element custom CSS
|
|
41
42
|
- NO LINKS in configuration
|
|
42
43
|
- Retry on errors up to 10x
|
|
43
44
|
|
|
@@ -123,8 +124,7 @@ BAD: \`<e-flexbox style="height:100vh"><e-div-block style="height:100vh">overflo
|
|
|
123
124
|
# PARAMETERS
|
|
124
125
|
- **xmlStructure**: Valid XML with configuration-id attributes
|
|
125
126
|
- **elementConfig**: configuration-id → widget PropValues
|
|
126
|
-
- **
|
|
127
|
-
- **customCSS**: configuration-id → CSS rules (no selectors, semicolon-separated)
|
|
127
|
+
- **style**: configuration-id → raw CSS declarations (property → value strings; no selectors)
|
|
128
128
|
` );
|
|
129
129
|
|
|
130
130
|
buildCompositionsToolPrompt.example( `
|
|
@@ -134,13 +134,12 @@ Section with heading + button (NO explicit heights - content sizes naturally):
|
|
|
134
134
|
elementConfig: {
|
|
135
135
|
"section1": { "tag": { "$$type": "string", "value": "section" } }
|
|
136
136
|
},
|
|
137
|
-
|
|
138
|
-
"Section Title": "padding: 6rem 4rem; background: linear-gradient(135deg, #faf8f5 0%, #f0ebe4 100%);"
|
|
139
|
-
},
|
|
140
|
-
stylesConfig: {
|
|
137
|
+
style: {
|
|
141
138
|
"Section Title": {
|
|
142
|
-
"
|
|
143
|
-
"
|
|
139
|
+
"padding": "6rem 4rem",
|
|
140
|
+
"background": "linear-gradient(135deg, #faf8f5 0%, #f0ebe4 100%)",
|
|
141
|
+
"font-size": "3.5rem",
|
|
142
|
+
"color": "#2d2a26"
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
}
|
|
@@ -155,8 +154,8 @@ Note: No height/width specified on any element - flexbox handles layout automati
|
|
|
155
154
|
buildCompositionsToolPrompt.parameter( 'elementConfig', `Record mapping configuration IDs to widget PropValues.` );
|
|
156
155
|
|
|
157
156
|
buildCompositionsToolPrompt.parameter(
|
|
158
|
-
'
|
|
159
|
-
`Record mapping configuration IDs to
|
|
157
|
+
'style',
|
|
158
|
+
`Record mapping configuration IDs to raw CSS declarations (property → value strings).`
|
|
160
159
|
);
|
|
161
160
|
|
|
162
161
|
buildCompositionsToolPrompt.instruction(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
4
4
|
|
|
5
5
|
export const inputSchema = {
|
|
6
6
|
xmlStructure: z.string().describe( 'The XML structure representing the composition to be built' ),
|
|
@@ -13,25 +13,18 @@ export const inputSchema = {
|
|
|
13
13
|
)
|
|
14
14
|
)
|
|
15
15
|
.describe( 'A record mapping element IDs to their configuration objects. REQUIRED' ),
|
|
16
|
-
|
|
16
|
+
style: z
|
|
17
17
|
.record(
|
|
18
18
|
z.string().describe( 'The configuration id' ),
|
|
19
19
|
z.record(
|
|
20
|
-
z.string().describe( '
|
|
21
|
-
z.
|
|
20
|
+
z.string().describe( 'A CSS property name, e.g. "color", "padding".' ),
|
|
21
|
+
z.string().describe( 'A CSS value, e.g. "6rem 4rem", "#2d2a26".' )
|
|
22
22
|
)
|
|
23
23
|
)
|
|
24
24
|
.describe(
|
|
25
|
-
|
|
25
|
+
'A record mapping element configuration IDs to their raw CSS declarations (property→value). Converted to native styles server-side; any declaration that cannot be converted is stored as the element custom CSS.'
|
|
26
26
|
)
|
|
27
27
|
.default( {} ),
|
|
28
|
-
customCSS: z
|
|
29
|
-
.record(
|
|
30
|
-
z.string().describe( 'The configuration id' ),
|
|
31
|
-
z.string().describe( 'The custom CSS for the element. MANDATORY' )
|
|
32
|
-
)
|
|
33
|
-
.describe( 'A record mapping element IDs to their custom CSS.' )
|
|
34
|
-
.default( {} ),
|
|
35
28
|
};
|
|
36
29
|
|
|
37
30
|
export const outputSchema = {
|
|
@@ -11,7 +11,8 @@ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
|
11
11
|
import { CompositionBuilder } from '../../../composition-builder/composition-builder';
|
|
12
12
|
import { AVAILABLE_WIDGETS_URI_V4 } from '../../resources/available-widgets-resource';
|
|
13
13
|
import { DYNAMIC_TAGS_URI } from '../../resources/dynamic-tags-resource';
|
|
14
|
-
import { BEST_PRACTICES_URI,
|
|
14
|
+
import { BEST_PRACTICES_URI, WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
15
|
+
import { convertStyleBlocksToAtomic } from '../../utils/convert-css-to-atomic';
|
|
15
16
|
import { isWidgetAvailableForLLM } from '../../utils/element-data-util';
|
|
16
17
|
import { getCompositionTargetContainer } from '../../utils/get-composition-target-container';
|
|
17
18
|
import { BUILD_COMPOSITIONS_GUIDE_URI, generatePrompt } from './prompt';
|
|
@@ -41,7 +42,6 @@ export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
|
41
42
|
requiredResources: [
|
|
42
43
|
{ description: 'Build compositions guide', uri: BUILD_COMPOSITIONS_GUIDE_URI },
|
|
43
44
|
{ description: 'Widgets schema', uri: WIDGET_SCHEMA_URI },
|
|
44
|
-
{ description: 'Styles schema', uri: STYLE_SCHEMA_URI },
|
|
45
45
|
{ description: 'Global Classes', uri: 'elementor://global-classes' },
|
|
46
46
|
{ description: 'Global Variables', uri: 'elementor://global-variables' },
|
|
47
47
|
{ description: 'Styles best practices', uri: BEST_PRACTICES_URI },
|
|
@@ -51,8 +51,10 @@ export const initBuildCompositionsTool = ( reg: MCPRegistryEntry ) => {
|
|
|
51
51
|
outputSchema,
|
|
52
52
|
handler: async ( rawParams ) => {
|
|
53
53
|
assertCompositionXmlUsesV4WidgetsOnly( rawParams.xmlStructure );
|
|
54
|
-
const {
|
|
54
|
+
const { stylesConfig: convertedStyles, customCSS } = await convertCompositionStyles( rawParams.style );
|
|
55
|
+
const { xmlStructure, elementConfig, stylesConfig } = adaptLeafRootParams( {
|
|
55
56
|
...rawParams,
|
|
57
|
+
stylesConfig: convertedStyles,
|
|
56
58
|
widgetsCache: getWidgetsCache() ?? {},
|
|
57
59
|
} );
|
|
58
60
|
|
|
@@ -143,6 +145,26 @@ Remember: Global classes ensure design consistency and reusability. Don't skip a
|
|
|
143
145
|
} );
|
|
144
146
|
};
|
|
145
147
|
|
|
148
|
+
async function convertCompositionStyles( style: Record< string, Record< string, string > > ) {
|
|
149
|
+
const stylesConfig: Record< string, Record< string, unknown > > = {};
|
|
150
|
+
const customCSS: Record< string, string > = {};
|
|
151
|
+
|
|
152
|
+
if ( ! style || Object.keys( style ).length === 0 ) {
|
|
153
|
+
return { stylesConfig, customCSS };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const results = await convertStyleBlocksToAtomic( style );
|
|
157
|
+
|
|
158
|
+
for ( const [ configId, { props, customCss } ] of Object.entries( results ) ) {
|
|
159
|
+
stylesConfig[ configId ] = props;
|
|
160
|
+
if ( customCss ) {
|
|
161
|
+
customCSS[ configId ] = customCss;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return { stylesConfig, customCSS };
|
|
166
|
+
}
|
|
167
|
+
|
|
146
168
|
function assertCompositionXmlUsesV4WidgetsOnly( xmlStructure: string ) {
|
|
147
169
|
const doc = new DOMParser().parseFromString( xmlStructure, 'application/xml' );
|
|
148
170
|
if ( doc.querySelector( 'parsererror' ) ) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { toolPrompts } from '@elementor/editor-mcp';
|
|
2
2
|
|
|
3
3
|
import { DYNAMIC_TAGS_URI } from '../../resources/dynamic-tags-resource';
|
|
4
|
-
import {
|
|
4
|
+
import { WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
5
5
|
|
|
6
6
|
export const CONFIGURE_ELEMENT_GUIDE_URI = 'elementor://canvas/tools/configure-element-guide';
|
|
7
7
|
|
|
@@ -12,54 +12,43 @@ export const generatePrompt = () => {
|
|
|
12
12
|
Configure an existing element on the page.
|
|
13
13
|
|
|
14
14
|
# **CRITICAL - REQUIRED INFORMATION (Must read before using this tool)**
|
|
15
|
-
1. [${ WIDGET_SCHEMA_URI }]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
3. If not sure about the PropValues schema, you can use the "get-element-configuration-values" tool to retrieve the current PropValues configuration of the element.
|
|
22
|
-
|
|
23
|
-
Before using this tool, check the definitions of the elements PropTypes at the resource "widget-schema-by-type" at editor-canvas__elementor://widgets/schema/{widgetType}
|
|
24
|
-
All widgets share a common _style property for styling, which uses the common styles schema.
|
|
25
|
-
Retrieve and check the common styles schema at the resource list "styles-schema" at editor-canvas__elementor://styles/schema/{category}
|
|
15
|
+
1. [${ WIDGET_SCHEMA_URI }] — **Widget properties** (\`propertiesToChange\`): each widgetType (e.g. e-heading, e-button) has its own PropType schema; values must be PropValues with \`$$type\`.
|
|
16
|
+
2. [elementor://global-variables] — **Design tokens for styling**: use labels in CSS as \`var(--label)\` or \`var(--label, fallback)\`; only variables listed here are valid.
|
|
17
|
+
3. **Styling** (\`style\` parameter): flat map of CSS property → value strings — **not** PropValues. The server converts to native styles; unconvertible declarations become custom CSS.
|
|
18
|
+
4. **Current state**: \`get-element-configuration-values\` returns \`properties\` as PropValues and \`style\` in stored form; when writing, send raw CSS in \`style\`, not copied PropValues.
|
|
19
|
+
|
|
20
|
+
Before using this tool, read the widget PropType schema at editor-canvas__elementor://widgets/schema/{widgetType}
|
|
26
21
|
|
|
27
22
|
# When to use this tool
|
|
28
23
|
When a user requires to change anything in an element, such as updating text, colors, sizes, or other configurable properties.
|
|
29
24
|
This tool handles elements of type "widget".
|
|
30
|
-
This tool handles styling elements, using the "
|
|
25
|
+
This tool handles styling elements, using the "style" parameter (raw CSS as a property → value map).
|
|
31
26
|
|
|
32
|
-
To CLEAR a property (i.e., set it to default or none), provide null as a value
|
|
27
|
+
To CLEAR a property (i.e., set it to default or none), provide null as a value - example: \`background-color: null\`.
|
|
33
28
|
|
|
34
29
|
The element's schema must be known before using this tool.
|
|
35
|
-
The style schema must be known before using this tool.
|
|
36
|
-
|
|
37
|
-
Attached resource link describing how PropType schema should be parsed as PropValue for this tool.
|
|
38
|
-
|
|
39
|
-
Read carefully the PropType Schema of the element and it's styles, then apply correct PropValue according to the schema.
|
|
40
30
|
|
|
41
|
-
PropValue structure
|
|
31
|
+
**PropValue structure (for \`propertiesToChange\` only — not for \`style\`):**
|
|
42
32
|
{
|
|
43
33
|
"$$type": string, // MANDATORY as defined in the PropType schema under the "key" property
|
|
44
34
|
value: unknown // The value according to the PropType schema for kinds of "array", use array with PropValues items inside. For "object", read the shape property of the PropType schema. For "plain", use strings.
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
<IMPORTANT>
|
|
48
|
-
ALWAYS MAKE SURE you have the PropType schemas for the element you are configuring
|
|
38
|
+
ALWAYS MAKE SURE you have the PropType schemas for the element you are configuring. If you are not sure, retrieve the schema from the resources mentioned above.
|
|
49
39
|
</IMPORTANT>
|
|
50
40
|
|
|
51
|
-
You can use multiple property changes at once by providing multiple entries in the propertiesToChange object
|
|
41
|
+
You can use multiple property changes at once by providing multiple entries in the propertiesToChange object.
|
|
52
42
|
Some properties are nested, use the root property name, then objects with nested values inside, as the complete schema suggests.
|
|
53
43
|
|
|
54
44
|
Make sure you have the "widget-schema-by-type" resource available to retrieve the PropType schema for the element type you are configuring.
|
|
55
|
-
Make sure you have the "styles-schema" resources available to retrieve the common styles schema.
|
|
56
45
|
|
|
57
46
|
# How to configure elements
|
|
58
|
-
We use a dedicated PropType Schema for configuring
|
|
59
|
-
For
|
|
60
|
-
For all non-primitive
|
|
47
|
+
We use a dedicated PropType Schema for configuring element properties (propertiesToChange). When you configure an element property, you must use the EXACT PropType Value as defined in the schema.
|
|
48
|
+
For styling, use the "style" parameter with raw CSS declarations (property → value strings) - e.g. \`color: var(--primary-text, #000); height: 4rem;\`;
|
|
49
|
+
For all non-primitive entries in \`propertiesToChange\`, provide the schema \`key\` as \`$$type\` in the generated object, as it is MANDATORY for parsing.
|
|
61
50
|
|
|
62
|
-
Use the EXACT
|
|
51
|
+
Use the EXACT PropType schema given, and ALWAYS include the \`key\` from the schema for every property you are changing in \`propertiesToChange\`.
|
|
63
52
|
|
|
64
53
|
# Dynamic tags
|
|
65
54
|
A value can be made dynamic wherever its schema exposes a variant with "$$type": "dynamic". This may be the property root OR a NESTED field: for example an image is made dynamic on its "src" (the root stays "image"), NOT on the whole "image" value.
|
|
@@ -90,8 +79,8 @@ Do NOT send "group" (it is resolved automatically). Use { "settings": {} } only
|
|
|
90
79
|
);
|
|
91
80
|
|
|
92
81
|
configureElementToolPrompt.parameter(
|
|
93
|
-
'
|
|
94
|
-
'
|
|
82
|
+
'style',
|
|
83
|
+
'A flat map of raw CSS declarations (property → value), e.g. { "line-height": "1.25rem", "color": "var(--primary-text, #000)" }. Set a value to null to reset that property to its default. OPTIONAL.'
|
|
95
84
|
);
|
|
96
85
|
|
|
97
86
|
configureElementToolPrompt.example( `
|
|
@@ -108,20 +97,9 @@ Do NOT send "group" (it is resolved automatically). Use { "settings": {} } only
|
|
|
108
97
|
value: false
|
|
109
98
|
},
|
|
110
99
|
},
|
|
111
|
-
|
|
112
|
-
'line-height':
|
|
113
|
-
|
|
114
|
-
value: {
|
|
115
|
-
size: {
|
|
116
|
-
$$type: 'number',
|
|
117
|
-
value: 20
|
|
118
|
-
},
|
|
119
|
-
unit: {
|
|
120
|
-
$$type: 'string',
|
|
121
|
-
value: 'px'
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
100
|
+
style: {
|
|
101
|
+
'line-height': '1.25rem',
|
|
102
|
+
'color': 'var(--primary-text, #000)'
|
|
125
103
|
},
|
|
126
104
|
elementId: 'element-id',
|
|
127
105
|
elementType: 'element-type'
|
|
@@ -130,7 +108,7 @@ Do NOT send "group" (it is resolved automatically). Use { "settings": {} } only
|
|
|
130
108
|
` );
|
|
131
109
|
|
|
132
110
|
configureElementToolPrompt.instruction(
|
|
133
|
-
'The $$type property is MANDATORY for every value; it is
|
|
111
|
+
'The $$type property is MANDATORY for every value in propertiesToChange; it is not used in the style parameter (raw CSS only).'
|
|
134
112
|
);
|
|
135
113
|
|
|
136
114
|
configureElementToolPrompt.instruction( `
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from '@elementor/schema';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { WIDGET_SCHEMA_URI } from '../../resources/widgets-schema-resource';
|
|
4
4
|
|
|
5
5
|
export const inputSchema = {
|
|
6
6
|
propertiesToChange: z
|
|
@@ -12,13 +12,19 @@ export const inputSchema = {
|
|
|
12
12
|
z.any()
|
|
13
13
|
)
|
|
14
14
|
.describe( 'An object record containing property names and their new values to be set on the element' ),
|
|
15
|
-
|
|
15
|
+
style: z
|
|
16
16
|
.record(
|
|
17
|
-
z.string().describe( '
|
|
18
|
-
z
|
|
19
|
-
|
|
17
|
+
z.string().describe( 'A CSS property name, e.g. "color", "margin-top".' ),
|
|
18
|
+
z
|
|
19
|
+
.string()
|
|
20
|
+
.nullable()
|
|
21
|
+
.describe(
|
|
22
|
+
'A CSS value, e.g. "red", "10px", "1px solid #000". Use null to reset the property to its default.'
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
.describe(
|
|
26
|
+
'Raw CSS declarations as a flat property→value map. Converted to native styles server-side; any declaration that cannot be converted is stored as the element custom CSS. A null value resets that property to its default.'
|
|
20
27
|
)
|
|
21
|
-
.describe( 'An object record containing style property names and their new values to be set on the element' )
|
|
22
28
|
.default( {} ),
|
|
23
29
|
elementType: z.string().describe( 'The type of the element to retrieve the schema' ),
|
|
24
30
|
elementId: z.string().describe( 'The unique id of the element to configure' ),
|