@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.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-global-classes",
|
|
3
|
-
"version": "4.1.0-
|
|
3
|
+
"version": "4.1.0-688",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,28 +39,28 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "4.1.0-
|
|
43
|
-
"@elementor/editor-current-user": "4.1.0-
|
|
44
|
-
"@elementor/editor-documents": "4.1.0-
|
|
45
|
-
"@elementor/editor-editing-panel": "4.1.0-
|
|
46
|
-
"@elementor/editor-mcp": "4.1.0-
|
|
47
|
-
"@elementor/editor-panels": "4.1.0-
|
|
48
|
-
"@elementor/editor-props": "4.1.0-
|
|
49
|
-
"@elementor/editor-variables": "4.1.0-
|
|
50
|
-
"@elementor/editor-styles": "4.1.0-
|
|
51
|
-
"@elementor/editor-canvas": "4.1.0-
|
|
52
|
-
"@elementor/editor-styles-repository": "4.1.0-
|
|
53
|
-
"@elementor/editor-ui": "4.1.0-
|
|
54
|
-
"@elementor/editor-v1-adapters": "4.1.0-
|
|
55
|
-
"@elementor/http-client": "4.1.0-
|
|
42
|
+
"@elementor/editor": "4.1.0-688",
|
|
43
|
+
"@elementor/editor-current-user": "4.1.0-688",
|
|
44
|
+
"@elementor/editor-documents": "4.1.0-688",
|
|
45
|
+
"@elementor/editor-editing-panel": "4.1.0-688",
|
|
46
|
+
"@elementor/editor-mcp": "4.1.0-688",
|
|
47
|
+
"@elementor/editor-panels": "4.1.0-688",
|
|
48
|
+
"@elementor/editor-props": "4.1.0-688",
|
|
49
|
+
"@elementor/editor-variables": "4.1.0-688",
|
|
50
|
+
"@elementor/editor-styles": "4.1.0-688",
|
|
51
|
+
"@elementor/editor-canvas": "4.1.0-688",
|
|
52
|
+
"@elementor/editor-styles-repository": "4.1.0-688",
|
|
53
|
+
"@elementor/editor-ui": "4.1.0-688",
|
|
54
|
+
"@elementor/editor-v1-adapters": "4.1.0-688",
|
|
55
|
+
"@elementor/http-client": "4.1.0-688",
|
|
56
56
|
"@elementor/icons": "^1.68.0",
|
|
57
|
-
"@elementor/query": "4.1.0-
|
|
58
|
-
"@elementor/schema": "4.1.0-
|
|
59
|
-
"@elementor/store": "4.1.0-
|
|
57
|
+
"@elementor/query": "4.1.0-688",
|
|
58
|
+
"@elementor/schema": "4.1.0-688",
|
|
59
|
+
"@elementor/store": "4.1.0-688",
|
|
60
60
|
"@elementor/ui": "1.36.17",
|
|
61
|
-
"@elementor/utils": "4.1.0-
|
|
61
|
+
"@elementor/utils": "4.1.0-688",
|
|
62
62
|
"@wordpress/i18n": "^5.13.0",
|
|
63
|
-
"@elementor/events": "4.1.0-
|
|
63
|
+
"@elementor/events": "4.1.0-688"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"react": "^18.3.1",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { __useDispatch as useDispatch } from '@elementor/store';
|
|
3
|
+
|
|
4
|
+
import { apiClient } from '../api';
|
|
5
|
+
import { slice } from '../store';
|
|
6
|
+
|
|
7
|
+
export function GlobalStylesImportListener() {
|
|
8
|
+
const dispatch = useDispatch();
|
|
9
|
+
|
|
10
|
+
useEffect( () => {
|
|
11
|
+
const handleGlobalStylesImported = ( event: CustomEvent ) => {
|
|
12
|
+
const importedClasses = event.detail?.global_classes;
|
|
13
|
+
|
|
14
|
+
if ( importedClasses?.items && importedClasses?.order ) {
|
|
15
|
+
dispatch(
|
|
16
|
+
slice.actions.load( {
|
|
17
|
+
preview: {
|
|
18
|
+
items: importedClasses.items,
|
|
19
|
+
order: importedClasses.order,
|
|
20
|
+
},
|
|
21
|
+
frontend: {
|
|
22
|
+
items: importedClasses.items,
|
|
23
|
+
order: importedClasses.order,
|
|
24
|
+
},
|
|
25
|
+
} )
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Promise.all( [ apiClient.all( 'preview' ), apiClient.all( 'frontend' ) ] )
|
|
30
|
+
.then( ( [ previewRes, frontendRes ] ) => {
|
|
31
|
+
const { data: previewData } = previewRes;
|
|
32
|
+
const { data: frontendData } = frontendRes;
|
|
33
|
+
|
|
34
|
+
dispatch(
|
|
35
|
+
slice.actions.load( {
|
|
36
|
+
preview: {
|
|
37
|
+
items: previewData.data,
|
|
38
|
+
order: previewData.meta.order,
|
|
39
|
+
},
|
|
40
|
+
frontend: {
|
|
41
|
+
items: frontendData.data,
|
|
42
|
+
order: frontendData.meta.order,
|
|
43
|
+
},
|
|
44
|
+
} )
|
|
45
|
+
);
|
|
46
|
+
} )
|
|
47
|
+
.catch( () => {} );
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
window.addEventListener( 'elementor/global-styles/imported', handleGlobalStylesImported as EventListener );
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
window.removeEventListener(
|
|
54
|
+
'elementor/global-styles/imported',
|
|
55
|
+
handleGlobalStylesImported as EventListener
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
}, [ dispatch ] );
|
|
59
|
+
|
|
60
|
+
return null;
|
|
61
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { __registerSlice as registerSlice } from '@elementor/store';
|
|
|
11
11
|
import { ClassManagerButton } from './components/class-manager/class-manager-button';
|
|
12
12
|
import { panel } from './components/class-manager/class-manager-panel';
|
|
13
13
|
import { ConvertLocalClassToGlobalClass } from './components/convert-local-class-to-global-class';
|
|
14
|
+
import { GlobalStylesImportListener } from './components/global-styles-import-listener';
|
|
14
15
|
import { OpenPanelFromUrl } from './components/open-panel-from-url';
|
|
15
16
|
import { PopulateStore } from './components/populate-store';
|
|
16
17
|
import { GLOBAL_CLASSES_PROVIDER_KEY, globalClassesStylesProvider } from './global-classes-styles-provider';
|
|
@@ -35,6 +36,11 @@ export function init() {
|
|
|
35
36
|
component: SyncWithDocumentSave,
|
|
36
37
|
} );
|
|
37
38
|
|
|
39
|
+
injectIntoLogic( {
|
|
40
|
+
id: 'global-classes-import-listener',
|
|
41
|
+
component: GlobalStylesImportListener,
|
|
42
|
+
} );
|
|
43
|
+
|
|
38
44
|
injectIntoLogic( {
|
|
39
45
|
id: 'global-classes-prefetch-css-class-usage',
|
|
40
46
|
component: PrefetchCssClassUsage,
|
|
@@ -7,10 +7,13 @@ import { UPDATE_CLASS_CAPABILITY_KEY } from './capabilities';
|
|
|
7
7
|
import { saveGlobalClasses } from './save-global-classes';
|
|
8
8
|
import { selectIsDirty } from './store';
|
|
9
9
|
|
|
10
|
+
let pendingSave: Promise< void > | null = null;
|
|
11
|
+
|
|
10
12
|
export function syncWithDocumentSave( panelActions?: { open: () => void } ) {
|
|
11
13
|
const unsubscribe = syncDirtyState();
|
|
12
14
|
|
|
13
15
|
bindSaveAction( panelActions );
|
|
16
|
+
bindBeforeSaveTemplateAction();
|
|
14
17
|
|
|
15
18
|
return unsubscribe;
|
|
16
19
|
}
|
|
@@ -25,25 +28,51 @@ function syncDirtyState() {
|
|
|
25
28
|
} );
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
function triggerSave( panelActions?: { open: () => void }, context: 'preview' | 'frontend' = 'preview' ) {
|
|
32
|
+
const user = getCurrentUser();
|
|
33
|
+
const canEdit = user?.capabilities.includes( UPDATE_CLASS_CAPABILITY_KEY );
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
if ( ! canEdit ) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
33
38
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
if ( pendingSave ) {
|
|
40
|
+
return pendingSave;
|
|
41
|
+
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
const promise = saveGlobalClasses( {
|
|
44
|
+
context,
|
|
45
|
+
onApprove: panelActions?.open,
|
|
46
|
+
} );
|
|
47
|
+
|
|
48
|
+
pendingSave = promise;
|
|
49
|
+
promise.finally( () => {
|
|
50
|
+
pendingSave = null;
|
|
51
|
+
} );
|
|
52
|
+
|
|
53
|
+
return promise;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function bindSaveAction( panelActions?: { open: () => void } ) {
|
|
57
|
+
registerDataHook( 'dependency', 'document/save/save', ( args ) => {
|
|
58
|
+
triggerSave( panelActions, args.status === 'publish' ? 'frontend' : 'preview' );
|
|
42
59
|
|
|
43
60
|
return true;
|
|
44
61
|
} );
|
|
45
62
|
}
|
|
46
63
|
|
|
64
|
+
function bindBeforeSaveTemplateAction() {
|
|
65
|
+
window.addEventListener( 'elementor/global-styles/before-save', ( ( event: CustomEvent ) => {
|
|
66
|
+
if ( ! pendingSave && isDirty() ) {
|
|
67
|
+
triggerSave();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( pendingSave ) {
|
|
71
|
+
event.detail.promises.push( pendingSave );
|
|
72
|
+
}
|
|
73
|
+
} ) as EventListener );
|
|
74
|
+
}
|
|
75
|
+
|
|
47
76
|
function isDirty() {
|
|
48
77
|
return selectIsDirty( getState() );
|
|
49
78
|
}
|