@elementor/editor-global-classes 3.35.0-493 → 4.0.0-495

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
@@ -2480,9 +2480,14 @@ var schema = {
2480
2480
  action: import_schema3.z.enum(["create", "modify", "delete"]).describe("Operation to perform"),
2481
2481
  classId: import_schema3.z.string().optional().describe("Global class ID (required for modify). Get from elementor://global-classes resource."),
2482
2482
  globalClassName: import_schema3.z.string().optional().describe("Global class name (required for create)"),
2483
- props: import_schema3.z.record(import_schema3.z.any()).describe(
2484
- 'key-value of style-schema PropValues. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
2485
- ),
2483
+ props: import_schema3.z.object({
2484
+ default: import_schema3.z.record(import_schema3.z.any()).describe(
2485
+ 'key-value of style-schema PropValues. Available properties at dynamic resource "elementor://styles/schema/{property-name}"'
2486
+ ),
2487
+ hover: import_schema3.z.record(import_schema3.z.any()).describe("key-value of style-schema PropValues, for :hover css state. optional").optional(),
2488
+ focus: import_schema3.z.record(import_schema3.z.any()).describe("key-value of style-schema PropValues, for :focus css state. optional").optional(),
2489
+ active: import_schema3.z.record(import_schema3.z.any()).describe("key-value of style-schema PropValues, for :active css state. optional").optional()
2490
+ }),
2486
2491
  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).")
2487
2492
  };
