@elementor/editor-global-classes 4.1.0-837 → 4.1.0-beta1

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
@@ -836,10 +836,12 @@ function calculateChanges(state, initialData) {
836
836
  const initialDataIds = Object.keys(initialData.items);
837
837
  const { order: stateOrder } = state;
838
838
  const { order: initialDataOrder } = initialData;
839
+ const stateOrderIdSet = new Set(stateOrder);
840
+ const deleted = initialDataOrder.filter((id2) => !stateOrderIdSet.has(id2));
839
841
  const order = stateOrder.join(";") !== initialDataOrder.join(";");
840
842
  return {
841
843
  added: stateIds.filter((id2) => !initialDataIds.includes(id2)),
842
- deleted: initialDataIds.filter((id2) => !stateIds.includes(id2)),
844
+ deleted,
843
845
  modified: stateIds.filter((id2) => {
844
846
  return id2 in initialData.items && hash(state.items[id2]) !== hash(initialData.items[id2]);
845
847
  }),
@@ -2872,17 +2874,8 @@ import { __useDispatch as useDispatch2 } from "@elementor/store";
2872
2874
  function GlobalStylesImportListener() {
2873
2875
  const dispatch7 = useDispatch2();
2874
2876
  useEffect5(() => {
2875
- const handleGlobalStylesImported = (event) => {
2876
- const importedClasses = event.detail?.global_classes;
2877
- if (importedClasses?.items && importedClasses?.order) {
2878
- const { items } = importedClasses;
2879
- dispatch7(
2880
- slice.actions.mergeExistingClasses({
2881
- preview: items,
2882
- frontend: items
2883
- })
2884
- );
2885
- }
2877
+ const handleGlobalStylesImported = () => {
2878
+ loadCurrentDocumentClasses();
2886
2879
  };
2887
2880
  window.addEventListener(GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
2888
2881
  return () => {
@@ -2937,24 +2930,15 @@ function PopulateStore() {
2937
2930
  // src/mcp-integration/mcp-apply-unapply-global-classes.ts
2938
2931
  import { doApplyClasses, doGetAppliedClasses, doUnapplyClass } from "@elementor/editor-editing-panel";
2939
2932
  import { z } from "@elementor/schema";
2940
- function initMcpApplyUnapplyGlobalClasses(server) {
2941
- server.addTool({
2942
- schema: {
2943
- classId: z.string().describe("The ID of the class to apply"),
2944
- elementId: z.string().describe("The ID of the element to which the class will be applied")
2945
- },
2946
- outputSchema: {
2947
- result: z.string().describe("Result message indicating the success of the apply operation"),
2948
- llm_instructions: z.string().describe("Instructions what to do next, Important to follow these instructions!")
2949
- },
2950
- name: "apply-global-class",
2951
- modelPreferences: {
2952
- intelligencePriority: 0.7,
2953
- speedPriority: 0.8
2954
- },
2955
- description: `Apply a global class to an element, enabling consistent styling through your design system.
2956
2933
 
2957
- ## When to use this tool:
2934
+ // src/mcp-integration/apply-global-class-guide-prompt.ts
2935
+ import { toolPrompts } from "@elementor/editor-mcp";
2936
+ var APPLY_GLOBAL_CLASS_GUIDE_URI = "elementor://global-classes/tools/apply-global-class-guide";
2937
+ var generateApplyGlobalClassGuidePrompt = () => {
2938
+ const prompt = toolPrompts("apply-global-class");
2939
+ prompt.description("Apply a global class to an element, enabling consistent styling through your design system.");
2940
+ prompt.instruction(
2941
+ `## When to use this tool:
2958
2942
  **ALWAYS use this IMMEDIATELY AFTER building compositions** to apply the global classes you created beforehand:
2959
2943
  - After using "build-compositions" tool, apply semantic classes to the created elements
2960
2944
  - When applying consistent typography styles (heading-primary, text-body, etc.)
@@ -2963,18 +2947,59 @@ function initMcpApplyUnapplyGlobalClasses(server) {
2963
2947
 
2964
2948
  **DO NOT use this tool** for:
2965
2949
  - Elements that don't share styles with other elements (use inline styles instead)
2966
- - Layout-specific properties (those should remain inline in stylesConfig)
2967
-
2968
- ## Prerequisites:
2950
+ - Layout-specific properties (those should remain inline in stylesConfig)`
2951
+ );
2952
+ prompt.instruction(
2953
+ `## Prerequisites:
2969
2954
  - **REQUIRED**: Get the list of available global classes from 'elementor://global-classes' resource
2970
2955
  - **REQUIRED**: Get element IDs from the composition XML returned by "build-compositions" tool
2971
2956
  - Ensure you have the most up-to-date list of classes applied to the element to avoid duplicates
2972
- - Make sure you have the correct class ID that you want to apply
2973
-
2974
- ## Best Practices:
2957
+ - Make sure you have the correct class ID that you want to apply`
2958
+ );
2959
+ prompt.instruction(
2960
+ `## Best Practices:
2975
2961
  1. Apply multiple classes to a single element if needed (typography + color + spacing)
2976
2962
  2. After applying, the tool will remind you to remove duplicate inline styles from elementConfig
2977
- 3. Classes should describe purpose, not implementation (e.g., "heading-primary" not "big-red-text")`,
2963
+ 3. Classes should describe purpose, not implementation (e.g., "heading-primary" not "big-red-text")`
2964
+ );
2965
+ return prompt.prompt();
2966
+ };
2967
+
2968
+ // src/mcp-integration/mcp-apply-unapply-global-classes.ts
2969
+ function initMcpApplyUnapplyGlobalClasses(server) {
2970
+ const { addTool, resource } = server;
2971
+ const applyGlobalClassGuideText = generateApplyGlobalClassGuidePrompt();
2972
+ resource(
2973
+ "apply-global-class-guide",
2974
+ APPLY_GLOBAL_CLASS_GUIDE_URI,
2975
+ {
2976
+ description: "Workflow, prerequisites, and best practices for apply-global-class",
2977
+ mimeType: "text/plain",
2978
+ title: "Apply global class tool guide"
2979
+ },
2980
+ async (uri) => ({
2981
+ contents: [{ mimeType: "text/plain", text: applyGlobalClassGuideText, uri: uri.href }]
2982
+ })
2983
+ );
2984
+ addTool({
2985
+ schema: {
2986
+ classId: z.string().describe("The ID of the class to apply"),
2987
+ elementId: z.string().describe("The ID of the element to which the class will be applied")
2988
+ },
2989
+ outputSchema: {
2990
+ result: z.string().describe("Result message indicating the success of the apply operation"),
2991
+ llm_instructions: z.string().describe("Instructions what to do next, Important to follow these instructions!")
2992
+ },
2993
+ name: "apply-global-class",
2994
+ modelPreferences: {
2995
+ intelligencePriority: 0.7,
2996
+ speedPriority: 0.8
2997
+ },
2998
+ description: `Apply a global class to an element for shared design-system styling. Read the full guide at [${APPLY_GLOBAL_CLASS_GUIDE_URI}].`,
2999
+ requiredResources: [
3000
+ { description: "Apply global class tool guide", uri: APPLY_GLOBAL_CLASS_GUIDE_URI },
3001
+ { description: "Global classes list", uri: GLOBAL_CLASSES_URI }
3002
+ ],
2978
3003
  handler: async (params) => {
2979
3004
  const { classId, elementId } = params;
2980
3005
  const appliedClasses = doGetAppliedClasses(elementId);
@@ -2985,7 +3010,7 @@ function initMcpApplyUnapplyGlobalClasses(server) {
2985
3010
  };
2986
3011
  }
2987
3012
  });
2988
- server.addTool({
3013
+ addTool({
2989
3014
  name: "unapply-global-class",
2990
3015
  schema: {
2991
3016
  classId: z.string().describe("The ID of the class to unapply"),
@@ -2998,21 +3023,8 @@ function initMcpApplyUnapplyGlobalClasses(server) {
2998
3023
  intelligencePriority: 0.7,
2999
3024
  speedPriority: 0.8
3000
3025
  },
3001
- description: `Unapply a (global) class from the current element
3002
-
3003
- ## When to use this tool:
3004
- - When a user requests to unapply a global class or a class from an element in the Elementor editor.
3005
- - When you need to remove a specific class from an element's applied classes.
3006
-
3007
- ## Prerequisites:
3008
- - Ensure you have the most up-to-date list of classes applied to the element to avoid errors.
3009
- The list is available at always up-to-date resource 'elementor://global-classes'.
3010
- - Make sure you have the correct class ID that you want to unapply.
3011
-
3012
- <note>
3013
- If the user want to unapply a class by it's name and not ID, retrieve the id from the list, available at uri elementor://global-classes
3014
- </note>
3015
- `,
3026
+ description: `Unapply a global class from an element by class ID. Resolve class names to IDs via [${GLOBAL_CLASSES_URI}].`,
3027
+ requiredResources: [{ description: "Global classes list", uri: GLOBAL_CLASSES_URI }],
3016
3028
  handler: async (params) => {
3017
3029
  const { classId, elementId } = params;
3018
3030
  const ok = doUnapplyClass(elementId, classId);
@@ -3053,19 +3065,15 @@ function initMcpApplyGetGlobalClassUsages(reg) {
3053
3065
  intelligencePriority: 0.6,
3054
3066
  speedPriority: 0.8
3055
3067
  },
3056
- description: `Retrieve the usages of global-classes ACROSS PAGES designed by Elementor editor.
3057
-
3058
- ## Prerequisites: CRITICAL
3059
- - The list of global classes and their applid values is available at resource uri elementor://global-classes
3068
+ description: `Retrieve usages of global classes across all Elementor pages. Heavy operation \u2014 scans every page in the site.
3060
3069
 
3061
- ## When to use this tool:
3062
- - When a user requests to see where a specific global class is being used across the site.
3063
- - When you need to manage or clean up unused global classes.
3064
- - Before deleting a global class, to ensure it is not in use in any other pages.
3070
+ ## When to use:
3071
+ - Before deleting or radically changing a class \u2014 to understand cross-page side effects and decide whether to consult the user.
3072
+ - To identify unused global classes for cleanup.
3065
3073
 
3066
- ## When NOT to use this tool:
3067
- - For getting the list of global classes, refer to the resource at uri elementor://global-classes
3068
- `,
3074
+ ## When NOT to use:
3075
+ - To list global classes themselves \u2014 use the global-classes resource instead (this tool returns usages, not the class list).`,
3076
+ requiredResources: [{ description: "Global classes list", uri: GLOBAL_CLASSES_URI }],
3069
3077
  outputSchema: globalClassesUsageSchema,
3070
3078
  handler: async () => {
3071
3079
  const data = await fetchCssClassUsage();
@@ -3265,15 +3273,7 @@ var initManageGlobalClasses = (reg) => {
3265
3273
  intelligencePriority: 0.85,
3266
3274
  speedPriority: 0.6
3267
3275
  },
3268
- description: `Manages global classes (create/modify) in Elementor editor. Check [elementor://global-classes] and style schemas first.
3269
-
3270
- 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.
3271
- MODIFY: Requires classId, props. Get classId from [elementor://global-classes] resource.
3272
-
3273
- Naming pattern: [element-type]-[purpose/variant]-[modifier]
3274
- DO NOT create global classes for: one-off styles, layout-specific properties.
3275
-
3276
- Use style schema at [elementor://styles/schema/{category}] for valid props. Errors include exact schema mismatch details.`,
3276
+ 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 compositions. Do NOT create classes for one-off styles or layout-specific properties.`,
3277
3277
  schema,
3278
3278
  outputSchema,
3279
3279
  handler
@@ -3363,16 +3363,6 @@ async function attemptDelete(opts) {
3363
3363
 
3364
3364
  // src/mcp-integration/index.ts
3365
3365
  var initMcpIntegration = (reg, canvasMcpEntry) => {
3366
- const { setMCPDescription } = reg;
3367
- setMCPDescription(
3368
- `Everything related to V4 ( Atomic ) global classes.
3369
- # Global classes
3370
- - Create/update/delete global classes
3371
- - Get list of global classes
3372
- - Get details of a global class
3373
- - Get details of a global class
3374
- `
3375
- );
3376
3366
  initMcpApplyUnapplyGlobalClasses(reg);
3377
3367
  initMcpApplyGetGlobalClassUsages(reg);
3378
3368
  initManageGlobalClasses(reg);
@@ -3499,7 +3489,15 @@ function init() {
3499
3489
  getThemeColor: (theme) => theme.palette.global.dark
3500
3490
  });
3501
3491
  initMcpIntegration(
3502
- getMCPByDomain("classes", { instructions: "MCP server for management of Elementor global classes" }),
3492
+ getMCPByDomain("classes", {
3493
+ instructions: "MCP server for management of Elementor global classes",
3494
+ docs: `Everything related to V4 ( Atomic ) global classes.
3495
+ # Global classes
3496
+ - Create/update/delete global classes
3497
+ - Get list of global classes
3498
+ - Get details of a global class
3499
+ `
3500
+ }),
3503
3501
  getMCPByDomain("canvas")
3504
3502
  );
3505
3503
  }