@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.mjs CHANGED
@@ -2897,7 +2897,7 @@ function initMcpApplyUnapplyGlobalClasses(server) {
2897
2897
  const appliedClasses = doGetAppliedClasses(elementId);
2898
2898
  doApplyClasses(elementId, [...appliedClasses, classId]);
2899
2899
  return {
2900
- llm_instructions: "Please check the element-configuration, find DUPLICATES in the style schema that are in the class, and remove them",
2900
+ llm_instructions: "Please check the element configuration, find inline styles duplicated by the applied global class, and remove them",
2901
2901
  result: `Class ${classId} applied to element ${elementId} successfully.`
2902
2902
  };
2903
2903
  }
@@ -2990,40 +2990,20 @@ function initMcpApplyGetGlobalClassUsages(reg) {
2990
2990
  }
2991
2991
 
2992
2992
  // src/mcp-integration/mcp-manage-global-classes.ts
2993
- import { BREAKPOINTS_SCHEMA_FULL_URI, STYLE_SCHEMA_FULL_URI } from "@elementor/editor-canvas";
2994
- import { Schema } from "@elementor/editor-props";
2995
- import { getStylesSchema } from "@elementor/editor-styles";
2993
+ import { BREAKPOINTS_SCHEMA_FULL_URI, convertStyleBlocksToAtomic } from "@elementor/editor-canvas";
2996
2994
  import { z as z3 } from "@elementor/schema";
2997
2995
  var schema = {
2998
2996
  action: z3.enum(["create", "modify", "delete"]).describe("Operation to perform"),
2999
2997
  classId: z3.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
3000
2998
  globalClassName: z3.string().optional().describe("Global class name (required for create)"),
3001
- props: z3.object({
3002
- default: z3.record(
3003
- z3.string().describe("The style property name"),
3004
- z3.any().describe(`The style PropValue, refer to [${STYLE_SCHEMA_FULL_URI}] how to generate values`)
3005
- ).describe(
3006
- "An object record containing style property names and their new values. MUST contain at least one property \u2014 empty objects are rejected."
3007
- ),
3008
- hover: z3.record(
3009
- z3.string().describe("The style property name"),
3010
- z3.any().describe(`The style PropValue, refer to [${STYLE_SCHEMA_FULL_URI}] how to generate values`)
3011
- ).describe(
3012
- "An object record containing style property names and their new values to be set on the element. for :hover css state. optional"
3013
- ).optional(),
3014
- focus: z3.record(
3015
- z3.string().describe("The style property name"),
3016
- z3.any().describe(`The style PropValue, refer to [${STYLE_SCHEMA_FULL_URI}] how to generate values`)
3017
- ).describe(
3018
- "An object record containing style property names and their new values to be set on the element. for :focus css state. optional"
3019
- ).optional(),
3020
- active: z3.record(
3021
- z3.string().describe("The style property name"),
3022
- z3.any().describe(`The style PropValue, refer to [${STYLE_SCHEMA_FULL_URI}] how to generate values`)
3023
- ).describe(
3024
- "An object record containing style property names and their new values to be set on the element. for :active css state. optional"
3025
- ).optional()
3026
- }),
2999
+ style: z3.object({
3000
+ default: z3.string().describe("Plaintext CSS for the default state. MUST be non-empty \u2014 blank strings are rejected."),
3001
+ hover: z3.string().describe("Plaintext CSS for the :hover state. optional").optional(),
3002
+ focus: z3.string().describe("Plaintext CSS for the :focus state. optional").optional(),
3003
+ active: z3.string().describe("Plaintext CSS for the :active state. optional").optional()
3004
+ }).describe(
3005
+ "Plaintext CSS per pseudo-state. All states are converted in one bulk request; unconvertible declarations are stored as custom CSS."
3006
+ ),
3027
3007
  breakpoint: z3.nullable(z3.string().describe("Responsive breakpoint name for styles. Defaults to desktop (null).")).default(null).describe("Responsive breakpoint name for styles. Defaults to desktop (null).")
3028
3008
  };
