@elementor/editor-default-styles 4.5.0-1213 → 4.5.0-1215
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 +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +129 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -22
- package/src/components/default-styles-header-location.tsx +7 -0
- package/src/components/default-styles-tab-embedded.tsx +30 -24
- package/src/index.ts +1 -0
- package/src/init.ts +13 -0
- package/src/mcp/index.ts +7 -0
- package/src/mcp/manage-default-styles-tool.ts +153 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { type MCPRegistryEntry } from '@elementor/editor-mcp';
|
|
2
|
+
import { type StyleDefinition } from '@elementor/editor-styles';
|
|
3
|
+
import { __privateRunCommandSync as runCommandSync } from '@elementor/editor-v1-adapters';
|
|
4
|
+
import { type HttpResponse, httpService } from '@elementor/http-client';
|
|
5
|
+
import { z } from '@elementor/schema';
|
|
6
|
+
import { __getState as getState } from '@elementor/store';
|
|
7
|
+
|
|
8
|
+
import { defaultStylesStylesProvider } from '../default-styles-provider';
|
|
9
|
+
import { selectData, selectInitialData, type StateWithDefaultStyles } from '../store';
|
|
10
|
+
|
|
11
|
+
const MCP_PROXY_URL = 'elementor/v1/mcp-proxy';
|
|
12
|
+
const TOOL_NAME = 'manage-default-styles';
|
|
13
|
+
|
|
14
|
+
type ManageDefaultStylesResult = Partial< StyleDefinition > & {
|
|
15
|
+
status: 'ok' | 'error';
|
|
16
|
+
tag?: string;
|
|
17
|
+
message?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ManageDefaultStylesResponse = {
|
|
21
|
+
status: string;
|
|
22
|
+
results?: ManageDefaultStylesResult[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type ManageDefaultStylesParams = {
|
|
26
|
+
action: 'update' | 'delete';
|
|
27
|
+
tag: string;
|
|
28
|
+
css?: string;
|
|
29
|
+
mode?: 'patch' | 'replace';
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type EditorDefaultStylesSnapshot = Record<
|
|
33
|
+
string,
|
|
34
|
+
{
|
|
35
|
+
type: StyleDefinition[ 'type' ];
|
|
36
|
+
variants: StyleDefinition[ 'variants' ];
|
|
37
|
+
}
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
export const initManageDefaultStylesTool = ( reg: MCPRegistryEntry ) => {
|
|
41
|
+
const { addTool } = reg;
|
|
42
|
+
|
|
43
|
+
addTool( {
|
|
44
|
+
name: TOOL_NAME,
|
|
45
|
+
description:
|
|
46
|
+
'Manage V4 site-wide default styles on the active kit, keyed by HTML wrapper tag (h1..h6, p, a, section, div, ...). Update or delete using raw CSS declarations (up to 20 operations).',
|
|
47
|
+
schema: {
|
|
48
|
+
action: z.enum( [ 'update', 'delete' ] ),
|
|
49
|
+
tag: z.string().describe( 'HTML wrapper tag to target (e.g. h1, h2, p, a).' ),
|
|
50
|
+
css: z
|
|
51
|
+
.string()
|
|
52
|
+
.optional()
|
|
53
|
+
.describe(
|
|
54
|
+
'Plain CSS string. Supports &:hover/&:focus/&:active nesting and @media(--breakpoint) blocks. font-family must be a single Google Font name (no fallback stacks). In patch mode: "prop: null" removes that prop; "all: null" wipes the variant. Required for update.'
|
|
55
|
+
),
|
|
56
|
+
mode: z
|
|
57
|
+
.enum( [ 'patch', 'replace' ] )
|
|
58
|
+
.optional()
|
|
59
|
+
.describe(
|
|
60
|
+
'Merge strategy for update — patch (default): merge incoming props with existing; replace: discard all existing variants for the affected breakpoints.'
|
|
61
|
+
),
|
|
62
|
+
},
|
|
63
|
+
outputSchema: {
|
|
64
|
+
status: z.enum( [ 'ok' ] ).describe( 'Operation status' ),
|
|
65
|
+
tag: z.string().describe( 'HTML tag of the affected default style.' ),
|
|
66
|
+
},
|
|
67
|
+
isDestructive: true,
|
|
68
|
+
handler: async ( params ) => {
|
|
69
|
+
const editorDefaultStyles = buildEditorDefaultStylesSnapshot( params.tag );
|
|
70
|
+
|
|
71
|
+
const { data } = await httpService().post< HttpResponse< ManageDefaultStylesResponse > >( MCP_PROXY_URL, {
|
|
72
|
+
tool: TOOL_NAME,
|
|
73
|
+
input: {
|
|
74
|
+
operations: [ params ],
|
|
75
|
+
dry_run: true,
|
|
76
|
+
editor_default_styles: editorDefaultStyles,
|
|
77
|
+
},
|
|
78
|
+
} );
|
|
79
|
+
|
|
80
|
+
const result = data.data.results?.[ 0 ];
|
|
81
|
+
|
|
82
|
+
if ( result?.status !== 'ok' ) {
|
|
83
|
+
throw new Error( result?.message || 'Unexpected response from server' );
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
applyPlannedDefaultStylesChange( params, result );
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
status: 'ok' as const,
|
|
90
|
+
tag: result.tag ?? params.tag,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
} );
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const buildEditorDefaultStylesSnapshot = ( tag: string ): EditorDefaultStylesSnapshot => {
|
|
97
|
+
const state = getState() as StateWithDefaultStyles;
|
|
98
|
+
const style = selectData( state )[ tag ];
|
|
99
|
+
|
|
100
|
+
if ( style ) {
|
|
101
|
+
return {
|
|
102
|
+
[ tag ]: {
|
|
103
|
+
type: style.type,
|
|
104
|
+
variants: style.variants,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const initialStyle = selectInitialData( state )[ tag ];
|
|
110
|
+
|
|
111
|
+
if ( initialStyle ) {
|
|
112
|
+
return {
|
|
113
|
+
[ tag ]: {
|
|
114
|
+
type: initialStyle.type,
|
|
115
|
+
variants: [],
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const applyPlannedDefaultStylesChange = ( params: ManageDefaultStylesParams, result: ManageDefaultStylesResult ) => {
|
|
124
|
+
applyInEditor( params.action, result );
|
|
125
|
+
runCommandSync( 'document/save/set-is-modified', { status: true }, { internal: true } );
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const applyInEditor = ( action: 'update' | 'delete', result: ManageDefaultStylesResult ) => {
|
|
129
|
+
const { update, delete: remove } = defaultStylesStylesProvider.actions;
|
|
130
|
+
const tag = result.tag;
|
|
131
|
+
|
|
132
|
+
if ( ! tag ) {
|
|
133
|
+
throw new Error( 'Default style tag is missing from the response' );
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
switch ( action ) {
|
|
137
|
+
case 'update':
|
|
138
|
+
if ( ! result.type || ! result.variants ) {
|
|
139
|
+
throw new Error( 'Planned default style is incomplete in the response' );
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
update?.( {
|
|
143
|
+
id: tag,
|
|
144
|
+
label: tag,
|
|
145
|
+
type: result.type,
|
|
146
|
+
variants: result.variants,
|
|
147
|
+
} );
|
|
148
|
+
break;
|
|
149
|
+
case 'delete':
|
|
150
|
+
remove?.( tag );
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
};
|