2488
2493
  var outputSchema = {
@@ -2491,7 +2496,9 @@ var outputSchema = {
2491
2496
  message: import_schema3.z.string().optional().describe("Error details if status is error")
2492
2497
  };
2493
2498
  var handler = async (input) => {
2494
- const { action, classId, globalClassName, props, breakpoint } = input;
2499
+ const { action, classId: rawClassId, globalClassName, props: rawProps, breakpoint } = input;
2500
+ const propsWithStates = rawProps;
2501
+ let classId = rawClassId;
2495
2502
  if (action === "create" && !globalClassName) {
2496
2503
  return {
2497
2504
  status: "error",
@@ -2520,18 +2527,20 @@ var handler = async (input) => {
2520
2527
  const errors = [];
2521
2528
  const stylesSchema = (0, import_editor_styles3.getStylesSchema)();
2522
2529
  const validProps = Object.keys(stylesSchema);
2523
- Object.keys(props).forEach((key) => {
2524
- const propType = stylesSchema[key];
2525
- if (!propType) {
2526
- errors.push(`Property "${key}" does not exist in styles schema.`);
2527
- return;
2528
- }
2529
- const { valid, jsonSchema } = import_editor_props.Schema.validatePropValue(propType, props[key]);
2530
- if (!valid) {
2531
- errors.push(`- Property "${key}" has invalid value
2530
+ Object.values(propsWithStates).forEach((props) => {
2531
+ Object.keys(props).forEach((key) => {
2532
+ const propType = stylesSchema[key];
2533
+ if (!propType) {
2534
+ errors.push(`Property "${key}" does not exist in styles schema.`);
2535
+ return;
2536
+ }
2537
+ const { valid, jsonSchema } = import_editor_props.Schema.validatePropValue(propType, props[key]);
2538
+ if (!valid) {
2539
+ errors.push(`- Property "${key}" has invalid value
2532
2540
  Expected schema: ${jsonSchema}
2533
2541
  `);
2534
- }
2542
+ }
2543
+ });
2535
2544
  });
2536
2545
  if (errors.length > 0) {
2537
2546
  return {
@@ -2545,48 +2554,69 @@ Update your input and try again.`
2545
2554
  };
2546
2555
  }
2547
2556
  const Utils = window.elementorV2.editorVariables.Utils;
2548
- Object.keys(props).forEach((key) => {
2549
- props[key] = import_editor_props.Schema.adjustLlmPropValueSchema(props[key], {
2550
- transformers: Utils.globalVariablesLLMResolvers
2557
+ Object.values(propsWithStates).forEach((props) => {
2558
+ Object.keys(props).forEach((key) => {
2559
+ props[key] = import_editor_props.Schema.adjustLlmPropValueSchema(props[key], {
2560
+ transformers: Utils.globalVariablesLLMResolvers
2561
+ });
2551
2562
  });
2552
2563
  });
2553
2564
  const breakpointValue = breakpoint ?? "desktop";
2565
+ let result = {
2566
+ status: "error",
2567
+ classId: "",
2568
+ message: "unknown error"
2569
+ };
2554
2570
  try {
2555
- switch (action) {
2556
- case "create":
2557
- const newClassId = await attemptCreate({
2558
- props,
2559
- className: globalClassName,
2560
- stylesProvider: globalClassesStylesProvider,
2561
- breakpoint: breakpointValue
2562
- });
2563
- return newClassId ? {
2564
- status: "ok",
2565
- message: `created global class with ID ${newClassId}`
2566
- } : {
2567
- status: "error",
2568
- message: "error creating class"
2569
- };
2570
- case "modify":
2571
- const updated = await attemptUpdate({
2572
- classId,
2573
- props,
2574
- stylesProvider: globalClassesStylesProvider,
2575
- breakpoint: breakpointValue
2576
- });
2577
- return updated ? { status: "ok", classId } : {
2578
- status: "error",
2579
- message: "error modifying class"
2580
- };
2581
- case "delete":
2582
- const deleted = await attemptDelete({
2583
- classId,
2584
- stylesProvider: globalClassesStylesProvider
2585
- });
2586
- return deleted ? { status: "ok", message: `deleted global class with ID ${classId}` } : {
2587
- status: "error",
2588
- message: "error deleting class"
2589
- };
2571
+ let currentAction = action;
2572
+ for await (const [state, props] of Object.entries(propsWithStates)) {
2573
+ switch (currentAction) {
2574
+ case "create":
2575
+ const newClassId = await attemptCreate({
2576
+ props,
2577
+ className: globalClassName,
2578
+ stylesProvider: globalClassesStylesProvider,
2579
+ breakpoint: breakpointValue,
2580
+ state
2581
+ });
2582
+ if (newClassId && currentAction === "create") {
2583
+ currentAction = "modify";
2584
+ classId = newClassId;
2585
+ }
2586
+ result = newClassId ? {
2587
+ status: "ok",
2588
+ message: `created global class with ID ${newClassId}`
2589
+ } : {
2590
+ status: "error",
2591
+ message: "error creating class"
2592
+ };
2593
+ break;
2594
+ case "modify":
2595
+ const updated = await attemptUpdate({
2596
+ classId,
2597
+ props,
2598
+ stylesProvider: globalClassesStylesProvider,
2599
+ breakpoint: breakpointValue,
2600
+ state
2601
+ });
2602
+ result = updated ? { status: "ok", classId } : {
2603
+ status: "error",
2604
+ message: "error modifying class"
2605
+ };
2606
+ break;
2607
+ case "delete":
2608
+ const deleted = await attemptDelete({
2609
+ classId,
2610
+ stylesProvider: globalClassesStylesProvider
2611
+ });
2612
+ result = deleted ? { status: "ok", message: `deleted global class with ID ${classId}` } : {
2613
+ status: "error",
2614
+ message: "error deleting class"
2615
+ };
2616
+ break;
2617
+ default:
2618
+ throw new Error(`Unsupported action ${action}`);
2619
+ }
2590
2620
  }
2591
2621
  } catch (error) {
2592
2622
  return {
@@ -2594,6 +2624,7 @@ Update your input and try again.`
2594
2624
  message: `${action} failed: ${error.message || "Unknown error"}`
2595
2625
  };
2596
2626
  }
2627
+ return result;
2597
2628
  };
2598
2629
  var initManageGlobalClasses = (reg) => {
2599
2630
  const { addTool } = reg;
@@ -2623,7 +2654,7 @@ Use style schema at [elementor://styles/schema/{category}] for valid props. Erro
2623
2654
  });
2624
2655
  };
2625
2656
  async function attemptCreate(opts) {
2626
- const { props, breakpoint, className, stylesProvider } = opts;
2657
+ const { props, breakpoint, className, stylesProvider, state } = opts;
2627
2658
  const { create, delete: deleteClass2 } = stylesProvider.actions;
2628
2659
  if (!className) {
2629
2660
  throw new Error("Global class name is a required for creation");
@@ -2635,7 +2666,7 @@ async function attemptCreate(opts) {
2635
2666
  {
2636
2667
  meta: {
2637
2668
  breakpoint,
2638
- state: null
2669
+ state: state === "default" ? null : state
2639
2670
  },
2640
2671
  custom_css: null,
2641
2672
  props
@@ -2650,7 +2681,7 @@ async function attemptCreate(opts) {
2650
2681
  }
2651
2682
  }
2652
2683
  async function attemptUpdate(opts) {
2653
- const { props, breakpoint, classId, stylesProvider } = opts;
2684
+ const { props, breakpoint, classId, stylesProvider, state } = opts;
2654
2685
  const { updateProps, update } = stylesProvider.actions;
2655
2686
  if (!classId) {
2656
2687
  throw new Error("Class ID is required for modification");
@@ -2665,7 +2696,7 @@ async function attemptUpdate(opts) {
2665
2696
  props,
2666
2697
  meta: {
2667
2698
  breakpoint,
2668
- state: null
2699
+ state
2669
2700
  }
2670
2701
  });
2671
2702
  await saveGlobalClasses({ context: "frontend" });