@elementor/editor-global-classes 0.14.1 → 0.15.3

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.
@@ -0,0 +1,34 @@
1
+ import { getCurrentDocument, getV1DocumentsManager } from '@elementor/editor-documents';
2
+ import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
3
+
4
+ import { globalClassesStylesProvider } from '../../global-classes-styles-provider';
5
+
6
+ let isDeleted = false;
7
+
8
+ export const deleteClass = ( id: string ) => {
9
+ globalClassesStylesProvider.actions.delete( id );
10
+ isDeleted = true;
11
+ };
12
+
13
+ export const onDelete = async () => {
14
+ await reloadDocument();
15
+
16
+ isDeleted = false;
17
+ };
18
+
19
+ export const hasDeletedItems = () => isDeleted;
20
+
21
+ // When deleting a class, we remove it from all the documents that have it applied.
22
+ // In order to reflect the changes in the active document, we need to reload it.
23
+ const reloadDocument = () => {
24
+ const currentDocument = getCurrentDocument();
25
+ const documentsManager = getV1DocumentsManager();
26
+
27
+ documentsManager.invalidateCache();
28
+
29
+ return runCommand( 'editor/documents/switch', {
30
+ id: currentDocument?.id,
31
+ shouldScroll: false,
32
+ shouldNavigateToDefaultRoute: false,
33
+ } );
34
+ };
@@ -13,7 +13,7 @@ import {
13
13
  } from '@elementor/ui';
14
14
  import { __ } from '@wordpress/i18n';
15
15
 
16
- import { globalClassesStylesProvider } from '../../global-classes-styles-provider';
16
+ import { deleteClass } from './delete-class';
17
17
 
18
18
  type DeleteConfirmationDialogProps = Pick< StyleDefinition, 'id' | 'label' >;
19
19
 
@@ -50,7 +50,7 @@ const DeleteConfirmationDialog = ( { label, id }: DeleteConfirmationDialogProps
50
50
  const { closeDialog } = useDeleteConfirmation();
51
51
 
52
52
  const onConfirm = () => {
53
- globalClassesStylesProvider.actions.delete( id );
53
+ deleteClass( id );
54
54
 
55
55
  closeDialog();
56
56
  };
@@ -59,7 +59,7 @@ const DeleteConfirmationDialog = ( { label, id }: DeleteConfirmationDialogProps
59
59
  <Dialog open onClose={ closeDialog } aria-labelledby={ TITLE_ID } maxWidth="xs">
60
60
  <DialogTitle id={ TITLE_ID } display="flex" alignItems="center" gap={ 1 } sx={ { lineHeight: 1 } }>
61
61
  <AlertOctagonFilledIcon color="error" />
62
- { __( 'Delete global class', 'elementor' ) }
62
+ { __( 'Delete this class?', 'elementor' ) }
63
63
  </DialogTitle>
64
64
  <DialogContent>
65
65
  <DialogContentText variant="body2" color="textPrimary">
@@ -75,7 +75,7 @@ const DeleteConfirmationDialog = ( { label, id }: DeleteConfirmationDialogProps
75
75
  </DialogContent>
76
76
  <DialogActions>
77
77
  <Button color="secondary" onClick={ closeDialog }>
78
- { __( 'Cancel', 'elementor' ) }
78
+ { __( 'Not now', 'elementor' ) }
79
79
  </Button>
80
80
  <Button variant="contained" color="error" onClick={ onConfirm }>
81
81
  { __( 'Delete', 'elementor' ) }
@@ -258,11 +258,11 @@ const getIndicatorBorder = ( { isActive, isError, theme }: { isActive: boolean;
258
258
 
259
259
  const validateLabel = ( newLabel: string ) => {
260
260
  if ( ! stylesRepository.isLabelValid( newLabel ) ) {
261
- return __( 'Format is not valid', 'elementor' );
261
+ return __( 'Invalid format', 'elementor' );
262
262
  }
263
263
 
264
264
  if ( stylesRepository.isLabelExist( newLabel ) ) {
265
- return __( 'Existing name', 'elementor' );
265
+ return __( 'Name exists', 'elementor' );
266
266
  }
267
267
 
268
268
  return null;
@@ -67,7 +67,7 @@ export const globalClassesStylesProvider = {
67
67
  },
68
68
  subscribe: ( cb ) => subscribeWithSelector( ( state: StateWithGlobalClasses ) => state.globalClasses, cb ),
69
69
  labels: {
70
- singular: __( 'Global class', 'elementor' ),
71
- plural: __( 'Global CSS classes', 'elementor' ),
70
+ singular: __( 'class', 'elementor' ),
71
+ plural: __( 'classes', 'elementor' ),
72
72
  },
73
73
  } satisfies StylesProvider;