@elementor/editor-global-classes 4.1.0-686 → 4.1.0-688

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
@@ -2474,8 +2474,59 @@ function createClassName(prefix) {
2474
2474
  return newClassName;
2475
2475
  }
2476
2476
 
2477
+ // src/components/global-styles-import-listener.tsx
2478
+ import { useEffect as useEffect4 } from "react";
2479
+ import { __useDispatch as useDispatch2 } from "@elementor/store";
2480
+ function GlobalStylesImportListener() {
2481
+ const dispatch5 = useDispatch2();
2482
+ useEffect4(() => {
2483
+ const handleGlobalStylesImported = (event) => {
2484
+ const importedClasses = event.detail?.global_classes;
2485
+ if (importedClasses?.items && importedClasses?.order) {
2486
+ dispatch5(
2487
+ slice.actions.load({
2488
+ preview: {
2489
+ items: importedClasses.items,
2490
+ order: importedClasses.order
2491
+ },
2492
+ frontend: {
2493
+ items: importedClasses.items,
2494
+ order: importedClasses.order
2495
+ }
2496
+ })
2497
+ );
2498
+ }
2499
+ Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(([previewRes, frontendRes]) => {
2500
+ const { data: previewData } = previewRes;
2501
+ const { data: frontendData } = frontendRes;
2502
+ dispatch5(
2503
+ slice.actions.load({
2504
+ preview: {
2505
+ items: previewData.data,
2506
+ order: previewData.meta.order
2507
+ },
2508
+ frontend: {
2509
+ items: frontendData.data,
2510
+ order: frontendData.meta.order
2511
+ }
2512
+ })
2513
+ );
2514
+ }).catch(() => {
2515
+ });
2516
+ };
2517
+ window.addEventListener("elementor/global-styles/imported", handleGlobalStylesImported);
2518
+ return () => {
2519
+ window.removeEventListener(
2520
+ "elementor/global-styles/imported",
2521
+ handleGlobalStylesImported
2522
+ );
2523
+ };
2524
+ }, [dispatch5]);
2525
+ return null;
2526
+ }
2527
+
2477
2528
  // src/components/open-panel-from-url.tsx
2478
- import { useEffect as useEffect4, useRef as useRef2 } from "react";
2529
+ import { useEffect as useEffect5, useRef as useRef2 } from "react";
2479
2530
  import { __privateListenTo as listenTo, routeOpenEvent } from "@elementor/editor-v1-adapters";
2480
2531
  var ACTIVE_PANEL_PARAM = "active-panel";
2481
2532
  var PANEL_ID = "global-classes-manager";
