@elementor/editor-global-classes 0.9.1 → 0.10.0

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.
@@ -15,7 +15,7 @@ import { useDirtyState } from '../../hooks/use-dirty-state';
15
15
  import { publishGlobalClasses } from '../../publish-global-classes';
16
16
  import { ClassManagerIntroduction } from './class-manager-introduction';
17
17
  import { GlobalClassesList } from './global-classes-list';
18
- import { UnsavedChangesDialog, useDialog } from './unsaved-changes-dialog';
18
+ import { SaveChangesDialog, useDialog } from './save-changes-dialog';
19
19
 
20
20
  export const { panel, usePanelActions } = createPanel( {
21
21
  id: 'class-manager-panel',
@@ -24,14 +24,8 @@ export const { panel, usePanelActions } = createPanel( {
24
24
 
25
25
  export function ClassManagerPanel() {
26
26
  const isDirty = useDirtyState();
27
-
28
27
  const { close: closePanel } = usePanelActions();
29
-
30
- const {
31
- open: openUnsavedChangesDialog,
32
- close: closeUnsavedChangesDialog,
33
- isOpen: isUnsavedChangesDialogOpen,
34
- } = useDialog();
28
+ const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = useDialog();
35
29
 
36
30
  return (
37
31
  <>
@@ -47,7 +41,7 @@ export function ClassManagerPanel() {
47
41
  sx={ { marginLeft: 'auto' } }
48
42
  onClose={ () => {
49
43
  if ( isDirty ) {
50
- openUnsavedChangesDialog();
44
+ openSaveChangesDialog();
51
45
  return;
52
46
  }
53
47
 
@@ -74,33 +68,34 @@ export function ClassManagerPanel() {
74
68
  </Panel>
75
69
  </ErrorBoundary>
76
70
  <ClassManagerIntroduction />
77
- { isUnsavedChangesDialogOpen && (
78
- <UnsavedChangesDialog>
79
- <UnsavedChangesDialog.Title>
80
- { __( 'You have unsaved changes', 'elementor' ) }
81
- </UnsavedChangesDialog.Title>
82
- <UnsavedChangesDialog.Content>
83
- { __( 'You have unsaved changes in the Class Manager.', 'elementor' ) }
84
- <br />
85
- { __( 'To avoid losing your updates, save your changes before leaving.', 'elementor' ) }
86
- </UnsavedChangesDialog.Content>
87
- <UnsavedChangesDialog.Actions
71
+ { isSaveChangesDialogOpen && (
72
+ <SaveChangesDialog>
73
+ <SaveChangesDialog.Title>{ __( 'You have unsaved changes', 'elementor' ) }</SaveChangesDialog.Title>
74
+ <SaveChangesDialog.Content>
75
+ <SaveChangesDialog.ContentText>
76
+ { __( 'You have unsaved changes in the Class Manager.', 'elementor' ) }
77
+ </SaveChangesDialog.ContentText>
78
+ <SaveChangesDialog.ContentText>
79
+ { __( 'To avoid losing your updates, save your changes before leaving.', 'elementor' ) }
80
+ </SaveChangesDialog.ContentText>
81
+ </SaveChangesDialog.Content>
82
+ <SaveChangesDialog.Actions
88
83
  actions={ {
89
84
  cancel: {
90
85
  label: __( 'Cancel', 'elementor' ),
91
- action: closeUnsavedChangesDialog,
86
+ action: closeSaveChangesDialog,
92
87
  },
93
88
  confirm: {
94
89
  label: __( 'Save & Continue', 'elementor' ),
95
- action: () => {
96
- publishGlobalClasses();
97
- closeUnsavedChangesDialog();
90
+ action: async () => {
91
+ await publishGlobalClasses();
92
+ closeSaveChangesDialog();
98
93
  closePanel();
99
94
  },
100
95
  },
101
96
  } }
102
97
  />
103
- </UnsavedChangesDialog>
98
+ </SaveChangesDialog>
104
99
  ) }
105
100
  </>
106
101
  );
@@ -0,0 +1,84 @@
1
+ import * as React from 'react';
2
+ import { useState } from 'react';
3
+ import { AlertTriangleFilledIcon } from '@elementor/icons';
4
+ import {
5
+ Button,
6
+ Dialog,
7
+ DialogActions,
8
+ DialogContent,
9
+ DialogContentText,
10
+ type DialogContentTextProps,
11
+ type DialogProps,
12
+ DialogTitle,
13
+ } from '@elementor/ui';
14
+
15
+ const TITLE_ID = 'save-changes-dialog';
16
+
17
+ const SaveChangesDialog = ( { children, onClose }: Pick< DialogProps, 'children' | 'onClose' > ) => (
18
+ <Dialog open onClose={ onClose } aria-labelledby={ TITLE_ID } maxWidth="xs">
19
+ { children }
20
+ </Dialog>
21
+ );
22
+
23
+ const SaveChangesDialogTitle = ( { children }: React.PropsWithChildren ) => (
24
+ <DialogTitle id={ TITLE_ID } display="flex" alignItems="center" gap={ 1 } sx={ { lineHeight: 1 } }>
25
+ <AlertTriangleFilledIcon color="secondary" />
26
+ { children }
27
+ </DialogTitle>
28
+ );
29
+
30
+ const SaveChangesDialogContent = ( { children }: React.PropsWithChildren ) => (
31
+ <DialogContent>{ children }</DialogContent>
32
+ );
33
+
34
+ const SaveChangesDialogContentText = ( props: DialogContentTextProps ) => (
35
+ <DialogContentText variant="body2" color="textPrimary" display="flex" flexDirection="column" { ...props } />
36
+ );
37
+
38
+ type Action = {
39
+ label: string;
40
+ action: () => void | Promise< void >;
41
+ };
42
+
43
+ type ConfirmationDialogActionsProps = {
44
+ actions: {
45
+ cancel: Action;
46
+ confirm: Action;
47
+ };
48
+ };
49
+ const SaveChangesDialogActions = ( { actions }: ConfirmationDialogActionsProps ) => {
50
+ const [ isConfirming, setIsConfirming ] = useState( false );
51
+ const { cancel, confirm } = actions;
52
+
53
+ const onConfirm = async () => {
54
+ setIsConfirming( true );
55
+ await confirm.action();
56
+ setIsConfirming( false );
57
+ };
58
+ return (
59
+ <DialogActions>
60
+ <Button variant="text" color="secondary" onClick={ cancel.action }>
61
+ { cancel.label }
62
+ </Button>
63
+ <Button variant="contained" color="secondary" onClick={ onConfirm } loading={ isConfirming }>
64
+ { confirm.label }
65
+ </Button>
66
+ </DialogActions>
67
+ );
68
+ };
69
+
70
+ SaveChangesDialog.Title = SaveChangesDialogTitle;
71
+ SaveChangesDialog.Content = SaveChangesDialogContent;
72
+ SaveChangesDialog.ContentText = SaveChangesDialogContentText;
73
+ SaveChangesDialog.Actions = SaveChangesDialogActions;
74
+
75
+ const useDialog = () => {
76
+ const [ isOpen, setIsOpen ] = useState( false );
77
+
78
+ const open = () => setIsOpen( true );
79
+ const close = () => setIsOpen( false );
80
+
81
+ return { isOpen, open, close };
82
+ };
83
+
84
+ export { SaveChangesDialog, useDialog };
@@ -65,6 +65,6 @@ export const globalClassesStylesProvider = {
65
65
  subscribe: ( cb ) => subscribeWithSelector( ( state: StateWithGlobalClasses ) => state.globalClasses, cb ),
66
66
  labels: {
67
67
  singular: __( 'Global class', 'elementor' ),
68
- plural: __( 'Global CSS Classes', 'elementor' ),
68
+ plural: __( 'Global CSS classes', 'elementor' ),
69
69
  },
70
70
  } satisfies StylesProvider;
@@ -1,76 +0,0 @@
1
- import * as React from 'react';
2
- import { useState } from 'react';
3
- import { AlertTriangleFilledIcon } from '@elementor/icons';
4
- import {
5
- Button,
6
- Dialog,
7
- DialogActions,
8
- DialogContent,
9
- DialogContentText,
10
- type DialogProps,
11
- DialogTitle,
12
- } from '@elementor/ui';
13
-
14
- const TITLE_ID = 'unsaved-changes-dialog';
15
-
16
- const UnsavedChangesDialog = ( { children, onClose }: Pick< DialogProps, 'children' | 'onClose' > ) => (
17
- <Dialog open onClose={ onClose } aria-labelledby={ TITLE_ID } maxWidth="xs">
18
- { children }
19
- </Dialog>
20
- );
21
-
22
- const UnsavedChangesDialogTitle = ( { children }: React.PropsWithChildren ) => (
23
- <DialogTitle id={ TITLE_ID } display="flex" alignItems="center" gap={ 1 } sx={ { lineHeight: 1 } }>
24
- <AlertTriangleFilledIcon color="secondary" />
25
- { children }
26
- </DialogTitle>
27
- );
28
-
29
- const UnsavedChangesDialogContent = ( { children }: React.PropsWithChildren ) => (
30
- <DialogContent>
31
- <DialogContentText variant="body2" color="textPrimary">
32
- { children }
33
- </DialogContentText>
34
- </DialogContent>
35
- );
36
-
37
- type Action = {
38
- label: string;
39
- action: () => void;
40
- };
41
-
42
- type ConfirmationDialogActionsProps = {
43
- actions: {
44
- cancel: Action;
45
- confirm: Action;
46
- };
47
- };
48
- const UnsavedChangesDialogActions = ( { actions }: ConfirmationDialogActionsProps ) => {
49
- const { cancel, confirm } = actions;
50
-
51
- return (
52
- <DialogActions>
53
- <Button variant="text" color="secondary" onClick={ cancel.action }>
54
- { cancel.label }
55
- </Button>
56
- <Button variant="contained" color="secondary" onClick={ confirm.action }>
57
- { confirm.label }
58
- </Button>
59
- </DialogActions>
60
- );
61
- };
62
-
63
- UnsavedChangesDialog.Title = UnsavedChangesDialogTitle;
64
- UnsavedChangesDialog.Content = UnsavedChangesDialogContent;
65
- UnsavedChangesDialog.Actions = UnsavedChangesDialogActions;
66
-
67
- const useDialog = () => {
68
- const [ isOpen, setIsOpen ] = useState( false );
69
-
70
- const open = () => setIsOpen( true );
71
- const close = () => setIsOpen( false );
72
-
73
- return { isOpen, open, close };
74
- };
75
-
76
- export { UnsavedChangesDialog, useDialog };