@elementor/editor-global-classes 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.js
CHANGED
|
@@ -2864,7 +2864,7 @@ function initMcpApplyUnapplyGlobalClasses(server) {
|
|
|
2864
2864
|
const appliedClasses = (0, import_editor_editing_panel.doGetAppliedClasses)(elementId);
|
|
2865
2865
|
(0, import_editor_editing_panel.doApplyClasses)(elementId, [...appliedClasses, classId]);
|
|
2866
2866
|
return {
|
|
2867
|
-
llm_instructions: "Please check the element
|
|
2867
|
+
llm_instructions: "Please check the element configuration, find inline styles duplicated by the applied global class, and remove them",
|
|
2868
2868
|
result: `Class ${classId} applied to element ${elementId} successfully.`
|
|
2869
2869
|
};
|
|
2870
2870
|
}
|
|
@@ -2958,39 +2958,19 @@ function initMcpApplyGetGlobalClassUsages(reg) {
|
|
|
2958
2958
|
|
|
2959
2959
|
// src/mcp-integration/mcp-manage-global-classes.ts
|
|
2960
2960
|
var import_editor_canvas2 = require("@elementor/editor-canvas");
|
|
2961
|
-
var import_editor_props = require("@elementor/editor-props");
|
|
2962
|
-
var import_editor_styles3 = require("@elementor/editor-styles");
|
|
2963
2961
|
var import_schema3 = require("@elementor/schema");
|
|
2964
2962
|
var schema = {
|
|
2965
2963
|
action: import_schema3.z.enum(["create", "modify", "delete"]).describe("Operation to perform"),
|
|
2966
2964
|
classId: import_schema3.z.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
|
|
2967
2965
|
globalClassName: import_schema3.z.string().optional().describe("Global class name (required for create)"),
|
|
2968
|
-
|
|
2969
|
-
default: import_schema3.z.
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
).describe(
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
import_schema3.z.string().describe("The style property name"),
|
|
2977
|
-
import_schema3.z.any().describe(`The style PropValue, refer to [${import_editor_canvas2.STYLE_SCHEMA_FULL_URI}] how to generate values`)
|
|
2978
|
-
).describe(
|
|
2979
|
-
"An object record containing style property names and their new values to be set on the element. for :hover css state. optional"
|
|
2980
|
-
).optional(),
|
|
2981
|
-
focus: import_schema3.z.record(
|
|
2982
|
-
import_schema3.z.string().describe("The style property name"),
|
|
2983
|
-
import_schema3.z.any().describe(`The style PropValue, refer to [${import_editor_canvas2.STYLE_SCHEMA_FULL_URI}] how to generate values`)
|
|
2984
|
-
).describe(
|
|
2985
|
-
"An object record containing style property names and their new values to be set on the element. for :focus css state. optional"
|
|
2986
|
-
).optional(),
|
|
2987
|
-
active: import_schema3.z.record(
|
|
2988
|
-
import_schema3.z.string().describe("The style property name"),
|
|
2989
|
-
import_schema3.z.any().describe(`The style PropValue, refer to [${import_editor_canvas2.STYLE_SCHEMA_FULL_URI}] how to generate values`)
|
|
2990
|
-
).describe(
|
|
2991
|
-
"An object record containing style property names and their new values to be set on the element. for :active css state. optional"
|
|
2992
|
-
).optional()
|
|
2993
|
-
}),
|
|
2966
|
+
style: import_schema3.z.object({
|
|
2967
|
+
default: import_schema3.z.string().describe("Plaintext CSS for the default state. MUST be non-empty \u2014 blank strings are rejected."),
|
|
2968
|
+
hover: import_schema3.z.string().describe("Plaintext CSS for the :hover state. optional").optional(),
|
|
2969
|
+
focus: import_schema3.z.string().describe("Plaintext CSS for the :focus state. optional").optional(),
|
|
2970
|
+
active: import_schema3.z.string().describe("Plaintext CSS for the :active state. optional").optional()
|
|
2971
|
+
}).describe(
|
|
2972
|
+
"Plaintext CSS per pseudo-state. All states are converted in one bulk request; unconvertible declarations are stored as custom CSS."
|
|
2973
|
+
),
|
|
2994
2974
|
breakpoint: import_schema3.z.nullable(import_schema3.z.string().describe("Responsive breakpoint name for styles. Defaults to desktop (null).")).default(null).describe("Responsive breakpoint name for styles. Defaults to desktop (null).")
|
|
2995
2975
|
};
|
|
2996
2976
|
var outputSchema = {
|
|
@@ -2999,8 +2979,7 @@ var outputSchema = {
|
|
|
2999
2979
|
message: import_schema3.z.string().optional().describe("Error details if status is error")
|
|
3000
2980
|
};
|
|
3001
2981
|
var handler = async (input) => {
|
|
3002
|
-
const { action, classId: rawClassId, globalClassName,
|
|
3003
|
-
const propsWithStates = rawProps;
|
|
2982
|
+
const { action, classId: rawClassId, globalClassName, style: rawStyle, breakpoint } = input;
|
|
3004
2983
|
let classId = rawClassId;
|
|
3005
2984
|
if (action === "create" && !globalClassName) {
|
|
3006
2985
|
return {
|
|
@@ -3027,59 +3006,22 @@ var handler = async (input) => {
|
|
|
3027
3006
|
message: "Required actions not available"
|
|
3028
3007
|
};
|
|
3029
3008
|
}
|
|
3030
|
-
const
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
Object.keys(props).forEach((key) => {
|
|
3035
|
-
const propType = stylesSchema[key];
|
|
3036
|
-
if (!propType) {
|
|
3037
|
-
errors.push(`Property "${key}" does not exist in styles schema.`);
|
|
3038
|
-
return;
|
|
3039
|
-
}
|
|
3040
|
-
const { valid, jsonSchema } = import_editor_props.Schema.validatePropValue(propType, props[key]);
|
|
3041
|
-
if (!valid) {
|
|
3042
|
-
errors.push(`- Property "${key}" has invalid value
|
|
3043
|
-
Expected schema: ${jsonSchema}
|
|
3044
|
-
`);
|
|
3045
|
-
}
|
|
3046
|
-
});
|
|
3047
|
-
});
|
|
3048
|
-
if (action !== "delete") {
|
|
3049
|
-
const hasAnyProps = Object.values(propsWithStates).some(
|
|
3050
|
-
(stateProps) => Object.keys(stateProps).length > 0
|
|
3009
|
+
const styleBlocks = collectNonEmptyStyleBlocks(rawStyle);
|
|
3010
|
+
if (action !== "delete" && Object.keys(styleBlocks).length === 0) {
|
|
3011
|
+
throw new Error(
|
|
3012
|
+
'Style must not be empty. Provide plaintext CSS per state.\n\nExample: style.default = "display: flex; flex-direction: column; gap: 1rem;"'
|
|
3051
3013
|
);
|
|
3052
|
-
if (!hasAnyProps) {
|
|
3053
|
-
throw new Error(
|
|
3054
|
-
`Props must not be empty. Each prop must be a PropValue object from the style schema.
|
|
3055
|
-
|
|
3056
|
-
Example: { "display": { "$$type": "string", "value": "flex" }, "flex-direction": { "$$type": "string", "value": "column" } }
|
|
3057
|
-
|
|
3058
|
-
${import_editor_canvas2.STYLE_SCHEMA_FULL_URI} to get the allowed values (look at the "value" enum in the schema response), then construct { "$$type": "string", "value": "<chosen value>" } for each property.
|
|
3059
|
-
Available Properties: ${validProps.join(
|
|
3060
|
-
", "
|
|
3061
|
-
)}`
|
|
3062
|
-
);
|
|
3063
|
-
}
|
|
3064
3014
|
}
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3015
|
+
let convertedByState = {};
|
|
3016
|
+
if (action !== "delete") {
|
|
3017
|
+
const conversionResults = await (0, import_editor_canvas2.convertStyleBlocksToAtomic)(styleBlocks);
|
|
3018
|
+
convertedByState = Object.fromEntries(
|
|
3019
|
+
Object.entries(conversionResults).map(([state, { props, customCss }]) => [
|
|
3020
|
+
state,
|
|
3021
|
+
{ props, customCss: toStoredCustomCss(customCss) }
|
|
3022
|
+
])
|
|
3073
3023
|
);
|
|
3074
3024
|
}
|
|
3075
|
-
const Utils = window.elementorV2.editorVariables.Utils;
|
|
3076
|
-
Object.values(propsWithStates).forEach((props) => {
|
|
3077
|
-
Object.keys(props).forEach((key) => {
|
|
3078
|
-
props[key] = import_editor_props.Schema.adjustLlmPropValueSchema(props[key], {
|
|
3079
|
-
transformers: Utils.globalVariablesLLMResolvers
|
|
3080
|
-
});
|
|
3081
|
-
});
|
|
3082
|
-
});
|
|
3083
3025
|
const breakpointValue = breakpoint ?? "desktop";
|
|
3084
3026
|
let result = {
|
|
3085
3027
|
status: "error",
|
|
@@ -3098,11 +3040,12 @@ Update your input and try again.`
|
|
|
3098
3040
|
throw new Error("error deleting class");
|
|
3099
3041
|
}
|
|
3100
3042
|
let currentAction = action;
|
|
3101
|
-
for await (const [state, props] of Object.entries(
|
|
3043
|
+
for await (const [state, { props, customCss }] of Object.entries(convertedByState)) {
|
|
3102
3044
|
switch (currentAction) {
|
|
3103
3045
|
case "create":
|
|
3104
3046
|
const newClassId = await attemptCreate({
|
|
3105
3047
|
props,
|
|
3048
|
+
customCss,
|
|
3106
3049
|
className: globalClassName,
|
|
3107
3050
|
stylesProvider: globalClassesStylesProvider,
|
|
3108
3051
|
breakpoint: breakpointValue,
|
|
@@ -3123,6 +3066,7 @@ Update your input and try again.`
|
|
|
3123
3066
|
const updated = await attemptUpdate({
|
|
3124
3067
|
classId,
|
|
3125
3068
|
props,
|
|
3069
|
+
customCss,
|
|
3126
3070
|
stylesProvider: globalClassesStylesProvider,
|
|
3127
3071
|
breakpoint: breakpointValue,
|
|
3128
3072
|
state
|
|
@@ -3151,28 +3095,25 @@ var initManageGlobalClasses = (reg) => {
|
|
|
3151
3095
|
name: "manage-global-classes",
|
|
3152
3096
|
requiredResources: [
|
|
3153
3097
|
{ uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
|
|
3154
|
-
{ uri: import_editor_canvas2.STYLE_SCHEMA_FULL_URI, description: "Style schema resources" },
|
|
3155
3098
|
{ uri: import_editor_canvas2.BREAKPOINTS_SCHEMA_FULL_URI, description: "Breakpoints list" }
|
|
3156
3099
|
],
|
|
3157
3100
|
description: `Create or modify global classes for reusable design-system styling. Class names must reflect purpose (e.g. heading-primary, button-cta). Create classes BEFORE applying them. Do NOT create classes for one-off styles.
|
|
3158
3101
|
|
|
3159
|
-
IMPORTANT:
|
|
3160
|
-
|
|
3102
|
+
IMPORTANT: style must contain plaintext CSS rules per state \u2014 never pass empty strings.
|
|
3103
|
+
CSS is converted server-side in one bulk request; any declaration that cannot be converted is stored as the class custom CSS.
|
|
3161
3104
|
|
|
3162
3105
|
Example \u2014 creating a flex column class:
|
|
3163
|
-
|
|
3164
|
-
"display": { "$$type": "string", "value": "flex" },
|
|
3165
|
-
"flex-direction": { "$$type": "string", "value": "column" }
|
|
3166
|
-
}
|
|
3106
|
+
style.default = "display: flex; flex-direction: column; gap: 1rem;"
|
|
3167
3107
|
|
|
3168
|
-
|
|
3108
|
+
Example \u2014 hover state:
|
|
3109
|
+
style.hover = "opacity: 0.85;"`,
|
|
3169
3110
|
schema,
|
|
3170
3111
|
outputSchema,
|
|
3171
3112
|
handler
|
|
3172
3113
|
});
|
|
3173
3114
|
};
|
|
3174
3115
|
async function attemptCreate(opts) {
|
|
3175
|
-
const { props, breakpoint, className, stylesProvider, state } = opts;
|
|
3116
|
+
const { props, customCss, breakpoint, className, stylesProvider, state } = opts;
|
|
3176
3117
|
const { create, delete: deleteClass2 } = stylesProvider.actions;
|
|
3177
3118
|
if (!className) {
|
|
3178
3119
|
throw new Error("Global class name is a required for creation");
|
|
@@ -3186,7 +3127,7 @@ async function attemptCreate(opts) {
|
|
|
3186
3127
|
breakpoint,
|
|
3187
3128
|
state: state === "default" ? null : state
|
|
3188
3129
|
},
|
|
3189
|
-
custom_css:
|
|
3130
|
+
custom_css: customCss,
|
|
3190
3131
|
props
|
|
3191
3132
|
}
|
|
3192
3133
|
]);
|
|
@@ -3199,7 +3140,7 @@ async function attemptCreate(opts) {
|
|
|
3199
3140
|
}
|
|
3200
3141
|
}
|
|
3201
3142
|
async function attemptUpdate(opts) {
|
|
3202
|
-
const { props, breakpoint, classId, stylesProvider, state } = opts;
|
|
3143
|
+
const { props, customCss, breakpoint, classId, stylesProvider, state } = opts;
|
|
3203
3144
|
const { updateProps, update } = stylesProvider.actions;
|
|
3204
3145
|
if (!classId) {
|
|
3205
3146
|
throw new Error("Class ID is required for modification");
|
|
@@ -3213,6 +3154,7 @@ async function attemptUpdate(opts) {
|
|
|
3213
3154
|
updateProps({
|
|
3214
3155
|
id: classId,
|
|
3215
3156
|
props,
|
|
3157
|
+
custom_css: customCss,
|
|
3216
3158
|
meta: {
|
|
3217
3159
|
breakpoint,
|
|
3218
3160
|
state: state === "default" ? null : state
|
|
@@ -3249,6 +3191,21 @@ async function attemptDelete(opts) {
|
|
|
3249
3191
|
await saveGlobalClasses2({ context: "frontend" });
|
|
3250
3192
|
return true;
|
|
3251
3193
|
}
|
|
3194
|
+
function collectNonEmptyStyleBlocks(style) {
|
|
3195
|
+
const blocks = {};
|
|
3196
|
+
Object.entries(style).forEach(([state, cssText]) => {
|
|
3197
|
+
if (cssText?.trim()) {
|
|
3198
|
+
blocks[state] = cssText.trim();
|
|
3199
|
+
}
|
|
3200
|
+
});
|
|
3201
|
+
return blocks;
|
|
3202
|
+
}
|
|
3203
|
+
function toStoredCustomCss(customCss) {
|
|
3204
|
+
if (!customCss?.trim()) {
|
|
3205
|
+
return null;
|
|
3206
|
+
}
|
|
3207
|
+
return { raw: btoa(customCss) };
|
|
3208
|
+
}
|
|
3252
3209
|
|
|
3253
3210
|
// src/mcp-integration/index.ts
|
|
3254
3211
|
var initMcpIntegration = (reg, canvasMcpEntry) => {
|