@@ -2483,7 +2534,7 @@ var DEFAULT_PANEL_ROUTE = "panel/elements";
2483
2534
  function OpenPanelFromUrl() {
2484
2535
  const { open } = usePanelActions();
2485
2536
  const hasOpened = useRef2(false);
2486
- useEffect4(() => {
2537
+ useEffect5(() => {
2487
2538
  const urlParams = new URLSearchParams(window.location.search);
2488
2539
  const activePanel = urlParams.get(ACTIVE_PANEL_PARAM);
2489
2540
  if (activePanel !== PANEL_ID) {
@@ -2504,11 +2555,11 @@ function OpenPanelFromUrl() {
2504
2555
  }
2505
2556
 
2506
2557
  // src/components/populate-store.tsx
2507
- import { useEffect as useEffect5 } from "react";
2508
- import { __useDispatch as useDispatch2 } from "@elementor/store";
2558
+ import { useEffect as useEffect6 } from "react";
2559
+ import { __useDispatch as useDispatch3 } from "@elementor/store";
2509
2560
  function PopulateStore() {
2510
- const dispatch5 = useDispatch2();
2511
- useEffect5(() => {
2561
+ const dispatch5 = useDispatch3();
2562
+ useEffect6(() => {
2512
2563
  Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(
2513
2564
  ([previewRes, frontendRes]) => {
2514
2565
  const { data: previewData } = previewRes;
@@ -2973,7 +3024,7 @@ var initMcpIntegration = () => {
2973
3024
  };
2974
3025
 
2975
3026
  // src/sync-with-document.tsx
2976
- import { useEffect as useEffect6 } from "react";
3027
+ import { useEffect as useEffect7 } from "react";
2977
3028
  import { __privateListenTo as listenTo2, v1ReadyEvent } from "@elementor/editor-v1-adapters";
2978
3029
 
2979
3030
  // src/sync-with-document-save.ts
@@ -2981,9 +3032,11 @@ import { getCurrentUser } from "@elementor/editor-current-user";
2981
3032
  import { setDocumentModifiedStatus as setDocumentModifiedStatus2 } from "@elementor/editor-documents";
2982
3033
  import { registerDataHook } from "@elementor/editor-v1-adapters";
2983
3034
  import { __getState as getState4, __subscribeWithSelector as subscribeWithSelector2 } from "@elementor/store";
3035
+ var pendingSave = null;
2984
3036
  function syncWithDocumentSave(panelActions) {
2985
3037
  const unsubscribe = syncDirtyState();
2986
3038
  bindSaveAction(panelActions);
3039
+ bindBeforeSaveTemplateAction();
2987
3040
  return unsubscribe;
2988
3041
  }
2989
3042
  function syncDirtyState() {
@@ -2994,20 +3047,41 @@ function syncDirtyState() {
2994
3047
  setDocumentModifiedStatus2(true);
2995
3048
  });
2996
3049
  }
3050
+ function triggerSave(panelActions, context2 = "preview") {
3051
+ const user = getCurrentUser();
3052
+ const canEdit = user?.capabilities.includes(UPDATE_CLASS_CAPABILITY_KEY);
3053
+ if (!canEdit) {
3054
+ return null;
3055
+ }
3056
+ if (pendingSave) {
3057
+ return pendingSave;
3058
+ }
3059
+ const promise = saveGlobalClasses({
3060
+ context: context2,
3061
+ onApprove: panelActions?.open
3062
+ });
3063
+ pendingSave = promise;
3064
+ promise.finally(() => {
3065
+ pendingSave = null;
3066
+ });
3067
+ return promise;
3068
+ }
2997
3069
  function bindSaveAction(panelActions) {
2998
3070
  registerDataHook("dependency", "document/save/save", (args) => {
2999
- const user = getCurrentUser();
3000
- const canEdit = user?.capabilities.includes(UPDATE_CLASS_CAPABILITY_KEY);
3001
- if (!canEdit) {
3002
- return true;
3003
- }
3004
- saveGlobalClasses({
3005
- context: args.status === "publish" ? "frontend" : "preview",
3006
- onApprove: panelActions?.open
3007
- });
3071
+ triggerSave(panelActions, args.status === "publish" ? "frontend" : "preview");
3008
3072
  return true;
3009
3073
  });
3010
3074
  }
3075
+ function bindBeforeSaveTemplateAction() {
3076
+ window.addEventListener("elementor/global-styles/before-save", ((event) => {
3077
+ if (!pendingSave && isDirty()) {
3078
+ triggerSave();
3079
+ }
3080
+ if (pendingSave) {
3081
+ event.detail.promises.push(pendingSave);
3082
+ }
3083
+ }));
3084
+ }
3011
3085
  function isDirty() {
3012
3086
  return selectIsDirty(getState4());
3013
3087
  }
@@ -3015,7 +3089,7 @@ function isDirty() {
3015
3089
  // src/sync-with-document.tsx
3016
3090
  function SyncWithDocumentSave() {
3017
3091
  const panelActions = usePanelActions();
3018
- useEffect6(() => {
3092
+ useEffect7(() => {
3019
3093
  listenTo2(v1ReadyEvent(), () => {
3020
3094
  syncWithDocumentSave(panelActions);
3021
3095
  });
@@ -3036,6 +3110,10 @@ function init() {
3036
3110
  id: "global-classes-sync-with-document",
3037
3111
  component: SyncWithDocumentSave
3038
3112
  });
3113
+ injectIntoLogic({
3114
+ id: "global-classes-import-listener",
3115
+ component: GlobalStylesImportListener
3116
+ });
3039
3117
  injectIntoLogic({
3040
3118
  id: "global-classes-prefetch-css-class-usage",
3041
3119
  component: PrefetchCssClassUsage