3029
3009
  var outputSchema = {
@@ -3032,8 +3012,7 @@ var outputSchema = {
3032
3012
  message: z3.string().optional().describe("Error details if status is error")
3033
3013
  };
3034
3014
  var handler = async (input) => {
3035
- const { action, classId: rawClassId, globalClassName, props: rawProps, breakpoint } = input;
3036
- const propsWithStates = rawProps;
3015
+ const { action, classId: rawClassId, globalClassName, style: rawStyle, breakpoint } = input;
3037
3016
  let classId = rawClassId;
3038
3017
  if (action === "create" && !globalClassName) {
3039
3018
  return {
@@ -3060,59 +3039,22 @@ var handler = async (input) => {
3060
3039
  message: "Required actions not available"
3061
3040
  };
3062
3041
  }
3063
- const errors = [];
3064
- const stylesSchema = getStylesSchema();
3065
- const validProps = Object.keys(stylesSchema);
3066
- Object.values(propsWithStates).forEach((props) => {
3067
- Object.keys(props).forEach((key) => {
3068
- const propType = stylesSchema[key];
3069
- if (!propType) {
3070
- errors.push(`Property "${key}" does not exist in styles schema.`);
3071
- return;
3072
- }
3073
- const { valid, jsonSchema } = Schema.validatePropValue(propType, props[key]);
3074
- if (!valid) {
3075
- errors.push(`- Property "${key}" has invalid value
3076
- Expected schema: ${jsonSchema}
3077
- `);
3078
- }
3079
- });
3080
- });
3081
- if (action !== "delete") {
3082
- const hasAnyProps = Object.values(propsWithStates).some(
3083
- (stateProps) => Object.keys(stateProps).length > 0
3042
+ const styleBlocks = collectNonEmptyStyleBlocks(rawStyle);
3043
+ if (action !== "delete" && Object.keys(styleBlocks).length === 0) {
3044
+ throw new Error(
3045
+ 'Style must not be empty. Provide plaintext CSS per state.\n\nExample: style.default = "display: flex; flex-direction: column; gap: 1rem;"'
3084
3046
  );
3085
- if (!hasAnyProps) {
3086
- throw new Error(
3087
- `Props must not be empty. Each prop must be a PropValue object from the style schema.
3088
-
3089
- Example: { "display": { "$$type": "string", "value": "flex" }, "flex-direction": { "$$type": "string", "value": "column" } }
3090
-
3091
- ${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.
3092
- Available Properties: ${validProps.join(
3093
- ", "
3094
- )}`
3095
- );
3096
- }
3097
3047
  }
3098
- if (errors.length > 0) {
3099
- throw new Error(
3100
- `Validation errors:
3101
- ${errors.join("\n")}
3102
- Available Properties: ${validProps.join(
3103
- ", "
3104
- )}
3105
- Update your input and try again.`
3048
+ let convertedByState = {};
3049
+ if (action !== "delete") {
3050
+ const conversionResults = await convertStyleBlocksToAtomic(styleBlocks);
3051
+ convertedByState = Object.fromEntries(
3052
+ Object.entries(conversionResults).map(([state, { props, customCss }]) => [
3053
+ state,
3054
+ { props, customCss: toStoredCustomCss(customCss) }
3055
+ ])
3106
3056
  );
3107
3057
  }
3108
- const Utils = window.elementorV2.editorVariables.Utils;
3109
- Object.values(propsWithStates).forEach((props) => {
3110
- Object.keys(props).forEach((key) => {
3111
- props[key] = Schema.adjustLlmPropValueSchema(props[key], {
3112
- transformers: Utils.globalVariablesLLMResolvers
3113
- });
3114
- });
3115
- });
3116
3058
  const breakpointValue = breakpoint ?? "desktop";
3117
3059
  let result = {
3118
3060
  status: "error",
@@ -3131,11 +3073,12 @@ Update your input and try again.`
3131
3073
  throw new Error("error deleting class");
3132
3074
  }
3133
3075
  let currentAction = action;
3134
- for await (const [state, props] of Object.entries(propsWithStates)) {
3076
+ for await (const [state, { props, customCss }] of Object.entries(convertedByState)) {
3135
3077
  switch (currentAction) {
3136
3078
  case "create":
3137
3079
  const newClassId = await attemptCreate({
3138
3080
  props,
3081
+ customCss,
3139
3082
  className: globalClassName,
3140
3083
  stylesProvider: globalClassesStylesProvider,
3141
3084
  breakpoint: breakpointValue,
@@ -3156,6 +3099,7 @@ Update your input and try again.`
3156
3099
  const updated = await attemptUpdate({
3157
3100
  classId,
3158
3101
  props,
3102
+ customCss,
3159
3103
  stylesProvider: globalClassesStylesProvider,
3160
3104
  breakpoint: breakpointValue,
3161
3105
  state
@@ -3184,28 +3128,25 @@ var initManageGlobalClasses = (reg) => {
3184
3128
  name: "manage-global-classes",
3185
3129
  requiredResources: [
3186
3130
  { uri: GLOBAL_CLASSES_URI, description: "Global classes list" },
3187
- { uri: STYLE_SCHEMA_FULL_URI, description: "Style schema resources" },
3188
3131
  { uri: BREAKPOINTS_SCHEMA_FULL_URI, description: "Breakpoints list" }
3189
3132
  ],
3190
3133
  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.
3191
3134
 
3192
- IMPORTANT: props must contain actual CSS property values \u2014 never pass empty objects.
3193
- Fetch ${STYLE_SCHEMA_FULL_URI} to get the allowed values for each property, then use them to build the props object.
3135
+ IMPORTANT: style must contain plaintext CSS rules per state \u2014 never pass empty strings.
3136
+ CSS is converted server-side in one bulk request; any declaration that cannot be converted is stored as the class custom CSS.
3194
3137
 
3195
3138
  Example \u2014 creating a flex column class:
3196
- props.default = {
3197
- "display": { "$$type": "string", "value": "flex" },
3198
- "flex-direction": { "$$type": "string", "value": "column" }
3199
- }
3139
+ style.default = "display: flex; flex-direction: column; gap: 1rem;"
3200
3140
 
3201
- The style schema returns a JSON Schema. Extract the "value" enum to pick the right value, then construct { "$$type": "string", "value": "<picked value>" }.`,
3141
+ Example \u2014 hover state:
3142
+ style.hover = "opacity: 0.85;"`,
3202
3143
  schema,
3203
3144
  outputSchema,
3204
3145
  handler
3205
3146
  });
3206
3147
  };
3207
3148
  async function attemptCreate(opts) {
3208
- const { props, breakpoint, className, stylesProvider, state } = opts;
3149
+ const { props, customCss, breakpoint, className, stylesProvider, state } = opts;
3209
3150
  const { create, delete: deleteClass2 } = stylesProvider.actions;
3210
3151
  if (!className) {
3211
3152
  throw new Error("Global class name is a required for creation");
@@ -3219,7 +3160,7 @@ async function attemptCreate(opts) {
3219
3160
  breakpoint,
3220
3161
  state: state === "default" ? null : state
3221
3162
  },
3222
- custom_css: null,
3163
+ custom_css: customCss,
3223
3164
  props
3224
3165
  }
3225
3166
  ]);
@@ -3232,7 +3173,7 @@ async function attemptCreate(opts) {
3232
3173
  }
3233
3174
  }
3234
3175
  async function attemptUpdate(opts) {
3235
- const { props, breakpoint, classId, stylesProvider, state } = opts;
3176
+ const { props, customCss, breakpoint, classId, stylesProvider, state } = opts;
3236
3177
  const { updateProps, update } = stylesProvider.actions;
3237
3178
  if (!classId) {
3238
3179
  throw new Error("Class ID is required for modification");
@@ -3246,6 +3187,7 @@ async function attemptUpdate(opts) {
3246
3187
  updateProps({
3247
3188
  id: classId,
3248
3189
  props,
3190
+ custom_css: customCss,
3249
3191
  meta: {
3250
3192
  breakpoint,
3251
3193
  state: state === "default" ? null : state
@@ -3282,6 +3224,21 @@ async function attemptDelete(opts) {
3282
3224
  await saveGlobalClasses2({ context: "frontend" });
3283
3225
  return true;
3284
3226
  }
3227
+ function collectNonEmptyStyleBlocks(style) {
3228
+ const blocks = {};
3229
+ Object.entries(style).forEach(([state, cssText]) => {
3230
+ if (cssText?.trim()) {
3231
+ blocks[state] = cssText.trim();
3232
+ }
3233
+ });
3234
+ return blocks;
3235
+ }
3236
+ function toStoredCustomCss(customCss) {
3237
+ if (!customCss?.trim()) {
3238
+ return null;
3239
+ }
3240
+ return { raw: btoa(customCss) };
3241
+ }
3285
3242
 
3286
3243
  // src/mcp-integration/index.ts
3287
3244
  var initMcpIntegration = (reg, canvasMcpEntry) => {