@elementor/editor-default-styles 4.3.0-1062 → 4.4.0-1064
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 +144 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
- package/src/capabilities.ts +12 -0
- package/src/components/default-styles-tab-embedded.tsx +23 -17
- package/src/default-styles-provider.ts +2 -0
- package/src/init.ts +0 -7
- package/src/load-default-styles.ts +9 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-default-styles",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-1064",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,27 +39,27 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor": "4.
|
|
43
|
-
"@elementor/editor-app-bar": "4.
|
|
44
|
-
"@elementor/editor-controls": "4.
|
|
45
|
-
"@elementor/editor-documents": "4.
|
|
46
|
-
"@elementor/editor-editing-panel": "4.
|
|
47
|
-
"@elementor/editor-elements": "4.
|
|
48
|
-
"@elementor/editor-panels": "4.
|
|
49
|
-
"@elementor/editor-props": "4.
|
|
50
|
-
"@elementor/editor-responsive": "4.
|
|
51
|
-
"@elementor/editor-styles": "4.
|
|
52
|
-
"@elementor/editor-styles-repository": "4.
|
|
53
|
-
"@elementor/editor-ui": "4.
|
|
54
|
-
"@elementor/editor-v1-adapters": "4.
|
|
55
|
-
"@elementor/http-client": "4.
|
|
42
|
+
"@elementor/editor": "4.4.0-1064",
|
|
43
|
+
"@elementor/editor-app-bar": "4.4.0-1064",
|
|
44
|
+
"@elementor/editor-controls": "4.4.0-1064",
|
|
45
|
+
"@elementor/editor-documents": "4.4.0-1064",
|
|
46
|
+
"@elementor/editor-editing-panel": "4.4.0-1064",
|
|
47
|
+
"@elementor/editor-elements": "4.4.0-1064",
|
|
48
|
+
"@elementor/editor-panels": "4.4.0-1064",
|
|
49
|
+
"@elementor/editor-props": "4.4.0-1064",
|
|
50
|
+
"@elementor/editor-responsive": "4.4.0-1064",
|
|
51
|
+
"@elementor/editor-styles": "4.4.0-1064",
|
|
52
|
+
"@elementor/editor-styles-repository": "4.4.0-1064",
|
|
53
|
+
"@elementor/editor-ui": "4.4.0-1064",
|
|
54
|
+
"@elementor/editor-v1-adapters": "4.4.0-1064",
|
|
55
|
+
"@elementor/http-client": "4.4.0-1064",
|
|
56
56
|
"@elementor/icons": "~1.75.1",
|
|
57
|
-
"@elementor/menus": "4.
|
|
58
|
-
"@elementor/query": "4.
|
|
59
|
-
"@elementor/session": "4.
|
|
60
|
-
"@elementor/store": "4.
|
|
57
|
+
"@elementor/menus": "4.4.0-1064",
|
|
58
|
+
"@elementor/query": "4.4.0-1064",
|
|
59
|
+
"@elementor/session": "4.4.0-1064",
|
|
60
|
+
"@elementor/store": "4.4.0-1064",
|
|
61
61
|
"@elementor/ui": "1.37.5",
|
|
62
|
-
"@elementor/utils": "4.
|
|
62
|
+
"@elementor/utils": "4.4.0-1064",
|
|
63
63
|
"@wordpress/i18n": "^5.13.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type UserCapabilities } from '@elementor/editor-styles-repository';
|
|
2
|
+
|
|
3
|
+
export const UPDATE_DEFAULT_STYLES_CAPABILITY_KEY = 'manage_options';
|
|
4
|
+
|
|
5
|
+
export const getCapabilities = (): UserCapabilities => {
|
|
6
|
+
return {
|
|
7
|
+
update: UPDATE_DEFAULT_STYLES_CAPABILITY_KEY,
|
|
8
|
+
create: UPDATE_DEFAULT_STYLES_CAPABILITY_KEY,
|
|
9
|
+
delete: UPDATE_DEFAULT_STYLES_CAPABILITY_KEY,
|
|
10
|
+
updateProps: UPDATE_DEFAULT_STYLES_CAPABILITY_KEY,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { type Element, type ElementType } from '@elementor/editor-elements';
|
|
20
20
|
import { useActiveBreakpoint } from '@elementor/editor-responsive';
|
|
21
21
|
import { type StyleDefinitionID, type StyleDefinitionState } from '@elementor/editor-styles';
|
|
22
|
+
import { useUserStylesCapability } from '@elementor/editor-styles-repository';
|
|
22
23
|
import { SaveChangesDialog, ThemeProvider, useDialog } from '@elementor/editor-ui';
|
|
23
24
|
import { controlActionsMenu } from '@elementor/menus';
|
|
24
25
|
import { useMutation } from '@elementor/query';
|
|
@@ -41,6 +42,7 @@ import {
|
|
|
41
42
|
getDefaultActiveTag,
|
|
42
43
|
isAllowedDefaultStyleTag,
|
|
43
44
|
} from '../allowed-tags';
|
|
45
|
+
import { DEFAULT_STYLES_PROVIDER_KEY } from '../default-styles-provider';
|
|
44
46
|
import { saveDefaultStyles } from '../save-default-styles';
|
|
45
47
|
import { selectIsDirty, slice } from '../store';
|
|
46
48
|
import { TagChip } from './tag-chip';
|
|
@@ -99,6 +101,8 @@ export function DefaultStylesTabEmbedded( { onRequestClose, onExposeCloseAttempt
|
|
|
99
101
|
const isDirty = useSelector( selectIsDirty );
|
|
100
102
|
const { mutateAsync: save, isPending: isSaving } = useSave();
|
|
101
103
|
const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = useDialog();
|
|
104
|
+
const { userCan } = useUserStylesCapability();
|
|
105
|
+
const canEdit = userCan( DEFAULT_STYLES_PROVIDER_KEY ).updateProps;
|
|
102
106
|
|
|
103
107
|
const setSelectedTag = ( tag: AllowedHtmlTag ) => {
|
|
104
108
|
setSelectedTagState( tag );
|
|
@@ -106,13 +110,13 @@ export function DefaultStylesTabEmbedded( { onRequestClose, onExposeCloseAttempt
|
|
|
106
110
|
};
|
|
107
111
|
|
|
108
112
|
const handleClosePanel = useCallback( () => {
|
|
109
|
-
if ( isDirty ) {
|
|
113
|
+
if ( canEdit && isDirty ) {
|
|
110
114
|
openSaveChangesDialog();
|
|
111
115
|
return;
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
void onRequestClose();
|
|
115
|
-
}, [ isDirty, onRequestClose, openSaveChangesDialog ] );
|
|
119
|
+
}, [ canEdit, isDirty, onRequestClose, openSaveChangesDialog ] );
|
|
116
120
|
|
|
117
121
|
useEffect( () => {
|
|
118
122
|
if ( ! onExposeCloseAttempt ) {
|
|
@@ -124,7 +128,7 @@ export function DefaultStylesTabEmbedded( { onRequestClose, onExposeCloseAttempt
|
|
|
124
128
|
return () => onExposeCloseAttempt( null );
|
|
125
129
|
}, [ onExposeCloseAttempt, handleClosePanel ] );
|
|
126
130
|
|
|
127
|
-
usePreventUnload( isDirty );
|
|
131
|
+
usePreventUnload( canEdit && isDirty );
|
|
128
132
|
|
|
129
133
|
const handleTagSelect = ( _selected: Option[], reason: AutocompleteChangeReason, option: Option ) => {
|
|
130
134
|
if ( reason !== 'selectOption' || ! option.value ) {
|
|
@@ -225,24 +229,26 @@ export function DefaultStylesTabEmbedded( { onRequestClose, onExposeCloseAttempt
|
|
|
225
229
|
</ClassesPropProvider>
|
|
226
230
|
</ElementProvider>
|
|
227
231
|
</Box>
|
|
228
|
-
|
|
229
|
-
<
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
232
|
+
{ canEdit ? (
|
|
233
|
+
<Box sx={ { flexShrink: 0, px: 2, py: 1.5 } }>
|
|
234
|
+
<Button
|
|
235
|
+
fullWidth
|
|
236
|
+
size="small"
|
|
237
|
+
color="global"
|
|
238
|
+
variant="contained"
|
|
239
|
+
onClick={ () => void save() }
|
|
240
|
+
disabled={ ! isDirty }
|
|
241
|
+
loading={ isSaving }
|
|
242
|
+
>
|
|
243
|
+
{ __( 'Save changes', 'elementor' ) }
|
|
244
|
+
</Button>
|
|
245
|
+
</Box>
|
|
246
|
+
) : null }
|
|
241
247
|
</Stack>
|
|
242
248
|
</ControlReplacementsProvider>
|
|
243
249
|
</ControlActionsProvider>
|
|
244
250
|
|
|
245
|
-
{ isSaveChangesDialogOpen && (
|
|
251
|
+
{ canEdit && isSaveChangesDialogOpen && (
|
|
246
252
|
<SaveChangesDialog>
|
|
247
253
|
<SaveChangesDialog.Title onClose={ closeSaveChangesDialog }>
|
|
248
254
|
{ __( 'You have unsaved changes', 'elementor' ) }
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import { __ } from '@wordpress/i18n';
|
|
9
9
|
|
|
10
10
|
import { getAllowedDefaultStyleTags } from './allowed-tags';
|
|
11
|
+
import { getCapabilities } from './capabilities';
|
|
11
12
|
import { selectData, slice } from './store';
|
|
12
13
|
|
|
13
14
|
export const DEFAULT_STYLES_PROVIDER_KEY = 'default-styles';
|
|
@@ -35,6 +36,7 @@ export const defaultStylesStylesProvider = createStylesProvider( {
|
|
|
35
36
|
plural: __( 'tags', 'elementor' ),
|
|
36
37
|
},
|
|
37
38
|
subscribe: ( cb ) => subscribeWithStates( cb ),
|
|
39
|
+
capabilities: getCapabilities(),
|
|
38
40
|
actions: {
|
|
39
41
|
all: () =>
|
|
40
42
|
getAllowedDefaultStyleTags().map( ( tag ) => {
|
package/src/init.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { injectIntoLogic } from '@elementor/editor';
|
|
2
2
|
import { registerElementPanelDefaults } from '@elementor/editor-editing-panel';
|
|
3
3
|
import { stylesRepository } from '@elementor/editor-styles-repository';
|
|
4
|
-
import { isExperimentActive } from '@elementor/editor-v1-adapters';
|
|
5
4
|
import { __registerSlice as registerSlice } from '@elementor/store';
|
|
6
5
|
|
|
7
6
|
import { PopulateStore } from './components/populate-store';
|
|
8
7
|
import { defaultStylesStylesProvider } from './default-styles-provider';
|
|
9
8
|
import { slice } from './store';
|
|
10
9
|
|
|
11
|
-
const DEFAULT_STYLES_EXPERIMENT = 'e_default_styles';
|
|
12
|
-
|
|
13
10
|
export function init() {
|
|
14
|
-
if ( ! isExperimentActive( DEFAULT_STYLES_EXPERIMENT ) ) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
registerSlice( slice );
|
|
19
12
|
|
|
20
13
|
registerElementPanelDefaults( 'default-style', {
|
|
@@ -4,13 +4,15 @@ import { apiClient } from './api';
|
|
|
4
4
|
import { slice } from './store';
|
|
5
5
|
|
|
6
6
|
export async function loadDefaultStyles() {
|
|
7
|
-
|
|
7
|
+
try {
|
|
8
|
+
const response = await apiClient.all();
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const items = response.data.data;
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
dispatch(
|
|
13
|
+
slice.actions.load( {
|
|
14
|
+
data: items,
|
|
15
|
+
} )
|
|
16
|
+
);
|
|
17
|
+
} catch {}
|
|
16
18
|
}
|