@elementor/editor-global-classes 4.1.0-687 → 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.js +101 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
- package/src/components/global-styles-import-listener.tsx +61 -0
- package/src/init.ts +6 -0
- package/src/sync-with-document-save.ts +40 -11
package/dist/index.js
CHANGED
|
@@ -564,7 +564,7 @@ var import_editor = require("@elementor/editor");
|
|
|
564
564
|
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
565
565
|
var import_editor_panels2 = require("@elementor/editor-panels");
|
|
566
566
|
var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
|
|
567
|
-
var
|
|
567
|
+
var import_store28 = require("@elementor/store");
|
|
568
568
|
|
|
569
569
|
// src/components/class-manager/class-manager-button.tsx
|
|
570
570
|
var React20 = __toESM(require("react"));
|
|
@@ -2418,16 +2418,67 @@ function createClassName(prefix) {
|
|
|
2418
2418
|
return newClassName;
|
|
2419
2419
|
}
|
|
2420
2420
|
|
|
2421
|
-
// src/components/
|
|
2421
|
+
// src/components/global-styles-import-listener.tsx
|
|
2422
2422
|
var import_react10 = require("react");
|
|
2423
|
+
var import_store22 = require("@elementor/store");
|
|
2424
|
+
function GlobalStylesImportListener() {
|
|
2425
|
+
const dispatch5 = (0, import_store22.__useDispatch)();
|
|
2426
|
+
(0, import_react10.useEffect)(() => {
|
|
2427
|
+
const handleGlobalStylesImported = (event) => {
|
|
2428
|
+
const importedClasses = event.detail?.global_classes;
|
|
2429
|
+
if (importedClasses?.items && importedClasses?.order) {
|
|
2430
|
+
dispatch5(
|
|
2431
|
+
slice.actions.load({
|
|
2432
|
+
preview: {
|
|
2433
|
+
items: importedClasses.items,
|
|
2434
|
+
order: importedClasses.order
|
|
2435
|
+
},
|
|
2436
|
+
frontend: {
|
|
2437
|
+
items: importedClasses.items,
|
|
2438
|
+
order: importedClasses.order
|
|
2439
|
+
}
|
|
2440
|
+
})
|
|
2441
|
+
);
|
|
2442
|
+
}
|
|
2443
|
+
Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(([previewRes, frontendRes]) => {
|
|
2444
|
+
const { data: previewData } = previewRes;
|
|
2445
|
+
const { data: frontendData } = frontendRes;
|
|
2446
|
+
dispatch5(
|
|
2447
|
+
slice.actions.load({
|
|
2448
|
+
preview: {
|
|
2449
|
+
items: previewData.data,
|
|
2450
|
+
order: previewData.meta.order
|
|
2451
|
+
},
|
|
2452
|
+
frontend: {
|
|
2453
|
+
items: frontendData.data,
|
|
2454
|
+
order: frontendData.meta.order
|
|
2455
|
+
}
|
|
2456
|
+
})
|
|
2457
|
+
);
|
|
2458
|
+
}).catch(() => {
|
|
2459
|
+
});
|
|
2460
|
+
};
|
|
2461
|
+
window.addEventListener("elementor/global-styles/imported", handleGlobalStylesImported);
|
|
2462
|
+
return () => {
|
|
2463
|
+
window.removeEventListener(
|
|
2464
|
+
"elementor/global-styles/imported",
|
|
2465
|
+
handleGlobalStylesImported
|
|
2466
|
+
);
|
|
2467
|
+
};
|
|
2468
|
+
}, [dispatch5]);
|
|
2469
|
+
return null;
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
// src/components/open-panel-from-url.tsx
|
|
2473
|
+
var import_react11 = require("react");
|
|
2423
2474
|
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
2424
2475
|
var ACTIVE_PANEL_PARAM = "active-panel";
|
|
2425
2476
|
var PANEL_ID = "global-classes-manager";
|
|
2426
2477
|
var DEFAULT_PANEL_ROUTE = "panel/elements";
|
|
2427
2478
|
function OpenPanelFromUrl() {
|
|
2428
2479
|
const { open } = usePanelActions();
|
|
2429
|
-
const hasOpened = (0,
|
|
2430
|
-
(0,
|
|
2480
|
+
const hasOpened = (0, import_react11.useRef)(false);
|
|
2481
|
+
(0, import_react11.useEffect)(() => {
|
|
2431
2482
|
const urlParams = new URLSearchParams(window.location.search);
|
|
2432
2483
|
const activePanel = urlParams.get(ACTIVE_PANEL_PARAM);
|
|
2433
2484
|
if (activePanel !== PANEL_ID) {
|
|
@@ -2448,11 +2499,11 @@ function OpenPanelFromUrl() {
|
|
|
2448
2499
|
}
|
|
2449
2500
|
|
|
2450
2501
|
// src/components/populate-store.tsx
|
|
2451
|
-
var
|
|
2452
|
-
var
|
|
2502
|
+
var import_react12 = require("react");
|
|
2503
|
+
var import_store24 = require("@elementor/store");
|
|
2453
2504
|
function PopulateStore() {
|
|
2454
|
-
const dispatch5 = (0,
|
|
2455
|
-
(0,
|
|
2505
|
+
const dispatch5 = (0, import_store24.__useDispatch)();
|
|
2506
|
+
(0, import_react12.useEffect)(() => {
|
|
2456
2507
|
Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(
|
|
2457
2508
|
([previewRes, frontendRes]) => {
|
|
2458
2509
|
const { data: previewData } = previewRes;
|
|
@@ -2917,49 +2968,72 @@ var initMcpIntegration = () => {
|
|
|
2917
2968
|
};
|
|
2918
2969
|
|
|
2919
2970
|
// src/sync-with-document.tsx
|
|
2920
|
-
var
|
|
2971
|
+
var import_react13 = require("react");
|
|
2921
2972
|
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
2922
2973
|
|
|
2923
2974
|
// src/sync-with-document-save.ts
|
|
2924
2975
|
var import_editor_current_user3 = require("@elementor/editor-current-user");
|
|
2925
2976
|
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
2926
2977
|
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
2927
|
-
var
|
|
2978
|
+
var import_store26 = require("@elementor/store");
|
|
2979
|
+
var pendingSave = null;
|
|
2928
2980
|
function syncWithDocumentSave(panelActions) {
|
|
2929
2981
|
const unsubscribe = syncDirtyState();
|
|
2930
2982
|
bindSaveAction(panelActions);
|
|
2983
|
+
bindBeforeSaveTemplateAction();
|
|
2931
2984
|
return unsubscribe;
|
|
2932
2985
|
}
|
|
2933
2986
|
function syncDirtyState() {
|
|
2934
|
-
return (0,
|
|
2987
|
+
return (0, import_store26.__subscribeWithSelector)(selectIsDirty, () => {
|
|
2935
2988
|
if (!isDirty()) {
|
|
2936
2989
|
return;
|
|
2937
2990
|
}
|
|
2938
2991
|
(0, import_editor_documents5.setDocumentModifiedStatus)(true);
|
|
2939
2992
|
});
|
|
2940
2993
|
}
|
|
2994
|
+
function triggerSave(panelActions, context2 = "preview") {
|
|
2995
|
+
const user = (0, import_editor_current_user3.getCurrentUser)();
|
|
2996
|
+
const canEdit = user?.capabilities.includes(UPDATE_CLASS_CAPABILITY_KEY);
|
|
2997
|
+
if (!canEdit) {
|
|
2998
|
+
return null;
|
|
2999
|
+
}
|
|
3000
|
+
if (pendingSave) {
|
|
3001
|
+
return pendingSave;
|
|
3002
|
+
}
|
|
3003
|
+
const promise = saveGlobalClasses({
|
|
3004
|
+
context: context2,
|
|
3005
|
+
onApprove: panelActions?.open
|
|
3006
|
+
});
|
|
3007
|
+
pendingSave = promise;
|
|
3008
|
+
promise.finally(() => {
|
|
3009
|
+
pendingSave = null;
|
|
3010
|
+
});
|
|
3011
|
+
return promise;
|
|
3012
|
+
}
|
|
2941
3013
|
function bindSaveAction(panelActions) {
|
|
2942
3014
|
(0, import_editor_v1_adapters5.registerDataHook)("dependency", "document/save/save", (args) => {
|
|
2943
|
-
|
|
2944
|
-
const canEdit = user?.capabilities.includes(UPDATE_CLASS_CAPABILITY_KEY);
|
|
2945
|
-
if (!canEdit) {
|
|
2946
|
-
return true;
|
|
2947
|
-
}
|
|
2948
|
-
saveGlobalClasses({
|
|
2949
|
-
context: args.status === "publish" ? "frontend" : "preview",
|
|
2950
|
-
onApprove: panelActions?.open
|
|
2951
|
-
});
|
|
3015
|
+
triggerSave(panelActions, args.status === "publish" ? "frontend" : "preview");
|
|
2952
3016
|
return true;
|
|
2953
3017
|
});
|
|
2954
3018
|
}
|
|
3019
|
+
function bindBeforeSaveTemplateAction() {
|
|
3020
|
+
window.addEventListener("elementor/global-styles/before-save", ((event) => {
|
|
3021
|
+
if (!pendingSave && isDirty()) {
|
|
3022
|
+
triggerSave();
|
|
3023
|
+
}
|
|
3024
|
+
if (pendingSave) {
|
|
3025
|
+
event.detail.promises.push(pendingSave);
|
|
3026
|
+
}
|
|
3027
|
+
}));
|
|
3028
|
+
}
|
|
2955
3029
|
function isDirty() {
|
|
2956
|
-
return selectIsDirty((0,
|
|
3030
|
+
return selectIsDirty((0, import_store26.__getState)());
|
|
2957
3031
|
}
|
|
2958
3032
|
|
|
2959
3033
|
// src/sync-with-document.tsx
|
|
2960
3034
|
function SyncWithDocumentSave() {
|
|
2961
3035
|
const panelActions = usePanelActions();
|
|
2962
|
-
(0,
|
|
3036
|
+
(0, import_react13.useEffect)(() => {
|
|
2963
3037
|
(0, import_editor_v1_adapters6.__privateListenTo)((0, import_editor_v1_adapters6.v1ReadyEvent)(), () => {
|
|
2964
3038
|
syncWithDocumentSave(panelActions);
|
|
2965
3039
|
});
|
|
@@ -2969,7 +3043,7 @@ function SyncWithDocumentSave() {
|
|
|
2969
3043
|
|
|
2970
3044
|
// src/init.ts
|
|
2971
3045
|
function init() {
|
|
2972
|
-
(0,
|
|
3046
|
+
(0, import_store28.__registerSlice)(slice);
|
|
2973
3047
|
(0, import_editor_panels2.__registerPanel)(panel);
|
|
2974
3048
|
import_editor_styles_repository5.stylesRepository.register(globalClassesStylesProvider);
|
|
2975
3049
|
(0, import_editor.injectIntoLogic)({
|
|
@@ -2980,6 +3054,10 @@ function init() {
|
|
|
2980
3054
|
id: "global-classes-sync-with-document",
|
|
2981
3055
|
component: SyncWithDocumentSave
|
|
2982
3056
|
});
|
|
3057
|
+
(0, import_editor.injectIntoLogic)({
|
|
3058
|
+
id: "global-classes-import-listener",
|
|
3059
|
+
component: GlobalStylesImportListener
|
|
3060
|
+
});
|
|
2983
3061
|
(0, import_editor.injectIntoLogic)({
|
|
2984
3062
|
id: "global-classes-prefetch-css-class-usage",
|
|
2985
3063
|
component: PrefetchCssClassUsage
|